learnpath.class.php 329 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968
  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 as well as the dokeos_lp class.
  6. * @package dokeos.learnpath
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. * @license GNU/GPL - See Dokeos license directory for details
  9. */
  10. /**
  11. * Defines the learnpath parent class
  12. * @package chamilo.learnpath
  13. */
  14. class learnpath {
  15. var $attempt = 0; //the number for the current ID view
  16. var $cc; //course (code) this learnpath is located in
  17. var $current; //id of the current item the user is viewing
  18. var $current_score; //the score of the current item
  19. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  20. var $current_time_stop; //the time the user closed this resource
  21. var $default_status = 'not attempted';
  22. var $encoding = 'UTF-8';
  23. var $error = '';
  24. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  25. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  26. var $index; //the index of the active learnpath_item in $ordered_items array
  27. var $items = array();
  28. var $last; //item_id of last item viewed in the learning path
  29. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  30. var $license; //which license this course has been given - not used yet on 20060522
  31. var $lp_id; //DB ID for this learnpath
  32. var $lp_view_id; //DB ID for lp_view
  33. var $log_file; //file where to log learnpath API msg
  34. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  35. var $message = '';
  36. var $mode = 'embedded'; //holds the video display mode (fullscreen or embedded)
  37. var $name; //learnpath name (they generally have one)
  38. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  39. var $path = ''; //path inside the scorm directory (if scorm)
  40. var $theme; // the current theme of the learning path
  41. var $preview_image; // the current image of the learning path
  42. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  43. var $prevent_reinit = 1;
  44. // Describes the mode of progress bar display
  45. var $progress_bar_mode = '%';
  46. // Percentage progress as saved in the db
  47. var $progress_db = '0';
  48. var $proximity; //wether the content is distant or local or unknown
  49. var $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  50. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  51. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  52. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  53. //TODO check if this type variable is useful here (instead of just in the controller script)
  54. var $user_id; //ID of the user that is viewing/using the course
  55. var $update_queue = array();
  56. var $scorm_debug = 0;
  57. var $arrMenu = array(); //array for the menu items
  58. var $debug = 0; //logging level
  59. var $lp_session_id =0;
  60. /**
  61. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  62. * Also builds the list of items into $this->items.
  63. * @param string Course code
  64. * @param integer Learnpath ID
  65. * @param integer User ID
  66. * @return boolean True on success, false on error
  67. */
  68. function learnpath($course, $lp_id, $user_id) {
  69. //check params
  70. //check course code
  71. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  72. if(empty($course)){
  73. $this->error = 'Course code is empty';
  74. return false;
  75. }
  76. else
  77. {
  78. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  79. //$course = Database::escape_string($course);
  80. $course = $this->escape_string($course);
  81. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  82. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  83. //$res = Database::query($sql);
  84. $res = Database::query($sql);
  85. if(Database::num_rows($res)>0)
  86. {
  87. $this->cc = $course;
  88. }
  89. else
  90. {
  91. $this->error = 'Course code does not exist in database ('.$sql.')';
  92. return false;
  93. }
  94. }
  95. //check learnpath ID
  96. if(empty($lp_id))
  97. {
  98. $this->error = 'Learnpath ID is empty';
  99. return false;
  100. }
  101. else
  102. {
  103. //TODO make it flexible to use any course_code (still using env course code here)
  104. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  105. //$id = Database::escape_integer($id);
  106. $lp_id = $this->escape_string($lp_id);
  107. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  108. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  109. //$res = Database::query($sql);
  110. $res = Database::query($sql);
  111. if(Database::num_rows($res)>0)
  112. {
  113. $this->lp_id = $lp_id;
  114. $row = Database::fetch_array($res);
  115. $this->type = $row['lp_type'];
  116. $this->name = stripslashes($row['name']);
  117. $this->encoding = $row['default_encoding'];
  118. $this->proximity = $row['content_local'];
  119. $this->theme = $row['theme'];
  120. $this->maker = $row['content_maker'];
  121. $this->prevent_reinit = $row['prevent_reinit'];
  122. $this->license = $row['content_license'];
  123. $this->scorm_debug = $row['debug'];
  124. $this->js_lib = $row['js_lib'];
  125. $this->path = $row['path'];
  126. $this->preview_image= $row['preview_image'];
  127. $this->author= $row['author'];
  128. $this->lp_session_id = $row['session_id'];
  129. if($this->type == 2){
  130. if($row['force_commit'] == 1){
  131. $this->force_commit = true;
  132. }
  133. }
  134. $this->mode = $row['default_view_mod'];
  135. }
  136. else
  137. {
  138. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  139. return false;
  140. }
  141. }
  142. //check user ID
  143. if(empty($user_id)){
  144. $this->error = 'User ID is empty';
  145. return false;
  146. }
  147. else
  148. {
  149. //$main_table = Database::get_main_user_table();
  150. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  151. //$user_id = Database::escape_integer($user_id);
  152. $user_id = $this->escape_string($user_id);
  153. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  154. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  155. //$res = Database::query($sql);
  156. $res = Database::query($sql);
  157. if(Database::num_rows($res)>0)
  158. {
  159. $this->user_id = $user_id;
  160. }
  161. else
  162. {
  163. $this->error = 'User ID does not exist in database ('.$sql.')';
  164. return false;
  165. }
  166. }
  167. //end of variables checking
  168. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  169. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  170. //selecting by view_count descending allows to get the highest view_count first
  171. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  172. if ($this->debug > 2) {
  173. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);
  174. }
  175. //$res = Database::query($sql);
  176. $res = Database::query($sql);
  177. $view_id = 0; //used later to query lp_item_view
  178. if (Database :: num_rows($res) > 0) {
  179. if ($this->debug > 2) {
  180. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Found previous view', 0);
  181. }
  182. $row = Database :: fetch_array($res);
  183. $this->attempt = $row['view_count'];
  184. $this->lp_view_id = $row['id'];
  185. $this->last_item_seen = $row['last_item'];
  186. $this->progress_db = $row['progress'];
  187. } else {
  188. if ($this->debug > 2) {
  189. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - NOT Found previous view', 0);
  190. }
  191. $this->attempt = 1;
  192. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  193. $res_ins = Database::query($sql_ins);
  194. $this->lp_view_id = Database :: insert_id();
  195. if ($this->debug > 2) {
  196. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  197. }
  198. }
  199. //initialise items
  200. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  201. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  202. $res = Database::query($sql);
  203. while($row = Database::fetch_array($res))
  204. {
  205. $oItem = '';
  206. //$this->ordered_items[] = $row['id'];
  207. switch ($this->type) {
  208. case 3 : //aicc
  209. $oItem = new aiccItem('db', $row['id']);
  210. if (is_object($oItem)) {
  211. $my_item_id = $oItem->get_id();
  212. $oItem->set_lp_view($this->lp_view_id);
  213. $oItem->set_prevent_reinit($this->prevent_reinit);
  214. // Don't use reference here as the next loop will make the pointed object change
  215. $this->items[$my_item_id] = $oItem;
  216. $this->refs_list[$oItem->ref] = $my_item_id;
  217. if ($this->debug > 2) {
  218. error_log('New LP - learnpath::learnpath() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  219. }
  220. }
  221. break;
  222. case 2 :
  223. require_once ('scorm.class.php');
  224. require_once ('scormItem.class.php');
  225. $oItem = new scormItem('db', $row['id']);
  226. if (is_object($oItem)) {
  227. $my_item_id = $oItem->get_id();
  228. $oItem->set_lp_view($this->lp_view_id);
  229. $oItem->set_prevent_reinit($this->prevent_reinit);
  230. // Don't use reference here as the next loop will make the pointed object change
  231. $this->items[$my_item_id] = $oItem;
  232. $this->refs_list[$oItem->ref] = $my_item_id;
  233. if ($this->debug > 2) {
  234. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  235. }
  236. }
  237. break;
  238. case 1 :
  239. default :
  240. require_once ('learnpathItem.class.php');
  241. $oItem = new learnpathItem($row['id'], $user_id);
  242. if (is_object($oItem)) {
  243. $my_item_id = $oItem->get_id();
  244. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  245. $oItem->set_prevent_reinit($this->prevent_reinit);
  246. // Don't use reference here as the next loop will make the pointed object change
  247. $this->items[$my_item_id] = $oItem;
  248. $this->refs_list[$my_item_id] = $my_item_id;
  249. if ($this->debug > 2) {
  250. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  251. }
  252. }
  253. break;
  254. }
  255. //items is a list of pointers to all items, classified by DB ID, not SCO id
  256. if ($row['parent_item_id'] == 0 OR empty ($this->items[$row['parent_item_id']])) {
  257. $this->items[$row['id']]->set_level(0);
  258. } else {
  259. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  260. $this->items[$row['id']]->set_level($level);
  261. if (is_object($this->items[$row['parent_item_id']])) {
  262. //items is a list of pointers from item DB ids to item objects
  263. $this->items[$row['parent_item_id']]->add_child($row['id']);
  264. } else {
  265. if ($this->debug > 2) {
  266. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  267. }
  268. }
  269. }
  270. //get last viewing vars
  271. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  272. //this query should only return one or zero result
  273. $sql = "SELECT * " .
  274. "FROM $lp_item_view_table " .
  275. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  276. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  277. if ($this->debug > 2) {
  278. error_log('New LP - learnpath::learnpath() - Selecting item_views: ' . $sql, 0);
  279. }
  280. //get the item status
  281. $res2 = Database::query($sql);
  282. if (Database :: num_rows($res2) > 0) {
  283. //if this learnpath has already been used by this user, get his last attempt count and
  284. //the last item seen back into this object
  285. //$max = 0;
  286. $row2 = Database :: fetch_array($res2);
  287. if ($this->debug > 2) {
  288. error_log('New LP - learnpath::learnpath() - Got item_view: ' . print_r($row2, true), 0);
  289. }
  290. $this->items[$row['id']]->set_status($row2['status']);
  291. if (empty ($row2['status'])) {
  292. $this->items[$row['id']]->set_status($this->default_status);
  293. }
  294. //$this->attempt = $row['view_count'];
  295. //$this->last_item = $row['id'];
  296. } else //no item found in lp_item_view for this view
  297. {
  298. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  299. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  300. //$this->attempt = 1;
  301. //$this->last_item = 0;
  302. $this->items[$row['id']]->set_status($this->default_status);
  303. //Add that row to the lp_item_view table so that we have something to show in the stats page
  304. $sql_ins = "INSERT INTO $lp_item_view_table " .
  305. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  306. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  307. if ($this->debug > 2) {
  308. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  309. }
  310. $res_ins = Database::query($sql_ins);
  311. }
  312. //setting the view in the item object
  313. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  314. }
  315. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0);
  316. $this->max_ordered_items = 0;
  317. foreach ($this->ordered_items as $index => $dummy) {
  318. if ($index > $this->max_ordered_items AND !empty ($dummy)) {
  319. $this->max_ordered_items = $index;
  320. }
  321. }
  322. //TODO define the current item better
  323. $this->first();
  324. if ($this->debug > 2) {
  325. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  326. }
  327. }
  328. /**
  329. * 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
  330. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  331. *
  332. * @param int $parent
  333. * @param int $previous
  334. * @param string $type
  335. * @param int $id
  336. * @param string $title
  337. * @param string $description
  338. * @return int
  339. */
  340. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  341. if ($this->debug > 0) {
  342. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  343. }
  344. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  345. $parent = intval($parent);
  346. $previous = intval($previous);
  347. $type = $this->escape_string($type);
  348. $id = intval($id);
  349. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  350. if (empty ($max_time_allowed)) {
  351. $max_time_allowed = 0;
  352. }
  353. //$title = htmlspecialchars($title, ENT_QUOTES, $charset); // TODO: To be checked for encoding problems.
  354. //$title = $this->escape_string(api_convert_encoding($title, $this->encoding, $charset));
  355. $title = $this->escape_string(api_convert_encoding($title, $this->encoding, api_get_system_encoding()));
  356. $description = $this->escape_string(api_convert_encoding($description, $this->encoding, api_get_system_encoding()));
  357. $sql_count = " SELECT COUNT(id) AS num
  358. FROM " . $tbl_lp_item . "
  359. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  360. $res_count = Database::query($sql_count);
  361. $row = Database :: fetch_array($res_count);
  362. $num = $row['num'];
  363. if ($num > 0) {
  364. if ($previous == 0) {
  365. $sql = "SELECT id, next_item_id, display_order
  366. FROM " . $tbl_lp_item . "
  367. WHERE
  368. lp_id = " . $this->get_id() . " AND
  369. parent_item_id = " . $parent . " AND
  370. previous_item_id = 0 OR previous_item_id=" . $parent;
  371. $result = Database::query($sql);
  372. $row = Database :: fetch_array($result);
  373. $tmp_previous = 0;
  374. $next = $row['id'];
  375. $display_order = 0;
  376. } else {
  377. $previous = (int) $previous;
  378. $sql = "
  379. SELECT
  380. id,
  381. previous_item_id,
  382. next_item_id,
  383. display_order
  384. FROM " . $tbl_lp_item . "
  385. WHERE
  386. lp_id = " . $this->get_id() . " AND
  387. id = " . $previous;
  388. $result = Database::query($sql);
  389. $row = Database :: fetch_array($result);
  390. $tmp_previous = $row['id'];
  391. $next = $row['next_item_id'];
  392. $display_order = $row['display_order'];
  393. }
  394. } else {
  395. $tmp_previous = 0;
  396. $next = 0;
  397. $display_order = 0;
  398. }
  399. $new_item_id = -1;
  400. $id = $this->escape_string($id);
  401. if ($type == 'quiz') {
  402. $sql = 'SELECT SUM(ponderation)
  403. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  404. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  405. ON quiz_question.id = quiz_rel_question.question_id
  406. AND quiz_rel_question.exercice_id = ' . $id;
  407. $rsQuiz = Database::query($sql);
  408. $max_score = Database :: result($rsQuiz, 0, 0);
  409. } else {
  410. $max_score = 100;
  411. }
  412. if ($prerequisites != 0) {
  413. $sql_ins = "
  414. INSERT INTO " . $tbl_lp_item . " (
  415. lp_id,
  416. item_type,
  417. ref,
  418. title,
  419. description,
  420. path,
  421. max_score,
  422. parent_item_id,
  423. previous_item_id,
  424. next_item_id,
  425. display_order,
  426. prerequisite,
  427. max_time_allowed
  428. ) VALUES (
  429. " . $this->get_id() . ",
  430. '" . $type . "',
  431. '',
  432. '" . $title . "',
  433. '" . $description . "',
  434. '" . $id . "',
  435. '" . $max_score . "',
  436. " . $parent . ",
  437. " . $previous . ",
  438. " . $next . ",
  439. " . ($display_order +1) . ",
  440. " . $prerequisites . ",
  441. " . $max_time_allowed . "
  442. )";
  443. } else {
  444. //insert new item
  445. $sql_ins = "
  446. INSERT INTO " . $tbl_lp_item . " (
  447. lp_id,
  448. item_type,
  449. ref,
  450. title,
  451. description,
  452. path,
  453. max_score,
  454. parent_item_id,
  455. previous_item_id,
  456. next_item_id,
  457. display_order,
  458. max_time_allowed
  459. ) VALUES (
  460. " . $this->get_id() . ",
  461. '" . $type . "',
  462. '',
  463. '" . $title . "',
  464. '" . $description . "',
  465. '" . $id . "',
  466. '" . $max_score . "',
  467. " . $parent . ",
  468. " . $previous . ",
  469. " . $next . ",
  470. " . ($display_order +1) . ",
  471. " . $max_time_allowed . "
  472. )";
  473. }
  474. if ($this->debug > 2) {
  475. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  476. }
  477. $res_ins = Database::query($sql_ins);
  478. if ($res_ins > 0) {
  479. $new_item_id = Database :: insert_id($res_ins);
  480. //update the item that should come after the new item
  481. $sql_update_next = "
  482. UPDATE " . $tbl_lp_item . "
  483. SET previous_item_id = " . $new_item_id . "
  484. WHERE id = " . $next;
  485. $res_update_next = Database::query($sql_update_next);
  486. //update the item that should be before the new item
  487. $sql_update_previous = "
  488. UPDATE " . $tbl_lp_item . "
  489. SET next_item_id = " . $new_item_id . "
  490. WHERE id = " . $tmp_previous;
  491. $res_update_previous = Database::query($sql_update_previous);
  492. //update all the items after the new item
  493. $sql_update_order = "
  494. UPDATE " . $tbl_lp_item . "
  495. SET display_order = display_order + 1
  496. WHERE
  497. lp_id = " . $this->get_id() . " AND
  498. id <> " . $new_item_id . " AND
  499. parent_item_id = " . $parent . " AND
  500. display_order > " . $display_order;
  501. $res_update_previous = Database::query($sql_update_order);
  502. //update the item that should come after the new item
  503. $sql_update_ref = "
  504. UPDATE " . $tbl_lp_item . "
  505. SET ref = " . $new_item_id . "
  506. WHERE id = " . $new_item_id;
  507. Database::query($sql_update_ref);
  508. }
  509. // upload audio
  510. if (!empty ($_FILES['mp3']['name'])) {
  511. // create the audio folder if it does not exist yet
  512. global $_course;
  513. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  514. if (!is_dir($filepath . 'audio')) {
  515. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  516. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  517. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  518. }
  519. // upload the file in the documents tool
  520. include_once (api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  521. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  522. // getting the filename only
  523. $file_components = explode('/', $file_path);
  524. $file = $file_components[count($file_components) - 1];
  525. // store the mp3 file in the lp_item table
  526. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  527. Database::query($sql_insert_audio);
  528. }
  529. return $new_item_id;
  530. }
  531. /**
  532. * Static admin function allowing addition of a learnpath to a course.
  533. * @param string Course code
  534. * @param string Learnpath name
  535. * @param string Learnpath description string, if provided
  536. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  537. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  538. * @param string Zip file containing the learnpath or directory containing the learnpath
  539. * @return integer The new learnpath ID on success, 0 on failure
  540. */
  541. function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '') {
  542. global $charset;
  543. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  544. //TODO
  545. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  546. //check course code exists
  547. //check lp_name doesn't exist, otherwise append something
  548. $i = 0;
  549. $name = learnpath :: escape_string($name);
  550. //session_id
  551. $session_id = api_get_session_id();
  552. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  553. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  554. $res_name = Database::query($check_name);
  555. while (Database :: num_rows($res_name)) {
  556. //there is already one such name, update the current one a bit
  557. $i++;
  558. $name = $name . ' - ' . $i;
  559. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  560. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  561. $res_name = Database::query($check_name);
  562. }
  563. //new name does not exist yet; keep it
  564. //escape description
  565. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); //Kevin: added htmlentities()
  566. $type = 1;
  567. switch ($learnpath) {
  568. case 'guess' :
  569. break;
  570. case 'dokeos' :
  571. $type = 1;
  572. break;
  573. case 'aicc' :
  574. break;
  575. }
  576. switch ($origin) {
  577. case 'zip' :
  578. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  579. break;
  580. case 'manual' :
  581. default :
  582. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  583. $res_max = Database::query($get_max);
  584. if (Database :: num_rows($res_max) < 1) {
  585. $dsp = 1;
  586. } else {
  587. $row = Database :: fetch_array($res_max);
  588. $dsp = $row[0] + 1;
  589. }
  590. $sql_insert = "INSERT INTO $tbl_lp " .
  591. "(lp_type,name,description,path,default_view_mod," .
  592. "default_encoding,display_order,content_maker," .
  593. "content_local,js_lib,session_id) " .
  594. "VALUES ($type,'$name','$description','','embedded'," .
  595. "'UTF-8','$dsp','Dokeos'," .
  596. "'local','','".Database::escape_string($session_id)."')";
  597. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  598. $res_insert = Database::query($sql_insert);
  599. $id = Database :: insert_id();
  600. if ($id > 0) {
  601. //insert into item_property
  602. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  603. return $id;
  604. }
  605. break;
  606. }
  607. }
  608. /**
  609. * Appends a message to the message attribute
  610. * @param string Message to append.
  611. */
  612. function append_message($string) {
  613. if ($this->debug > 0) {
  614. error_log('New LP - In learnpath::append_message()', 0);
  615. }
  616. $this->message .= $string;
  617. }
  618. /**
  619. * Autocompletes the parents of an item in case it's been completed or passed
  620. * @param integer Optional ID of the item from which to look for parents
  621. */
  622. function autocomplete_parents($item) {
  623. if ($this->debug > 0) {
  624. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  625. }
  626. if (empty ($item)) {
  627. $item = $this->current;
  628. }
  629. $parent_id = $this->items[$item]->get_parent();
  630. if ($this->debug > 2) {
  631. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  632. }
  633. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  634. //if $item points to an object and there is a parent
  635. if ($this->debug > 2) {
  636. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  637. }
  638. $current_item = & $this->items[$item];
  639. $parent = & $this->items[$parent_id]; //get the parent
  640. //new experiment including failed and browsed in completed status
  641. $current_status = $current_item->get_status();
  642. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  643. //if the current item is completed or passes or succeeded
  644. $completed = true;
  645. if ($this->debug > 2) {
  646. error_log('New LP - Status of current item is alright', 0);
  647. }
  648. foreach ($parent->get_children() as $child) {
  649. //check all his brothers (his parent's children) for completion status
  650. if ($child != $item) {
  651. if ($this->debug > 2) {
  652. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  653. }
  654. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  655. //Trying completing parents of failed and browsed items as well
  656. if ($this->items[$child]->status_is(array (
  657. 'completed',
  658. 'passed',
  659. 'succeeded',
  660. 'browsed',
  661. 'failed'
  662. ))) {
  663. //keep completion status to true
  664. } else {
  665. if ($this->debug > 2) {
  666. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  667. }
  668. $completed = false;
  669. }
  670. }
  671. }
  672. if ($completed == true) { //if all the children were completed
  673. $parent->set_status('completed');
  674. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  675. $this->update_queue[$parent->get_id()] = $parent->get_status();
  676. if ($this->debug > 2) {
  677. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  678. }
  679. $this->autocomplete_parents($parent->get_id()); //recursive call
  680. }
  681. } else {
  682. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  683. }
  684. }
  685. }
  686. /**
  687. * Autosaves the current results into the database for the whole learnpath
  688. */
  689. function autosave() {
  690. if ($this->debug > 0) {
  691. error_log('New LP - In learnpath::autosave()', 0);
  692. }
  693. //TODO add aditionnal save operations for the learnpath itself
  694. }
  695. /**
  696. * Clears the message attribute
  697. */
  698. function clear_message() {
  699. if ($this->debug > 0) {
  700. error_log('New LP - In learnpath::clear_message()', 0);
  701. }
  702. $this->message = '';
  703. }
  704. /**
  705. * Closes the current resource
  706. *
  707. * Stops the timer
  708. * Saves into the database if required
  709. * Clears the current resource data from this object
  710. * @return boolean True on success, false on failure
  711. */
  712. function close() {
  713. if ($this->debug > 0) {
  714. error_log('New LP - In learnpath::close()', 0);
  715. }
  716. if (empty ($this->lp_id)) {
  717. $this->error = 'Trying to close this learnpath but no ID is set';
  718. return false;
  719. }
  720. $this->current_time_stop = time();
  721. if ($this->save) {
  722. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  723. /*
  724. $sql = "UPDATE $learnpath_view_table " .
  725. "SET " .
  726. "stop_time = ".$this->current_time_stop.", " .
  727. "score = ".$this->current_score.", ".
  728. "WHERE learnpath_id = '".$this->lp_id."'";
  729. //$res = Database::query($sql);
  730. $res = Database::query($res);
  731. if(Database::affected_rows($res)<1)
  732. {
  733. $this->error = 'Could not update learnpath_view table while closing learnpath';
  734. return false;
  735. }
  736. */
  737. }
  738. $this->ordered_items = array ();
  739. $this->index = 0;
  740. unset ($this->lp_id);
  741. //unset other stuff
  742. return true;
  743. }
  744. /**
  745. * Static admin function allowing removal of a learnpath
  746. * @param string Course code
  747. * @param integer Learnpath ID
  748. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  749. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  750. */
  751. function delete($course = null, $id = null, $delete = 'keep') {
  752. //TODO implement a way of getting this to work when the current object is not set
  753. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  754. //if(empty($course)){$course = api_get_course_id();}
  755. //if(empty($id)){$id = $this->get_id();}
  756. //If an ID is specifically given and the current LP is not the same,
  757. //prevent delete
  758. if (!empty ($id) && ($id != $this->lp_id)) {
  759. return false;
  760. }
  761. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  762. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  763. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  764. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  765. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  766. //delete lp item id
  767. foreach ($this->items as $id => $dummy) {
  768. //$this->items[$id]->delete();
  769. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  770. $res_del_item_view = Database::query($sql_del_view);
  771. }
  772. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  773. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  774. $res_del_item = Database::query($sql_del_item);
  775. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  776. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  777. $res_del_view = Database::query($sql_del_view);
  778. $this->toggle_publish($this->lp_id, 'i');
  779. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  780. if ($this->type == 2 OR $this->type == 3) {
  781. //this is a scorm learning path, delete the files as well
  782. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  783. $res = Database::query($sql);
  784. if (Database :: num_rows($res) > 0) {
  785. $row = Database :: fetch_array($res);
  786. $path = $row['path'];
  787. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  788. $res = Database::query($sql);
  789. if (Database :: num_rows($res) > 0) { //another learning path uses this directory, so don't delete it
  790. if ($this->debug > 2) {
  791. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  792. }
  793. } else {
  794. //no other LP uses that directory, delete it
  795. $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses
  796. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course
  797. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  798. if ($this->debug > 2) {
  799. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  800. }
  801. // Proposed by Christophe (clefevre).
  802. if (strcmp(substr($path, -2), "/.") == 0) {
  803. $path = substr($path, 0, -1); // Remove "." at the end
  804. }
  805. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  806. rmdirr($course_scorm_dir . $path);
  807. }
  808. }
  809. }
  810. }
  811. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  812. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  813. $res_del_lp = Database::query($sql_del_lp);
  814. $this->update_display_order(); //updates the display order of all lps
  815. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  816. require_once '../gradebook/lib/be.inc.php';
  817. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  818. //delete link of gradebook tool
  819. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  820. $result = Database::query($sql);
  821. $row = Database :: fetch_array($result, 'ASSOC');
  822. //fixing gradebook link deleted see #5229
  823. if (!empty($row['id'])) {
  824. $link = LinkFactory :: load($row['id']);
  825. if ($link[0] != null) {
  826. $link[0]->delete();
  827. }
  828. }
  829. //TODO: also delete items and item-views
  830. if (api_get_setting('search_enabled') == 'true') {
  831. require_once (api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  832. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  833. }
  834. }
  835. /**
  836. * Removes all the children of one item - dangerous!
  837. * @param integer Element ID of which children have to be removed
  838. * @return integer Total number of children removed
  839. */
  840. function delete_children_items($id) {
  841. if ($this->debug > 0) {
  842. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  843. }
  844. $num = 0;
  845. if (empty ($id) || $id != strval(intval($id))) {
  846. return false;
  847. }
  848. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  849. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  850. $res = Database::query($sql);
  851. while ($row = Database :: fetch_array($res)) {
  852. $num += $this->delete_children_items($row['id']);
  853. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  854. $res_del = Database::query($sql_del);
  855. $num++;
  856. }
  857. return $num;
  858. }
  859. /**
  860. * Removes an item from the current learnpath
  861. * @param integer Elem ID (0 if first)
  862. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  863. * @return integer Number of elements moved
  864. * @todo implement resource removal
  865. */
  866. function delete_item($id, $remove = 'keep') {
  867. if ($this->debug > 0) {
  868. error_log('New LP - In learnpath::delete_item()', 0);
  869. }
  870. //TODO - implement the resource removal
  871. if (empty ($id) || $id != strval(intval($id))) {
  872. return false;
  873. }
  874. //first select item to get previous, next, and display order
  875. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  876. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  877. $res_sel = Database::query($sql_sel);
  878. if (Database :: num_rows($res_sel) < 1) {
  879. return false;
  880. }
  881. $row = Database :: fetch_array($res_sel);
  882. $previous = $row['previous_item_id'];
  883. $next = $row['next_item_id'];
  884. $display = $row['display_order'];
  885. $parent = $row['parent_item_id'];
  886. $lp = $row['lp_id'];
  887. //delete children items
  888. $num = $this->delete_children_items($id);
  889. if ($this->debug > 2) {
  890. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  891. }
  892. //now delete the item
  893. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  894. if ($this->debug > 2) {
  895. error_log('New LP - Deleting item: ' . $sql_del, 0);
  896. }
  897. $res_del = Database::query($sql_del);
  898. //now update surrounding items
  899. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  900. $res_upd = Database::query($sql_upd);
  901. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  902. $res_upd = Database::query($sql_upd);
  903. //now update all following items with new display order
  904. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  905. $res_all = Database::query($sql_all);
  906. // remove from search engine if enabled
  907. if (api_get_setting('search_enabled') == 'true') {
  908. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  909. $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';
  910. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  911. $res = Database::query($sql);
  912. if (Database :: num_rows($res) > 0) {
  913. $row2 = Database :: fetch_array($res);
  914. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  915. $di = new DokeosIndexer();
  916. $di->remove_document((int) $row2['search_did']);
  917. }
  918. $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';
  919. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  920. Database::query($sql);
  921. }
  922. }
  923. /**
  924. * Updates an item's content in place
  925. * @param integer Element ID
  926. * @param integer Parent item ID
  927. * @param integer Previous item ID
  928. * @param string Item title
  929. * @param string Item description
  930. * @param string Prerequisites (optional)
  931. * @param string Indexing terms (optional)
  932. * @param array The array resulting of the $_FILES[mp3] element
  933. * @return boolean True on success, false on error
  934. */
  935. function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = NULL, $max_time_allowed = 0) {
  936. global $charset;
  937. if ($this->debug > 0) {
  938. error_log('New LP - In learnpath::edit_item()', 0);
  939. }
  940. if (empty ($max_time_allowed)) {
  941. $max_time_allowed = 0;
  942. }
  943. if (empty ($id) or ($id != strval(intval($id))) or empty ($title)) {
  944. return false;
  945. }
  946. $title = api_convert_encoding($title, $this->encoding, $charset);
  947. $description = api_convert_encoding($description, $this->encoding, $charset);
  948. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  949. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  950. $res_select = Database::query($sql_select);
  951. $row_select = Database :: fetch_array($res_select);
  952. $audio_update_sql = '';
  953. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  954. // create the audio folder if it does not exist yet
  955. global $_course;
  956. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  957. if (!is_dir($filepath . 'audio')) {
  958. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  959. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  960. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  961. }
  962. //upload file in documents
  963. $pi = pathinfo($audio['name']);
  964. if ($pi['extension'] == 'mp3') {
  965. $c_det = api_get_course_info($this->cc);
  966. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  967. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  968. $path = substr($path, 7);
  969. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  970. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  971. }
  972. }
  973. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  974. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  975. //TODO: htmlspecialchars to be checked for encoding related problems.
  976. if ($same_parent && $same_previous) {
  977. //only update title and description
  978. $sql_update = " UPDATE " . $tbl_lp_item . "
  979. SET title = '" . $this->escape_string($title) . "',
  980. prerequisite = '" . $prerequisites . "',
  981. description = '" . $this->escape_string($description) . "'
  982. " . $audio_update_sql . ",
  983. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  984. WHERE id = " . $id;
  985. $res_update = Database::query($sql_update);
  986. } else {
  987. $old_parent = $row_select['parent_item_id'];
  988. $old_previous = $row_select['previous_item_id'];
  989. $old_next = $row_select['next_item_id'];
  990. $old_order = $row_select['display_order'];
  991. $old_prerequisite = $row_select['prerequisite'];
  992. $old_max_time_allowed = $row_select['max_time_allowed'];
  993. /* BEGIN -- virtually remove the current item id */
  994. /* for the next and previous item it is like the current item doesn't exist anymore */
  995. if ($old_previous != 0) {
  996. $sql_update_next = "
  997. UPDATE " . $tbl_lp_item . "
  998. SET next_item_id = " . $old_next . "
  999. WHERE id = " . $old_previous;
  1000. $res_update_next = Database::query($sql_update_next);
  1001. //echo '<p>' . $sql_update_next . '</p>';
  1002. }
  1003. if ($old_next != 0) {
  1004. $sql_update_previous = "
  1005. UPDATE " . $tbl_lp_item . "
  1006. SET previous_item_id = " . $old_previous . "
  1007. WHERE id = " . $old_next;
  1008. $res_update_previous = Database::query($sql_update_previous);
  1009. //echo '<p>' . $sql_update_previous . '</p>';
  1010. }
  1011. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  1012. $sql_update_order = "
  1013. UPDATE " . $tbl_lp_item . "
  1014. SET display_order = display_order - 1
  1015. WHERE
  1016. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1017. parent_item_id = " . $old_parent;
  1018. $res_update_order = Database::query($sql_update_order);
  1019. //echo '<p>' . $sql_update_order . '</p>';
  1020. /* END -- virtually remove the current item id */
  1021. /* BEGIN -- update the current item id to his new location */
  1022. if ($previous == 0) {
  1023. //select the data of the item that should come after the current item
  1024. $sql_select_old = "
  1025. SELECT
  1026. id,
  1027. display_order
  1028. FROM " . $tbl_lp_item . "
  1029. WHERE
  1030. lp_id = " . $this->lp_id . " AND
  1031. parent_item_id = " . $parent . " AND
  1032. previous_item_id = " . $previous;
  1033. $res_select_old = Database::query($sql_select_old);
  1034. $row_select_old = Database :: fetch_array($res_select_old);
  1035. //echo '<p>' . $sql_select_old . '</p>';
  1036. //if the new parent didn't have children before
  1037. if (Database :: num_rows($res_select_old) == 0) {
  1038. $new_next = 0;
  1039. $new_order = 1;
  1040. } else {
  1041. $new_next = $row_select_old['id'];
  1042. $new_order = $row_select_old['display_order'];
  1043. }
  1044. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1045. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1046. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1047. } else {
  1048. //select the data of the item that should come before the current item
  1049. $sql_select_old = "
  1050. SELECT
  1051. next_item_id,
  1052. display_order
  1053. FROM " . $tbl_lp_item . "
  1054. WHERE id = " . $previous;
  1055. $res_select_old = Database::query($sql_select_old);
  1056. $row_select_old = Database :: fetch_array($res_select_old);
  1057. //echo '<p>' . $sql_select_old . '</p>';
  1058. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1059. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1060. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1061. $new_next = $row_select_old['next_item_id'];
  1062. $new_order = $row_select_old['display_order'] + 1;
  1063. }
  1064. //TODO: htmlspecialchars to be checked for encoding related problems.
  1065. //update the current item with the new data
  1066. $sql_update = "
  1067. UPDATE " . $tbl_lp_item . "
  1068. SET
  1069. title = '" . $this->escape_string($title) . "',
  1070. description = '" . $this->escape_string($description) . "',
  1071. parent_item_id = " . $parent . ",
  1072. previous_item_id = " . $previous . ",
  1073. next_item_id = " . $new_next . ",
  1074. display_order = " . $new_order . "
  1075. " . $audio_update_sql . "
  1076. WHERE id = " . $id;
  1077. $res_update_next = Database::query($sql_update);
  1078. //echo '<p>' . $sql_update . '</p>';
  1079. if ($previous != 0) {
  1080. //update the previous item's next_item_id
  1081. $sql_update_previous = "
  1082. UPDATE " . $tbl_lp_item . "
  1083. SET next_item_id = " . $id . "
  1084. WHERE id = " . $previous;
  1085. $res_update_next = Database::query($sql_update_previous);
  1086. //echo '<p>' . $sql_update_previous . '</p>';
  1087. }
  1088. if ($new_next != 0) {
  1089. //update the next item's previous_item_id
  1090. $sql_update_next = "
  1091. UPDATE " . $tbl_lp_item . "
  1092. SET previous_item_id = " . $id . "
  1093. WHERE id = " . $new_next;
  1094. $res_update_next = Database::query($sql_update_next);
  1095. //echo '<p>' . $sql_update_next . '</p>';
  1096. }
  1097. if ($old_prerequisite != $prerequisites) {
  1098. $sql_update_next = "
  1099. UPDATE " . $tbl_lp_item . "
  1100. SET prerequisite = " . $prerequisites . "
  1101. WHERE id = " . $id;
  1102. $res_update_next = Database::query($sql_update_next);
  1103. }
  1104. if ($old_max_time_allowed != $max_time_allowed) {
  1105. $sql_update_max_time_allowed = "
  1106. UPDATE " . $tbl_lp_item . "
  1107. SET max_time_allowed = " . $max_time_allowed . "
  1108. WHERE id = " . $id;
  1109. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1110. }
  1111. //update all the items with the same or a bigger display_order than
  1112. //the current item
  1113. $sql_update_order = "
  1114. UPDATE " . $tbl_lp_item . "
  1115. SET display_order = display_order + 1
  1116. WHERE
  1117. lp_id = " . $this->get_id() . " AND
  1118. id <> " . $id . " AND
  1119. parent_item_id = " . $parent . " AND
  1120. display_order >= " . $new_order;
  1121. $res_update_next = Database::query($sql_update_order);
  1122. //echo '<p>' . $sql_update_order . '</p>';
  1123. /* END -- update the current item id to his new location */
  1124. }
  1125. }
  1126. /**
  1127. * Updates an item's prereq in place
  1128. * @param integer Element ID
  1129. * @param string Prerequisite Element ID
  1130. * @param string Prerequisite item type
  1131. * @param string Prerequisite min score
  1132. * @param string Prerequisite max score
  1133. * @return boolean True on success, false on error
  1134. */
  1135. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1136. if ($this->debug > 0) {
  1137. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1138. }
  1139. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1140. return false;
  1141. }
  1142. $prerequisite_id = $this->escape_string($prerequisite_id);
  1143. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1144. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1145. $mastery_score = 0;
  1146. if (!is_numeric($max_score) || $max_score < 0)
  1147. $max_score = 100;
  1148. if ($mastery_score > $max_score)
  1149. $max_score = $mastery_score;
  1150. if (!is_numeric($prerequisite_id))
  1151. $prerequisite_id = 'NULL';
  1152. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1153. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1154. $res_upd = Database::query($sql_upd);
  1155. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1156. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1157. mastery_score = " . $mastery_score .
  1158. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1159. " WHERE ref = '" . $prerequisite_id . "'"; //will this be enough to ensure unicity?
  1160. $res_upd = Database::query($sql_upd);
  1161. }
  1162. //TODO update the item object (can be ignored for now because refreshed)
  1163. return true;
  1164. }
  1165. /**
  1166. * Escapes a string with the available database escape function
  1167. * @param string String to escape
  1168. * @return string String escaped
  1169. */
  1170. function escape_string($string) {
  1171. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1172. return Database :: escape_string($string);
  1173. }
  1174. /**
  1175. * Static admin function exporting a learnpath into a zip file
  1176. * @param string Export type (scorm, zip, cd)
  1177. * @param string Course code
  1178. * @param integer Learnpath ID
  1179. * @param string Zip file name
  1180. * @return string Zip file path (or false on error)
  1181. */
  1182. function export_lp($type, $course, $id, $zipname) {
  1183. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1184. //TODO
  1185. if (empty ($type) OR empty ($course) OR empty ($id) OR empty ($zipname)) {
  1186. return false;
  1187. }
  1188. $url = '';
  1189. switch ($type) {
  1190. case 'scorm' :
  1191. break;
  1192. case 'zip' :
  1193. break;
  1194. case 'cdrom' :
  1195. break;
  1196. }
  1197. return $url;
  1198. }
  1199. /**
  1200. * Gets all the chapters belonging to the same parent as the item/chapter given
  1201. * Can also be called as abstract method
  1202. * @param integer Item ID
  1203. * @return array A list of all the "brother items" (or an empty array on failure)
  1204. */
  1205. function get_brother_chapters($id) {
  1206. if ($this->debug > 0) {
  1207. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1208. }
  1209. if (empty ($id) OR $id != strval(intval($id))) {
  1210. return array ();
  1211. }
  1212. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1213. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1214. $res_parent = Database::query($sql_parent);
  1215. if (Database :: num_rows($res_parent) > 0) {
  1216. $row_parent = Database :: fetch_array($res_parent);
  1217. $parent = $row_parent['parent_item_id'];
  1218. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1219. $res_bros = Database::query($sql_bros);
  1220. $list = array ();
  1221. while ($row_bro = Database :: fetch_array($res_bros)) {
  1222. $list[] = $row_bro;
  1223. }
  1224. return $list;
  1225. }
  1226. return array ();
  1227. }
  1228. /**
  1229. * Gets all the items belonging to the same parent as the item given
  1230. * Can also be called as abstract method
  1231. * @param integer Item ID
  1232. * @return array A list of all the "brother items" (or an empty array on failure)
  1233. */
  1234. function get_brother_items($id) {
  1235. if ($this->debug > 0) {
  1236. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1237. }
  1238. if (empty ($id) OR $id != strval(intval($id))) {
  1239. return array ();
  1240. }
  1241. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1242. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1243. $res_parent = Database::query($sql_parent);
  1244. if (Database :: num_rows($res_parent) > 0) {
  1245. $row_parent = Database :: fetch_array($res_parent);
  1246. $parent = $row_parent['parent_item_id'];
  1247. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1248. $res_bros = Database::query($sql_bros);
  1249. $list = array ();
  1250. while ($row_bro = Database :: fetch_array($res_bros)) {
  1251. $list[] = $row_bro;
  1252. }
  1253. return $list;
  1254. }
  1255. return array ();
  1256. }
  1257. /**
  1258. * Get the specific prefix index terms of this learning path
  1259. * @return array Array of terms
  1260. */
  1261. function get_common_index_terms_by_prefix($prefix) {
  1262. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  1263. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1264. $prefix_terms = array ();
  1265. foreach ($terms as $term) {
  1266. $prefix_terms[] = $term['value'];
  1267. }
  1268. return $prefix_terms;
  1269. }
  1270. /**
  1271. * Gets the number of items currently completed
  1272. * @return integer The number of items currently completed
  1273. */
  1274. function get_complete_items_count() {
  1275. if ($this->debug > 0) {
  1276. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1277. }
  1278. $i = 0;
  1279. foreach ($this->items as $id => $dummy) {
  1280. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1281. //Trying failed and browsed considered "progressed" as well
  1282. if ($this->items[$id]->status_is(array (
  1283. 'completed',
  1284. 'passed',
  1285. 'succeeded',
  1286. 'browsed',
  1287. 'failed'
  1288. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1289. $i++;
  1290. }
  1291. }
  1292. return $i;
  1293. }
  1294. /**
  1295. * Gets the current item ID
  1296. * @return integer The current learnpath item id
  1297. */
  1298. function get_current_item_id() {
  1299. $current = 0;
  1300. if ($this->debug > 0) {
  1301. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1302. }
  1303. if (!empty ($this->current)) {
  1304. $current = $this->current;
  1305. }
  1306. if ($this->debug > 2) {
  1307. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1308. }
  1309. return $current;
  1310. }
  1311. /** Force to get the first learnpath item id
  1312. * @return integer The current learnpath item id
  1313. */
  1314. function get_first_item_id() {
  1315. $current = 0;
  1316. if (is_array($this->ordered_items)) {
  1317. $current = $this->ordered_items[0];
  1318. }
  1319. return $current;
  1320. }
  1321. /**
  1322. * Gets the total number of items available for viewing in this SCORM
  1323. * @return integer The total number of items
  1324. */
  1325. function get_total_items_count() {
  1326. if ($this->debug > 0) {
  1327. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1328. }
  1329. return count($this->items);
  1330. }
  1331. /**
  1332. * Gets the total number of items available for viewing in this SCORM but without chapters
  1333. * @return integer The total no-chapters number of items
  1334. */
  1335. function get_total_items_count_without_chapters() {
  1336. if ($this->debug > 0) {
  1337. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1338. }
  1339. $total = 0;
  1340. foreach ($this->items as $temp => $temp2) {
  1341. if (!in_array($temp2->get_type(), array (
  1342. 'dokeos_chapter',
  1343. 'chapter',
  1344. 'dir'
  1345. )))
  1346. $total++;
  1347. }
  1348. return $total;
  1349. }
  1350. /**
  1351. * Gets the first element URL.
  1352. * @return string URL to load into the viewer
  1353. */
  1354. function first() {
  1355. if ($this->debug > 0) {
  1356. error_log('New LP - In learnpath::first()', 0);
  1357. }
  1358. //test if the last_item_seen exists and is not a dir
  1359. if (count($this->ordered_items) == 0) {
  1360. $this->index = 0;
  1361. }
  1362. 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() != true) {
  1363. if ($this->debug > 2) {
  1364. 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);
  1365. }
  1366. $index = -1;
  1367. foreach ($this->ordered_items as $myindex => $item_id) {
  1368. if ($item_id == $this->last_item_seen) {
  1369. $index = $myindex;
  1370. break;
  1371. }
  1372. }
  1373. if ($index == -1) {
  1374. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1375. if ($this->debug > 2) {
  1376. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1377. }
  1378. return false;
  1379. } else {
  1380. $this->last = $this->last_item_seen;
  1381. $this->current = $this->last_item_seen;
  1382. $this->index = $index;
  1383. }
  1384. } else {
  1385. if ($this->debug > 2) {
  1386. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1387. }
  1388. $index = 0;
  1389. //loop through all ordered items and stop at the first item that is
  1390. //not a directory *and* that has not been completed yet
  1391. 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) {
  1392. $index++;
  1393. }
  1394. $this->last = $this->current;
  1395. //current is
  1396. $this->current = $this->ordered_items[$index];
  1397. $this->index = $index;
  1398. if ($this->debug > 2) {
  1399. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1400. }
  1401. }
  1402. if ($this->debug > 2) {
  1403. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1404. }
  1405. }
  1406. /**
  1407. * Gets the information about an item in a format usable as JavaScript to update
  1408. * the JS API by just printing this content into the <head> section of the message frame
  1409. * @param integer Item ID
  1410. * @return string
  1411. */
  1412. function get_js_info($item_id = '') {
  1413. if ($this->debug > 0) {
  1414. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1415. }
  1416. $info = '';
  1417. $item_id = $this->escape_string($item_id);
  1418. if (!empty ($item_id) && is_object($this->items[$item_id])) {
  1419. //if item is defined, return values from DB
  1420. $oItem = $this->items[$item_id];
  1421. $info .= '<script language="javascript">';
  1422. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1423. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1424. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1425. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1426. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1427. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1428. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1429. $info .= "top.set_flag_synchronized();";
  1430. $info .= '</script>';
  1431. if ($this->debug > 2) {
  1432. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1433. }
  1434. return $info;
  1435. } else {
  1436. //if item_id is empty, just update to default SCORM data
  1437. $info .= '<script language="javascript">';
  1438. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1439. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1440. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1441. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1442. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1443. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1444. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1445. $info .= "top.set_flag_synchronized();";
  1446. $info .= '</script>';
  1447. if ($this->debug > 2) {
  1448. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1449. }
  1450. return $info;
  1451. }
  1452. }
  1453. /**
  1454. * Gets the js library from the database
  1455. * @return string The name of the javascript library to be used
  1456. */
  1457. function get_js_lib() {
  1458. $lib = '';
  1459. if (!empty ($this->js_lib)) {
  1460. $lib = $this->js_lib;
  1461. }
  1462. return $lib;
  1463. }
  1464. /**
  1465. * Gets the learnpath database ID
  1466. * @return integer Learnpath ID in the lp table
  1467. */
  1468. function get_id() {
  1469. //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1470. if (!empty ($this->lp_id)) {
  1471. return $this->lp_id;
  1472. } else {
  1473. return 0;
  1474. }
  1475. }
  1476. /**
  1477. * Gets the last element URL.
  1478. * @return string URL to load into the viewer
  1479. */
  1480. function get_last() {
  1481. if ($this->debug > 0) {
  1482. error_log('New LP - In learnpath::get_last()', 0);
  1483. }
  1484. $this->index = count($this->ordered_items) - 1;
  1485. return $this->ordered_items[$this->index];
  1486. }
  1487. /**
  1488. * Gets the navigation bar for the learnpath display screen
  1489. * @return string The HTML string to use as a navigation bar
  1490. */
  1491. function get_navigation_bar() {
  1492. if ($this->debug > 0) {
  1493. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1494. }
  1495. //TODO find a good value for the following variables
  1496. $file = '';
  1497. $openDir = '';
  1498. $edoceo = '';
  1499. $time = 0;
  1500. $navbar = '';
  1501. $RequestUri = '';
  1502. $mycurrentitemid = $this->get_current_item_id();
  1503. if ($this->mode == 'fullscreen') {
  1504. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1505. ' <tr> ' . "\n" .
  1506. ' <td>' . "\n" .
  1507. ' <div class="buttons">' . "\n" .
  1508. ' <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" .
  1509. ' <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" .
  1510. ' <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" .
  1511. //' <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" .
  1512. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1513. ' </div>' . "\n" .
  1514. ' </td>' . "\n" .
  1515. ' </tr>' . "\n" .
  1516. '</table>' . "\n";
  1517. } else {
  1518. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1519. ' <tr> ' . "\n" .
  1520. ' <td>' . "\n" .
  1521. ' <div class="buttons">' . "\n" .
  1522. ' <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" .
  1523. ' <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" .
  1524. ' <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" .
  1525. // ' <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" .
  1526. ' </div>' . "\n" .
  1527. ' </td>' . "\n" .
  1528. ' </tr>' . "\n" .
  1529. '</table>' . "\n";
  1530. }
  1531. return $navbar;
  1532. }
  1533. /**
  1534. * Gets the next resource in queue (url).
  1535. * @return string URL to load into the viewer
  1536. */
  1537. function get_next_index() {
  1538. if ($this->debug > 0) {
  1539. error_log('New LP - In learnpath::get_next_index()', 0);
  1540. }
  1541. //TODO
  1542. $index = $this->index;
  1543. $index++;
  1544. if ($this->debug > 2) {
  1545. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1546. }
  1547. 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) {
  1548. $index++;
  1549. if ($index == $this->max_ordered_items) {
  1550. return $this->index;
  1551. }
  1552. }
  1553. if (empty ($this->ordered_items[$index])) {
  1554. return $this->index;
  1555. }
  1556. if ($this->debug > 2) {
  1557. error_log('New LP - index is now ' . $index, 0);
  1558. }
  1559. return $index;
  1560. }
  1561. /**
  1562. * Gets item_id for the next element
  1563. * @return integer Next item (DB) ID
  1564. */
  1565. function get_next_item_id() {
  1566. if ($this->debug > 0) {
  1567. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1568. }
  1569. $new_index = $this->get_next_index();
  1570. if (!empty ($new_index)) {
  1571. if (isset ($this->ordered_items[$new_index])) {
  1572. if ($this->debug > 2) {
  1573. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1574. }
  1575. return $this->ordered_items[$new_index];
  1576. }
  1577. }
  1578. if ($this->debug > 2) {
  1579. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1580. }
  1581. return 0;
  1582. }
  1583. /**
  1584. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1585. *
  1586. * Generally, the package provided is in the form of a zip file, so the function
  1587. * has been written to test a zip file. If not a zip, the function will return the
  1588. * default return value: ''
  1589. * @param string the path to the file
  1590. * @param string the original name of the file
  1591. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1592. */
  1593. function get_package_type($file_path, $file_name) {
  1594. //get name of the zip file without the extension
  1595. $file_info = pathinfo($file_name);
  1596. $filename = $file_info['basename']; //name including extension
  1597. $extension = $file_info['extension']; //extension only
  1598. if (!empty ($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1599. 'dll',
  1600. 'exe'
  1601. ))) {
  1602. return 'oogie';
  1603. }
  1604. if (!empty ($_POST['woogie']) && !in_array(strtolower($extension), array (
  1605. 'dll',
  1606. 'exe'
  1607. ))) {
  1608. return 'woogie';
  1609. }
  1610. $file_base_name = str_replace('.' . $extension, '', $filename); //filename without its extension
  1611. $zipFile = new pclZip($file_path);
  1612. // Check the zip content (real size and file extension)
  1613. $zipContentArray = $zipFile->listContent();
  1614. $package_type = '';
  1615. $at_root = false;
  1616. $manifest = '';
  1617. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1618. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1619. foreach ($zipContentArray as $thisContent) {
  1620. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1621. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1622. }
  1623. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== FALSE) {
  1624. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1625. $package_type = 'scorm';
  1626. break; //exit the foreach loop
  1627. }
  1628. elseif (preg_match('/aicc\//i', $thisContent['filename']) != false) {
  1629. //if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1630. $package_type = 'aicc';
  1631. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1632. } else {
  1633. $package_type = '';
  1634. }
  1635. }
  1636. }
  1637. return $package_type;
  1638. }
  1639. /**
  1640. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1641. * @return string URL to load into the viewer
  1642. */
  1643. function get_previous_index() {
  1644. if ($this->debug > 0) {
  1645. error_log('New LP - In learnpath::get_previous_index()', 0);
  1646. }
  1647. $index = $this->index;
  1648. if (isset ($this->ordered_items[$index -1])) {
  1649. $index--;
  1650. 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')) {
  1651. $index--;
  1652. if ($index < 0) {
  1653. return $this->index;
  1654. }
  1655. }
  1656. } else {
  1657. if ($this->debug > 2) {
  1658. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1659. }
  1660. //no previous item
  1661. }
  1662. return $index;
  1663. }
  1664. /**
  1665. * Gets item_id for the next element
  1666. * @return integer Previous item (DB) ID
  1667. */
  1668. function get_previous_item_id() {
  1669. if ($this->debug > 0) {
  1670. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1671. }
  1672. $new_index = $this->get_previous_index();
  1673. return $this->ordered_items[$new_index];
  1674. }
  1675. /**
  1676. * Gets the progress value from the progress_db attribute
  1677. * @return integer Current progress value
  1678. */
  1679. function get_progress() {
  1680. if ($this->debug > 0) {
  1681. error_log('New LP - In learnpath::get_progress()', 0);
  1682. }
  1683. if (!empty ($this->progress_db)) {
  1684. return $this->progress_db;
  1685. }
  1686. return 0;
  1687. }
  1688. /**
  1689. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1690. * @param integer Learnpath ID
  1691. * @param integer User ID
  1692. * @param string Mode of display ('%','abs' or 'both')
  1693. * @param string Course database name (optional, defaults to '')
  1694. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1695. * @return integer Current progress value as found in the database
  1696. */
  1697. function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false) {
  1698. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1699. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1700. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1701. $res = Database::query($sql);
  1702. $view_id = 0;
  1703. if (Database :: num_rows($res) > 0) {
  1704. $row = Database :: fetch_array($res);
  1705. $progress = $row['progress'];
  1706. $view_id = $row['id'];
  1707. } else {
  1708. if ($sincere) {
  1709. return null;
  1710. }
  1711. }
  1712. if (empty ($progress)) {
  1713. $progress = '0';
  1714. }
  1715. if ($mode == '%') {
  1716. return $progress . '%';
  1717. } else {
  1718. //get the number of items completed and the number of items total
  1719. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1720. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1721. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1722. $res = Database::query($sql);
  1723. $row = Database :: fetch_array($res);
  1724. $total = $row[0];
  1725. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1726. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1727. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1728. //trying as also counting browsed and failed items
  1729. $sql = "SELECT count(distinct(lp_item_id))
  1730. FROM $tbl_item_view as item_view
  1731. INNER JOIN $tbl_item as item
  1732. ON item.id = item_view.lp_item_id
  1733. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1734. WHERE lp_view_id = " . $view_id . "
  1735. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1736. $res = Database::query($sql);
  1737. $row = Database :: fetch_array($res);
  1738. $completed = $row[0];
  1739. if ($mode == 'abs') {
  1740. return $completed . '/' . $total;
  1741. }
  1742. elseif ($mode == 'both') {
  1743. if ($progress < ($completed / ($total ? $total : 1))) {
  1744. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1745. }
  1746. return $progress . '% (' . $completed . '/' . $total . ')';
  1747. }
  1748. }
  1749. return $progress;
  1750. }
  1751. /**
  1752. * Returns the HTML necessary to print a mediaplayer block inside a page
  1753. * @return string The mediaplayer HTML
  1754. */
  1755. function get_mediaplayer($autostart='true') {
  1756. global $_course;
  1757. // Database table definition
  1758. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1759. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1760. // getting all the information about the item
  1761. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp inner join " . $tbl_lp_item_view . " as lp_view on lp.id = lp_view.lp_item_id " .
  1762. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1763. $result = Database::query($sql);
  1764. $row = Database::fetch_assoc($result);
  1765. $output = '';
  1766. if (!empty ($row['audio'])) {
  1767. $list = $_SESSION['oLP']->get_toc();
  1768. $type_quiz = false;
  1769. foreach($list as $toc) {
  1770. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1771. $type_quiz = true;
  1772. }
  1773. }
  1774. if ($type_quiz) {
  1775. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1776. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1777. } else {
  1778. $autostart_audio = $autostart;
  1779. }
  1780. } else {
  1781. $autostart_audio = 'true';
  1782. }
  1783. // the mp3 player
  1784. $output = '<div id="container">';
  1785. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1786. $output .= '<script type="text/javascript">
  1787. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1788. s1.addParam("allowscriptaccess","always");
  1789. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1790. s1.write("container");
  1791. </script></div>';
  1792. }
  1793. return $output;
  1794. }
  1795. /**
  1796. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1797. * completed so far.
  1798. * @param string Mode in which we want the values
  1799. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1800. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1801. * @param boolean true if it comes from a Diplay LP view
  1802. * @return string HTML string containing the progress bar
  1803. */
  1804. function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1805. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1806. global $lp_theme_css;
  1807. // Setting up the CSS path of the current style if exists
  1808. if (!empty ($lp_theme_css)) {
  1809. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1810. } else {
  1811. $css_path = '../img/';
  1812. }
  1813. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1814. if (isset ($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1815. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1816. }
  1817. $text = $percentage . $text_add;
  1818. //Default progress bar config
  1819. // times that will be greater or shorter
  1820. $factor = 1.2;
  1821. if ($from_lp)
  1822. $progress_height = '26';
  1823. else
  1824. $progress_height = '16';
  1825. $size = str_replace('%', '', $percentage);
  1826. $output =
  1827. '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
  1828. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1829. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1830. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1831. if ($percentage <= 98) {
  1832. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1833. } else {
  1834. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1835. }
  1836. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
  1837. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1838. return $output;
  1839. }
  1840. /**
  1841. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1842. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1843. * //@param integer Additional steps to fake as completed
  1844. * @return list Percentage or number and symbol (% or /xx)
  1845. */
  1846. function get_progress_bar_text($mode = '', $add = 0) {
  1847. if ($this->debug > 0) {
  1848. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1849. }
  1850. if (empty ($mode)) {
  1851. $mode = $this->progress_bar_mode;
  1852. }
  1853. $total_items = $this->get_total_items_count_without_chapters();
  1854. if ($this->debug > 2) {
  1855. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1856. }
  1857. $i = $this->get_complete_items_count();
  1858. if ($this->debug > 2) {
  1859. error_log('New LP - Items completed so far: ' . $i, 0);
  1860. }
  1861. if ($add != 0) {
  1862. $i += $add;
  1863. if ($this->debug > 2) {
  1864. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1865. }
  1866. }
  1867. $text = '';
  1868. if ($i > $total_items) {
  1869. $i = $total_items;
  1870. }
  1871. if ($mode == '%') {
  1872. if ($total_items > 0) {
  1873. $percentage = ((float) $i / (float) $total_items) * 100;
  1874. } else {
  1875. $percentage = 0;
  1876. }
  1877. $percentage = number_format($percentage, 0);
  1878. $text = '%';
  1879. }
  1880. elseif ($mode == 'abs') {
  1881. $percentage = $i;
  1882. $text = '/' . $total_items;
  1883. }
  1884. return array (
  1885. $percentage,
  1886. $text
  1887. );
  1888. }
  1889. /**
  1890. * Gets the progress bar mode
  1891. * @return string The progress bar mode attribute
  1892. */
  1893. function get_progress_bar_mode() {
  1894. if ($this->debug > 0) {
  1895. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1896. }
  1897. if (!empty ($this->progress_bar_mode)) {
  1898. return $this->progress_bar_mode;
  1899. } else {
  1900. return '%';
  1901. }
  1902. }
  1903. /**
  1904. * Gets the learnpath proximity (remote or local)
  1905. * @return string Learnpath proximity
  1906. */
  1907. function get_proximity() {
  1908. if ($this->debug > 0) {
  1909. error_log('New LP - In learnpath::get_proximity()', 0);
  1910. }
  1911. if (!empty ($this->proximity)) {
  1912. return $this->proximity;
  1913. } else {
  1914. return '';
  1915. }
  1916. }
  1917. /**
  1918. * Gets the learnpath theme (remote or local)
  1919. * @return string Learnpath theme
  1920. */
  1921. function get_theme() {
  1922. if ($this->debug > 0) {
  1923. error_log('New LP - In learnpath::get_theme()', 0);
  1924. }
  1925. if (!empty ($this->theme)) {
  1926. return $this->theme;
  1927. } else {
  1928. return '';
  1929. }
  1930. }
  1931. /**
  1932. * Gets the learnpath session id
  1933. * @return string Learnpath theme
  1934. */
  1935. function get_lp_session_id() {
  1936. if ($this->debug > 0) {
  1937. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1938. }
  1939. if (!empty ($this->lp_session_id)) {
  1940. return $this->lp_session_id;
  1941. } else {
  1942. return 0;
  1943. }
  1944. }
  1945. /**
  1946. * Gets the learnpath image
  1947. * @return string Web URL of the LP image
  1948. */
  1949. function get_preview_image() {
  1950. if ($this->debug > 0) {
  1951. error_log('New LP - In learnpath::get_preview_image()', 0);
  1952. }
  1953. if (!empty ($this->preview_image)) {
  1954. return $this->preview_image;
  1955. } else {
  1956. return '';
  1957. }
  1958. }
  1959. /**
  1960. * Gets the learnpath author
  1961. * @return string LP's author
  1962. */
  1963. function get_author() {
  1964. if ($this->debug > 0) {
  1965. error_log('New LP - In learnpath::get_author()', 0);
  1966. }
  1967. if (!empty ($this->author)) {
  1968. return $this->author;
  1969. } else {
  1970. return '';
  1971. }
  1972. }
  1973. /**
  1974. * Generate a new prerequisites string for a given item. If this item was a sco and
  1975. * its prerequisites were strings (instead of IDs), then transform those strings into
  1976. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1977. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1978. * same rule as the scorm_export() method
  1979. * @param integer Item ID
  1980. * @return string Prerequisites string ready for the export as SCORM
  1981. */
  1982. function get_scorm_prereq_string($item_id) {
  1983. if ($this->debug > 0) {
  1984. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  1985. }
  1986. if (!is_object($this->items[$item_id])) {
  1987. return false;
  1988. }
  1989. $oItem = $this->items[$item_id];
  1990. $prereq = $oItem->get_prereq_string();
  1991. if (empty ($prereq)) {
  1992. return '';
  1993. }
  1994. 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,
  1995. //then simply return it (with the ITEM_ prefix)
  1996. return 'ITEM_' . $prereq;
  1997. } else {
  1998. if (isset ($this->refs_list[$prereq])) {
  1999. //it's a simple string item from which the ID can be found in the refs list
  2000. //so we can transform it directly to an ID for export
  2001. return 'ITEM_' . $this->refs_list[$prereq];
  2002. } else {
  2003. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  2004. //and replace them, one by one, by the internal IDs (dokeos db)
  2005. //TODO modify the '*' replacement to replace the multiplier in front of it
  2006. //by a space as well
  2007. $find = array (
  2008. '&',
  2009. '|',
  2010. '~',
  2011. '=',
  2012. '<>',
  2013. '{',
  2014. '}',
  2015. '*',
  2016. '(',
  2017. ')'
  2018. );
  2019. $replace = array (
  2020. ' ',
  2021. ' ',
  2022. ' ',
  2023. ' ',
  2024. ' ',
  2025. ' ',
  2026. ' ',
  2027. ' ',
  2028. ' ',
  2029. ' '
  2030. );
  2031. $prereq_mod = str_replace($find, $replace, $prereq);
  2032. $ids = split(' ', $prereq_mod);
  2033. foreach ($ids as $id) {
  2034. $id = trim($id);
  2035. if (isset ($this->refs_list[$id])) {
  2036. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2037. }
  2038. }
  2039. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2040. return $prereq;
  2041. }
  2042. }
  2043. }
  2044. /**
  2045. * Returns the XML DOM document's node
  2046. * @param resource Reference to a list of objects to search for the given ITEM_*
  2047. * @param string The identifier to look for
  2048. * @return mixed The reference to the element found with that identifier. False if not found
  2049. */
  2050. function get_scorm_xml_node(& $children, $id) {
  2051. for ($i = 0; $i < $children->length; $i++) {
  2052. $item_temp = $children->item($i);
  2053. if ($item_temp->nodeName == 'item') {
  2054. if ($item_temp->getAttribute('identifier') == $id) {
  2055. return $item_temp;
  2056. }
  2057. }
  2058. $subchildren = $item_temp->childNodes;
  2059. if ($subchildren->length > 0) {
  2060. $val = $this->get_scorm_xml_node($subchildren, $id);
  2061. if (is_object($val)) {
  2062. return $val;
  2063. }
  2064. }
  2065. }
  2066. return false;
  2067. }
  2068. /**
  2069. * Returns a usable array of stats related to the current learnpath and user
  2070. * @return array Well-formatted array containing status for the current learnpath
  2071. */
  2072. function get_stats() {
  2073. if ($this->debug > 0) {
  2074. error_log('New LP - In learnpath::get_stats()', 0);
  2075. }
  2076. //TODO
  2077. }
  2078. /**
  2079. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2080. * the given course (for all learnpaths and all users)
  2081. * @param string Course code
  2082. * @return array Well-formatted array containing status for the course's learnpaths
  2083. */
  2084. function get_stats_course($course) {
  2085. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  2086. //TODO
  2087. }
  2088. /**
  2089. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2090. * the given course and learnpath (for all users)
  2091. * @param string Course code
  2092. * @param integer Learnpath ID
  2093. * @return array Well-formatted array containing status for the specified learnpath
  2094. */
  2095. function get_stats_lp($course, $lp) {
  2096. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  2097. //TODO
  2098. }
  2099. /**
  2100. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2101. * the given course, learnpath and user.
  2102. * @param string Course code
  2103. * @param integer Learnpath ID
  2104. * @param integer User ID
  2105. * @return array Well-formatted array containing status for the specified learnpath and user
  2106. */
  2107. function get_stats_lp_user($course, $lp, $user) {
  2108. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  2109. //TODO
  2110. }
  2111. /**
  2112. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2113. * the given course and learnpath (for all users)
  2114. * @param string Course code
  2115. * @param integer User ID
  2116. * @return array Well-formatted array containing status for the user's learnpaths
  2117. */
  2118. function get_stats_user($course, $user) {
  2119. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  2120. //TODO
  2121. }
  2122. /**
  2123. * Gets the status list for all LP's items
  2124. * @return array Array of [index] => [item ID => current status]
  2125. */
  2126. function get_items_status_list() {
  2127. if ($this->debug > 0) {
  2128. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2129. }
  2130. $list = array ();
  2131. foreach ($this->ordered_items as $item_id) {
  2132. $list[] = array (
  2133. $item_id => $this->items[$item_id]->get_status()
  2134. );
  2135. }
  2136. return $list;
  2137. }
  2138. /**
  2139. * Return the number of interactions for the given learnpath Item View ID.
  2140. * This method can be used as static.
  2141. * @param integer Item View ID
  2142. * @return integer Number of interactions
  2143. */
  2144. function get_interactions_count_from_db($lp_iv_id = 0) {
  2145. if (empty ($lp_iv_id)) {
  2146. return -1;
  2147. }
  2148. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2149. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2150. $res = Database::query($sql);
  2151. $row = Database :: fetch_array($res);
  2152. $num = $row[0];
  2153. return $num;
  2154. }
  2155. /**
  2156. * Return the interactions as an array for the given lp_iv_id.
  2157. * This method can be used as static.
  2158. * @param integer Learnpath Item View ID
  2159. * @return array
  2160. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2161. */
  2162. function get_iv_interactions_array($lp_iv_id = 0) {
  2163. $charset = api_get_setting('platform_charset');
  2164. $list = array ();
  2165. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2166. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2167. $res = Database::query($sql);
  2168. $num = Database :: num_rows($res);
  2169. if ($num > 0) {
  2170. $list[] = array (
  2171. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2172. "id" => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES, $charset),
  2173. "type" => api_htmlentities(get_lang('Type'), ENT_QUOTES, $charset),
  2174. "time" => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES, $charset),
  2175. "correct_responses" => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES, $charset),
  2176. "student_response" => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES, $charset),
  2177. "result" => api_htmlentities(get_lang('Result'), ENT_QUOTES, $charset),
  2178. "latency" => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES, $charset)
  2179. );
  2180. while ($row = Database :: fetch_array($res)) {
  2181. $list[] = array (
  2182. "order_id" => ($row['order_id'] + 1),
  2183. "id" => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2184. "type" => $row['interaction_type'],
  2185. "time" => $row['completion_time'],
  2186. //"correct_responses"=>$row['correct_responses'],
  2187. //hide correct responses from students
  2188. "correct_responses" => '',
  2189. "student_response" => $row['student_response'],
  2190. "result" => $row['result'],
  2191. "latency" => $row['latency']
  2192. );
  2193. }
  2194. }
  2195. return $list;
  2196. }
  2197. /**
  2198. * Return the number of objectives for the given learnpath Item View ID.
  2199. * This method can be used as static.
  2200. * @param integer Item View ID
  2201. * @return integer Number of objectives
  2202. */
  2203. function get_objectives_count_from_db($lp_iv_id = 0) {
  2204. if (empty ($lp_iv_id)) {
  2205. return -1;
  2206. }
  2207. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2208. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2209. $res = Database::query($sql);
  2210. $row = Database :: fetch_array($res);
  2211. $num = $row[0];
  2212. return $num;
  2213. }
  2214. /**
  2215. * Return the objectives as an array for the given lp_iv_id.
  2216. * This method can be used as static.
  2217. * @param integer Learnpath Item View ID
  2218. * @return array
  2219. * @todo Translate labels
  2220. */
  2221. function get_iv_objectives_array($lp_iv_id = 0) {
  2222. global $chatset;
  2223. $list = array ();
  2224. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2225. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2226. $res = Database::query($sql);
  2227. $num = Database :: num_rows($res);
  2228. if ($num > 0) {
  2229. $list[] = array (
  2230. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2231. "objective_id" => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES, $charset),
  2232. "score_raw" => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES, $charset),
  2233. "score_max" => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES, $charset),
  2234. "score_min" => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES, $charset),
  2235. "status" => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES, $charset)
  2236. );
  2237. while ($row = Database :: fetch_array($res)) {
  2238. $list[] = array (
  2239. "order_id" => ($row['order_id'] + 1),
  2240. "objective_id" => urldecode($row['objective_id']), //urldecode because they often have %2F or stuff like that
  2241. "score_raw" => $row['score_raw'],
  2242. "score_max" => $row['score_max'],
  2243. "score_min" => $row['score_min'],
  2244. "status" => $row['status']
  2245. );
  2246. }
  2247. }
  2248. return $list;
  2249. }
  2250. /**
  2251. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2252. * used by get_html_toc() to be ready to display
  2253. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2254. */
  2255. function get_toc() {
  2256. if ($this->debug > 0) {
  2257. error_log('New LP - In learnpath::get_toc()', 0);
  2258. }
  2259. $toc = array ();
  2260. //echo "<pre>".print_r($this->items,true)."</pre>";
  2261. foreach ($this->ordered_items as $item_id) {
  2262. if ($this->debug > 2) {
  2263. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2264. }
  2265. //TODO change this link generation and use new function instead
  2266. $toc[] = array (
  2267. 'id' => $item_id,
  2268. 'title' => $this->items[$item_id]->get_title(),
  2269. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2270. 'status' => $this->items[$item_id]->get_status(),
  2271. 'level' => $this->items[$item_id]->get_level(),
  2272. 'type' => $this->items[$item_id]->get_type(),
  2273. 'description' => $this->items[$item_id]->get_description(),
  2274. 'path' => $this->items[$item_id]->get_path(),
  2275. );
  2276. }
  2277. if ($this->debug > 2) {
  2278. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2279. }
  2280. return $toc;
  2281. }
  2282. /**
  2283. * Generate and return the table of contents for this learnpath. The JS
  2284. * table returned is used inside of scorm_api.php
  2285. * @return string A JS array vairiable construction
  2286. */
  2287. function get_items_details_as_js($varname='olms.lms_item_types') {
  2288. if ($this->debug > 0) {
  2289. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2290. }
  2291. $toc = $varname.' = new Array();';
  2292. //echo "<pre>".print_r($this->items,true)."</pre>";
  2293. foreach ($this->ordered_items as $item_id) {
  2294. if ($this->debug > 2) {
  2295. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2296. }
  2297. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2298. }
  2299. if ($this->debug > 2) {
  2300. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2301. }
  2302. return $toc;
  2303. }
  2304. /**
  2305. * Gets the learning path type
  2306. * @param boolean Return the name? If false, return the ID. Default is false.
  2307. * @return mixed Type ID or name, depending on the parameter
  2308. */
  2309. function get_type($get_name = false) {
  2310. $res = false;
  2311. if ($this->debug > 0) {
  2312. error_log('New LP - In learnpath::get_type()', 0);
  2313. }
  2314. if (!empty ($this->type)) {
  2315. if ($get_name) {
  2316. //get it from the lp_type table in main db
  2317. } else {
  2318. $res = $this->type;
  2319. }
  2320. }
  2321. if ($this->debug > 2) {
  2322. error_log('New LP - In learnpath::get_type() - Returning ' . ($res == false ? 'false' : $res), 0);
  2323. }
  2324. return $res;
  2325. }
  2326. /**
  2327. * Gets the learning path type as static method
  2328. * @param boolean Return the name? If false, return the ID. Default is false.
  2329. * @return mixed Type ID or name, depending on the parameter
  2330. */
  2331. function get_type_static($lp_id = 0) {
  2332. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2333. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2334. $res = Database::query($sql);
  2335. if ($res === false) {
  2336. return null;
  2337. }
  2338. if (Database :: num_rows($res) <= 0) {
  2339. return null;
  2340. }
  2341. $row = Database :: fetch_array($res);
  2342. return $row['lp_type'];
  2343. }
  2344. /**
  2345. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2346. * This method can be used as abstract and is recursive
  2347. * @param integer Learnpath ID
  2348. * @param integer Parent ID of the items to look for
  2349. * @return mixed Ordered list of item IDs or false on error
  2350. */
  2351. function get_flat_ordered_items_list($lp, $parent = 0) {
  2352. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2353. $list = array ();
  2354. if (empty ($lp)) {
  2355. return false;
  2356. }
  2357. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2358. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2359. $res = Database::query($sql);
  2360. while ($row = Database :: fetch_array($res)) {
  2361. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id']);
  2362. $list[] = $row['id'];
  2363. foreach ($sublist as $item) {
  2364. $list[] = $item;
  2365. }
  2366. }
  2367. return $list;
  2368. }
  2369. /**
  2370. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2371. * @return string HTML TOC ready to display
  2372. */
  2373. function get_html_toc() {
  2374. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  2375. $charset = api_get_setting('platform_charset');
  2376. $display_action_links_with_icons = false;
  2377. if ($this->debug > 0) {
  2378. error_log('New LP - In learnpath::get_html_toc()', 0);
  2379. }
  2380. $list = $this->get_toc();
  2381. //echo $this->current;
  2382. //$parent = $this->items[$this->current]->get_parent();
  2383. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2384. $html = '<div class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS(api_convert_encoding($this->get_name(), $this->encoding, $charset)) . '</div></div>';
  2385. // build, display
  2386. if ($is_allowed_to_edit) {
  2387. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2388. //var_dump($this->get_lp_session_id());
  2389. if ($this->get_lp_session_id()==api_get_session_id()) {
  2390. $html .= '<div class="actions_lp">';
  2391. if ($display_action_links_with_icons) {
  2392. $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>";
  2393. $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>";
  2394. $html .= '<span>' . Display :: return_icon('learnpath_view_na.gif', get_lang("Display")) . ' <b>' . get_lang("Display") . '</b></span>';
  2395. } else {
  2396. $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>";
  2397. $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>";
  2398. $html .= '<span><b>' . get_lang('Display') . '</b></span>';
  2399. }
  2400. $html .= '</div>';
  2401. }
  2402. }
  2403. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
  2404. require_once ('resourcelinker.inc.php');
  2405. //temp variables
  2406. $mycurrentitemid = $this->get_current_item_id();
  2407. $color_counter = 0;
  2408. $i = 0;
  2409. foreach ($list as $item) {
  2410. if ($this->debug > 2) {
  2411. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2412. }
  2413. //TODO complete this
  2414. $icon_name = array (
  2415. 'not attempted' => '../img/notattempted.gif',
  2416. 'incomplete' => '../img/incomplete.gif',
  2417. 'failed' => '../img/failed.gif',
  2418. 'completed' => '../img/completed.gif',
  2419. 'passed' => '../img/passed.gif',
  2420. 'succeeded' => '../img/succeeded.gif',
  2421. 'browsed' => '../img/completed.gif'
  2422. );
  2423. $style = 'scorm_item';
  2424. $scorm_color_background = 'scorm_item';
  2425. $style_item = 'scorm_item';
  2426. $current = false;
  2427. if ($item['id'] == $this->current) {
  2428. $style = 'scorm_item_highlight';
  2429. $scorm_color_background = 'scorm_item_highlight';
  2430. } else
  2431. if ($color_counter % 2 == 0) {
  2432. $scorm_color_background = 'scorm_item_1';
  2433. } else {
  2434. $scorm_color_background = 'scorm_item_2';
  2435. }
  2436. if ($scorm_color_background != '') {
  2437. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2438. }
  2439. //the anchor will let us center the TOC on the currently viewed item &^D
  2440. if ($item['type'] != 'dokeos_module' AND $item['type'] != 'dokeos_chapter') {
  2441. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2442. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2443. } else {
  2444. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2445. }
  2446. $title = $item['title'];
  2447. if (empty ($title)) {
  2448. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2449. }
  2450. //$title = api_htmlentities($title, ENT_QUOTES, $this->encoding);
  2451. $title = Security::remove_XSS($title);
  2452. if ($item['type'] != 'dokeos_chapter' and $item['type'] != 'dir' AND $item['type'] != 'dokeos_module') {
  2453. //$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>" ;
  2454. $url = $this->get_link('http', $item['id']);
  2455. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2456. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2457. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2458. $html .= '<a href="" onclick="switch_item(' .
  2459. $mycurrentitemid . ',' .
  2460. $item['id'] . ');' .
  2461. 'return false;" >' . stripslashes($title) . '</a>';
  2462. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2463. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2464. } elseif ($item['type'] == 'dir') {
  2465. $html .= stripslashes($title);
  2466. }
  2467. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2468. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2469. $user_id = api_get_user_id();
  2470. $course_id = api_get_course_id();
  2471. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2472. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2473. $result = Database::query($sql);
  2474. $count = Database :: num_rows($result);
  2475. if ($item['type'] == 'quiz') {
  2476. if ($item['status'] == 'completed') {
  2477. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2478. }
  2479. } else {
  2480. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2481. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2482. }
  2483. }
  2484. $html .= "</div>";
  2485. if ($scorm_color_background != '') {
  2486. $html .= '</div>';
  2487. }
  2488. $color_counter++;
  2489. }
  2490. $html .= "</div>\n";
  2491. return $html;
  2492. }
  2493. /**
  2494. * Gets the learnpath maker name - generally the editor's name
  2495. * @return string Learnpath maker name
  2496. */
  2497. function get_maker() {
  2498. if ($this->debug > 0) {
  2499. error_log('New LP - In learnpath::get_maker()', 0);
  2500. }
  2501. if (!empty ($this->maker)) {
  2502. return $this->maker;
  2503. } else {
  2504. return '';
  2505. }
  2506. }
  2507. /**
  2508. * Gets the user-friendly message stored in $this->message
  2509. * @return string Message
  2510. */
  2511. function get_message() {
  2512. if ($this->debug > 0) {
  2513. error_log('New LP - In learnpath::get_message()', 0);
  2514. }
  2515. return $this->message;
  2516. }
  2517. /**
  2518. * Gets the learnpath name/title
  2519. * @return string Learnpath name/title
  2520. */
  2521. function get_name() {
  2522. if ($this->debug > 0) {
  2523. error_log('New LP - In learnpath::get_name()', 0);
  2524. }
  2525. if (!empty ($this->name)) {
  2526. return $this->name;
  2527. } else {
  2528. return 'N/A';
  2529. }
  2530. }
  2531. /**
  2532. * Gets a link to the resource from the present location, depending on item ID.
  2533. * @param string Type of link expected
  2534. * @param integer Learnpath item ID
  2535. * @return string Link to the lp_item resource
  2536. */
  2537. function get_link($type = 'http', $item_id = null) {
  2538. if ($this->debug > 0) {
  2539. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2540. }
  2541. if (empty($item_id)) {
  2542. if ($this->debug > 2) {
  2543. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2544. }
  2545. $item_id = $this->get_current_item_id();
  2546. }
  2547. if (empty ($item_id)) {
  2548. if ($this->debug > 2) {
  2549. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2550. }
  2551. //still empty, this means there was no item_id given and we are not in an object context or
  2552. //the object property is empty, return empty link
  2553. $item_id = $this->first();
  2554. return '';
  2555. }
  2556. $file = '';
  2557. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2558. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2559. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2560. $item_id = Database::escape_string($item_id);
  2561. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2562. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2563. if ($this->debug > 2) {
  2564. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2565. }
  2566. $res = Database::query($sel);
  2567. if (Database :: num_rows($res) > 0) {
  2568. $row = Database :: fetch_array($res);
  2569. //var_dump($row);
  2570. $lp_type = $row['ltype'];
  2571. $lp_path = $row['lpath'];
  2572. $lp_item_type = $row['litype'];
  2573. $lp_item_path = $row['lipath'];
  2574. $lp_item_params = $row['liparams'];
  2575. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2576. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2577. }
  2578. //$lp_item_params = '?'.$lp_item_params;
  2579. //add ? if none - left commented to give freedom to scorm implementation
  2580. //if(substr($lp_item_params,0,1)!='?'){
  2581. // $lp_item_params = '?'.$lp_item_params;
  2582. //}
  2583. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2584. if ($type == 'http') {
  2585. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2586. } else {
  2587. $course_path = $sys_course_path; //system path
  2588. }
  2589. //now go through the specific cases to get the end of the path
  2590. switch ($lp_type) {
  2591. case 1 :
  2592. if ($lp_item_type == 'dokeos_chapter') {
  2593. $file = 'lp_content.php?type=dir';
  2594. } else {
  2595. require_once ('resourcelinker.inc.php');
  2596. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2597. // check how much attempts of a exercise exits in lp
  2598. $lp_item_id = $this->get_current_item_id();
  2599. $lp_view_id = $this->get_view_id();
  2600. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2601. $list = $this->get_toc();
  2602. $type_quiz = false;
  2603. foreach ($list as $toc) {
  2604. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2605. $type_quiz = true;
  2606. }
  2607. }
  2608. if ($type_quiz) {
  2609. $lp_item_id = Database :: escape_string($lp_item_id);
  2610. $lp_view_id = Database :: escape_string($lp_view_id);
  2611. $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'";
  2612. $result = Database::query($sql);
  2613. $row_count = Database :: fetch_row($result);
  2614. $count_item_view = (int) $row_count[0];
  2615. $not_multiple_attempt = 0;
  2616. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2617. $not_multiple_attempt = 1;
  2618. }
  2619. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2620. }
  2621. $tmp_array = explode("/", $file);
  2622. $document_name = $tmp_array[count($tmp_array) - 1];
  2623. if (strpos($document_name, '_DELETED_')) {
  2624. $file = 'blank.php?error=document_deleted';
  2625. }
  2626. }
  2627. break;
  2628. case 2 :
  2629. if ($this->debug > 2) {
  2630. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2631. }
  2632. if ($lp_item_type != 'dir') {
  2633. //Quite complex here:
  2634. //we want to make sure 'http://' (and similar) links can
  2635. //be loaded as is (withouth the Dokeos path in front) but
  2636. //some contents use this form: resource.htm?resource=http://blablabla
  2637. //which means we have to find a protocol at the path's start, otherwise
  2638. //it should not be considered as an external URL
  2639. //if($this->prerequisites_match($item_id)){
  2640. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2641. if ($this->debug > 2) {
  2642. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2643. }
  2644. //distant url, return as is
  2645. $file = $lp_item_path;
  2646. } else {
  2647. if ($this->debug > 2) {
  2648. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2649. }
  2650. //prevent getting untranslatable urls
  2651. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2652. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2653. //prepare the path
  2654. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2655. //TODO fix this for urls with protocol header
  2656. $file = str_replace('//', '/', $file);
  2657. $file = str_replace(':/', '://', $file);
  2658. if (substr($lp_path, -1) == '/') {
  2659. $lp_path = substr($lp_path, 0, -1);
  2660. }
  2661. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2662. //if file not found
  2663. $decoded = html_entity_decode($lp_item_path);
  2664. list ($decoded) = explode('?', $decoded);
  2665. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2666. require_once ('resourcelinker.inc.php');
  2667. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2668. if (empty($file)) {
  2669. $file = 'blank.php?error=document_not_found';
  2670. } else {
  2671. $tmp_array = explode("/", $file);
  2672. $document_name = $tmp_array[count($tmp_array) - 1];
  2673. if (strpos($document_name, '_DELETED_')) {
  2674. $file = 'blank.php?error=document_deleted';
  2675. } else {
  2676. $file = 'blank.php?error=document_not_found';
  2677. }
  2678. }
  2679. } else {
  2680. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2681. }
  2682. }
  2683. }
  2684. //}else{
  2685. //prerequisites did not match
  2686. //$file = 'blank.php';
  2687. //}
  2688. //We want to use parameters if they were defined in the imsmanifest
  2689. if ($file != 'blank.php') {
  2690. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2691. }
  2692. } else {
  2693. $file = 'lp_content.php?type=dir';
  2694. }
  2695. break;
  2696. case 3 :
  2697. if ($this->debug > 2) {
  2698. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2699. }
  2700. //formatting AICC HACP append URL
  2701. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2702. if ($lp_item_type != 'dir') {
  2703. //Quite complex here:
  2704. //we want to make sure 'http://' (and similar) links can
  2705. //be loaded as is (withouth the Dokeos path in front) but
  2706. //some contents use this form: resource.htm?resource=http://blablabla
  2707. //which means we have to find a protocol at the path's start, otherwise
  2708. //it should not be considered as an external URL
  2709. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2710. if ($this->debug > 2) {
  2711. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2712. }
  2713. //distant url, return as is
  2714. $file = $lp_item_path;
  2715. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2716. /*
  2717. if(stristr($file,'<servername>')!==false){
  2718. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2719. }
  2720. */
  2721. if (stripos($file, '<servername>') !== false) {
  2722. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2723. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2724. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2725. }
  2726. //
  2727. $file .= $aicc_append;
  2728. } else {
  2729. if ($this->debug > 2) {
  2730. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2731. }
  2732. //prevent getting untranslatable urls
  2733. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2734. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2735. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2736. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2737. //TODO fix this for urls with protocol header
  2738. $file = str_replace('//', '/', $file);
  2739. $file = str_replace(':/', '://', $file);
  2740. $file .= $aicc_append;
  2741. }
  2742. } else {
  2743. $file = 'lp_content.php?type=dir';
  2744. }
  2745. break;
  2746. case 4 :
  2747. break;
  2748. default :
  2749. break;
  2750. }
  2751. }
  2752. if ($this->debug > 2) {
  2753. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2754. }
  2755. return $file;
  2756. }
  2757. /**
  2758. * Gets the latest usable view or generate a new one
  2759. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2760. * @return integer DB lp_view id
  2761. */
  2762. function get_view($attempt_num = 0) {
  2763. if ($this->debug > 0) {
  2764. error_log('New LP - In learnpath::get_view()', 0);
  2765. }
  2766. $search = '';
  2767. //use $attempt_num to enable multi-views management (disabled so far)
  2768. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2769. $search = 'AND view_count = ' . $attempt_num;
  2770. }
  2771. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2772. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2773. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2774. "WHERE lp_id = " . $this->get_id() . " " .
  2775. "AND user_id = " . $this->get_user_id() . " " .
  2776. $search .
  2777. " ORDER BY view_count DESC";
  2778. $res = Database::query($sql);
  2779. if (Database :: num_rows($res) > 0) {
  2780. $row = Database :: fetch_array($res);
  2781. $this->lp_view_id = $row['id'];
  2782. } else {
  2783. //no database record, create one
  2784. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2785. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2786. $res = Database::query($sql);
  2787. $id = Database :: insert_id();
  2788. $this->lp_view_id = $id;
  2789. }
  2790. return $this->lp_view_id;
  2791. }
  2792. /**
  2793. * Gets the current view id
  2794. * @return integer View ID (from lp_view)
  2795. */
  2796. function get_view_id() {
  2797. if ($this->debug > 0) {
  2798. error_log('New LP - In learnpath::get_view_id()', 0);
  2799. }
  2800. if (!empty ($this->lp_view_id)) {
  2801. return $this->lp_view_id;
  2802. } else {
  2803. return 0;
  2804. }
  2805. }
  2806. /**
  2807. * Gets the update queue
  2808. * @return array Array containing IDs of items to be updated by JavaScript
  2809. */
  2810. function get_update_queue() {
  2811. if ($this->debug > 0) {
  2812. error_log('New LP - In learnpath::get_update_queue()', 0);
  2813. }
  2814. return $this->update_queue;
  2815. }
  2816. /**
  2817. * Gets the user ID
  2818. * @return integer User ID
  2819. */
  2820. function get_user_id() {
  2821. if ($this->debug > 0) {
  2822. error_log('New LP - In learnpath::get_user_id()', 0);
  2823. }
  2824. if (!empty ($this->user_id)) {
  2825. return $this->user_id;
  2826. } else {
  2827. return false;
  2828. }
  2829. }
  2830. /**
  2831. * Checks if any of the items has an audio element attached
  2832. * @return bool True or false
  2833. */
  2834. function has_audio() {
  2835. if ($this->debug > 1) {
  2836. error_log('New LP - In learnpath::has_audio()', 0);
  2837. }
  2838. $has = false;
  2839. foreach ($this->items as $i => $item) {
  2840. if (!empty ($this->items[$i]->audio)) {
  2841. $has = true;
  2842. break;
  2843. }
  2844. }
  2845. return $has;
  2846. }
  2847. /**
  2848. * Logs a message into a file
  2849. * @param string Message to log
  2850. * @return boolean True on success, false on error or if msg empty
  2851. */
  2852. function log($msg) {
  2853. if ($this->debug > 0) {
  2854. error_log('New LP - In learnpath::log()', 0);
  2855. }
  2856. //TODO
  2857. $this->error .= $msg . "\n";
  2858. return true;
  2859. }
  2860. /**
  2861. * Moves an item up and down at its level
  2862. * @param integer Item to move up and down
  2863. * @param string Direction 'up' or 'down'
  2864. * @return integer New display order, or false on error
  2865. */
  2866. function move_item($id, $direction) {
  2867. if ($this->debug > 0) {
  2868. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2869. }
  2870. if (empty ($id) or empty ($direction)) {
  2871. return false;
  2872. }
  2873. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2874. $sql_sel = "
  2875. SELECT *
  2876. FROM " . $tbl_lp_item . "
  2877. WHERE id = " . $id;
  2878. $res_sel = Database::query($sql_sel);
  2879. //check if elem exists
  2880. if (Database :: num_rows($res_sel) < 1) {
  2881. return false;
  2882. }
  2883. //gather data
  2884. $row = Database :: fetch_array($res_sel);
  2885. $previous = $row['previous_item_id'];
  2886. $next = $row['next_item_id'];
  2887. $display = $row['display_order'];
  2888. $parent = $row['parent_item_id'];
  2889. $lp = $row['lp_id'];
  2890. //update the item (switch with previous/next one)
  2891. switch ($direction) {
  2892. case 'up' :
  2893. if ($this->debug > 2) {
  2894. error_log('Movement up detected', 0);
  2895. }
  2896. if ($display <= 1) { /*do nothing*/
  2897. } else {
  2898. $sql_sel2 = "SELECT *
  2899. FROM $tbl_lp_item
  2900. WHERE id = $previous";
  2901. if ($this->debug > 2) {
  2902. error_log('Selecting previous: ' . $sql_sel2, 0);
  2903. }
  2904. $res_sel2 = Database::query($sql_sel2);
  2905. if (Database :: num_rows($res_sel2) < 1) {
  2906. $previous_previous = 0;
  2907. }
  2908. //gather data
  2909. $row2 = Database :: fetch_array($res_sel2);
  2910. $previous_previous = $row2['previous_item_id'];
  2911. //update previous_previous item (switch "next" with current)
  2912. if ($previous_previous != 0) {
  2913. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2914. if ($this->debug > 2) {
  2915. error_log($sql_upd2, 0);
  2916. }
  2917. $res_upd2 = Database::query($sql_upd2);
  2918. }
  2919. //update previous item (switch with current)
  2920. if ($previous != 0) {
  2921. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2922. if ($this->debug > 2) {
  2923. error_log($sql_upd2, 0);
  2924. }
  2925. $res_upd2 = Database::query($sql_upd2);
  2926. }
  2927. //update current item (switch with previous)
  2928. if ($id != 0) {
  2929. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2930. if ($this->debug > 2) {
  2931. error_log($sql_upd2, 0);
  2932. }
  2933. $res_upd2 = Database::query($sql_upd2);
  2934. }
  2935. //update next item (new previous item)
  2936. if ($next != 0) {
  2937. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2938. if ($this->debug > 2) {
  2939. error_log($sql_upd2, 0);
  2940. }
  2941. $res_upd2 = Database::query($sql_upd2);
  2942. }
  2943. $display = $display -1;
  2944. }
  2945. break;
  2946. case 'down' :
  2947. if ($this->debug > 2) {
  2948. error_log('Movement down detected', 0);
  2949. }
  2950. if ($next == 0) { /*do nothing*/
  2951. } else {
  2952. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2953. if ($this->debug > 2) {
  2954. error_log('Selecting next: ' . $sql_sel2, 0);
  2955. }
  2956. $res_sel2 = Database::query($sql_sel2);
  2957. if (Database :: num_rows($res_sel2) < 1) {
  2958. $next_next = 0;
  2959. }
  2960. //gather data
  2961. $row2 = Database :: fetch_array($res_sel2);
  2962. $next_next = $row2['next_item_id'];
  2963. //update previous item (switch with current)
  2964. if ($previous != 0) {
  2965. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2966. $res_upd2 = Database::query($sql_upd2);
  2967. }
  2968. //update current item (switch with previous)
  2969. if ($id != 0) {
  2970. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2971. $res_upd2 = Database::query($sql_upd2);
  2972. }
  2973. //update next item (new previous item)
  2974. if ($next != 0) {
  2975. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2976. $res_upd2 = Database::query($sql_upd2);
  2977. }
  2978. //update next_next item (switch "previous" with current)
  2979. if ($next_next != 0) {
  2980. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2981. $res_upd2 = Database::query($sql_upd2);
  2982. }
  2983. $display = $display +1;
  2984. }
  2985. break;
  2986. default :
  2987. return false;
  2988. }
  2989. return $display;
  2990. }
  2991. /**
  2992. * Move a learnpath up (display_order)
  2993. * @param integer Learnpath ID
  2994. */
  2995. function move_up($lp_id) {
  2996. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2997. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2998. $res = Database::query($sql);
  2999. if ($res === false)
  3000. return false;
  3001. $lps = array ();
  3002. $lp_order = array ();
  3003. $num = Database :: num_rows($res);
  3004. //first check the order is correct, globally (might be wrong because
  3005. //of versions < 1.8.4)
  3006. if ($num > 0) {
  3007. $i = 1;
  3008. while ($row = Database :: fetch_array($res)) {
  3009. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3010. $need_fix = true;
  3011. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3012. $res_u = Database::query($sql_u);
  3013. }
  3014. $row['display_order'] = $i;
  3015. $lps[$row['id']] = $row;
  3016. $lp_order[$i] = $row['id'];
  3017. $i++;
  3018. }
  3019. }
  3020. if ($num > 1) //if there's only one element, no need to sort
  3021. {
  3022. $order = $lps[$lp_id]['display_order'];
  3023. if ($order > 1) //if it's the first element, no need to move up
  3024. {
  3025. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order -1];
  3026. $res_u1 = Database::query($sql_u1);
  3027. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order -1) . " WHERE id = " . $lp_id;
  3028. $res_u2 = Database::query($sql_u2);
  3029. }
  3030. }
  3031. }
  3032. /**
  3033. * Move a learnpath down (display_order)
  3034. * @param integer Learnpath ID
  3035. */
  3036. function move_down($lp_id) {
  3037. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3038. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3039. $res = Database::query($sql);
  3040. if ($res === false)
  3041. return false;
  3042. $lps = array ();
  3043. $lp_order = array ();
  3044. $num = Database :: num_rows($res);
  3045. $max = 0;
  3046. //first check the order is correct, globally (might be wrong because
  3047. //of versions < 1.8.4)
  3048. if ($num > 0) {
  3049. $i = 1;
  3050. while ($row = Database :: fetch_array($res)) {
  3051. $max = $i;
  3052. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3053. $need_fix = true;
  3054. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3055. $res_u = Database::query($sql_u);
  3056. }
  3057. $row['display_order'] = $i;
  3058. $lps[$row['id']] = $row;
  3059. $lp_order[$i] = $row['id'];
  3060. $i++;
  3061. }
  3062. }
  3063. if ($num > 1) //if there's only one element, no need to sort
  3064. {
  3065. $order = $lps[$lp_id]['display_order'];
  3066. if ($order < $max) //if it's the first element, no need to move up
  3067. {
  3068. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order +1];
  3069. $res_u1 = Database::query($sql_u1);
  3070. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order +1) . " WHERE id = " . $lp_id;
  3071. $res_u2 = Database::query($sql_u2);
  3072. }
  3073. }
  3074. }
  3075. /**
  3076. * Updates learnpath attributes to point to the next element
  3077. * The last part is similar to set_current_item but processing the other way around
  3078. */
  3079. function next() {
  3080. if ($this->debug > 0) {
  3081. error_log('New LP - In learnpath::next()', 0);
  3082. }
  3083. $this->last = $this->get_current_item_id();
  3084. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3085. $this->autocomplete_parents($this->last);
  3086. $new_index = $this->get_next_index();
  3087. if ($this->debug > 2) {
  3088. error_log('New LP - New index: ' . $new_index, 0);
  3089. }
  3090. $this->index = $new_index;
  3091. if ($this->debug > 2) {
  3092. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3093. }
  3094. $this->current = $this->ordered_items[$new_index];
  3095. if ($this->debug > 2) {
  3096. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3097. }
  3098. }
  3099. /**
  3100. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3101. * class, this might be redefined to allow several behaviours depending on the document type.
  3102. * @param integer Resource ID
  3103. * @return boolean True on success, false otherwise
  3104. */
  3105. function open($id) {
  3106. if ($this->debug > 0) {
  3107. error_log('New LP - In learnpath::open()', 0);
  3108. }
  3109. //TODO
  3110. //set the current resource attribute to this resource
  3111. //switch on element type (redefine in child class?)
  3112. //set status for this item to "opened"
  3113. //start timer
  3114. //initialise score
  3115. $this->index = 0; //or = the last item seen (see $this->last)
  3116. }
  3117. /**
  3118. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3119. * and the prerequisite string on error.
  3120. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3121. * @param integer Optional item ID. If none given, uses the current open item.
  3122. * @return boolean True if prerequisites are matched, false otherwise
  3123. * @return string Empty string if true returned, prerequisites string otherwise.
  3124. */
  3125. function prerequisites_match($item = null) {
  3126. if ($this->debug > 0) {
  3127. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3128. }
  3129. if (empty ($item)) {
  3130. $item = $this->current;
  3131. }
  3132. if (is_object($this->items[$item])) {
  3133. $prereq_string = $this->items[$item]->get_prereq_string();
  3134. if (empty ($prereq_string)) {
  3135. return true;
  3136. }
  3137. //clean spaces
  3138. $prereq_string = str_replace(' ', '', $prereq_string);
  3139. if ($this->debug > 0) {
  3140. error_log('Found prereq_string: ' . $prereq_string, 0);
  3141. }
  3142. //now send to the parse_prereq() function that will check this component's prerequisites
  3143. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3144. if ($result === false) {
  3145. $this->set_error_msg($this->items[$item]->prereq_alert);
  3146. }
  3147. } else {
  3148. $result = true;
  3149. if ($this->debug > 1) {
  3150. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3151. }
  3152. }
  3153. if ($this->debug > 1) {
  3154. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3155. }
  3156. return $result;
  3157. }
  3158. /**
  3159. * Updates learnpath attributes to point to the previous element
  3160. * The last part is similar to set_current_item but processing the other way around
  3161. */
  3162. function previous() {
  3163. if ($this->debug > 0) {
  3164. error_log('New LP - In learnpath::previous()', 0);
  3165. }
  3166. $this->last = $this->get_current_item_id();
  3167. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3168. $this->autocomplete_parents($this->last);
  3169. $new_index = $this->get_previous_index();
  3170. $this->index = $new_index;
  3171. $this->current = $this->ordered_items[$new_index];
  3172. }
  3173. /**
  3174. * Publishes a learnpath. This basically means show or hide the learnpath
  3175. * to normal users.
  3176. * Can be used as abstract
  3177. * @param integer Learnpath ID
  3178. * @param string New visibility
  3179. */
  3180. function toggle_visibility($lp_id, $set_visibility = 1) {
  3181. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  3182. $action = 'visible';
  3183. if ($set_visibility != 1) {
  3184. $action = 'invisible';
  3185. }
  3186. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3187. }
  3188. /**
  3189. * Publishes a learnpath. This basically means show or hide the learnpath
  3190. * on the course homepage
  3191. * Can be used as abstract
  3192. * @param integer Learnpath ID
  3193. * @param string New visibility
  3194. */
  3195. function toggle_publish($lp_id, $set_visibility = 'v') {
  3196. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  3197. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3198. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3199. $result = Database::query($sql);
  3200. $row = Database :: fetch_array($result);
  3201. $name = domesticate($row['name']);
  3202. if ($set_visibility == 'i') {
  3203. $s = $name . " " . get_lang('_no_published');
  3204. $dialogBox = $s;
  3205. $v = 0;
  3206. }
  3207. if ($set_visibility == 'v') {
  3208. $s = $name . " " . get_lang('_published');
  3209. $dialogBox = $s;
  3210. $v = 1;
  3211. }
  3212. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3213. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
  3214. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  3215. $result = Database::query($sql);
  3216. $num = Database :: num_rows($result);
  3217. $row2 = Database :: fetch_array($result);
  3218. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  3219. if (($set_visibility == 'i') && ($num > 0)) {
  3220. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  3221. }
  3222. elseif (($set_visibility == 'v') && ($num == 0)) {
  3223. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
  3224. } else {
  3225. //parameter and database incompatible, do nothing
  3226. }
  3227. $result = Database::query($sql);
  3228. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3229. }
  3230. /**
  3231. * Restart the whole learnpath. Return the URL of the first element.
  3232. * Make sure the results are saved with anoter method. This method should probably be
  3233. * redefined in children classes.
  3234. * To use a similar method statically, use the create_new_attempt() method
  3235. * @return string URL to load in the viewer
  3236. */
  3237. function restart() {
  3238. if ($this->debug > 0) {
  3239. error_log('New LP - In learnpath::restart()', 0);
  3240. }
  3241. //TODO
  3242. //call autosave method to save the current progress
  3243. //$this->index = 0;
  3244. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3245. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  3246. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ")";
  3247. if ($this->debug > 2) {
  3248. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3249. }
  3250. $res = Database::query($sql);
  3251. if ($view_id = Database :: insert_id($res)) {
  3252. $this->lp_view_id = $view_id;
  3253. $this->attempt = $this->attempt + 1;
  3254. } else {
  3255. $this->error = 'Could not insert into item_view table...';
  3256. return false;
  3257. }
  3258. $this->autocomplete_parents($this->current);
  3259. foreach ($this->items as $index => $dummy) {
  3260. $this->items[$index]->restart();
  3261. $this->items[$index]->set_lp_view($this->lp_view_id);
  3262. }
  3263. $this->first();
  3264. return true;
  3265. }
  3266. /**
  3267. * Saves the current item
  3268. * @return boolean
  3269. */
  3270. function save_current() {
  3271. if ($this->debug > 0) {
  3272. error_log('New LP - In learnpath::save_current()', 0);
  3273. }
  3274. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3275. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3276. if ($this->debug > 2) {
  3277. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3278. }
  3279. if ($this->debug > 2) {
  3280. error_log('' . print_r($this->items, true), 0);
  3281. }
  3282. if (is_object($this->items[$this->current])) {
  3283. //$res = $this->items[$this->current]->save(false);
  3284. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3285. $this->autocomplete_parents($this->current);
  3286. $status = $this->items[$this->current]->get_status();
  3287. $this->append_message('new_item_status: ' . $status);
  3288. $this->update_queue[$this->current] = $status;
  3289. return $res;
  3290. }
  3291. return false;
  3292. }
  3293. /**
  3294. * Saves the given item
  3295. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3296. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3297. * @return boolean
  3298. */
  3299. function save_item($item_id = null, $from_outside = true) {
  3300. if ($this->debug > 0) {
  3301. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3302. }
  3303. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3304. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3305. if (empty ($item_id)) {
  3306. $item_id = $this->escape_string($_REQUEST['id']);
  3307. }
  3308. if (empty ($item_id)) {
  3309. $item_id = $this->get_current_item_id();
  3310. }
  3311. if ($this->debug > 2) {
  3312. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3313. }
  3314. if (is_object($this->items[$item_id])) {
  3315. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3316. //$res = $this->items[$item_id]->save($from_outside);
  3317. $this->autocomplete_parents($item_id);
  3318. $status = $this->items[$item_id]->get_status();
  3319. $this->append_message('new_item_status: ' . $status);
  3320. $this->update_queue[$item_id] = $status;
  3321. return $res;
  3322. }
  3323. return false;
  3324. }
  3325. /**
  3326. * Saves the last item seen's ID only in case
  3327. */
  3328. function save_last()
  3329. {
  3330. if ($this->debug > 0) {
  3331. error_log('New LP - In learnpath::save_last()', 0);
  3332. }
  3333. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3334. if (isset ($this->current)) {
  3335. if ($this->debug > 2) {
  3336. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3337. }
  3338. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3339. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id();
  3340. if ($this->debug > 2) {
  3341. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3342. }
  3343. $res = Database::query($sql);
  3344. }
  3345. //save progress
  3346. list ($progress, $text) = $this->get_progress_bar_text('%');
  3347. if ($progress >= 0 AND $progress <= 100) {
  3348. $progress = (int) $progress;
  3349. $sql = "UPDATE $table SET progress = $progress " .
  3350. "WHERE lp_id = " . $this->get_id() . " AND " .
  3351. "user_id = " . $this->get_user_id();
  3352. $res = Database::query($sql); //ignore errors as some tables might not have the progress field just yet
  3353. $this->progress_db = $progress;
  3354. }
  3355. }
  3356. /**
  3357. * Sets the current item ID (checks if valid and authorized first)
  3358. * @param integer New item ID. If not given or not authorized, defaults to current
  3359. */
  3360. function set_current_item($item_id = null) {
  3361. if ($this->debug > 0) {
  3362. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3363. }
  3364. if (empty ($item_id)) {
  3365. if ($this->debug > 2) {
  3366. error_log('New LP - No new current item given, ignore...', 0);
  3367. }
  3368. //do nothing
  3369. } else {
  3370. if ($this->debug > 2) {
  3371. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3372. }
  3373. if (is_numeric($item_id)) {
  3374. $item_id = $this->escape_string($item_id);
  3375. //TODO check in database here
  3376. $this->last = $this->current;
  3377. $this->current = $item_id;
  3378. //TODO update $this->index as well
  3379. foreach ($this->ordered_items as $index => $item) {
  3380. if ($item == $this->current) {
  3381. $this->index = $index;
  3382. break;
  3383. }
  3384. }
  3385. if ($this->debug > 2) {
  3386. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3387. }
  3388. } else {
  3389. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3390. }
  3391. }
  3392. }
  3393. /**
  3394. * Sets the encoding
  3395. * @param string New encoding
  3396. */
  3397. function set_encoding($enc = 'ISO-8859-15') {
  3398. if ($this->debug > 0) {
  3399. error_log('New LP - In learnpath::set_encoding()', 0);
  3400. }
  3401. $enc = strtoupper($enc);
  3402. $encodings = array (
  3403. 'UTF-8',
  3404. 'ISO-8859-1',
  3405. 'ISO-8859-15',
  3406. 'cp1251',
  3407. 'cp1252',
  3408. 'KOI8-R',
  3409. 'BIG5',
  3410. 'GB2312',
  3411. 'Shift_JIS',
  3412. 'EUC-JP',
  3413. ''
  3414. );
  3415. if (in_array($enc, $encodings)) {
  3416. $lp = $this->get_id();
  3417. if ($lp != 0) {
  3418. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3419. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3420. $res = Database::query($sql);
  3421. return $res;
  3422. }
  3423. }
  3424. return false;
  3425. }
  3426. /**
  3427. * Sets the JS lib setting in the database directly.
  3428. * This is the JavaScript library file this lp needs to load on startup
  3429. * @param string Proximity setting
  3430. */
  3431. function set_jslib($lib = '') {
  3432. if ($this->debug > 0) {
  3433. error_log('New LP - In learnpath::set_jslib()', 0);
  3434. }
  3435. $lp = $this->get_id();
  3436. if ($lp != 0) {
  3437. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3438. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3439. $res = Database::query($sql);
  3440. return $res;
  3441. } else {
  3442. return false;
  3443. }
  3444. }
  3445. /**
  3446. * Sets the name of the LP maker (publisher) (and save)
  3447. * @param string Optional string giving the new content_maker of this learnpath
  3448. */
  3449. function set_maker($name = '') {
  3450. if ($this->debug > 0) {
  3451. error_log('New LP - In learnpath::set_maker()', 0);
  3452. }
  3453. if (empty ($name))
  3454. return false;
  3455. $this->maker = $this->escape_string($name);
  3456. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3457. $lp_id = $this->get_id();
  3458. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3459. if ($this->debug > 2) {
  3460. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3461. }
  3462. //$res = Database::query($sql);
  3463. $res = Database::query($sql);
  3464. return true;
  3465. }
  3466. /**
  3467. * Sets the name of the current learnpath (and save)
  3468. * @param string Optional string giving the new name of this learnpath
  3469. */
  3470. function set_name($name = '') {
  3471. if ($this->debug > 0) {
  3472. error_log('New LP - In learnpath::set_name()', 0);
  3473. }
  3474. if (empty ($name))
  3475. return false;
  3476. $this->name = $this->escape_string($name);
  3477. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3478. $lp_id = $this->get_id();
  3479. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3480. if ($this->debug > 2) {
  3481. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3482. }
  3483. //$res = Database::query($sql);
  3484. $res = Database::query($sql);
  3485. // if the lp is visible on the homepage, change his name there
  3486. if (Database::affected_rows()) {
  3487. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3488. $sql = 'UPDATE ' . $table . ' SET
  3489. name = "' . $this->name . '"
  3490. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3491. Database::query($sql);
  3492. }
  3493. return true;
  3494. }
  3495. /**
  3496. * Set index specified prefix terms for all items in this path
  3497. * @param string Comma-separated list of terms
  3498. * @param char Xapian term prefix
  3499. * @return boolean False on error, true otherwise
  3500. */
  3501. function set_terms_by_prefix($terms_string, $prefix) {
  3502. if (api_get_setting('search_enabled') !== 'true')
  3503. return FALSE;
  3504. $terms_string = trim($terms_string);
  3505. $terms = explode(',', $terms_string);
  3506. array_walk($terms, 'trim_value');
  3507. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3508. //var_dump($stored_terms);
  3509. //var_dump($terms);
  3510. // don't do anything if no change, verify only at DB, not the search engine
  3511. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3512. return FALSE;
  3513. require_once ('xapian.php'); //TODO try catch every xapian use or make wrappers on api
  3514. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  3515. require_once (api_get_path(LIBRARY_PATH) . 'search/xapian/XapianQuery.php');
  3516. require_once (api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
  3517. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3518. //TODO: make query secure agains XSS : use member attr instead of post var
  3519. $lp_id = intval($_POST['lp_id']);
  3520. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3521. $result = Database::query($sql);
  3522. $di = new DokeosIndexer();
  3523. while ($lp_item = Database :: fetch_array($result)) {
  3524. // get search_did
  3525. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3526. $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';
  3527. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3528. $res = Database::query($sql);
  3529. if (Database::num_rows($res)>0) {
  3530. $se_ref = Database :: fetch_array($res);
  3531. // compare terms
  3532. $doc = $di->get_document($se_ref['search_did']);
  3533. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3534. //var_dump($xapian_terms);
  3535. $xterms = array ();
  3536. foreach ($xapian_terms as $xapian_term)
  3537. $xterms[] = substr($xapian_term['name'], 1);
  3538. $dterms = $terms;
  3539. //var_dump($xterms);
  3540. //var_dump($dterms);
  3541. $missing_terms = array_diff($dterms, $xterms);
  3542. $deprecated_terms = array_diff($xterms, $dterms);
  3543. // save it to search engine
  3544. foreach ($missing_terms as $term) {
  3545. $doc->add_term($prefix . $term, 1);
  3546. }
  3547. foreach ($deprecated_terms as $term) {
  3548. $doc->remove_term($prefix . $term);
  3549. }
  3550. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3551. $di->getDb()->flush();
  3552. }
  3553. }
  3554. return true;
  3555. }
  3556. /**
  3557. * Sets the theme of the LP (local/remote) (and save)
  3558. * @param string Optional string giving the new theme of this learnpath
  3559. * @return bool returns true if theme name is not empty
  3560. */
  3561. function set_theme($name = '') {
  3562. if ($this->debug > 0) {
  3563. error_log('New LP - In learnpath::set_theme()', 0);
  3564. }
  3565. $this->theme = $this->escape_string($name);
  3566. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3567. $lp_id = $this->get_id();
  3568. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3569. if ($this->debug > 2) {
  3570. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3571. }
  3572. //$res = Database::query($sql);
  3573. $res = Database::query($sql);
  3574. return true;
  3575. }
  3576. /**
  3577. * Sets the image of an LP (and save)
  3578. * @param string Optional string giving the new image of this learnpath
  3579. * @return bool returns true if theme name is not empty
  3580. */
  3581. function set_preview_image($name = '') {
  3582. if ($this->debug > 0) {
  3583. error_log('New LP - In learnpath::set_preview_image()', 0);
  3584. }
  3585. $this->preview_image = $this->escape_string($name);
  3586. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3587. $lp_id = $this->get_id();
  3588. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3589. if ($this->debug > 2) {
  3590. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3591. }
  3592. $res = Database::query($sql);
  3593. return true;
  3594. }
  3595. /**
  3596. * Sets the author of a LP (and save)
  3597. * @param string Optional string giving the new author of this learnpath
  3598. * @return bool returns true if author's name is not empty
  3599. */
  3600. function set_author($name = '') {
  3601. if ($this->debug > 0) {
  3602. error_log('New LP - In learnpath::set_author()', 0);
  3603. }
  3604. $this->author = $this->escape_string($name);
  3605. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3606. $lp_id = $this->get_id();
  3607. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3608. if ($this->debug > 2) {
  3609. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3610. }
  3611. $res = Database::query($sql);
  3612. return true;
  3613. }
  3614. /**
  3615. * Sets the location/proximity of the LP (local/remote) (and save)
  3616. * @param string Optional string giving the new location of this learnpath
  3617. */
  3618. function set_proximity($name = '') {
  3619. if ($this->debug > 0) {
  3620. error_log('New LP - In learnpath::set_proximity()', 0);
  3621. }
  3622. if (empty ($name))
  3623. return false;
  3624. $this->proximity = $this->escape_string($name);
  3625. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3626. $lp_id = $this->get_id();
  3627. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3628. if ($this->debug > 2) {
  3629. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3630. }
  3631. //$res = Database::query($sql);
  3632. $res = Database::query($sql);
  3633. return true;
  3634. }
  3635. /**
  3636. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3637. * @param integer DB ID of the item
  3638. */
  3639. function set_previous_item($id) {
  3640. if ($this->debug > 0) {
  3641. error_log('New LP - In learnpath::set_previous_item()', 0);
  3642. }
  3643. $this->last = $id;
  3644. }
  3645. /**
  3646. * Sets the object's error message
  3647. * @param string Error message. If empty, reinits the error string
  3648. * @return void
  3649. */
  3650. function set_error_msg($error = '') {
  3651. if ($this->debug > 0) {
  3652. error_log('New LP - In learnpath::set_error_msg()', 0);
  3653. }
  3654. if (empty ($error)) {
  3655. $this->error = '';
  3656. } else {
  3657. $this->error .= $error;
  3658. }
  3659. }
  3660. /**
  3661. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3662. *
  3663. */
  3664. function start_current_item($allow_new_attempt = false) {
  3665. if ($this->debug > 0) {
  3666. error_log('New LP - In learnpath::start_current_item()', 0);
  3667. }
  3668. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3669. $type = $this->get_type();
  3670. $item_type = $this->items[$this->current]->get_type();
  3671. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3672. $this->items[$this->current]->open($allow_new_attempt);
  3673. $this->autocomplete_parents($this->current);
  3674. $prereq_check = $this->prerequisites_match($this->current);
  3675. $this->items[$this->current]->save(false, $prereq_check);
  3676. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3677. } else {
  3678. //if sco, then it is supposed to have been updated by some other call
  3679. }
  3680. if ($item_type == 'sco') {
  3681. $this->items[$this->current]->restart();
  3682. }
  3683. }
  3684. if ($this->debug > 0) {
  3685. error_log('New LP - End of learnpath::start_current_item()', 0);
  3686. }
  3687. return true;
  3688. }
  3689. /**
  3690. * Stops the processing and counters for the old item (as held in $this->last)
  3691. * @param
  3692. */
  3693. function stop_previous_item() {
  3694. if ($this->debug > 0) {
  3695. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3696. }
  3697. if ($this->last != 0 AND $this->last != $this->current AND is_object($this->items[$this->last])) {
  3698. if ($this->debug > 2) {
  3699. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3700. }
  3701. switch ($this->get_type()) {
  3702. case '3' :
  3703. if ($this->items[$this->last]->get_type() != 'au') {
  3704. if ($this->debug > 2) {
  3705. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3706. }
  3707. $this->items[$this->last]->close();
  3708. //$this->autocomplete_parents($this->last);
  3709. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3710. } else {
  3711. if ($this->debug > 2) {
  3712. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3713. }
  3714. }
  3715. case '2' :
  3716. if ($this->items[$this->last]->get_type() != 'sco') {
  3717. if ($this->debug > 2) {
  3718. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3719. }
  3720. $this->items[$this->last]->close();
  3721. //$this->autocomplete_parents($this->last);
  3722. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3723. } else {
  3724. if ($this->debug > 2) {
  3725. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3726. }
  3727. }
  3728. break;
  3729. case '1' :
  3730. default :
  3731. if ($this->debug > 2) {
  3732. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3733. }
  3734. $this->items[$this->last]->close();
  3735. break;
  3736. }
  3737. } else {
  3738. if ($this->debug > 2) {
  3739. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3740. }
  3741. return false;
  3742. }
  3743. return true;
  3744. }
  3745. /**
  3746. * Updates the default view mode from fullscreen to embedded and inversely
  3747. * @return string The current default view mode ('fullscreen' or 'embedded')
  3748. */
  3749. function update_default_view_mode() {
  3750. if ($this->debug > 0) {
  3751. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3752. }
  3753. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3754. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3755. $res = Database::query($sql);
  3756. if (Database :: num_rows($res) > 0) {
  3757. $row = Database :: fetch_array($res);
  3758. $view_mode = $row['default_view_mod'];
  3759. if ($view_mode == 'fullscreen') {
  3760. $view_mode = 'embedded';
  3761. }
  3762. elseif ($view_mode == 'embedded') {
  3763. $view_mode = 'fullscreen';
  3764. }
  3765. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3766. $res = Database::query($sql);
  3767. $this->mode = $view_mode;
  3768. return $view_mode;
  3769. } else {
  3770. if ($this->debug > 2) {
  3771. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3772. }
  3773. }
  3774. return -1;
  3775. }
  3776. /**
  3777. * Updates the default behaviour about auto-commiting SCORM updates
  3778. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3779. */
  3780. function update_default_scorm_commit() {
  3781. if ($this->debug > 0) {
  3782. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3783. }
  3784. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3785. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3786. $res = Database::query($sql);
  3787. if (Database :: num_rows($res) > 0) {
  3788. $row = Database :: fetch_array($res);
  3789. $force = $row['force_commit'];
  3790. if ($force == 1) {
  3791. $force = 0;
  3792. $force_return = false;
  3793. }
  3794. elseif ($force == 0) {
  3795. $force = 1;
  3796. $force_return = true;
  3797. }
  3798. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3799. $res = Database::query($sql);
  3800. $this->force_commit = $force_return;
  3801. return $force_return;
  3802. } else {
  3803. if ($this->debug > 2) {
  3804. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3805. }
  3806. }
  3807. return -1;
  3808. }
  3809. /**
  3810. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3811. * @return bool True on success, false on failure
  3812. */
  3813. function update_display_order() {
  3814. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3815. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3816. $res = Database::query($sql);
  3817. if ($res === false)
  3818. return false;
  3819. $lps = array ();
  3820. $lp_order = array ();
  3821. $num = Database :: num_rows($res);
  3822. //first check the order is correct, globally (might be wrong because
  3823. //of versions < 1.8.4)
  3824. if ($num > 0) {
  3825. $i = 1;
  3826. while ($row = Database :: fetch_array($res)) {
  3827. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3828. $need_fix = true;
  3829. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3830. $res_u = Database::query($sql_u);
  3831. }
  3832. $i++;
  3833. }
  3834. }
  3835. return true;
  3836. }
  3837. /**
  3838. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3839. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3840. */
  3841. function update_reinit() {
  3842. if ($this->debug > 0) {
  3843. error_log('New LP - In learnpath::update_reinit()', 0);
  3844. }
  3845. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3846. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3847. $res = Database::query($sql);
  3848. if (Database :: num_rows($res) > 0) {
  3849. $row = Database :: fetch_array($res);
  3850. $force = $row['prevent_reinit'];
  3851. if ($force == 1) {
  3852. $force = 0;
  3853. }
  3854. elseif ($force == 0) {
  3855. $force = 1;
  3856. }
  3857. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  3858. $res = Database::query($sql);
  3859. $this->prevent_reinit = $force;
  3860. return $force;
  3861. } else {
  3862. if ($this->debug > 2) {
  3863. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3864. }
  3865. }
  3866. return -1;
  3867. }
  3868. /**
  3869. * Updates the "scorm_debug" value that shows or hide the debug window
  3870. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3871. */
  3872. function update_scorm_debug() {
  3873. if ($this->debug > 0) {
  3874. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  3875. }
  3876. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3877. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3878. $res = Database::query($sql);
  3879. if (Database :: num_rows($res) > 0) {
  3880. $row = Database :: fetch_array($res);
  3881. $force = $row['debug'];
  3882. if ($force == 1) {
  3883. $force = 0;
  3884. }
  3885. elseif ($force == 0) {
  3886. $force = 1;
  3887. }
  3888. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  3889. $res = Database::query($sql);
  3890. $this->scorm_debug = $force;
  3891. return $force;
  3892. } else {
  3893. if ($this->debug > 2) {
  3894. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3895. }
  3896. }
  3897. return -1;
  3898. }
  3899. /**
  3900. * Function that makes a call to the function sort_tree_array and create_tree_array
  3901. *
  3902. * @author Kevin Van Den Haute
  3903. *
  3904. * @param unknown_type $array
  3905. */
  3906. function tree_array($array) {
  3907. if ($this->debug > 1) {
  3908. error_log('New LP - In learnpath::tree_array()', 0);
  3909. }
  3910. $array = $this->sort_tree_array($array);
  3911. $this->create_tree_array($array);
  3912. }
  3913. /**
  3914. * Creates an array with the elements of the learning path tree in it
  3915. *
  3916. * @author Kevin Van Den Haute
  3917. *
  3918. * @param array $array
  3919. * @param int $parent
  3920. * @param int $depth
  3921. * @param array $tmp
  3922. */
  3923. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  3924. if ($this->debug > 1) {
  3925. error_log('New LP - In learnpath::create_tree_array())', 0);
  3926. }
  3927. if (is_array($array)) {
  3928. for ($i = 0; $i < count($array); $i++) {
  3929. if ($array[$i]['parent_item_id'] == $parent) {
  3930. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  3931. $tmp[] = $array[$i]['parent_item_id'];
  3932. $depth++;
  3933. }
  3934. $preq = (empty ($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  3935. $this->arrMenu[] = array (
  3936. 'id' => $array[$i]['id'],
  3937. 'item_type' => $array[$i]['item_type'],
  3938. 'title' => $array[$i]['title'],
  3939. 'path' => $array[$i]['path'],
  3940. 'description' => $array[$i]['description'],
  3941. 'parent_item_id' => $array[$i]['parent_item_id'],
  3942. 'previous_item_id' => $array[$i]['previous_item_id'],
  3943. 'next_item_id' => $array[$i]['next_item_id'],
  3944. 'min_score' => $array[$i]['min_score'],
  3945. 'max_score' => $array[$i]['max_score'],
  3946. 'mastery_score' => $array[$i]['mastery_score'],
  3947. 'display_order' => $array[$i]['display_order'],
  3948. 'prerequisite' => $preq,
  3949. 'depth' => $depth,
  3950. 'audio' => $array[$i]['audio']
  3951. );
  3952. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3953. }
  3954. }
  3955. }
  3956. }
  3957. /**
  3958. * Sorts a multi dimensional array by parent id and display order
  3959. * @author Kevin Van Den Haute
  3960. *
  3961. * @param array $array (array with al the learning path items in it)
  3962. *
  3963. * @return array
  3964. */
  3965. function sort_tree_array($array) {
  3966. foreach ($array as $key => $row) {
  3967. $parent[$key] = $row['parent_item_id'];
  3968. $position[$key] = $row['display_order'];
  3969. }
  3970. if (count($array) > 0)
  3971. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3972. return $array;
  3973. }
  3974. /**
  3975. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3976. * Also the actions for the modules, chapters and documents are in this table.
  3977. *
  3978. * @author Kevin Van Den Haute
  3979. *
  3980. * @param int $lp_id
  3981. *
  3982. * @return string
  3983. */
  3984. function overview() {
  3985. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  3986. $platform_charset = api_get_system_encoding();
  3987. if ($this->debug > 0) {
  3988. error_log('New LP - In learnpath::overview()', 0);
  3989. }
  3990. global $charset, $_course;
  3991. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  3992. $return = '';
  3993. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  3994. $sql = "SELECT * FROM " . $tbl_lp_item . "
  3995. WHERE lp_id = " . $this->lp_id;
  3996. $result = Database::query($sql);
  3997. $arrLP = array ();
  3998. while ($row = Database :: fetch_array($result)) {
  3999. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4000. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4001. $arrLP[] = array (
  4002. 'id' => $row['id'],
  4003. 'item_type' => $row['item_type'],
  4004. 'title' => $row['title'],
  4005. 'path' => $row['path'],
  4006. 'description' => $row['description'],
  4007. 'parent_item_id' => $row['parent_item_id'],
  4008. 'previous_item_id' => $row['previous_item_id'],
  4009. 'next_item_id' => $row['next_item_id'],
  4010. 'max_score' => $row['max_score'],
  4011. 'min_score' => $row['min_score'],
  4012. 'mastery_score' => $row['mastery_score'],
  4013. 'prerequisite' => $row['prerequisite'],
  4014. 'display_order' => $row['display_order'],
  4015. 'audio' => $row['audio']
  4016. );
  4017. }
  4018. $this->tree_array($arrLP);
  4019. $arrLP = $this->arrMenu;
  4020. unset ($this->arrMenu);
  4021. if ($is_allowed_to_edit) {
  4022. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4023. $return .= '<div class="actions">';
  4024. $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>';
  4025. $return .= '<span>' . Display :: return_icon('learnpath_organize_na.gif', get_lang("BasicOverview")) . ' <b>' . get_lang('BasicOverview') . '</b></span>';
  4026. $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');
  4027. $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>';
  4028. $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>';
  4029. $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>';
  4030. $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>';
  4031. $return .= '</div>';
  4032. }
  4033. // we need to start a form when we want to update all the mp3 files
  4034. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4035. $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">';
  4036. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4037. }
  4038. $return .= '<table class="data_table">' . "\n";
  4039. $return .= "\t" . '<tr>' . "\n";
  4040. $return .= "\t" . '<th width="60%">' . get_lang("Title") . '</th>' . "\n";
  4041. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  4042. $return .= "\t" . '<th>' . get_lang("Audio") . '</th>' . "\n";
  4043. $return .= "\t" . '<th>' . get_lang("Move") . '</th>' . "\n";
  4044. $return .= "\t" . '<th>' . get_lang("Actions") . '</th>' . "\n";
  4045. $return .= "\t" . '</tr>' . "\n";
  4046. for ($i = 0; $i < count($arrLP); $i++) {
  4047. $title = $arrLP[$i]['title'];
  4048. if ($arrLP[$i]['description'] == '')
  4049. $arrLP[$i]['description'] = '&nbsp;';
  4050. if (($i % 2) == 0) {
  4051. $oddclass = "row_odd";
  4052. } else {
  4053. $oddclass = "row_even";
  4054. }
  4055. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4056. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4057. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4058. $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";
  4059. } else
  4060. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4061. $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";
  4062. } else {
  4063. //$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";
  4064. $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";
  4065. }
  4066. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4067. // The audio column
  4068. $return .= "\t\t" . '<td align="center">';
  4069. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4070. if (!empty ($arrLP[$i]['audio'])) {
  4071. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4072. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4073. $return .= '<script type="text/javascript">
  4074. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4075. s1.addParam("allowscriptaccess","always");
  4076. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4077. s1.write("container' . $i . '");
  4078. </script>';
  4079. } else {
  4080. $return .= ' - ';
  4081. }
  4082. } else {
  4083. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4084. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4085. if (!empty ($arrLP[$i]['audio'])) {
  4086. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4087. }
  4088. }
  4089. }
  4090. $return .= '</td>' . "\n";
  4091. if ($is_allowed_to_edit) {
  4092. $return .= "\t\t" . '<td align="center">' . "\n";
  4093. if ($arrLP[$i]['previous_item_id'] != 0) {
  4094. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  4095. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4096. $return .= '</a>' . "\n";
  4097. } else
  4098. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4099. if ($arrLP[$i]['next_item_id'] != 0) {
  4100. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  4101. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4102. $return .= '</a>' . "\n";
  4103. } else
  4104. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4105. $return .= "\t\t" . '</td>' . "\n";
  4106. $return .= "\t\t" . '<td align="center">' . "\n";
  4107. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4108. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4109. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4110. $return .= '</a>' . "\n";
  4111. } else {
  4112. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4113. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4114. $return .= '</a>' . "\n";
  4115. }
  4116. $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($title) . '\');">';
  4117. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4118. $return .= '</a>' . "\n";
  4119. $return .= "\t\t" . '</td>' . "\n";
  4120. }
  4121. $return .= "\t" . '</tr>' . "\n";
  4122. }
  4123. if (count($arrLP) == 0) {
  4124. $return .= "\t" . '<tr>' . "\n";
  4125. $return .= "\t\t" . '<td colspan="4">' . get_lang("NoItemsInLp") . '</td>' . "\n";
  4126. $return .= "\t" . '</tr>' . "\n";
  4127. }
  4128. $return .= '</table>' . "\n";
  4129. // we need to close the form when we are updating the mp3 files
  4130. if ($_GET['updateaudio'] == 'true') {
  4131. $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?
  4132. }
  4133. // we need to close the form when we are updating the mp3 files
  4134. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4135. $return .= '</form>';
  4136. }
  4137. return $return;
  4138. }
  4139. /**
  4140. * This function builds the action menu
  4141. *
  4142. * */
  4143. function build_action_menu() {
  4144. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4145. echo '<div class="actions">';
  4146. //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  4147. echo '<span>' . Display :: return_icon('learnpath_build_na.gif', get_lang('Build')) . ' <b>' . get_lang('Build') . '</b></span>';
  4148. 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>';
  4149. 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>';
  4150. Display :: display_icon('i.gif');
  4151. 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>';
  4152. 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>';
  4153. 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>';
  4154. 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>';
  4155. echo '</div>';
  4156. }
  4157. /**
  4158. * This functions builds the LP tree based on data from the database.
  4159. *
  4160. * @return string
  4161. * @uses dtree.js :: necessary javascript for building this tree
  4162. */
  4163. function build_tree() {
  4164. $platform_charset = api_get_system_encoding();
  4165. $return = "<script type=\"text/javascript\">\n";
  4166. $return .= "\tm = new dTree('m');\n\n";
  4167. $return .= "\tm.config.folderLinks = true;\n";
  4168. $return .= "\tm.config.useCookies = true;\n";
  4169. $return .= "\tm.config.useIcons = true;\n";
  4170. $return .= "\tm.config.useLines = true;\n";
  4171. $return .= "\tm.config.useSelection = true;\n";
  4172. $return .= "\tm.config.useStatustext = false;\n\n";
  4173. $menu = 0;
  4174. $parent = '';
  4175. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4176. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4177. $sql = " SELECT * FROM " . $tbl_lp_item . "
  4178. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4179. $result = Database::query($sql);
  4180. $arrLP = array ();
  4181. while ($row = Database :: fetch_array($result)) {
  4182. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4183. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4184. //$row['title'] = Security :: remove_XSS($row['title']);
  4185. $arrLP[] = array (
  4186. 'id' => $row['id'],
  4187. 'item_type' => $row['item_type'],
  4188. 'title' => $row['title'],
  4189. 'path' => $row['path'],
  4190. 'description' => $row['description'],
  4191. 'parent_item_id' => $row['parent_item_id'],
  4192. 'previous_item_id' => $row['previous_item_id'],
  4193. 'next_item_id' => $row['next_item_id'],
  4194. 'max_score' => $row['max_score'],
  4195. 'min_score' => $row['min_score'],
  4196. 'mastery_score' => $row['mastery_score'],
  4197. 'display_order' => $row['display_order']
  4198. );
  4199. }
  4200. $this->tree_array($arrLP);
  4201. $arrLP = $this->arrMenu;
  4202. unset ($this->arrMenu);
  4203. $title = '';
  4204. for ($i = 0; $i < count($arrLP); $i++) {
  4205. $title = addslashes($arrLP[$i]['title']);
  4206. $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;
  4207. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4208. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4209. $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";
  4210. } else
  4211. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4212. $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";
  4213. } else {
  4214. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4215. }
  4216. if ($menu < $arrLP[$i]['id'])
  4217. $menu = $arrLP[$i]['id'];
  4218. }
  4219. $return .= "\n\tdocument.write(m);\n";
  4220. $return .= "\t if(!m.selectedNode) m.s(1);";
  4221. $return .= "</script>\n";
  4222. return $return;
  4223. }
  4224. /**
  4225. * Create a new document //still needs some finetuning
  4226. *
  4227. * @param array $_course
  4228. * @return string
  4229. */
  4230. function create_document($_course) {
  4231. global $charset;
  4232. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4233. if (strstr($dir, '..'))
  4234. $dir = '/';
  4235. if ($dir[0] == '.')
  4236. $dir = substr($dir, 1);
  4237. if ($dir[0] != '/')
  4238. $dir = '/' . $dir;
  4239. if ($dir[strlen($dir) - 1] != '/')
  4240. $dir .= '/';
  4241. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4242. if (!is_dir($filepath)) {
  4243. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4244. $dir = '/';
  4245. }
  4246. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  4247. //is already escaped twice when it gets here
  4248. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4249. $title = disable_dangerous_file($title);
  4250. $filename = $title;
  4251. $content = $_POST['content_lp'];
  4252. $tmp_filename = $filename;
  4253. $i = 0;
  4254. while (file_exists($filepath . $tmp_filename . '.html'))
  4255. $tmp_filename = $filename . '_' . ++ $i;
  4256. $filename = $tmp_filename . '.html';
  4257. $content = stripslashes(text_filter($content));
  4258. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH) . 'courses/', $content);
  4259. // change the path of mp3 to absolute
  4260. // first regexp deals with ../../../ urls
  4261. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4262. //second regexp deals with audio/ urls
  4263. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4264. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  4265. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4266. if (!file_exists($filepath . $filename)) {
  4267. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4268. fputs($fp, $content);
  4269. fclose($fp);
  4270. $file_size = filesize($filepath . $filename);
  4271. $save_file_path = $dir . $filename;
  4272. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4273. if ($document_id) {
  4274. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(),null,null,null,null,api_get_session_id());
  4275. //update parent folders
  4276. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4277. $new_comment = (isset ($_POST['comment'])) ? trim($_POST['comment']) : '';
  4278. $new_title = (isset ($_POST['title'])) ? trim($_POST['title']) : '';
  4279. if ($new_comment || $new_title) {
  4280. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4281. $ct = '';
  4282. if ($new_comment)
  4283. $ct .= ", comment='" . $new_comment . "'";
  4284. if ($new_title)
  4285. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4286. $sql_update = "
  4287. UPDATE " . $tbl_doc . "
  4288. SET " . substr($ct, 1) . "
  4289. WHERE id = " . $document_id;
  4290. Database::query($sql_update);
  4291. }
  4292. }
  4293. return $document_id;
  4294. }
  4295. }
  4296. }
  4297. /**
  4298. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4299. *
  4300. * @param array $_course array
  4301. * @return void
  4302. */
  4303. function edit_document($_course) {
  4304. global $_configuration;
  4305. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4306. if (strstr($dir, '..'))
  4307. $dir = '/';
  4308. if ($dir[0] == '.')
  4309. $dir = substr($dir, 1);
  4310. if ($dir[0] != '/')
  4311. $dir = '/' . $dir;
  4312. if ($dir[strlen($dir) - 1] != '/')
  4313. $dir .= '/';
  4314. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4315. if (!is_dir($filepath)) {
  4316. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4317. $dir = '/';
  4318. }
  4319. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4320. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4321. $sql = "SELECT path
  4322. FROM " . $table_doc . "
  4323. WHERE id = " . Database::escape_string($_POST['path']);
  4324. $res = Database::query($sql);
  4325. $row = Database :: fetch_array($res);
  4326. $content = stripslashes($_POST['content_lp']);
  4327. $file = $filepath . $row['path'];
  4328. if ($fp = @ fopen($file, 'w')) {
  4329. $content = text_filter($content);
  4330. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'] . '/courses/', $content);
  4331. // change the path of mp3 to absolute
  4332. // first regexp deals with ../../../ urls
  4333. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4334. //second regexp deals with audio/ urls
  4335. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4336. fputs($fp, $content);
  4337. fclose($fp);
  4338. }
  4339. }
  4340. }
  4341. /**
  4342. * Displays the selected item, with a panel for manipulating the item
  4343. *
  4344. * @param int $item_id
  4345. * @param string $msg
  4346. * @return string
  4347. */
  4348. function display_item($item_id, $iframe = true, $msg = '') {
  4349. global $_course; //will disappear
  4350. $return = '';
  4351. if (is_numeric($item_id)) {
  4352. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4353. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4354. $sql = "SELECT lp.*
  4355. FROM " . $tbl_lp_item . " as lp
  4356. WHERE lp.id = " . Database :: escape_string($item_id);
  4357. $result = Database::query($sql);
  4358. while ($row = Database :: fetch_array($result)) {
  4359. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4360. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4361. $return .= '<div style="padding:10px;">';
  4362. if ($msg != '')
  4363. $return .= $msg;
  4364. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], api_get_system_encoding(), $this->encoding));
  4365. //$row['title'] = Security::remove_XSS(api_convert_encoding($row['title'], $this->encoding, api_get_system_encoding()));
  4366. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4367. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4368. //$return .= '<hr />';
  4369. if ($row['item_type'] == TOOL_DOCUMENT) {
  4370. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4371. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4372. $result = Database::query($sql_doc);
  4373. $path_file = Database :: result($result, 0, 0);
  4374. $path_parts = pathinfo($path_file);
  4375. if (in_array($path_parts['extension'], array (
  4376. 'html',
  4377. 'txt',
  4378. 'png',
  4379. 'jpg',
  4380. 'JPG',
  4381. 'jpeg',
  4382. 'JPEG',
  4383. 'gif',
  4384. 'swf'
  4385. ))) {
  4386. $return .= $this->display_document($row['path'], true, true);
  4387. }
  4388. }
  4389. $return .= '</div>';
  4390. }
  4391. }
  4392. return $return;
  4393. }
  4394. /**
  4395. * Shows the needed forms for editing a specific item
  4396. *
  4397. * @param int $item_id
  4398. * @return string
  4399. */
  4400. function display_edit_item($item_id) {
  4401. global $_course; //will disappear
  4402. $return = '';
  4403. if (is_numeric($item_id)) {
  4404. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4405. $sql = "SELECT *
  4406. FROM " . $tbl_lp_item . "
  4407. WHERE id = " . Database :: escape_string($item_id);
  4408. $res = Database::query($sql);
  4409. $row = Database :: fetch_array($res);
  4410. switch ($row['item_type']) {
  4411. case 'dokeos_chapter' :
  4412. case 'dir' :
  4413. case 'asset' :
  4414. case 'sco' :
  4415. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4416. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4417. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', 'edit', $item_id, $row);
  4418. } else {
  4419. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', $row);
  4420. }
  4421. break;
  4422. case TOOL_DOCUMENT :
  4423. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4424. $sql_step = " SELECT lp.*, doc.path as dir
  4425. FROM " . $tbl_lp_item . " as lp
  4426. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4427. WHERE lp.id = " . Database :: escape_string($item_id);
  4428. $res_step = Database::query($sql_step);
  4429. $row_step = Database :: fetch_array($res_step);
  4430. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4431. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4432. break;
  4433. case TOOL_LINK :
  4434. $link_id = (string) $row['path'];
  4435. if (ctype_digit($link_id)) {
  4436. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4437. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4438. $res_link = Database::query($sql_select);
  4439. $row_link = Database :: fetch_array($res_link);
  4440. if (is_array($row_link)) {
  4441. $row['url'] = $row_link['url'];
  4442. }
  4443. }
  4444. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4445. $return .= $this->display_link_form('edit', $item_id, $row);
  4446. break;
  4447. case 'dokeos_module' :
  4448. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4449. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4450. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule") . ' :', 'edit', $item_id, $row);
  4451. } else {
  4452. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule") . ' :', $row);
  4453. }
  4454. break;
  4455. case TOOL_QUIZ :
  4456. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4457. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4458. break;
  4459. case TOOL_HOTPOTATOES :
  4460. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4461. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4462. break;
  4463. case TOOL_STUDENTPUBLICATION :
  4464. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4465. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4466. break;
  4467. case TOOL_FORUM :
  4468. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4469. $return .= $this->display_forum_form('edit', $item_id, $row);
  4470. break;
  4471. case TOOL_THREAD :
  4472. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4473. $return .= $this->display_thread_form('edit', $item_id, $row);
  4474. break;
  4475. }
  4476. }
  4477. return $return;
  4478. }
  4479. /**
  4480. * Function that displays a list with al the resources that could be added to the learning path
  4481. *
  4482. * @return string
  4483. */
  4484. function display_resources() {
  4485. global $_course; //TODO: don't use globals
  4486. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4487. $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.
  4488. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4489. $return .= '<div class="sectioncomment">';
  4490. /* get all the docs */
  4491. $return .= $this->get_documents();
  4492. /* get all the exercises */
  4493. $return .= $this->get_exercises();
  4494. /* get all the links */
  4495. $return .= $this->get_links();
  4496. /* get al the student publications */
  4497. $return .= $this->get_student_publications();
  4498. /* get al the forums */
  4499. $return .= $this->get_forums();
  4500. $return .= '</div>';
  4501. return $return;
  4502. }
  4503. /**
  4504. * Returns the extension of a document
  4505. *
  4506. * @param unknown_type $filename
  4507. * @return unknown
  4508. */
  4509. function get_extension($filename) {
  4510. $explode = explode('.', $filename);
  4511. return $explode[count($explode) - 1];
  4512. }
  4513. /**
  4514. * Displays a document by id
  4515. *
  4516. * @param unknown_type $id
  4517. * @return unknown
  4518. */
  4519. function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4520. global $_course; //temporary
  4521. $return = '';
  4522. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4523. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4524. WHERE id = " . $id;
  4525. $res_doc = Database::query($sql_doc);
  4526. $row_doc = Database :: fetch_array($res_doc);
  4527. //if($show_title)
  4528. //$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>';
  4529. //TODO: add a path filter
  4530. if ($iframe) {
  4531. $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>';
  4532. } else {
  4533. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4534. }
  4535. return $return;
  4536. }
  4537. /**
  4538. * Return HTML form to add/edit a quiz
  4539. *
  4540. * @param string Action (add/edit)
  4541. * @param integer Item ID if already exists
  4542. * @param mixed Extra information (quiz ID if integer)
  4543. * @return string HTML form
  4544. */
  4545. function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4546. global $charset;
  4547. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4548. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4549. if ($id != 0 && is_array($extra_info)) {
  4550. $item_title = stripslashes($extra_info['title']);
  4551. $item_description = stripslashes($extra_info['description']);
  4552. }
  4553. elseif (is_numeric($extra_info)) {
  4554. $sql_quiz = "
  4555. SELECT
  4556. title,
  4557. description
  4558. FROM " . $tbl_quiz . "
  4559. WHERE id = " . $extra_info;
  4560. $result = Database::query($sql_quiz);
  4561. $row = Database :: fetch_array($result);
  4562. $item_title = $row['title'];
  4563. $item_description = $row['description'];
  4564. } else {
  4565. $item_title = '';
  4566. $item_description = '';
  4567. }
  4568. $return = ' <div class="row">
  4569. <div class="form_header">';
  4570. if ($id != 0 && is_array($extra_info))
  4571. $parent = $extra_info['parent_item_id'];
  4572. else
  4573. $parent = 0;
  4574. $sql = "
  4575. SELECT *
  4576. FROM " . $tbl_lp_item . "
  4577. WHERE
  4578. lp_id = " . $this->lp_id;
  4579. $result = Database::query($sql);
  4580. $arrLP = array ();
  4581. while ($row = Database :: fetch_array($result)) {
  4582. $arrLP[] = array (
  4583. 'id' => $row['id'],
  4584. 'item_type' => $row['item_type'],
  4585. 'title' => $row['title'],
  4586. 'path' => $row['path'],
  4587. 'description' => $row['description'],
  4588. 'parent_item_id' => $row['parent_item_id'],
  4589. 'previous_item_id' => $row['previous_item_id'],
  4590. 'next_item_id' => $row['next_item_id'],
  4591. 'display_order' => $row['display_order'],
  4592. 'max_score' => $row['max_score'],
  4593. 'min_score' => $row['min_score'],
  4594. 'mastery_score' => $row['mastery_score'],
  4595. 'prerequisite' => $row['prerequisite'],
  4596. 'max_time_allowed' => $row['max_time_allowed']
  4597. );
  4598. }
  4599. $this->tree_array($arrLP);
  4600. $arrLP = $this->arrMenu;
  4601. unset ($this->arrMenu);
  4602. if ($action == 'add')
  4603. $return .= get_lang("CreateTheExercise") . '&nbsp;:' . "\n";
  4604. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentExercise") . '&nbsp;:' . "\n";
  4605. else
  4606. $return .= get_lang("EditCurrentExecice") . '&nbsp;:' . "\n";
  4607. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4608. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4609. }
  4610. $return .= ' </div>
  4611. </div>';
  4612. $return .= '<div class="sectioncomment">';
  4613. $return .= '<form method="POST">' . "\n";
  4614. $return .= "\t" . '<table class="lp_form">' . "\n";
  4615. if ($action != 'move') {
  4616. $return .= "\t\t" . '<tr>' . "\n";
  4617. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4618. $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";
  4619. $return .= "\t\t" . '</tr>' . "\n";
  4620. }
  4621. $return .= "\t\t" . '<tr>' . "\n";
  4622. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4623. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4624. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4625. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4626. $arrHide = array (
  4627. $id
  4628. );
  4629. $parent_item_id = $_SESSION['parent_item_id'];
  4630. for ($i = 0; $i < count($arrLP); $i++) {
  4631. if ($action != 'add') {
  4632. 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)) {
  4633. $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>';
  4634. } else {
  4635. $arrHide[] = $arrLP[$i]['id'];
  4636. }
  4637. } else {
  4638. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4639. $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>';
  4640. }
  4641. }
  4642. if (is_array($arrLP)) {
  4643. reset($arrLP);
  4644. }
  4645. $return .= "\t\t\t\t" . '</select>';
  4646. $return .= "\t\t\t" . '</td>' . "\n";
  4647. $return .= "\t\t" . '</tr>' . "\n";
  4648. $return .= "\t\t" . '<tr>' . "\n";
  4649. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4650. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4651. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4652. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4653. for ($i = 0; $i < count($arrLP); $i++) {
  4654. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4655. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4656. $selected = 'selected="selected" ';
  4657. elseif ($action == 'add') $selected = 'selected="selected" ';
  4658. else
  4659. $selected = '';
  4660. $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>';
  4661. }
  4662. }
  4663. $return .= "\t\t\t\t" . '</select>';
  4664. $return .= "\t\t\t" . '</td>' . "\n";
  4665. $return .= "\t\t" . '</tr>' . "\n";
  4666. if ($action != 'move') {
  4667. $id_prerequisite = 0;
  4668. if (is_array($arrLP)) {
  4669. foreach ($arrLP as $key => $value) {
  4670. if ($value['id'] == $id) {
  4671. $id_prerequisite = $value['prerequisite'];
  4672. break;
  4673. }
  4674. }
  4675. }
  4676. $arrHide = array ();
  4677. for ($i = 0; $i < count($arrLP); $i++) {
  4678. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4679. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4680. $s_selected_position = $arrLP[$i]['id'];
  4681. elseif ($action == 'add') $s_selected_position = 0;
  4682. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4683. }
  4684. }
  4685. /*//comented the prerequisites, only visible in edit (exercise)
  4686. $return .= "\t\t" . '<tr>' . "\n";
  4687. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4688. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4689. foreach($arrHide as $key => $value){
  4690. if($key==$s_selected_position && $action == 'add'){
  4691. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4692. }
  4693. elseif($key==$id_prerequisite && $action == 'edit'){
  4694. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4695. }
  4696. else{
  4697. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4698. }
  4699. }
  4700. $return .= "</select></td>";
  4701. */
  4702. $return .= "\t\t" . '</tr>' . "\n";
  4703. /*$return .= "\t\t" . '<tr>' . "\n";
  4704. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4705. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4706. //Remove temporaly the test description
  4707. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4708. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4709. $return .= "\t\t" . '</tr>' . "\n"; */
  4710. }
  4711. $return .= "\t\t" . '<tr>' . "\n";
  4712. if ($action == 'add') {
  4713. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4714. } else {
  4715. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4716. }
  4717. $return .= "\t\t" . '</tr>' . "\n";
  4718. $return .= "\t" . '</table>' . "\n";
  4719. if ($action == 'move') {
  4720. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4721. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4722. }
  4723. if (is_numeric($extra_info)) {
  4724. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4725. }
  4726. elseif (is_array($extra_info)) {
  4727. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4728. }
  4729. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4730. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4731. $return .= '</form>' . "\n";
  4732. $return .= '</div>' . "\n";
  4733. return $return;
  4734. }
  4735. /**
  4736. * Addition of Hotpotatoes tests
  4737. * @param string Action
  4738. * @param integer Internal ID of the item
  4739. * @param mixed Extra information - can be an array with title and description indexes
  4740. * @return string HTML structure to display the hotpotatoes addition formular
  4741. */
  4742. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4743. global $charset;
  4744. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4745. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4746. if ($id != 0 && is_array($extra_info)) {
  4747. $item_title = stripslashes($extra_info['title']);
  4748. $item_description = stripslashes($extra_info['description']);
  4749. }
  4750. elseif (is_numeric($extra_info)) {
  4751. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4752. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4753. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4754. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4755. $res_hot = Database::query($sql_hot);
  4756. $row = Database :: fetch_array($res_hot);
  4757. $item_title = $row['title'];
  4758. $item_description = $row['description'];
  4759. if (!empty ($row['comment'])) {
  4760. $item_title = $row['comment'];
  4761. }
  4762. } else {
  4763. $item_title = '';
  4764. $item_description = '';
  4765. }
  4766. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4767. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4768. $return = '<div style="margin:3px 12px;">';
  4769. if ($id != 0 && is_array($extra_info))
  4770. $parent = $extra_info['parent_item_id'];
  4771. else
  4772. $parent = 0;
  4773. $sql = "
  4774. SELECT *
  4775. FROM " . $tbl_lp_item . "
  4776. WHERE
  4777. lp_id = " . $this->lp_id;
  4778. $result = Database::query($sql);
  4779. $arrLP = array ();
  4780. while ($row = Database :: fetch_array($result)) {
  4781. $arrLP[] = array (
  4782. 'id' => $row['id'],
  4783. 'item_type' => $row['item_type'],
  4784. 'title' => $row['title'],
  4785. 'path' => $row['path'],
  4786. 'description' => $row['description'],
  4787. 'parent_item_id' => $row['parent_item_id'],
  4788. 'previous_item_id' => $row['previous_item_id'],
  4789. 'next_item_id' => $row['next_item_id'],
  4790. 'display_order' => $row['display_order'],
  4791. 'max_score' => $row['max_score'],
  4792. 'min_score' => $row['min_score'],
  4793. 'mastery_score' => $row['mastery_score'],
  4794. 'prerequisite' => $row['prerequisite'],
  4795. 'max_time_allowed' => $row['max_time_allowed']
  4796. );
  4797. }
  4798. $this->tree_array($arrLP);
  4799. $arrLP = $this->arrMenu;
  4800. unset ($this->arrMenu);
  4801. if ($action == 'add')
  4802. $return .= '<p class="lp_title">' . get_lang("CreateTheExercise") . '&nbsp;:</p>' . "\n";
  4803. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentExercise") . '&nbsp;:</p>' . "\n";
  4804. else
  4805. $return .= '<p class="lp_title">' . get_lang("EditCurrentExecice") . '&nbsp;:</p>' . "\n";
  4806. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4807. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4808. }
  4809. $return .= '<form method="POST">' . "\n";
  4810. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4811. $return .= "\t\t" . '<tr>' . "\n";
  4812. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . ' :</label></td>' . "\n";
  4813. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4814. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4815. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4816. $arrHide = array (
  4817. $id
  4818. );
  4819. if (count($arrLP) > 0) {
  4820. for ($i = 0; $i < count($arrLP); $i++) {
  4821. if ($action != 'add') {
  4822. 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)) {
  4823. $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>';
  4824. } else {
  4825. $arrHide[] = $arrLP[$i]['id'];
  4826. }
  4827. } else {
  4828. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4829. $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>';
  4830. }
  4831. }
  4832. reset($arrLP);
  4833. }
  4834. $return .= "\t\t\t\t" . '</select>';
  4835. $return .= "\t\t\t" . '</td>' . "\n";
  4836. $return .= "\t\t" . '</tr>' . "\n";
  4837. $return .= "\t\t" . '<tr>' . "\n";
  4838. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . ' :</label></td>' . "\n";
  4839. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4840. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4841. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4842. for ($i = 0; $i < count($arrLP); $i++) {
  4843. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4844. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4845. $selected = 'selected="selected" ';
  4846. elseif ($action == 'add') $selected = 'selected="selected" ';
  4847. else
  4848. $selected = '';
  4849. $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>';
  4850. }
  4851. }
  4852. $return .= "\t\t\t\t" . '</select>';
  4853. $return .= "\t\t\t" . '</td>' . "\n";
  4854. $return .= "\t\t" . '</tr>' . "\n";
  4855. if ($action != 'move') {
  4856. $return .= "\t\t" . '<tr>' . "\n";
  4857. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . ' :</label></td>' . "\n";
  4858. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4859. $return .= "\t\t" . '</tr>' . "\n";
  4860. $id_prerequisite = 0;
  4861. if (is_array($arrLP) && count($arrLP) > 0) {
  4862. foreach ($arrLP as $key => $value) {
  4863. if ($value['id'] == $id) {
  4864. $id_prerequisite = $value['prerequisite'];
  4865. break;
  4866. }
  4867. }
  4868. $arrHide = array ();
  4869. for ($i = 0; $i < count($arrLP); $i++) {
  4870. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4871. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4872. $s_selected_position = $arrLP[$i]['id'];
  4873. elseif ($action == 'add') $s_selected_position = 0;
  4874. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4875. }
  4876. }
  4877. }
  4878. $return .= "\t\t" . '<tr>' . "\n";
  4879. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4880. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4881. foreach ($arrHide as $key => $value) {
  4882. if ($key == $s_selected_position && $action == 'add') {
  4883. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4884. }
  4885. elseif ($key == $id_prerequisite && $action == 'edit') {
  4886. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4887. } else {
  4888. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  4889. }
  4890. }
  4891. $return .= "</select></td>";
  4892. $return .= "\t\t" . '</tr>' . "\n";
  4893. $return .= "\t\t" . '<tr>' . "\n";
  4894. //Remove temporaly the test description
  4895. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4896. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4897. $return .= "\t\t" . '</tr>' . "\n";
  4898. }
  4899. $return .= "\t\t" . '<tr>' . "\n";
  4900. $return .= "\t\t\t" . '<td> &nbsp;</td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>' . "\n";
  4901. $return .= "\t\t" . '</tr>' . "\n";
  4902. $return .= "\t" . '</table>' . "\n";
  4903. if ($action == 'move') {
  4904. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4905. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4906. }
  4907. if (is_numeric($extra_info)) {
  4908. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4909. }
  4910. elseif (is_array($extra_info)) {
  4911. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4912. }
  4913. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  4914. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4915. $return .= '</form>' . "\n";
  4916. $return .= '</div>' . "\n";
  4917. return $return;
  4918. }
  4919. //fin du hotpot form
  4920. /**
  4921. * Return the form to display the forum edit/add option
  4922. *
  4923. * @param string Action (add/edit)
  4924. * @param integer ID of the lp_item if already exists
  4925. * @param mixed Forum ID or title
  4926. * @return string HTML form
  4927. */
  4928. function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  4929. global $charset;
  4930. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4931. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  4932. if ($id != 0 && is_array($extra_info)) {
  4933. $item_title = stripslashes($extra_info['title']);
  4934. }
  4935. elseif (is_numeric($extra_info)) {
  4936. $sql_forum = "
  4937. SELECT
  4938. forum_title as title, forum_comment as comment
  4939. FROM " . $tbl_forum . "
  4940. WHERE forum_id = " . $extra_info;
  4941. $result = Database::query($sql_forum);
  4942. $row = Database :: fetch_array($result);
  4943. $item_title = $row['title'];
  4944. $item_description = $row['comment'];
  4945. } else {
  4946. $item_title = '';
  4947. $item_description = '';
  4948. }
  4949. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4950. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4951. $return = ' <div class="row">
  4952. <div class="form_header">';
  4953. if ($id != 0 && is_array($extra_info))
  4954. $parent = $extra_info['parent_item_id'];
  4955. else
  4956. $parent = 0;
  4957. $sql = "
  4958. SELECT *
  4959. FROM " . $tbl_lp_item . "
  4960. WHERE
  4961. lp_id = " . $this->lp_id;
  4962. $result = Database::query($sql);
  4963. $arrLP = array ();
  4964. while ($row = Database :: fetch_array($result)) {
  4965. $arrLP[] = array (
  4966. 'id' => $row['id'],
  4967. 'item_type' => $row['item_type'],
  4968. 'title' => $row['title'],
  4969. 'path' => $row['path'],
  4970. 'description' => $row['description'],
  4971. 'parent_item_id' => $row['parent_item_id'],
  4972. 'previous_item_id' => $row['previous_item_id'],
  4973. 'next_item_id' => $row['next_item_id'],
  4974. 'display_order' => $row['display_order'],
  4975. 'max_score' => $row['max_score'],
  4976. 'min_score' => $row['min_score'],
  4977. 'mastery_score' => $row['mastery_score'],
  4978. 'prerequisite' => $row['prerequisite']
  4979. );
  4980. }
  4981. $this->tree_array($arrLP);
  4982. $arrLP = $this->arrMenu;
  4983. unset ($this->arrMenu);
  4984. if ($action == 'add')
  4985. $return .= get_lang("CreateTheForum") . '&nbsp;:' . "\n";
  4986. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentForum") . '&nbsp;:' . "\n";
  4987. else
  4988. $return .= get_lang("EditCurrentForum") . '&nbsp;:' . "\n";
  4989. $return .= ' </div>
  4990. </div>';
  4991. $return .= '<div class="sectioncomment">';
  4992. $return .= '<form method="POST">' . "\n";
  4993. $return .= "\t" . '<table class="lp_form">' . "\n";
  4994. if ($action != 'move') {
  4995. $return .= "\t\t" . '<tr>' . "\n";
  4996. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4997. $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";
  4998. $return .= "\t\t" . '</tr>' . "\n";
  4999. }
  5000. $return .= "\t\t" . '<tr>' . "\n";
  5001. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5002. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5003. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5004. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5005. $arrHide = array (
  5006. $id
  5007. );
  5008. $parent_item_id = $_SESSION['parent_item_id'];
  5009. for ($i = 0; $i < count($arrLP); $i++) {
  5010. if ($action != 'add') {
  5011. 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)) {
  5012. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5013. } else {
  5014. $arrHide[] = $arrLP[$i]['id'];
  5015. }
  5016. } else {
  5017. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5018. $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>';
  5019. }
  5020. }
  5021. if (is_array($arrLP)) {
  5022. reset($arrLP);
  5023. }
  5024. $return .= "\t\t\t\t" . '</select>';
  5025. $return .= "\t\t\t" . '</td>' . "\n";
  5026. $return .= "\t\t" . '</tr>' . "\n";
  5027. $return .= "\t\t" . '<tr>' . "\n";
  5028. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5029. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5030. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5031. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5032. for ($i = 0; $i < count($arrLP); $i++) {
  5033. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5034. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5035. $selected = 'selected="selected" ';
  5036. elseif ($action == 'add') $selected = 'selected="selected" ';
  5037. else
  5038. $selected = '';
  5039. $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>';
  5040. }
  5041. }
  5042. $return .= "\t\t\t\t" . '</select>';
  5043. $return .= "\t\t\t" . '</td>' . "\n";
  5044. $return .= "\t\t" . '</tr>' . "\n";
  5045. if ($action != 'move') {
  5046. $return .= "\t\t" . '<tr>' . "\n";
  5047. //Remove temporaly the test description
  5048. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5049. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5050. $return .= "\t\t" . '</tr>' . "\n";
  5051. $id_prerequisite = 0;
  5052. if (is_array($arrLP)) {
  5053. foreach ($arrLP as $key => $value) {
  5054. if ($value['id'] == $id) {
  5055. $id_prerequisite = $value['prerequisite'];
  5056. break;
  5057. }
  5058. }
  5059. }
  5060. $arrHide = array ();
  5061. for ($i = 0; $i < count($arrLP); $i++) {
  5062. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5063. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5064. $s_selected_position = $arrLP[$i]['id'];
  5065. elseif ($action == 'add') $s_selected_position = 0;
  5066. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5067. }
  5068. }
  5069. /* //comented the prerequisites, only visible in edit (forum)
  5070. $return .= "\t\t" . '<tr>' . "\n";
  5071. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5072. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5073. foreach($arrHide as $key => $value) {
  5074. if($key==$s_selected_position && $action == 'add') {
  5075. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5076. }elseif($key==$id_prerequisite && $action == 'edit') {
  5077. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5078. } else {
  5079. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5080. }
  5081. }
  5082. $return .= "</select></td>";
  5083. */
  5084. $return .= "\t\t" . '</tr>' . "\n";
  5085. }
  5086. $return .= "\t\t" . '<tr>' . "\n";
  5087. if ($action == 'add') {
  5088. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5089. } else {
  5090. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5091. }
  5092. $return .= "\t\t" . '</tr>' . "\n";
  5093. $return .= "\t" . '</table>' . "\n";
  5094. if ($action == 'move') {
  5095. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5096. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5097. }
  5098. if (is_numeric($extra_info)) {
  5099. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5100. }
  5101. elseif (is_array($extra_info)) {
  5102. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5103. }
  5104. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5105. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5106. $return .= '</form>' . "\n";
  5107. $return .= '</div>' . "\n";
  5108. return $return;
  5109. }
  5110. /**
  5111. * Return HTML form to add/edit forum threads
  5112. * @param string Action (add/edit)
  5113. * @param integer Item ID if already exists in learning path
  5114. * @param mixed Extra information (thread ID if integer)
  5115. * @return string HTML form
  5116. */
  5117. function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5118. global $charset;
  5119. echo '
  5120. <style>
  5121. div.row div.label {
  5122. width:110px;
  5123. }
  5124. div.row div.formw {
  5125. width: 82%;
  5126. }
  5127. </style>';
  5128. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5129. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5130. if ($id != 0 && is_array($extra_info)) {
  5131. $item_title = stripslashes($extra_info['title']);
  5132. }
  5133. elseif (is_numeric($extra_info)) {
  5134. $sql_forum = "
  5135. SELECT
  5136. thread_title as title
  5137. FROM " . $tbl_forum . "
  5138. WHERE thread_id = " . $extra_info;
  5139. $result = Database::query($sql_forum);
  5140. $row = Database :: fetch_array($result);
  5141. $item_title = $row['title'];
  5142. $item_description = '';
  5143. } else {
  5144. $item_title = '';
  5145. $item_description = '';
  5146. }
  5147. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5148. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5149. $return = '<div style="margin:3px 12px;">';
  5150. if ($id != 0 && is_array($extra_info))
  5151. $parent = $extra_info['parent_item_id'];
  5152. else
  5153. $parent = 0;
  5154. $sql = "
  5155. SELECT *
  5156. FROM " . $tbl_lp_item . "
  5157. WHERE
  5158. lp_id = " . $this->lp_id;
  5159. $result = Database::query($sql);
  5160. $arrLP = array ();
  5161. while ($row = Database :: fetch_array($result)) {
  5162. $arrLP[] = array (
  5163. 'id' => $row['id'],
  5164. 'item_type' => $row['item_type'],
  5165. 'title' => $row['title'],
  5166. 'path' => $row['path'],
  5167. 'description' => $row['description'],
  5168. 'parent_item_id' => $row['parent_item_id'],
  5169. 'previous_item_id' => $row['previous_item_id'],
  5170. 'next_item_id' => $row['next_item_id'],
  5171. 'display_order' => $row['display_order'],
  5172. 'max_score' => $row['max_score'],
  5173. 'min_score' => $row['min_score'],
  5174. 'mastery_score' => $row['mastery_score'],
  5175. 'prerequisite' => $row['prerequisite']
  5176. );
  5177. }
  5178. $this->tree_array($arrLP);
  5179. $arrLP = $this->arrMenu;
  5180. unset ($this->arrMenu);
  5181. if ($action == 'add')
  5182. $return .= '<p class="lp_title">' . get_lang("CreateTheForum") . '&nbsp;:</p>' . "\n";
  5183. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentForum") . '&nbsp;:</p>' . "\n";
  5184. else
  5185. $return .= '<p class="lp_title">' . get_lang("EditCurrentForum") . '&nbsp;:</p>' . "\n";
  5186. $return .= '<form method="POST">' . "\n";
  5187. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5188. $return .= "\t\t" . '<tr>' . "\n";
  5189. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . '&nbsp;:</label></td>' . "\n";
  5190. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5191. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5192. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5193. $arrHide = array (
  5194. $id
  5195. );
  5196. for ($i = 0; $i < count($arrLP); $i++) {
  5197. if ($action != 'add') {
  5198. 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)) {
  5199. $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>';
  5200. } else {
  5201. $arrHide[] = $arrLP[$i]['id'];
  5202. }
  5203. } else {
  5204. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5205. $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>';
  5206. }
  5207. }
  5208. if ($arrLP != null) {
  5209. reset($arrLP);
  5210. }
  5211. $return .= "\t\t\t\t" . '</select>';
  5212. $return .= "\t\t\t" . '</td>' . "\n";
  5213. $return .= "\t\t" . '</tr>' . "\n";
  5214. $return .= "\t\t" . '<tr>' . "\n";
  5215. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . '&nbsp;:</label></td>' . "\n";
  5216. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5217. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5218. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5219. for ($i = 0; $i < count($arrLP); $i++) {
  5220. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5221. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5222. $selected = 'selected="selected" ';
  5223. elseif ($action == 'add') $selected = 'selected="selected" ';
  5224. else
  5225. $selected = '';
  5226. $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>';
  5227. }
  5228. }
  5229. $return .= "\t\t\t\t" . '</select>';
  5230. $return .= "\t\t\t" . '</td>' . "\n";
  5231. $return .= "\t\t" . '</tr>' . "\n";
  5232. if ($action != 'move') {
  5233. $return .= "\t\t" . '<tr>' . "\n";
  5234. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . '&nbsp;:</label></td>' . "\n";
  5235. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5236. $return .= "\t\t" . '</tr>' . "\n";
  5237. $return .= "\t\t" . '<tr>' . "\n";
  5238. //Remove temporaly the test description
  5239. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5240. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5241. $return .= "\t\t" . '</tr>' . "\n";
  5242. $id_prerequisite = 0;
  5243. if ($arrLP != null) {
  5244. foreach ($arrLP as $key => $value) {
  5245. if ($value['id'] == $id) {
  5246. $id_prerequisite = $value['prerequisite'];
  5247. break;
  5248. }
  5249. }
  5250. }
  5251. $arrHide = array ();
  5252. for ($i = 0; $i < count($arrLP); $i++) {
  5253. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5254. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5255. $s_selected_position = $arrLP[$i]['id'];
  5256. elseif ($action == 'add') $s_selected_position = 0;
  5257. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5258. }
  5259. }
  5260. $return .= "\t\t" . '<tr>' . "\n";
  5261. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang("Prerequisites") . '&nbsp;:</label></td>' . "\n";
  5262. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang("NoPrerequisites") . '</option>';
  5263. foreach ($arrHide as $key => $value) {
  5264. if ($key == $s_selected_position && $action == 'add') {
  5265. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5266. }
  5267. elseif ($key == $id_prerequisite && $action == 'edit') {
  5268. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5269. } else {
  5270. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5271. }
  5272. }
  5273. $return .= "</select></td>";
  5274. $return .= "\t\t" . '</tr>' . "\n";
  5275. }
  5276. $return .= "\t\t" . '<tr>' . "\n";
  5277. $return .= "\t\t\t" . '<td colspan="2">
  5278. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5279. $return .= "\t\t" . '</tr>' . "\n";
  5280. $return .= "\t" . '</table>' . "\n";
  5281. if ($action == 'move') {
  5282. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5283. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5284. }
  5285. if (is_numeric($extra_info)) {
  5286. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5287. }
  5288. elseif (is_array($extra_info)) {
  5289. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5290. }
  5291. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5292. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5293. $return .= '</form>' . "\n";
  5294. $return .= '</div>' . "\n";
  5295. return $return;
  5296. }
  5297. /**
  5298. * Return the HTML form to display an item (generally a section/module item)
  5299. *
  5300. * @param string Item type (module/dokeos_module)
  5301. * @param string Title (optional, only when creating)
  5302. * @param string Action ('add'/'edit')
  5303. * @param integer lp_item ID
  5304. * @param mixed Extra info
  5305. * @return string HTML form
  5306. */
  5307. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5308. global $_course;
  5309. global $charset;
  5310. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5311. if ($id != 0 && is_array($extra_info)) {
  5312. $item_title = $extra_info['title'];
  5313. $item_description = $extra_info['description'];
  5314. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5315. } else {
  5316. $item_title = '';
  5317. $item_description = '';
  5318. }
  5319. $return = ' <div class="row">
  5320. <div class="form_header">';
  5321. if ($id != 0 && is_array($extra_info))
  5322. $parent = $extra_info['parent_item_id'];
  5323. else
  5324. $parent = 0;
  5325. $sql = "
  5326. SELECT *
  5327. FROM " . $tbl_lp_item . "
  5328. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5329. if ($item_type == 'module')
  5330. $sql .= " AND parent_item_id = 0";
  5331. $result = Database::query($sql);
  5332. $arrLP = array ();
  5333. while ($row = Database :: fetch_array($result)) {
  5334. $arrLP[] = array (
  5335. 'id' => $row['id'],
  5336. 'item_type' => $row['item_type'],
  5337. 'title' => $row['title'],
  5338. 'path' => $row['path'],
  5339. 'description' => $row['description'],
  5340. 'parent_item_id' => $row['parent_item_id'],
  5341. 'previous_item_id' => $row['previous_item_id'],
  5342. 'next_item_id' => $row['next_item_id'],
  5343. 'max_score' => $row['max_score'],
  5344. 'min_score' => $row['min_score'],
  5345. 'mastery_score' => $row['mastery_score'],
  5346. 'prerequisite' => $row['prerequisite'],
  5347. 'display_order' => $row['display_order']
  5348. );
  5349. }
  5350. $this->tree_array($arrLP);
  5351. $arrLP = $this->arrMenu;
  5352. unset ($this->arrMenu);
  5353. $return .= $title . "\n";
  5354. $return .= ' </div>
  5355. </div>';
  5356. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5357. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"]);
  5358. //$defaults["title"] = api_convert_encoding($item_title, $charset, $this->encoding);
  5359. $defaults["title"] = api_html_entity_decode(api_convert_encoding($item_title, $charset, $this->encoding), ENT_QUOTES, $charset);
  5360. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5361. $form->addElement('html', $return);
  5362. //$arrHide = array($id);
  5363. $arrHide[0]['value'] = Security :: remove_XSS(api_convert_encoding($this->name, api_get_system_encoding(), $_SESSION['oLP']->encoding));
  5364. $arrHide[0]['padding'] = 3;
  5365. $charset = api_get_system_encoding();
  5366. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5367. for ($i = 0; $i < count($arrLP); $i++) {
  5368. if ($action != 'add') {
  5369. 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)) {
  5370. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5371. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5372. if ($parent == $arrLP[$i]['id']) {
  5373. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5374. }
  5375. }
  5376. } else {
  5377. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5378. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5379. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5380. if ($parent == $arrLP[$i]['id']) {
  5381. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5382. }
  5383. }
  5384. }
  5385. }
  5386. if ($action != 'move') {
  5387. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5388. $form->applyFilter('title', 'html_filter');
  5389. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5390. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5391. } else {
  5392. $form->addElement('hidden', 'title');
  5393. }
  5394. $parent_select = & $form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
  5395. foreach ($arrHide as $key => $value) {
  5396. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5397. }
  5398. $parent_select->setSelected($s_selected_parent);
  5399. }
  5400. if (is_array($arrLP)) {
  5401. reset($arrLP);
  5402. }
  5403. $arrHide = array ();
  5404. //POSITION
  5405. for ($i = 0; $i < count($arrLP); $i++) {
  5406. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5407. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5408. $s_selected_position = $arrLP[$i]['id'];
  5409. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5410. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5411. }
  5412. }
  5413. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5414. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5415. foreach ($arrHide as $key => $value) {
  5416. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5417. }
  5418. if (!empty ($s_selected_position)) {
  5419. $position->setSelected($s_selected_position);
  5420. }
  5421. if (is_array($arrLP)) {
  5422. reset($arrLP);
  5423. }
  5424. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5425. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5426. $form->addElement('hidden', 'parent', '0');
  5427. }
  5428. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5429. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5430. if ($item_type == 'sco') {
  5431. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5432. }
  5433. $renderer = $form->defaultRenderer();
  5434. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5435. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5436. $defaults["content_lp"] = file_get_contents($item_path);
  5437. }
  5438. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5439. $form->addElement('hidden', 'post_time', time());
  5440. $form->setDefaults($defaults);
  5441. return $form->return_form();
  5442. }
  5443. /**
  5444. * Returns the form to update or create a document
  5445. *
  5446. * @param string Action (add/edit)
  5447. * @param integer ID of the lp_item (if already exists)
  5448. * @param mixed Integer if document ID, string if info ('new')
  5449. * @return string HTML form
  5450. */
  5451. function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5452. global $charset;
  5453. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5454. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5455. $path_parts = pathinfo($extra_info['dir']);
  5456. $no_display_edit_textarea = false;
  5457. //If action==edit document
  5458. //We don't display the document form if it's not an editable document (html or txt file)
  5459. if ($action == "edit") {
  5460. if (is_array($extra_info)) {
  5461. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5462. $no_display_edit_textarea = true;
  5463. }
  5464. }
  5465. }
  5466. $no_display_add = false;
  5467. //If action==add an existing document
  5468. //We don't display the document form if it's not an editable document (html or txt file)
  5469. if ($action == "add") {
  5470. if (is_numeric($extra_info)) {
  5471. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5472. $result = Database::query($sql_doc);
  5473. $path_file = Database :: result($result, 0, 0);
  5474. $path_parts = pathinfo($path_file);
  5475. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5476. $no_display_add = true;
  5477. }
  5478. }
  5479. }
  5480. if ($id != 0 && is_array($extra_info)) {
  5481. $item_title = stripslashes($extra_info['title']);
  5482. $item_description = stripslashes($extra_info['description']);
  5483. $item_terms = stripslashes($extra_info['terms']);
  5484. if (empty ($item_title)) {
  5485. $path_parts = pathinfo($extra_info['path']);
  5486. $item_title = stripslashes($path_parts['filename']);
  5487. }
  5488. }
  5489. elseif (is_numeric($extra_info)) {
  5490. $sql_doc = "SELECT path, title
  5491. FROM " . $tbl_doc . "
  5492. WHERE id = " . Database :: escape_string($extra_info);
  5493. $result = Database::query($sql_doc);
  5494. $row = Database :: fetch_array($result);
  5495. $explode = explode('.', $row['title']);
  5496. if (count($explode) > 1) {
  5497. for ($i = 0; $i < count($explode) - 1; $i++)
  5498. $item_title .= $explode[$i];
  5499. } else {
  5500. $item_title = $row['title'];
  5501. }
  5502. $item_title = str_replace('_', ' ', $item_title);
  5503. if (empty ($item_title)) {
  5504. $path_parts = pathinfo($row['path']);
  5505. $item_title = stripslashes($path_parts['filename']);
  5506. }
  5507. } else {
  5508. $item_title = '';
  5509. $item_description = '';
  5510. }
  5511. $return = ' <div class="row">
  5512. <div class="form_header">';
  5513. if ($id != 0 && is_array($extra_info))
  5514. $parent = $extra_info['parent_item_id'];
  5515. else
  5516. $parent = 0;
  5517. $sql = "
  5518. SELECT *
  5519. FROM " . $tbl_lp_item . "
  5520. WHERE
  5521. lp_id = " . $this->lp_id;
  5522. $result = Database::query($sql);
  5523. $arrLP = array ();
  5524. while ($row = Database :: fetch_array($result)) {
  5525. $arrLP[] = array (
  5526. 'id' => $row['id'],
  5527. 'item_type' => $row['item_type'],
  5528. 'title' => $row['title'],
  5529. 'path' => $row['path'],
  5530. 'description' => $row['description'],
  5531. 'parent_item_id' => $row['parent_item_id'],
  5532. 'previous_item_id' => $row['previous_item_id'],
  5533. 'next_item_id' => $row['next_item_id'],
  5534. 'display_order' => $row['display_order'],
  5535. 'max_score' => $row['max_score'],
  5536. 'min_score' => $row['min_score'],
  5537. 'mastery_score' => $row['mastery_score'],
  5538. 'prerequisite' => $row['prerequisite']
  5539. );
  5540. }
  5541. $this->tree_array($arrLP);
  5542. $arrLP = $this->arrMenu;
  5543. unset ($this->arrMenu);
  5544. if ($action == 'add') {
  5545. $return .= get_lang("CreateTheDocument") . "\n";
  5546. }
  5547. elseif ($action == 'move') {
  5548. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5549. } else {
  5550. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5551. }
  5552. $return .= ' </div>
  5553. </div>';
  5554. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5555. $return .= Display :: return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
  5556. }
  5557. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5558. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
  5559. $defaults["title"] = Security :: remove_XSS(api_convert_encoding($item_title, api_get_system_encoding() ,$this->encoding));
  5560. if (empty ($item_title)) {
  5561. $defaults["title"] = Security :: remove_XSS($item_title);
  5562. }
  5563. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5564. $form->addElement('html', $return);
  5565. if ($action != 'move') {
  5566. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5567. $form->applyFilter('title', 'html_filter');
  5568. }
  5569. //$arrHide = array($id);
  5570. $arrHide[0]['value'] = $this->name;
  5571. $arrHide[0]['padding'] = 3;
  5572. for ($i = 0; $i < count($arrLP); $i++) {
  5573. if ($action != 'add') {
  5574. 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)) {
  5575. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5576. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5577. if ($parent == $arrLP[$i]['id']) {
  5578. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5579. }
  5580. }
  5581. } else {
  5582. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  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. }
  5590. }
  5591. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
  5592. $my_count=0;
  5593. foreach ($arrHide as $key => $value) {
  5594. if ($my_count!=0) {
  5595. // the LP name is also the first section and is not in the same charset like the other sections
  5596. $value['value'] = Security :: remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
  5597. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5598. } else {
  5599. $value['value'] = Security :: remove_XSS($value['value']);
  5600. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5601. }
  5602. $my_count++;
  5603. }
  5604. if (!empty ($id)) {
  5605. $parent_select->setSelected($parent);
  5606. } else {
  5607. $parent_item_id = $_SESSION['parent_item_id'];
  5608. $parent_select->setSelected($parent_item_id);
  5609. }
  5610. if (is_array($arrLP)) {
  5611. reset($arrLP);
  5612. }
  5613. $arrHide = array ();
  5614. //POSITION
  5615. for ($i = 0; $i < count($arrLP); $i++) {
  5616. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5617. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5618. $s_selected_position = $arrLP[$i]['id'];
  5619. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5620. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
  5621. }
  5622. }
  5623. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5624. $position->addOption(get_lang("FirstPosition"), 0);
  5625. foreach ($arrHide as $key => $value) {
  5626. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5627. }
  5628. $position->setSelected($s_selected_position);
  5629. if (is_array($arrLP)) {
  5630. reset($arrLP);
  5631. }
  5632. if ($action != 'move') {
  5633. $id_prerequisite = 0;
  5634. if (is_array($arrLP)) {
  5635. foreach ($arrLP as $key => $value) {
  5636. if ($value['id'] == $id) {
  5637. $id_prerequisite = $value['prerequisite'];
  5638. break;
  5639. }
  5640. }
  5641. }
  5642. //comented the prerequisites, only visible in edit (new document)
  5643. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5644. //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5645. // form element for uploading an mp3 file
  5646. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5647. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5648. /* Code deprecated - moved to lp level (not lp-item)
  5649. if ( api_get_setting('search_enabled') === 'true' )
  5650. {
  5651. //add terms field
  5652. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5653. $terms->setValue($item_terms);
  5654. }
  5655. */
  5656. $arrHide = array ();
  5657. for ($i = 0; $i < count($arrLP); $i++) {
  5658. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5659. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5660. $s_selected_position = $arrLP[$i]['id'];
  5661. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5662. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5663. }
  5664. }
  5665. /* foreach($arrHide as $key => $value){
  5666. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5667. if($key==$s_selected_position && $action == 'add'){
  5668. $select_prerequisites -> setSelected(0);
  5669. }
  5670. elseif($key==$id_prerequisite && $action == 'edit'){
  5671. $select_prerequisites -> setSelected($id_prerequisite);
  5672. }
  5673. }
  5674. */
  5675. if (!$no_display_add) {
  5676. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5677. if (isset ($_POST['content']))
  5678. $content = stripslashes($_POST['content']);
  5679. elseif (is_array($extra_info)) {
  5680. //If it's an html document or a text file
  5681. if (!$no_display_edit_textarea) {
  5682. $content = $this->display_document($extra_info['path'], false, false);
  5683. }
  5684. }
  5685. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5686. else
  5687. $content = '';
  5688. if (!$no_display_edit_textarea) {
  5689. // We need to claculate here some specific settings for the online editor.
  5690. // The calculated settings work for documents in the Documents tool
  5691. // (on the root or in subfolders).
  5692. // For documents in native scorm packages it is unclear whether the
  5693. // online editor should be activated or not.
  5694. $relative_path = $extra_info['dir'];
  5695. if ($relative_path == 'n/') {
  5696. // A new document, it is in the root of the repository.
  5697. $relative_path = '';
  5698. $relative_prefix = '';
  5699. } else {
  5700. // The document already exists. Whe have to determine its relative path towards the repository root.
  5701. $relative_path = explode('/', $relative_path);
  5702. $cnt = count($relative_path) - 2;
  5703. if ($cnt < 0) {
  5704. $cnt = 0;
  5705. }
  5706. $relative_prefix = str_repeat('../', $cnt);
  5707. $relative_path = array_slice($relative_path, 1, $cnt);
  5708. $relative_path = implode('/', $relative_path);
  5709. if (strlen($relative_path) > 0) {
  5710. $relative_path = $relative_path . '/';
  5711. }
  5712. }
  5713. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5714. 'CreateDocumentDir' => $relative_prefix,
  5715. 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/',
  5716. 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path
  5717. );
  5718. if ($_GET['action'] == 'add_item') {
  5719. $class = 'add';
  5720. $text = get_lang('LPCreateDocument');
  5721. } else
  5722. if ($_GET['action'] == 'edit_item') {
  5723. $class = 'save';
  5724. $text = get_lang('SaveDocument');
  5725. }
  5726. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5727. $renderer = $form->defaultRenderer();
  5728. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5729. $form->addElement('html', '<div style="margin:3px 12px">');
  5730. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5731. $form->addElement('html', '</div>');
  5732. $defaults["content_lp"] = $content;
  5733. }
  5734. }
  5735. elseif (is_numeric($extra_info)) {
  5736. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5737. $return = $this->display_document($extra_info, true, true, true);
  5738. $form->addElement('html', $return);
  5739. }
  5740. }
  5741. }
  5742. if ($action == 'move') {
  5743. $form->addElement('hidden', 'title', $item_title);
  5744. $form->addElement('hidden', 'description', $item_description);
  5745. }
  5746. if (is_numeric($extra_info)) {
  5747. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5748. $form->addElement('hidden', 'path', $extra_info);
  5749. }
  5750. elseif (is_array($extra_info)) {
  5751. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5752. $form->addElement('hidden', 'path', $extra_info['path']);
  5753. }
  5754. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5755. $form->addElement('hidden', 'post_time', time());
  5756. $form->setDefaults($defaults);
  5757. return $form->return_form();
  5758. }
  5759. /**
  5760. * Return HTML form to add/edit a link item
  5761. *
  5762. * @param string Action (add/edit)
  5763. * @param integer Item ID if exists
  5764. * @param mixed Extra info
  5765. * @return string HTML form
  5766. */
  5767. function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5768. global $charset;
  5769. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5770. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5771. if ($id != 0 && is_array($extra_info)) {
  5772. $item_title = stripslashes($extra_info['title']);
  5773. $item_description = stripslashes($extra_info['description']);
  5774. $item_url = stripslashes($extra_info['url']);
  5775. }
  5776. elseif (is_numeric($extra_info)) {
  5777. $sql_link = "
  5778. SELECT
  5779. title,
  5780. description,
  5781. url
  5782. FROM " . $tbl_link . "
  5783. WHERE id = " . $extra_info;
  5784. $result = Database::query($sql_link);
  5785. $row = Database :: fetch_array($result);
  5786. $item_title = $row['title'];
  5787. $item_description = $row['description'];
  5788. $item_url = $row['url'];
  5789. } else {
  5790. $item_title = '';
  5791. $item_description = '';
  5792. $item_url = '';
  5793. }
  5794. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5795. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5796. $return = ' <div class="row">
  5797. <div class="form_header">';
  5798. if ($id != 0 && is_array($extra_info))
  5799. $parent = $extra_info['parent_item_id'];
  5800. else
  5801. $parent = 0;
  5802. $sql = "
  5803. SELECT *
  5804. FROM " . $tbl_lp_item . "
  5805. WHERE
  5806. lp_id = " . $this->lp_id;
  5807. $result = Database::query($sql);
  5808. $arrLP = array ();
  5809. while ($row = Database :: fetch_array($result)) {
  5810. $arrLP[] = array (
  5811. 'id' => $row['id'],
  5812. 'item_type' => $row['item_type'],
  5813. 'title' => $row['title'],
  5814. 'path' => $row['path'],
  5815. 'description' => $row['description'],
  5816. 'parent_item_id' => $row['parent_item_id'],
  5817. 'previous_item_id' => $row['previous_item_id'],
  5818. 'next_item_id' => $row['next_item_id'],
  5819. 'display_order' => $row['display_order'],
  5820. 'max_score' => $row['max_score'],
  5821. 'min_score' => $row['min_score'],
  5822. 'mastery_score' => $row['mastery_score'],
  5823. 'prerequisite' => $row['prerequisite']
  5824. );
  5825. }
  5826. $this->tree_array($arrLP);
  5827. $arrLP = $this->arrMenu;
  5828. unset ($this->arrMenu);
  5829. if ($action == 'add')
  5830. $return .= get_lang("CreateTheLink") . '&nbsp;:' . "\n";
  5831. elseif ($action == 'move') $return .= get_lang("MoveCurrentLink") . '&nbsp;:' . "\n";
  5832. else
  5833. $return .= get_lang("EditCurrentLink") . '&nbsp;:' . "\n";
  5834. $return .= ' </div>
  5835. </div>';
  5836. $return .= '<div class="sectioncomment">';
  5837. $return .= '<form method="POST">' . "\n";
  5838. $return .= "\t" . '<table>' . "\n";
  5839. if ($action != 'move') {
  5840. $return .= "\t\t" . '<tr>' . "\n";
  5841. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5842. $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";
  5843. $return .= "\t\t" . '</tr>' . "\n";
  5844. }
  5845. $return .= "\t\t" . '<tr>' . "\n";
  5846. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5847. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5848. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5849. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5850. $arrHide = array (
  5851. $id
  5852. );
  5853. $parent_item_id = $_SESSION['parent_item_id'];
  5854. for ($i = 0; $i < count($arrLP); $i++) {
  5855. if ($action != 'add') {
  5856. 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)) {
  5857. $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>';
  5858. } else {
  5859. $arrHide[] = $arrLP[$i]['id'];
  5860. }
  5861. } else {
  5862. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5863. $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>';
  5864. }
  5865. }
  5866. if (is_array($arrLP)) {
  5867. reset($arrLP);
  5868. }
  5869. $return .= "\t\t\t\t" . '</select>';
  5870. $return .= "\t\t\t" . '</td>' . "\n";
  5871. $return .= "\t\t" . '</tr>' . "\n";
  5872. $return .= "\t\t" . '<tr>' . "\n";
  5873. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5874. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5875. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5876. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  5877. for ($i = 0; $i < count($arrLP); $i++) {
  5878. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5879. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5880. $selected = 'selected="selected" ';
  5881. elseif ($action == 'add') $selected = 'selected="selected" ';
  5882. else
  5883. $selected = '';
  5884. $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>';
  5885. }
  5886. }
  5887. $return .= "\t\t\t\t" . '</select>';
  5888. $return .= "\t\t\t" . '</td>' . "\n";
  5889. $return .= "\t\t" . '</tr>' . "\n";
  5890. if ($action != 'move') {
  5891. //Description filed is commentd for link
  5892. /*$return .= "\t\t" . '<tr>' . "\n";
  5893. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
  5894. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" style="width:100%;" name="description" class="learnpath_item_form" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5895. $return .= "\t\t" . '</tr>' . "\n";*/
  5896. $return .= "\t\t" . '<tr>' . "\n";
  5897. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  5898. $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";
  5899. $return .= "\t\t" . '</tr>' . "\n";
  5900. $id_prerequisite = 0;
  5901. if (is_array($arrLP)) {
  5902. foreach ($arrLP as $key => $value) {
  5903. if ($value['id'] == $id) {
  5904. $id_prerequisite = $value['prerequisite'];
  5905. break;
  5906. }
  5907. }
  5908. }
  5909. $arrHide = array ();
  5910. for ($i = 0; $i < count($arrLP); $i++) {
  5911. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5912. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5913. $s_selected_position = $arrLP[$i]['id'];
  5914. elseif ($action == 'add') $s_selected_position = 0;
  5915. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5916. }
  5917. }
  5918. /*//comented the prerequisites, only visible in edit (link)
  5919. $return .= "\t\t" . '<tr>' . "\n";
  5920. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5921. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5922. foreach($arrHide as $key => $value)
  5923. {
  5924. if($key==$s_selected_position && $action == 'add')
  5925. {
  5926. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5927. }
  5928. elseif($key==$id_prerequisite && $action == 'edit'){
  5929. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5930. }
  5931. else{
  5932. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5933. }
  5934. }
  5935. $return .= "</select></td>";
  5936. */
  5937. $return .= "\t\t" . '</tr>' . "\n";
  5938. }
  5939. $return .= "\t\t" . '<tr>' . "\n";
  5940. if ($action == 'add') {
  5941. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  5942. } else {
  5943. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  5944. }
  5945. $return .= "\t\t" . '</tr>' . "\n";
  5946. $return .= "\t" . '</table>' . "\n";
  5947. if ($action == 'move') {
  5948. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5949. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5950. }
  5951. if (is_numeric($extra_info)) {
  5952. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5953. }
  5954. elseif (is_array($extra_info)) {
  5955. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5956. }
  5957. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  5958. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5959. $return .= '</form>' . "\n";
  5960. $return .= '</div>' . "\n";
  5961. return $return;
  5962. }
  5963. /**
  5964. * Return HTML form to add/edit a student publication (work)
  5965. *
  5966. * @param string Action (add/edit)
  5967. * @param integer Item ID if already exists
  5968. * @param mixed Extra info (work ID if integer)
  5969. * @return string HTML form
  5970. */
  5971. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  5972. global $charset;
  5973. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5974. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  5975. if ($id != 0 && is_array($extra_info)) {
  5976. $item_title = stripslashes($extra_info['title']);
  5977. $item_description = stripslashes($extra_info['description']);
  5978. }
  5979. elseif (is_numeric($extra_info)) {
  5980. $sql_publication = "
  5981. SELECT
  5982. title,
  5983. description
  5984. FROM " . $tbl_publication . "
  5985. WHERE id = " . $extra_info;
  5986. $result = Database::query($sql_publication);
  5987. $row = Database :: fetch_array($result);
  5988. $item_title = $row['title'];
  5989. } else {
  5990. $item_title = get_lang('Student_publication');
  5991. }
  5992. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5993. $return = ' <div class="row">
  5994. <div class="form_header">';
  5995. if ($id != 0 && is_array($extra_info))
  5996. $parent = $extra_info['parent_item_id'];
  5997. else
  5998. $parent = 0;
  5999. $sql = "
  6000. SELECT *
  6001. FROM " . $tbl_lp_item . "
  6002. WHERE
  6003. lp_id = " . $this->lp_id;
  6004. $result = Database::query($sql);
  6005. $arrLP = array ();
  6006. while ($row = Database :: fetch_array($result)) {
  6007. $arrLP[] = array (
  6008. 'id' => $row['id'],
  6009. 'item_type' => $row['item_type'],
  6010. 'title' => $row['title'],
  6011. 'path' => $row['path'],
  6012. 'description' => $row['description'],
  6013. 'parent_item_id' => $row['parent_item_id'],
  6014. 'previous_item_id' => $row['previous_item_id'],
  6015. 'next_item_id' => $row['next_item_id'],
  6016. 'display_order' => $row['display_order'],
  6017. 'max_score' => $row['max_score'],
  6018. 'min_score' => $row['min_score'],
  6019. 'mastery_score' => $row['mastery_score'],
  6020. 'prerequisite' => $row['prerequisite']
  6021. );
  6022. }
  6023. $this->tree_array($arrLP);
  6024. $arrLP = $this->arrMenu;
  6025. unset ($this->arrMenu);
  6026. if ($action == 'add')
  6027. $return .= get_lang("Student_publication") . '&nbsp;:' . "\n";
  6028. elseif ($action == 'move') $return .= get_lang("MoveCurrentStudentPublication") . '&nbsp;:' . "\n";
  6029. else
  6030. $return .= get_lang("EditCurrentStudentPublication") . '&nbsp;:' . "\n";
  6031. $return .= ' </div>
  6032. </div>';
  6033. $return .= '<div class="sectioncomment">';
  6034. $return .= '<form method="POST">' . "\n";
  6035. $return .= "\t" . '<table class="lp_form">' . "\n";
  6036. if ($action != 'move') {
  6037. $return .= "\t\t" . '<tr>' . "\n";
  6038. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6039. $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";
  6040. $return .= "\t\t" . '</tr>' . "\n";
  6041. }
  6042. $return .= "\t\t" . '<tr>' . "\n";
  6043. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6044. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6045. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6046. $parent_item_id = $_SESSION['parent_item_id'];
  6047. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6048. $arrHide = array (
  6049. $id
  6050. );
  6051. for ($i = 0; $i < count($arrLP); $i++) {
  6052. if ($action != 'add') {
  6053. 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)) {
  6054. $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>';
  6055. } else {
  6056. $arrHide[] = $arrLP[$i]['id'];
  6057. }
  6058. } else {
  6059. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6060. $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>';
  6061. }
  6062. }
  6063. if (is_array($arrLP)) {
  6064. reset($arrLP);
  6065. }
  6066. $return .= "\t\t\t\t" . '</select>';
  6067. $return .= "\t\t\t" . '</td>' . "\n";
  6068. $return .= "\t\t" . '</tr>' . "\n";
  6069. $return .= "\t\t" . '<tr>' . "\n";
  6070. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6071. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6072. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6073. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  6074. for ($i = 0; $i < count($arrLP); $i++) {
  6075. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6076. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6077. $selected = 'selected="selected" ';
  6078. elseif ($action == 'add') $selected = 'selected="selected" ';
  6079. else
  6080. $selected = '';
  6081. $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>';
  6082. }
  6083. }
  6084. $return .= "\t\t\t\t" . '</select>';
  6085. $return .= "\t\t\t" . '</td>' . "\n";
  6086. $return .= "\t\t" . '</tr>' . "\n";
  6087. if ($action != 'move') {
  6088. $id_prerequisite = 0;
  6089. if (is_array($arrLP)) {
  6090. foreach ($arrLP as $key => $value) {
  6091. if ($value['id'] == $id) {
  6092. $id_prerequisite = $value['prerequisite'];
  6093. break;
  6094. }
  6095. }
  6096. }
  6097. $arrHide = array ();
  6098. for ($i = 0; $i < count($arrLP); $i++) {
  6099. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6100. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6101. $s_selected_position = $arrLP[$i]['id'];
  6102. elseif ($action == 'add') $s_selected_position = 0;
  6103. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  6104. }
  6105. }
  6106. //comented the prerequisites, only visible in edit (work)
  6107. /*
  6108. $return .= "\t\t" . '<tr>' . "\n";
  6109. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6110. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  6111. foreach($arrHide as $key => $value){
  6112. if($key==$s_selected_position && $action == 'add'){
  6113. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6114. }
  6115. elseif($key==$id_prerequisite && $action == 'edit'){
  6116. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6117. }
  6118. else{
  6119. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6120. }
  6121. }
  6122. $return .= "</select></td>";
  6123. */
  6124. $return .= "\t\t" . '</tr>' . "\n";
  6125. }
  6126. $return .= "\t\t" . '<tr>' . "\n";
  6127. if ($action == 'add') {
  6128. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6129. } else {
  6130. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6131. }
  6132. $return .= "\t\t" . '</tr>' . "\n";
  6133. $return .= "\t" . '</table>' . "\n";
  6134. if ($action == 'move') {
  6135. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6136. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6137. }
  6138. if (is_numeric($extra_info)) {
  6139. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6140. }
  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. *
  6153. * @return unknown
  6154. */
  6155. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6156. global $charset, $_course;
  6157. $return = '<div class="actions">';
  6158. switch ($item_type) {
  6159. case 'dokeos_chapter' :
  6160. case 'chapter' :
  6161. //comented the message cause should not show it
  6162. //$lang = get_lang('TitleManipulateChapter');
  6163. break;
  6164. case 'dokeos_module' :
  6165. case 'module' :
  6166. //comented the message cause should not show it
  6167. //$lang = get_lang('TitleManipulateModule');
  6168. break;
  6169. case TOOL_DOCUMENT :
  6170. //comented the message cause should not show it
  6171. //$lang = get_lang('TitleManipulateDocument');
  6172. break;
  6173. case TOOL_LINK :
  6174. case 'link' :
  6175. //comented the message cause should not show it
  6176. //$lang = get_lang('TitleManipulateLink');
  6177. break;
  6178. case TOOL_QUIZ :
  6179. //comented the message cause should not show it
  6180. //$lang = get_lang('TitleManipulateQuiz');
  6181. break;
  6182. case TOOL_STUDENTPUBLICATION :
  6183. //comented the message cause should not show it
  6184. //$lang = get_lang('TitleManipulateStudentPublication');
  6185. break;
  6186. }
  6187. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6188. $sql = "
  6189. SELECT
  6190. *
  6191. FROM " . $tbl_lp_item . " as lp
  6192. WHERE
  6193. lp.id = " . $item_id;
  6194. $result = Database::query($sql);
  6195. $row = Database::fetch_assoc($result);
  6196. $s_title = $row['title'];
  6197. $s_title = api_convert_encoding($s_title, $charset, $this->encoding);
  6198. // we display an audio player if needed
  6199. if (!empty ($row['audio'])) {
  6200. $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>';
  6201. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6202. $return .= '<script type="text/javascript">
  6203. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6204. s1.addParam("allowscriptaccess","always");
  6205. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6206. s1.write("container");
  6207. </script>';
  6208. }
  6209. //commented ":" for message in step
  6210. //$return .= $lang.': ';
  6211. $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>';
  6212. $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>';
  6213. // commented for now as prerequisites cannot be added to chapters
  6214. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6215. $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>';
  6216. }
  6217. $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>';
  6218. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  6219. //$return.="</td><td valign='top'>";
  6220. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  6221. ob_start();
  6222. $audio_recorder_studentview = 'false';
  6223. $audio_recorder_item_id = $item_id;
  6224. if (api_get_setting('service_visio', 'active') == 'true') {
  6225. include ('audiorecorder.inc.php');
  6226. }
  6227. $return .= ob_get_contents();
  6228. ob_end_clean();
  6229. // end of audiorecorder include
  6230. $return .= '</div>';
  6231. return $return;
  6232. }
  6233. /**
  6234. * Creates the javascript needed for filling up the checkboxes without page reload
  6235. *
  6236. * @return string
  6237. */
  6238. function create_js() {
  6239. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6240. $return .= 'function load_cbo(id){' . "\n";
  6241. $return .= "var cbo = document.getElementById('idPosition');\n";
  6242. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6243. $return .= 'cbo.options[i] = null;' . "\n";
  6244. $return .= 'var k=0;' . "\n";
  6245. $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
  6246. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
  6247. $return .= 'k=i;';
  6248. $return .= '}' . "\n\n";
  6249. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6250. $return .= '}';
  6251. $return .= 'var child_name = new Array();' . "\n";
  6252. $return .= 'var child_value = new Array();' . "\n\n";
  6253. $return .= 'child_name[0] = new Array();' . "\n";
  6254. $return .= 'child_value[0] = new Array();' . "\n\n";
  6255. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6256. $sql_zero = "
  6257. SELECT *
  6258. FROM " . $tbl_lp_item . "
  6259. WHERE
  6260. lp_id = " . $this->lp_id . " AND
  6261. parent_item_id = 0
  6262. ORDER BY display_order ASC";
  6263. $res_zero = Database::query($sql_zero);
  6264. global $charset;
  6265. $i = 0;
  6266. while ($row_zero = Database :: fetch_array($res_zero)) {
  6267. $return .= 'child_name[0][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_zero['title'], $charset, $this->encoding) . '\"";' . "\n";
  6268. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6269. }
  6270. $return .= "\n";
  6271. $sql = "
  6272. SELECT *
  6273. FROM " . $tbl_lp_item . "
  6274. WHERE
  6275. lp_id = " . $this->lp_id;
  6276. $res = Database::query($sql);
  6277. while ($row = Database :: fetch_array($res)) {
  6278. $sql_parent = "
  6279. SELECT *
  6280. FROM " . $tbl_lp_item . "
  6281. WHERE parent_item_id = " . $row['id'] . "
  6282. ORDER BY display_order ASC";
  6283. $res_parent = Database::query($sql_parent);
  6284. $i = 0;
  6285. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6286. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6287. while ($row_parent = Database :: fetch_array($res_parent)) {
  6288. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_parent['title'], $charset, $this->encoding) . '\"";' . "\n";
  6289. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6290. }
  6291. $return .= "\n";
  6292. }
  6293. $return .= '</script>' . "\n";
  6294. return $return;
  6295. }
  6296. /**
  6297. * Display the form to allow moving an item
  6298. *
  6299. * @param integer Item ID
  6300. * @return string HTML form
  6301. */
  6302. function display_move_item($item_id) {
  6303. global $_course; //will disappear
  6304. global $charset;
  6305. $return = '';
  6306. if (is_numeric($item_id)) {
  6307. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6308. $sql = "SELECT *
  6309. FROM " . $tbl_lp_item . "
  6310. WHERE id = " . $item_id;
  6311. $res = Database::query($sql);
  6312. $row = Database :: fetch_array($res);
  6313. switch ($row['item_type']) {
  6314. case 'dokeos_chapter' :
  6315. case 'dir' :
  6316. case 'asset' :
  6317. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6318. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6319. break;
  6320. case 'dokeos_module' :
  6321. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6322. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6323. break;
  6324. case TOOL_DOCUMENT :
  6325. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6326. $return .= $this->display_document_form('move', $item_id, $row);
  6327. break;
  6328. case TOOL_LINK :
  6329. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6330. $return .= $this->display_link_form('move', $item_id, $row);
  6331. break;
  6332. case TOOL_HOTPOTATOES :
  6333. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6334. $return .= $this->display_link_form('move', $item_id, $row);
  6335. break;
  6336. case TOOL_QUIZ :
  6337. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6338. $return .= $this->display_quiz_form('move', $item_id, $row);
  6339. break;
  6340. case TOOL_STUDENTPUBLICATION :
  6341. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6342. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6343. break;
  6344. case TOOL_FORUM :
  6345. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6346. $return .= $this->display_forum_form('move', $item_id, $row);
  6347. }
  6348. }
  6349. return $return;
  6350. }
  6351. /**
  6352. * Displays a basic form on the overview page for changing the item title and the item description.
  6353. *
  6354. * @param string $item_type
  6355. * @param string $title
  6356. * @param array $data
  6357. * @return string
  6358. */
  6359. function display_item_small_form($item_type, $title = '', $data) {
  6360. global $charset;
  6361. $return .= '<div class="lp_small_form">' . "\n";
  6362. $return .= '<p class="lp_title">' . $title . '</p>';
  6363. $return .= '<form method="post">' . "\n";
  6364. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6365. $return .= "\t\t" . '<tr>' . "\n";
  6366. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6367. $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";
  6368. $return .= "\t\t" . '</tr>' . "\n";
  6369. //it said these lines of code - see SVN#11724 and SVN#10770
  6370. //$return .= "\t\t" . '<tr>' . "\n";
  6371. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6372. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6373. //$return .= "\t\t" . '</tr>' . "\n";
  6374. $return .= "\t\t" . '<tr>' . "\n";
  6375. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6376. $return .= "\t\t" . '</tr>' . "\n";
  6377. $return .= "\t\t" . '</table>' . "\n";
  6378. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6379. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6380. $return .= '</form>';
  6381. $return .= '</div>';
  6382. return $return;
  6383. }
  6384. /**
  6385. * Return HTML form to allow prerequisites selection
  6386. *
  6387. * @param integer Item ID
  6388. * @return string HTML form
  6389. */
  6390. function display_item_prerequisites_form($item_id) {
  6391. global $charset;
  6392. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6393. /* current prerequisite */
  6394. $sql = "
  6395. SELECT *
  6396. FROM " . $tbl_lp_item . "
  6397. WHERE id = " . $item_id;
  6398. $result = Database::query($sql);
  6399. $row = Database :: fetch_array($result);
  6400. $preq_id = $row['prerequisite'];
  6401. //$preq_mastery = $row['mastery_score'];
  6402. //$preq_max = $row['max_score'];
  6403. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6404. $return = ' <div class="row">
  6405. <div class="form_header">';
  6406. $return .= get_lang('AddEditPrerequisites');
  6407. $return .= '</div> </div>';
  6408. $return .= '<div class="sectioncomment">';
  6409. $return .= '<form method="POST">';
  6410. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6411. $return .= '<tr style="border-collapse:collapse;">';
  6412. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6413. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6414. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6415. $return .= '</tr>';
  6416. //Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6417. $return .= '<tr >';
  6418. $return .= '<td colspan="3" class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6419. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6420. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6421. $return .= '</td><td />';
  6422. $return .= '</tr>';
  6423. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6424. $result = Database::query($sql);
  6425. $arrLP = array ();
  6426. while ($row = Database :: fetch_array($result)) {
  6427. $arrLP[] = array (
  6428. 'id' => $row['id'],
  6429. 'item_type' => $row['item_type'],
  6430. 'title' => api_convert_encoding($row['title'], $charset, $this->encoding),
  6431. 'ref' => $row['ref'],
  6432. 'description' => $row['description'],
  6433. 'parent_item_id' => $row['parent_item_id'],
  6434. 'previous_item_id' => $row['previous_item_id'],
  6435. 'next_item_id' => $row['next_item_id'],
  6436. 'max_score' => $row['max_score'],
  6437. 'min_score' => $row['min_score'],
  6438. 'mastery_score' => $row['mastery_score'],
  6439. 'prerequisite' => $row['prerequisite'],
  6440. 'next_item_id' => $row['next_item_id'],
  6441. 'display_order' => $row['display_order']
  6442. );
  6443. if ($row['ref'] == $preq_id) {
  6444. $preq_mastery = $row['mastery_score'];
  6445. $preq_max = $row['max_score'];
  6446. }
  6447. }
  6448. $this->tree_array($arrLP);
  6449. $arrLP = $this->arrMenu;
  6450. unset ($this->arrMenu);
  6451. for ($i = 0; $i < count($arrLP); $i++) {
  6452. if ($arrLP[$i]['id'] == $item_id)
  6453. break;
  6454. $return .= '<tr >';
  6455. $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"' : '') . '>';
  6456. $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'] . '" />';
  6457. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6458. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  6459. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6460. } else
  6461. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  6462. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6463. } else {
  6464. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6465. }
  6466. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6467. $return .= '</td>';
  6468. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6469. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6470. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6471. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6472. $return .= '</td>';
  6473. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6474. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6475. $return .= '</td>';
  6476. }
  6477. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6478. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6479. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6480. $return .= '</td>';
  6481. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6482. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6483. $return .= '</td>';
  6484. }
  6485. $return .= '</tr>';
  6486. }
  6487. $return .= '<tr>';
  6488. $return .= '<td colspan="3">';
  6489. $return .= '</td>';
  6490. $return .= '</tr>';
  6491. $return .= '</table>';
  6492. $return .= '<div style="padding-top:3px;">';
  6493. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang("ModifyPrerequisites") . ' </button></td>' . "\n";
  6494. $return .= '</div>';
  6495. $return .= '</form>';
  6496. $return .= '</div>';
  6497. return $return;
  6498. }
  6499. /**
  6500. * Creates a list with all the documents in it
  6501. *
  6502. * @return string
  6503. */
  6504. function get_documents() {
  6505. global $_course;
  6506. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6507. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6508. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6509. $path = '/';
  6510. $path = Database::escape_string(str_replace('_', '\_', $path));
  6511. $added_slash = ($path == '/') ? '' : '/';
  6512. //condition for the session
  6513. $current_session_id = api_get_session_id();
  6514. $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]}')))";
  6515. $sql_doc = "SELECT docs.*
  6516. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6517. WHERE docs.id = last.ref
  6518. AND docs.path LIKE '".$path.$added_slash."%'
  6519. AND docs.path NOT LIKE '%_DELETED_%'
  6520. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6521. //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
  6522. $res_doc = Database::query($sql_doc);
  6523. $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>';
  6524. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6525. $resources = Database::store_result($res_doc);
  6526. $resources_sorted = array ();
  6527. // if you want to debug it, I advise you to do "echo" on the eval statements
  6528. foreach ($resources as $resource) {
  6529. $resource_paths = explode('/', $resource['path']);
  6530. array_shift($resource_paths);
  6531. $path_to_eval = $last_path = '';
  6532. $is_file = false;
  6533. foreach ($resource_paths as $key => $resource_path) {
  6534. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // it's a folder
  6535. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6536. } else
  6537. if (strpos($resource_path, '.') !== false)
  6538. $is_file = true;
  6539. $last_path = $resource_path;
  6540. }
  6541. if ($is_file) {
  6542. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6543. } else {
  6544. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6545. }
  6546. }
  6547. $return .= $this->write_resources_tree($resources_sorted);
  6548. if (Database :: num_rows($res_doc) == 0)
  6549. $return .= '<div class="lp_resource_element">' . get_lang("NoDocuments") . '</div>';
  6550. $return .= '</div>';
  6551. return $return;
  6552. }
  6553. /**
  6554. * Generate and return an HTML list of resources based on a given array.
  6555. *
  6556. * This list is used to show the course creator a list of available resources to choose from
  6557. * when creating a learning path.
  6558. * @param array Array of elements to add to the list
  6559. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6560. * @return string The HTML list
  6561. */
  6562. function write_resources_tree($resources_sorted, $num = 0) {
  6563. include_once (api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  6564. if (count($resources_sorted) > 0) {
  6565. foreach ($resources_sorted as $key => $resource) {
  6566. if (is_int($resource['id'])) { // it's a folder
  6567. $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'] . '">';
  6568. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6569. $return .= "</div></div>\r\n";
  6570. } else {
  6571. // it's a file
  6572. $icon = choose_image($resource);
  6573. $position = strrpos($icon, '.');
  6574. $icon = substr($icon, 0, $position) . '_small.gif';
  6575. $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>\r\n";
  6576. }
  6577. }
  6578. }
  6579. return $return;
  6580. }
  6581. /**
  6582. * Creates a list with all the exercises (quiz) in it
  6583. *
  6584. * @return string
  6585. */
  6586. function get_exercises() {
  6587. // new for hotpotatoes
  6588. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6589. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6590. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6591. $session_id = api_get_session_id();
  6592. $condition_session = api_get_session_condition($session_id);
  6593. $sql_quiz = "
  6594. SELECT *
  6595. FROM " . $tbl_quiz . "
  6596. WHERE active<>'-1' $condition_session
  6597. ORDER BY title ASC";
  6598. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6599. " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
  6600. " ORDER BY id ASC";
  6601. $res_quiz = Database::query($sql_quiz);
  6602. $res_hot = Database::query($sql_hot);
  6603. $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>';
  6604. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6605. while ($row_hot = Database :: fetch_array($res_hot)) {
  6606. $return .= '<div class="lp_resource_element">';
  6607. //display quizhotpotatoes
  6608. $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
  6609. $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'] : $row_hot['title']) . '</a>';
  6610. //$return .= $row_quiz['title'];
  6611. $return .= '</div>';
  6612. }
  6613. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6614. $return .= '<div class="lp_resource_element">';
  6615. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6616. $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 . '">' . $row_quiz['title'] . '</a>';
  6617. //$return .= $row_quiz['title'];
  6618. $return .= '</div>';
  6619. }
  6620. if (Database :: num_rows($res_quiz) == 0)
  6621. $return .= '<div class="lp_resource_element">' . get_lang("NoExercisesAvailable") . '</div>';
  6622. $return .= '<div class="lp_resource_element">';
  6623. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6624. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6625. $return .= '</div>';
  6626. $return .= '</div>';
  6627. return $return;
  6628. }
  6629. /**
  6630. * Creates a list with all the links in it
  6631. *
  6632. * @return string
  6633. */
  6634. function get_links() {
  6635. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6636. $session_id = api_get_session_id();
  6637. $condition_session = api_get_session_condition($session_id,false);
  6638. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6639. $res_link = Database::query($sql_link);
  6640. $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>';
  6641. $return .= '<div class="lp_resource_elements" id="resLink">';
  6642. while ($row_link = Database :: fetch_array($res_link)) {
  6643. $return .= '<div class="lp_resource_element">';
  6644. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6645. $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>';
  6646. $return .= '</div>';
  6647. }
  6648. $return .= '<div class="lp_resource_element">';
  6649. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6650. $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>';
  6651. $return .= '</div>';
  6652. if (Database :: num_rows($res_link) == 0)
  6653. $return .= '<div class="lp_resource_element">' . get_lang("NoLinksAvailable") . '</div>';
  6654. $return .= '</div>';
  6655. return $return;
  6656. }
  6657. /**
  6658. * Creates a list with all the student publications in it
  6659. *
  6660. * @return unknown
  6661. */
  6662. function get_student_publications() {
  6663. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6664. $session_id = api_get_session_id();
  6665. $condition_session = api_get_session_condition($session_id,false);
  6666. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6667. $res_student = Database::query($sql_student);
  6668. $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>';
  6669. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6670. $return .= '<div class="lp_resource_element">';
  6671. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6672. $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>';
  6673. $return .= '</div>';
  6674. $return .= '</div>';
  6675. return $return;
  6676. }
  6677. /**
  6678. * Creates a list with all the forums in it
  6679. *
  6680. * @return string
  6681. */
  6682. function get_forums() {
  6683. include ('../forum/forumfunction.inc.php');
  6684. include ('../forum/forumconfig.inc.php');
  6685. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6686. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6687. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6688. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6689. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6690. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6691. $a_forums = get_forums();
  6692. $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>';
  6693. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6694. foreach ($a_forums as $forum) {
  6695. $return .= '<div class="lp_resource_element">';
  6696. $return .= '<script type="text/javascript">
  6697. function toggle_forum(forum_id){
  6698. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6699. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6700. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6701. }
  6702. else {
  6703. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6704. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6705. }
  6706. }
  6707. </script>
  6708. ';
  6709. if (!empty($forum['forum_id'])) {
  6710. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6711. $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>
  6712. <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">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
  6713. }
  6714. $a_threads = get_threads($forum['forum_id']);
  6715. if (is_array($a_threads)) {
  6716. foreach ($a_threads as $thread) {
  6717. $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 . '">' . $thread['thread_title'] . '</a></li>';
  6718. }
  6719. }
  6720. $return .= '</ul></div>';
  6721. }
  6722. $return .= '<div class="lp_resource_element">';
  6723. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6724. $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>';
  6725. $return .= '</div>';
  6726. return $return;
  6727. }
  6728. /**
  6729. * Exports the learning path as a SCORM package. This is the main function that
  6730. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6731. * whole thing and returns the zip.
  6732. *
  6733. * This method needs to be called in PHP5, as it will fail with non-adequate
  6734. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6735. * you need to call it on a learnpath object.
  6736. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6737. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6738. * path has been modified, it should use the generic method here below.
  6739. * @TODO link this function with the export_lp() function in the same class
  6740. * @param string Optional name of zip file. If none, title of learnpath is
  6741. * domesticated and trailed with ".zip"
  6742. * @return string Returns the zip package string, or null if error
  6743. */
  6744. function scorm_export()
  6745. {
  6746. global $_course;
  6747. global $charset;
  6748. if (!class_exists('DomDocument'))
  6749. {
  6750. error_log('DOM functions not supported for PHP version below 5.0',0);
  6751. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6752. return null;
  6753. }
  6754. //remove memory and time limits as much as possible as this might be a long process...
  6755. if(function_exists('ini_set'))
  6756. {
  6757. $mem = ini_get('memory_limit');
  6758. if(substr($mem,-1,1)=='M')
  6759. {
  6760. $mem_num = substr($mem,0,-1);
  6761. if($mem_num<128)
  6762. {
  6763. ini_set('memory_limit','128M');
  6764. }
  6765. }
  6766. else
  6767. {
  6768. ini_set('memory_limit','128M');
  6769. }
  6770. ini_set('max_execution_time',600);
  6771. //}else{
  6772. //error_log('Scorm export: could not change memory and time limits',0);
  6773. }
  6774. //Create the zip handler (this will remain available throughout the method)
  6775. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6776. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6777. $temp_dir_short = uniqid();
  6778. $temp_zip_dir = $archive_path."/".$temp_dir_short;
  6779. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6780. $zip_folder=new PclZip($temp_zip_file);
  6781. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6782. $root_path = $main_path = api_get_path(SYS_PATH);
  6783. $files_cleanup = array();
  6784. //place to temporarily stash the zipfiles
  6785. //create the temp dir if it doesn't exist
  6786. //or do a cleanup befor creating the zipfile
  6787. if(!is_dir($temp_zip_dir))
  6788. {
  6789. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6790. }
  6791. else
  6792. {//cleanup: check the temp dir for old files and delete them
  6793. $handle=opendir($temp_zip_dir);
  6794. while (false!==($file = readdir($handle)))
  6795. {
  6796. if ($file != "." && $file != "..")
  6797. {
  6798. unlink("$temp_zip_dir/$file");
  6799. }
  6800. }
  6801. closedir($handle);
  6802. }
  6803. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6804. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6805. {
  6806. // remove the possible . at the end of the path
  6807. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6808. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6809. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  6810. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6811. }
  6812. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6813. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6814. //Aggregation Model official document, secion "2.3 Content Packaging"
  6815. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6816. $root = $xmldoc->createElement('manifest');
  6817. $root->setAttribute('identifier','SingleCourseManifest');
  6818. $root->setAttribute('version','1.1');
  6819. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6820. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6821. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6822. $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');
  6823. //Build mandatory sub-root container elements
  6824. $metadata = $xmldoc->createElement('metadata');
  6825. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6826. $metadata->appendChild($md_schema);
  6827. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6828. $metadata->appendChild($md_schemaversion);
  6829. $root->appendChild($metadata);
  6830. $organizations = $xmldoc->createElement('organizations');
  6831. $resources = $xmldoc->createElement('resources');
  6832. //Build the only organization we will use in building our learnpaths
  6833. $organizations->setAttribute('default','dokeos_scorm_export');
  6834. $organization = $xmldoc->createElement('organization');
  6835. $organization->setAttribute('identifier','dokeos_scorm_export');
  6836. //to set the title of the SCORM entity (=organization), we take the name given
  6837. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6838. //learning path charset) as it is the encoding that defines how it is stored
  6839. //in the database. Then we convert it to HTML entities again as the "&" character
  6840. //alone is not authorized in XML (must be &amp;)
  6841. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6842. $org_title = $xmldoc->createElement('title',htmlentities(api_htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6843. $organization->appendChild($org_title);
  6844. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6845. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6846. //format
  6847. $link_updates = array();
  6848. foreach($this->items as $index => $item){
  6849. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6850. {
  6851. //get included documents from this item
  6852. if($item->type=='sco')
  6853. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6854. else
  6855. $inc_docs = $item->get_resources_from_source();
  6856. //give a child element <item> to the <organization> element
  6857. $my_item_id = $item->get_id();
  6858. $my_item = $xmldoc->createElement('item');
  6859. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6860. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6861. $my_item->setAttribute('isvisible','true');
  6862. //give a child element <title> to the <item> element
  6863. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  6864. $my_item->appendChild($my_title);
  6865. //give a child element <adlcp:prerequisites> to the <item> element
  6866. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6867. $my_prereqs->setAttribute('type','aicc_script');
  6868. $my_item->appendChild($my_prereqs);
  6869. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6870. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6871. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6872. //$xmldoc->createElement('adlcp:timelimitaction','');
  6873. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6874. //$xmldoc->createElement('adlcp:datafromlms','');
  6875. //give a child element <adlcp:masteryscore> to the <item> element
  6876. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  6877. $my_item->appendChild($my_masteryscore);
  6878. //attach this item to the organization element or hits parent if there is one
  6879. if(!empty($item->parent) && $item->parent!=0)
  6880. {
  6881. $children = $organization->childNodes;
  6882. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6883. if(is_object($possible_parent))
  6884. {
  6885. $possible_parent->appendChild($my_item);
  6886. }
  6887. else
  6888. {
  6889. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6890. }
  6891. }
  6892. else
  6893. {
  6894. if($this->debug>0){error_log('No parent');}
  6895. $organization->appendChild($my_item);
  6896. }
  6897. //get the path of the file(s) from the course directory root
  6898. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6899. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  6900. $my_sub_dir = dirname($my_file_path);
  6901. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  6902. //give a <resource> child to the <resources> element
  6903. $my_resource = $xmldoc->createElement('resource');
  6904. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6905. $my_resource->setAttribute('type','webcontent');
  6906. $my_resource->setAttribute('href',$my_xml_file_path);
  6907. //adlcp:scormtype can be either 'sco' or 'asset'
  6908. if($item->type=='sco')
  6909. {
  6910. $my_resource->setAttribute('adlcp:scormtype','sco');
  6911. }
  6912. else
  6913. {
  6914. $my_resource->setAttribute('adlcp:scormtype','asset');
  6915. }
  6916. //xml:base is the base directory to find the files declared in this resource
  6917. $my_resource->setAttribute('xml:base','');
  6918. //give a <file> child to the <resource> element
  6919. $my_file = $xmldoc->createElement('file');
  6920. $my_file->setAttribute('href',$my_xml_file_path);
  6921. $my_resource->appendChild($my_file);
  6922. //dependency to other files - not yet supported
  6923. $i = 1;
  6924. foreach($inc_docs as $doc_info)
  6925. {
  6926. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6927. $my_dep = $xmldoc->createElement('resource');
  6928. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6929. $my_dep->setAttribute('identifier',$res_id);
  6930. $my_dep->setAttribute('type','webcontent');
  6931. $my_dep->setAttribute('adlcp:scormtype','asset');
  6932. $my_dep_file = $xmldoc->createElement('file');
  6933. //check type of URL
  6934. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6935. if($doc_info[1] == 'remote')
  6936. { //remote file. Save url as is
  6937. $my_dep_file->setAttribute('href',$doc_info[0]);
  6938. $my_dep->setAttribute('xml:base','');
  6939. }elseif($doc_info[1] == 'local'){
  6940. switch($doc_info[2])
  6941. {
  6942. case 'url': //local URL - save path as url for now, don't zip file
  6943. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6944. $current_dir = dirname($abs_path);
  6945. $file_path = realpath($abs_path);
  6946. $my_dep_file->setAttribute('href',$file_path);
  6947. $my_dep->setAttribute('xml:base','');
  6948. if(strstr($file_path,$main_path) !== false)
  6949. {//the calculated real path is really inside the dokeos root path
  6950. //reduce file path to what's under the DocumentRoot
  6951. $file_path = substr($file_path,strlen($root_path)-1);
  6952. //echo $file_path;echo '<br><br>';
  6953. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6954. $zip_files_abs[] = $file_path;
  6955. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6956. $my_dep_file->setAttribute('href',$file_path);
  6957. $my_dep->setAttribute('xml:base','');
  6958. }
  6959. else if (empty($file_path))
  6960. {
  6961. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6962. if(strpos($document_root,-1)=='/')
  6963. {
  6964. $document_root = substr(0, -1, $document_root);
  6965. }*/
  6966. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6967. $file_path = str_replace('//','/',$file_path);
  6968. if(file_exists($file_path))
  6969. {
  6970. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6971. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6972. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6973. $my_dep_file->setAttribute('href',$file_path);
  6974. $my_dep->setAttribute('xml:base','');
  6975. }
  6976. }
  6977. break;
  6978. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6979. $my_dep_file->setAttribute('href',$doc_info[0]);
  6980. $my_dep->setAttribute('xml:base','');
  6981. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6982. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  6983. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  6984. $abs_img_path_without_subdir = $doc_info[0];
  6985. $relp = api_get_path(REL_PATH); //the url-append config param
  6986. $pos = strpos($abs_img_path_without_subdir,$relp);
  6987. if($pos===0)
  6988. {
  6989. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  6990. }
  6991. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6992. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  6993. $file_path = str_replace('\\','/',$file_path);
  6994. $file_path = str_replace('//','/',$file_path);
  6995. //error_log(__LINE__.'Abs path: '.$file_path,0);
  6996. //prepare the current directory path (until just under 'document') with a trailing slash
  6997. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6998. //check if the current document is in that path
  6999. if(strstr($file_path,$cur_path) !== false)
  7000. {
  7001. //the document is in that path, now get the relative path
  7002. //to the containing document
  7003. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7004. $relative_path ='';
  7005. if(strstr($file_path,$cur_path)!==false)
  7006. {
  7007. $relative_path = substr($file_path,strlen($orig_file_path));
  7008. $file_path = substr($file_path,strlen($cur_path));
  7009. }
  7010. else
  7011. {
  7012. //this case is still a problem as it's difficult to calculate a relative path easily
  7013. //might still generate wrong links
  7014. //$file_path = substr($file_path,strlen($cur_path));
  7015. //calculate the directory path to the current file (without trailing slash)
  7016. $my_relative_path = dirname($file_path);
  7017. $my_relative_file = basename($file_path);
  7018. //calculate the directory path to the containing file (without trailing slash)
  7019. $my_orig_file_path = substr($orig_file_path,0,-1);
  7020. $dotdot = '';
  7021. $subdir = '';
  7022. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  7023. {
  7024. $my_relative_path2 = dirname($my_relative_path);
  7025. $my_orig_file_path = dirname($my_orig_file_path);
  7026. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  7027. $dotdot += '../';
  7028. $my_relative_path = $my_relative_path2;
  7029. }
  7030. $relative_path = $dotdot.$subdir.$my_relative_file;
  7031. }
  7032. //put the current document in the zip (this array is the array
  7033. //that will manage documents already in the course folder - relative)
  7034. $zip_files[] = $file_path;
  7035. //update the links to the current document in the containing document (make them relative)
  7036. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  7037. $my_dep_file->setAttribute('href',$file_path);
  7038. $my_dep->setAttribute('xml:base','');
  7039. }
  7040. elseif(strstr($file_path,$main_path) !== false)
  7041. {//the calculated real path is really inside the dokeos root path
  7042. //reduce file path to what's under the DocumentRoot
  7043. $file_path = substr($file_path,strlen($root_path));
  7044. //echo $file_path;echo '<br><br>';
  7045. //error_log('Reduced path: '.$file_path,0);
  7046. $zip_files_abs[] = $file_path;
  7047. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7048. $my_dep_file->setAttribute('href','document/'.$file_path);
  7049. $my_dep->setAttribute('xml:base','');
  7050. }
  7051. else if (empty($file_path))
  7052. {
  7053. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7054. if(strpos($document_root,-1)=='/')
  7055. {
  7056. $document_root = substr(0, -1, $document_root);
  7057. }*/
  7058. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7059. $file_path = str_replace('//','/',$file_path);
  7060. if(file_exists($file_path))
  7061. {
  7062. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7063. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7064. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7065. $my_dep_file->setAttribute('href','document/'.$file_path);
  7066. $my_dep->setAttribute('xml:base','');
  7067. }
  7068. }
  7069. break;
  7070. 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
  7071. if(substr($doc_info[0],0,2)=='..')
  7072. { //relative path going up
  7073. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7074. $file_path = realpath($current_dir.$doc_info[0]);
  7075. //error_log($file_path.' <-> '.$main_path,0);
  7076. if(strstr($file_path,$main_path) !== false)
  7077. {//the calculated real path is really inside the dokeos root path
  7078. //reduce file path to what's under the DocumentRoot
  7079. $file_path = substr($file_path,strlen($root_path));
  7080. //error_log('Reduced path: '.$file_path,0);
  7081. $zip_files_abs[] = $file_path;
  7082. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7083. $my_dep_file->setAttribute('href','document/'.$file_path);
  7084. $my_dep->setAttribute('xml:base','');
  7085. }
  7086. }else{
  7087. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7088. $my_dep_file->setAttribute('href',$doc_info[0]);
  7089. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7090. }
  7091. break;
  7092. default:
  7093. $my_dep_file->setAttribute('href',$doc_info[0]);
  7094. $my_dep->setAttribute('xml:base','');
  7095. break;
  7096. }
  7097. }
  7098. $my_dep->appendChild($my_dep_file);
  7099. $resources->appendChild($my_dep);
  7100. $dependency = $xmldoc->createElement('dependency');
  7101. $dependency->setAttribute('identifierref',$res_id);
  7102. $my_resource->appendChild($dependency);
  7103. $i++;
  7104. }
  7105. //$my_dependency = $xmldoc->createElement('dependency');
  7106. //$my_dependency->setAttribute('identifierref','');
  7107. $resources->appendChild($my_resource);
  7108. $zip_files[] = $my_file_path;
  7109. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  7110. }
  7111. else
  7112. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  7113. if($item->type == TOOL_LINK)
  7114. {
  7115. $my_item = $xmldoc->createElement('item');
  7116. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7117. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7118. $my_item->setAttribute('isvisible','true');
  7119. //give a child element <title> to the <item> element
  7120. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7121. $my_item->appendChild($my_title);
  7122. //give a child element <adlcp:prerequisites> to the <item> element
  7123. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7124. $my_prereqs->setAttribute('type','aicc_script');
  7125. $my_item->appendChild($my_prereqs);
  7126. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  7127. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7128. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  7129. //$xmldoc->createElement('adlcp:timelimitaction','');
  7130. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  7131. //$xmldoc->createElement('adlcp:datafromlms','');
  7132. //give a child element <adlcp:masteryscore> to the <item> element
  7133. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7134. $my_item->appendChild($my_masteryscore);
  7135. //attach this item to the organization element or its parent if there is one
  7136. if(!empty($item->parent) && $item->parent!=0)
  7137. {
  7138. $children = $organization->childNodes;
  7139. for($i=0;$i<$children->length;$i++){
  7140. $item_temp = $children->item($i);
  7141. if ($item_temp -> nodeName == 'item')
  7142. {
  7143. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7144. {
  7145. $item_temp -> appendChild($my_item);
  7146. }
  7147. }
  7148. }
  7149. }
  7150. else
  7151. {
  7152. $organization->appendChild($my_item);
  7153. }
  7154. $my_file_path = 'link_'.$item->get_id().'.html';
  7155. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7156. $rs = Database::query($sql);
  7157. if($link = Database :: fetch_array($rs))
  7158. {
  7159. $url = $link['url'];
  7160. $title = stripslashes($link['title']);
  7161. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  7162. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7163. $my_sub_dir = dirname($my_file_path);
  7164. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7165. //give a <resource> child to the <resources> element
  7166. $my_resource = $xmldoc->createElement('resource');
  7167. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7168. $my_resource->setAttribute('type','webcontent');
  7169. $my_resource->setAttribute('href',$my_xml_file_path);
  7170. //adlcp:scormtype can be either 'sco' or 'asset'
  7171. $my_resource->setAttribute('adlcp:scormtype','asset');
  7172. //xml:base is the base directory to find the files declared in this resource
  7173. $my_resource->setAttribute('xml:base','');
  7174. //give a <file> child to the <resource> element
  7175. $my_file = $xmldoc->createElement('file');
  7176. $my_file->setAttribute('href',$my_xml_file_path);
  7177. $my_resource->appendChild($my_file);
  7178. $resources->appendChild($my_resource);
  7179. }
  7180. }
  7181. elseif($item->type == TOOL_QUIZ)
  7182. {
  7183. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  7184. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  7185. $exe = new Exercise();
  7186. $exe->read($exe_id);
  7187. $my_item = $xmldoc->createElement('item');
  7188. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7189. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7190. $my_item->setAttribute('isvisible','true');
  7191. //give a child element <title> to the <item> element
  7192. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  7193. $my_item->appendChild($my_title);
  7194. $my_max_score = $xmldoc->createElement('max_score',$item->get_max());
  7195. $my_item->appendChild($my_max_score);
  7196. //give a child element <adlcp:prerequisites> to the <item> element
  7197. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7198. $my_prereqs->setAttribute('type','aicc_script');
  7199. $my_item->appendChild($my_prereqs);
  7200. //give a child element <adlcp:masteryscore> to the <item> element
  7201. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7202. $my_item->appendChild($my_masteryscore);
  7203. //attach this item to the organization element or hits parent if there is one
  7204. if(!empty($item->parent) && $item->parent!=0)
  7205. {
  7206. $children = $organization->childNodes;
  7207. for($i=0;$i<$children->length;$i++){
  7208. $item_temp = $children->item($i);
  7209. if ($item_temp -> nodeName == 'item')
  7210. {
  7211. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7212. {
  7213. $item_temp -> appendChild($my_item);
  7214. }
  7215. }
  7216. }
  7217. }
  7218. else
  7219. {
  7220. $organization->appendChild($my_item);
  7221. }
  7222. //include export scripts
  7223. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  7224. //get the path of the file(s) from the course directory root
  7225. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7226. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7227. //write the contents of the exported exercise into a (big) html file
  7228. //to later pack it into the exported SCORM. The file will be removed afterwards
  7229. $contents = export_exercise($exe_id,true);
  7230. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7231. $res = file_put_contents($tmp_file_path,$contents);
  7232. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7233. $files_cleanup[] = $tmp_file_path;
  7234. //error_log($tmp_path);die();
  7235. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7236. $my_sub_dir = dirname($my_file_path);
  7237. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7238. //give a <resource> child to the <resources> element
  7239. $my_resource = $xmldoc->createElement('resource');
  7240. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7241. $my_resource->setAttribute('type','webcontent');
  7242. $my_resource->setAttribute('href',$my_xml_file_path);
  7243. //adlcp:scormtype can be either 'sco' or 'asset'
  7244. $my_resource->setAttribute('adlcp:scormtype','sco');
  7245. //xml:base is the base directory to find the files declared in this resource
  7246. $my_resource->setAttribute('xml:base','');
  7247. //give a <file> child to the <resource> element
  7248. $my_file = $xmldoc->createElement('file');
  7249. $my_file->setAttribute('href',$my_xml_file_path);
  7250. $my_resource->appendChild($my_file);
  7251. //get included docs
  7252. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7253. //dependency to other files - not yet supported
  7254. $i = 1;
  7255. foreach($inc_docs as $doc_info)
  7256. {
  7257. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7258. $my_dep = $xmldoc->createElement('resource');
  7259. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7260. $my_dep->setAttribute('identifier',$res_id);
  7261. $my_dep->setAttribute('type','webcontent');
  7262. $my_dep->setAttribute('adlcp:scormtype','asset');
  7263. $my_dep_file = $xmldoc->createElement('file');
  7264. //check type of URL
  7265. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7266. if($doc_info[1] == 'remote')
  7267. { //remote file. Save url as is
  7268. $my_dep_file->setAttribute('href',$doc_info[0]);
  7269. $my_dep->setAttribute('xml:base','');
  7270. }elseif($doc_info[1] == 'local'){
  7271. switch($doc_info[2])
  7272. {
  7273. case 'url': //local URL - save path as url for now, don't zip file
  7274. //save file but as local file (retrieve from URL)
  7275. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7276. $current_dir = dirname($abs_path);
  7277. $file_path = realpath($abs_path);
  7278. $my_dep_file->setAttribute('href','document/'.$file_path);
  7279. $my_dep->setAttribute('xml:base','');
  7280. if(strstr($file_path,$main_path) !== false)
  7281. {//the calculated real path is really inside the dokeos root path
  7282. //reduce file path to what's under the DocumentRoot
  7283. $file_path = substr($file_path,strlen($root_path));
  7284. //echo $file_path;echo '<br><br>';
  7285. //error_log('Reduced path: '.$file_path,0);
  7286. $zip_files_abs[] = $file_path;
  7287. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7288. $my_dep_file->setAttribute('href','document/'.$file_path);
  7289. $my_dep->setAttribute('xml:base','');
  7290. }
  7291. else if (empty($file_path))
  7292. {
  7293. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7294. if(strpos($document_root,-1)=='/')
  7295. {
  7296. $document_root = substr(0, -1, $document_root);
  7297. }*/
  7298. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7299. $file_path = str_replace('//','/',$file_path);
  7300. if(file_exists($file_path))
  7301. {
  7302. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7303. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7304. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7305. $my_dep_file->setAttribute('href','document/'.$file_path);
  7306. $my_dep->setAttribute('xml:base','');
  7307. }
  7308. }
  7309. break;
  7310. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7311. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7312. $file_path = realpath($doc_info[0]);
  7313. $my_dep_file->setAttribute('href',$file_path);
  7314. $my_dep->setAttribute('xml:base','');
  7315. if(strstr($file_path,$main_path) !== false)
  7316. {//the calculated real path is really inside the dokeos root path
  7317. //reduce file path to what's under the DocumentRoot
  7318. $file_path = substr($file_path,strlen($root_path));
  7319. //echo $file_path;echo '<br><br>';
  7320. //error_log('Reduced path: '.$file_path,0);
  7321. $zip_files_abs[] = $file_path;
  7322. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7323. $my_dep_file->setAttribute('href','document/'.$file_path);
  7324. $my_dep->setAttribute('xml:base','');
  7325. }
  7326. else if (empty($file_path))
  7327. {
  7328. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7329. if(strpos($document_root,-1)=='/')
  7330. {
  7331. $document_root = substr(0, -1, $document_root);
  7332. }*/
  7333. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7334. $file_path = str_replace('//','/',$file_path);
  7335. if(file_exists($file_path))
  7336. {
  7337. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7338. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7339. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7340. $my_dep_file->setAttribute('href','document/'.$file_path);
  7341. $my_dep->setAttribute('xml:base','');
  7342. }
  7343. }
  7344. break;
  7345. 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
  7346. if(substr($doc_info[0],0,2)=='..')
  7347. { //relative path going up
  7348. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7349. $file_path = realpath($current_dir.$doc_info[0]);
  7350. //error_log($file_path.' <-> '.$main_path,0);
  7351. if(strstr($file_path,$main_path) !== false)
  7352. {//the calculated real path is really inside the dokeos root path
  7353. //reduce file path to what's under the DocumentRoot
  7354. $file_path = substr($file_path,strlen($root_path));
  7355. $file_path_dest=$file_path;
  7356. //file path is courses/DOKEOS/document/....
  7357. $info_file_path=explode('/',$file_path);
  7358. if ($info_file_path[0]=='courses') {//add character "/" in file path
  7359. $file_path_dest='/'.$file_path;
  7360. }
  7361. //error_log('Reduced path: '.$file_path,0);
  7362. $zip_files_abs[] = $file_path;
  7363. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path_dest);
  7364. $my_dep_file->setAttribute('href','document/'.$file_path);
  7365. $my_dep->setAttribute('xml:base','');
  7366. }
  7367. }else{
  7368. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7369. $my_dep_file->setAttribute('href',$doc_info[0]);
  7370. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7371. }
  7372. break;
  7373. default:
  7374. $my_dep_file->setAttribute('href',$doc_info[0]);// ../../courses/
  7375. $my_dep->setAttribute('xml:base','');
  7376. break;
  7377. }
  7378. }
  7379. $my_dep->appendChild($my_dep_file);
  7380. $resources->appendChild($my_dep);
  7381. $dependency = $xmldoc->createElement('dependency');
  7382. $dependency->setAttribute('identifierref',$res_id);
  7383. $my_resource->appendChild($dependency);
  7384. $i++;
  7385. }
  7386. $resources->appendChild($my_resource);
  7387. $zip_files[] = $my_file_path;
  7388. }
  7389. else
  7390. {
  7391. //get the path of the file(s) from the course directory root
  7392. $my_file_path = 'non_exportable.html';
  7393. $my_xml_file_path = api_htmlentities($my_file_path, ENT_COMPAT, $this->encoding);
  7394. $my_sub_dir = dirname($my_file_path);
  7395. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_COMPAT, $this->encoding);
  7396. //give a <resource> child to the <resources> element
  7397. $my_resource = $xmldoc->createElement('resource');
  7398. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7399. $my_resource->setAttribute('type','webcontent');
  7400. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7401. //adlcp:scormtype can be either 'sco' or 'asset'
  7402. $my_resource->setAttribute('adlcp:scormtype','asset');
  7403. //xml:base is the base directory to find the files declared in this resource
  7404. $my_resource->setAttribute('xml:base','');
  7405. //give a <file> child to the <resource> element
  7406. $my_file = $xmldoc->createElement('file');
  7407. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7408. $my_resource->appendChild($my_file);
  7409. $resources->appendChild($my_resource);
  7410. }
  7411. }
  7412. }
  7413. $organizations->appendChild($organization);
  7414. $root->appendChild($organizations);
  7415. $root->appendChild($resources);
  7416. $xmldoc->appendChild($root);
  7417. //todo: add a readme file here, with a short description and a link to the Reload player
  7418. //then add the file to the zip, then destroy the file (this is done automatically)
  7419. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7420. //error_log(print_r($zip_files,true),0);
  7421. foreach($zip_files as $file_path)
  7422. {
  7423. if(empty($file_path)){continue;}
  7424. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7425. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7426. $this->create_path($dest_file);
  7427. //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);
  7428. //echo $main_path.$file_path.'<br>';
  7429. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7430. //check if the file needs a link update
  7431. if(in_array($file_path,array_keys($link_updates))){
  7432. $string = file_get_contents($dest_file);
  7433. unlink($dest_file);
  7434. foreach($link_updates[$file_path] as $old_new)
  7435. {
  7436. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7437. //this is an ugly hack that allows .flv files to be found by the flv player that
  7438. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7439. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7440. // ../../.. to return from inc/lib/flv_player to the document/main path
  7441. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7442. {
  7443. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7444. }
  7445. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7446. {
  7447. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7448. }
  7449. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7450. }
  7451. file_put_contents($dest_file,$string);
  7452. }
  7453. }
  7454. foreach($zip_files_abs as $file_path)
  7455. {
  7456. if(empty($file_path)){continue;}
  7457. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7458. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7459. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7460. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7461. $this->create_path($dest_file);
  7462. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path,0);
  7463. //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);
  7464. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7465. copy($main_path.$file_path,$dest_file);
  7466. //check if the file needs a link update
  7467. if(in_array($file_path,array_keys($link_updates)))
  7468. {
  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. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7483. }
  7484. file_put_contents($dest_file,$string);
  7485. }
  7486. }
  7487. if(is_array($links_to_create))
  7488. {
  7489. foreach($links_to_create as $file=>$link)
  7490. {
  7491. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7492. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7493. }
  7494. }
  7495. // add non exportable message explanation
  7496. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7497. $file_content =
  7498. <<<EOD
  7499. <html>
  7500. <head>
  7501. <style>
  7502. .error-message {
  7503. font-family: arial, verdana, helvetica, sans-serif;
  7504. border-width: 1px;
  7505. border-style: solid;
  7506. left: 50%;
  7507. margin: 10px auto;
  7508. min-height: 30px;
  7509. padding: 5px;
  7510. right: 50%;
  7511. width: 500px;
  7512. background-color: #FFD1D1;
  7513. border-color: #FF0000;
  7514. color: #000;
  7515. }
  7516. </style>
  7517. <body>
  7518. <div class="error-message">
  7519. $lang_not_exportable
  7520. </div>
  7521. </body>
  7522. </html>
  7523. EOD;
  7524. if(!is_dir($archive_path.$temp_dir_short.'/document'))
  7525. {
  7526. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7527. }
  7528. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7529. //Add the extra files that go along with a SCORM package
  7530. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7531. $extra_files = scandir($main_code_path);
  7532. foreach ($extra_files as $extra_file) {
  7533. if (strpos($extra_file, '.') === 0)
  7534. continue;
  7535. else {
  7536. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7537. $this->create_path($dest_file);
  7538. copy($main_code_path.$extra_file,$dest_file);
  7539. }
  7540. }
  7541. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7542. $xmldoc->save($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7543. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7544. //clean possible temporary files
  7545. foreach($files_cleanup as $file)
  7546. {
  7547. $res = unlink($file);
  7548. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7549. }
  7550. //Send file to client
  7551. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7552. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7553. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7554. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7555. }
  7556. /**
  7557. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7558. * if it doesn't exist
  7559. */
  7560. function create_path($path) {
  7561. $path_bits = split('/', dirname($path));
  7562. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7563. $path_built = IS_WINDOWS_OS ? '' : '/';
  7564. foreach ($path_bits as $bit) {
  7565. if (!empty ($bit)) {
  7566. $new_path = $path_built . $bit;
  7567. if (is_dir($new_path)) {
  7568. $path_built = $new_path . '/';
  7569. } else {
  7570. mkdir($new_path, api_get_permissions_for_new_directories());
  7571. $path_built = $new_path . '/';
  7572. }
  7573. }
  7574. }
  7575. }
  7576. /**
  7577. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7578. * @return boolean The results of the unlink function, or false if there was no image to start with
  7579. */
  7580. function delete_lp_image() {
  7581. $img = $this->get_preview_image();
  7582. if ($img != '') {
  7583. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7584. $this->set_preview_image('');
  7585. return @ unlink($del_file);
  7586. } else {
  7587. return false;
  7588. }
  7589. }
  7590. /**
  7591. * Uploads an author image to the upload/learning_path/images directory
  7592. * @param array The image array, coming from the $_FILES superglobal
  7593. * @return boolean True on success, false on error
  7594. */
  7595. function upload_image($image_array) {
  7596. $image_moved = false;
  7597. if (!empty ($image_array['name'])) {
  7598. $upload_ok = process_uploaded_file($image_array);
  7599. $has_attachment = true;
  7600. } else {
  7601. $image_moved = true;
  7602. }
  7603. if ($upload_ok) {
  7604. if ($has_attachment) {
  7605. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7606. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7607. $updir = $sys_course_path . $courseDir;
  7608. // Try to add an extension to the file if it hasn't one
  7609. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7610. if (!filter_extension($new_file_name)) {
  7611. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7612. $image_moved = false;
  7613. } else {
  7614. $file_extension = explode('.', $image_array['name']);
  7615. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7616. $new_file_name = uniqid('') . '.' . $file_extension;
  7617. $new_path = $updir . '/' . $new_file_name;
  7618. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7619. // resize the image
  7620. include_once (api_get_path(LIBRARY_PATH) . 'image.lib.php');
  7621. $temp = new image($image_array['tmp_name']);
  7622. $picture_infos=@getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7623. if ($picture_infos[0] > 104) {
  7624. $thumbwidth = 104;
  7625. } else {
  7626. $thumbwidth = $picture_infos[0];
  7627. }
  7628. if ($picture_infos[1] > 96) {
  7629. $new_height = 96;
  7630. } else {
  7631. $new_height = $picture_infos[1];
  7632. }
  7633. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7634. $temp->resize($thumbwidth,$new_height,0);
  7635. $type=$picture_infos[2];
  7636. $result=false;
  7637. switch ($type)
  7638. {
  7639. case 2 :
  7640. $result=$temp->send_image('JPG',$new_path);
  7641. break;
  7642. case 3 :
  7643. $result=$temp->send_image('PNG',$new_path);
  7644. break;
  7645. case 1 :
  7646. $result=$temp->send_image('GIF',$new_path);
  7647. break;
  7648. }
  7649. $temp->resize($thumbwidth, $new_height, 0);
  7650. $type = $picture_infos[2];
  7651. $result = false;
  7652. switch ($type) {
  7653. case 2 :
  7654. $result = $temp->send_image('JPG', $new_path);
  7655. break;
  7656. case 3 :
  7657. $result = $temp->send_image('PNG', $new_path);
  7658. break;
  7659. case 1 :
  7660. $result = $temp->send_image('GIF', $new_path);
  7661. break;
  7662. }
  7663. // Storing the image filename
  7664. if ($result) {
  7665. $image_moved = true;
  7666. $this->set_preview_image($new_file_name);
  7667. return true;
  7668. }
  7669. }
  7670. }
  7671. }
  7672. return false;
  7673. }
  7674. }
  7675. if (!function_exists('trim_value')) {
  7676. function trim_value(& $value) {
  7677. $value = trim($value);
  7678. }
  7679. }