learnpath.class.php 314 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830
  1. <?php // $Id: index.php 16620 2008-10-25 20:03:54Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue Notre Dame, 152, B-1140 Evere, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  19. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  20. * @package dokeos.learnpath
  21. * @author Yannick Warnier <ywarnier@beeznest.org>
  22. * @license GNU/GPL - See Dokeos license directory for details
  23. */
  24. /**
  25. * Defines the learnpath parent class
  26. * @package dokeos.learnpath
  27. */
  28. class learnpath {
  29. var $attempt = 0; //the number for the current ID view
  30. var $cc; //course (code) this learnpath is located in
  31. var $current; //id of the current item the user is viewing
  32. var $current_score; //the score of the current item
  33. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  34. var $current_time_stop; //the time the user closed this resource
  35. var $default_status = 'not attempted';
  36. var $encoding = 'ISO-8859-1';
  37. var $error = '';
  38. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  39. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  40. var $index; //the index of the active learnpath_item in $ordered_items array
  41. var $items = array();
  42. var $last; //item_id of last item viewed in the learning path
  43. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  44. var $license; //which license this course has been given - not used yet on 20060522
  45. var $lp_id; //DB ID for this learnpath
  46. var $lp_view_id; //DB ID for lp_view
  47. var $log_file; //file where to log learnpath API msg
  48. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  49. var $message = '';
  50. var $mode='embedded'; //holds the video display mode (fullscreen or embedded)
  51. var $name; //learnpath name (they generally have one)
  52. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  53. var $path = ''; //path inside the scorm directory (if scorm)
  54. var $theme; // the current theme of the learning path
  55. var $preview_image; // the current image of the learning path
  56. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  57. var $prevent_reinit = 1;
  58. // Describes the mode of progress bar display
  59. var $progress_bar_mode = '%';
  60. // Percentage progress as saved in the db
  61. var $progress_db = '0';
  62. var $proximity; //wether the content is distant or local or unknown
  63. var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
  64. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  65. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  66. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  67. //TODO check if this type variable is useful here (instead of just in the controller script)
  68. var $user_id; //ID of the user that is viewing/using the course
  69. var $update_queue = array();
  70. var $scorm_debug = 0;
  71. var $arrMenu = array(); //array for the menu items
  72. var $debug = 0; //logging level
  73. /**
  74. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  75. * Also builds the list of items into $this->items.
  76. * @param string Course code
  77. * @param integer Learnpath ID
  78. * @param integer User ID
  79. * @return boolean True on success, false on error
  80. */
  81. function learnpath($course, $lp_id, $user_id) {
  82. //check params
  83. //check course code
  84. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  85. if(empty($course)){
  86. $this->error = 'Course code is empty';
  87. return false;
  88. }
  89. else
  90. {
  91. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  92. //$course = Database::escape_string($course);
  93. $course = $this->escape_string($course);
  94. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  95. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  96. //$res = Database::query($sql);
  97. $res = api_sql_query($sql, __FILE__, __LINE__);
  98. if(Database::num_rows($res)>0)
  99. {
  100. $this->cc = $course;
  101. }
  102. else
  103. {
  104. $this->error = 'Course code does not exist in database ('.$sql.')';
  105. return false;
  106. }
  107. }
  108. //check learnpath ID
  109. if(empty($lp_id))
  110. {
  111. $this->error = 'Learnpath ID is empty';
  112. return false;
  113. }
  114. else
  115. {
  116. //TODO make it flexible to use any course_code (still using env course code here)
  117. $lp_table = Database::get_course_table('lp');
  118. //$id = Database::escape_integer($id);
  119. $lp_id = $this->escape_string($lp_id);
  120. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  121. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  122. //$res = Database::query($sql);
  123. $res = api_sql_query($sql, __FILE__, __LINE__);
  124. if(Database::num_rows($res)>0)
  125. {
  126. $this->lp_id = $lp_id;
  127. $row = Database::fetch_array($res);
  128. $this->type = $row['lp_type'];
  129. $this->name = stripslashes($row['name']);
  130. $this->encoding = $row['default_encoding'];
  131. $this->proximity = $row['content_local'];
  132. $this->theme = $row['theme'];
  133. $this->maker = $row['content_maker'];
  134. $this->prevent_reinit = $row['prevent_reinit'];
  135. $this->license = $row['content_license'];
  136. $this->scorm_debug = $row['debug'];
  137. $this->js_lib = $row['js_lib'];
  138. $this->path = $row['path'];
  139. $this->preview_image= $row['preview_image'];
  140. $this->author= $row['author'];
  141. if($this->type == 2){
  142. if($row['force_commit'] == 1){
  143. $this->force_commit = true;
  144. }
  145. }
  146. $this->mode = $row['default_view_mod'];
  147. }
  148. else
  149. {
  150. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  151. return false;
  152. }
  153. }
  154. //check user ID
  155. if(empty($user_id)){
  156. $this->error = 'User ID is empty';
  157. return false;
  158. }
  159. else
  160. {
  161. //$main_table = Database::get_main_user_table();
  162. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  163. //$user_id = Database::escape_integer($user_id);
  164. $user_id = $this->escape_string($user_id);
  165. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  166. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  167. //$res = Database::query($sql);
  168. $res = api_sql_query($sql, __FILE__, __LINE__);
  169. if(Database::num_rows($res)>0)
  170. {
  171. $this->user_id = $user_id;
  172. }
  173. else
  174. {
  175. $this->error = 'User ID does not exist in database ('.$sql.')';
  176. return false;
  177. }
  178. }
  179. //end of variables checking
  180. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  181. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  182. //selecting by view_count descending allows to get the highest view_count first
  183. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  184. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
  185. //$res = Database::query($sql);
  186. $res = api_sql_query($sql, __FILE__, __LINE__);
  187. $view_id = 0; //used later to query lp_item_view
  188. if(Database::num_rows($res)>0)
  189. {
  190. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
  191. $row = Database::fetch_array($res);
  192. $this->attempt = $row['view_count'];
  193. $this->lp_view_id = $row['id'];
  194. $this->last_item_seen = $row['last_item'];
  195. $this->progress_db = $row['progress'];
  196. }
  197. else
  198. {
  199. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
  200. $this->attempt = 1;
  201. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  202. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  203. $this->lp_view_id = Database::get_last_insert_id();
  204. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
  205. }
  206. //initialise items
  207. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  208. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  209. $res = api_sql_query($sql, __FILE__, __LINE__);
  210. while($row = Database::fetch_array($res))
  211. {
  212. $oItem = '';
  213. //$this->ordered_items[] = $row['id'];
  214. switch($this->type){
  215. case 3: //aicc
  216. $oItem = new aiccItem('db',$row['id']);
  217. if(is_object($oItem)){
  218. $my_item_id = $oItem->get_id();
  219. $oItem->set_lp_view($this->lp_view_id);
  220. $oItem->set_prevent_reinit($this->prevent_reinit);
  221. // Don't use reference here as the next loop will make the pointed object change
  222. $this->items[$my_item_id] = $oItem;
  223. $this->refs_list[$oItem->ref]=$my_item_id;
  224. if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$my_item_id.' set in items[]',0);}
  225. }
  226. break;
  227. case 2:
  228. require_once('scorm.class.php');
  229. require_once('scormItem.class.php');
  230. $oItem = new scormItem('db',$row['id']);
  231. if(is_object($oItem)){
  232. $my_item_id = $oItem->get_id();
  233. $oItem->set_lp_view($this->lp_view_id);
  234. $oItem->set_prevent_reinit($this->prevent_reinit);
  235. // Don't use reference here as the next loop will make the pointed object change
  236. $this->items[$my_item_id] = $oItem;
  237. $this->refs_list[$oItem->ref]=$my_item_id;
  238. if($this->debug>2){error_log('New LP - object with id '.$my_item_id.' set in items[]',0);}
  239. }
  240. break;
  241. case 1:
  242. default:
  243. require_once('learnpathItem.class.php');
  244. $oItem = new learnpathItem($row['id'],$user_id);
  245. if(is_object($oItem)){
  246. $my_item_id = $oItem->get_id();
  247. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  248. $oItem->set_prevent_reinit($this->prevent_reinit);
  249. // Don't use reference here as the next loop will make the pointed object change
  250. $this->items[$my_item_id] = $oItem;
  251. $this->refs_list[$my_item_id]=$my_item_id;
  252. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$my_item_id.' set in items[]',0);}
  253. }
  254. break;
  255. }
  256. //items is a list of pointers to all items, classified by DB ID, not SCO id
  257. if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
  258. $this->items[$row['id']]->set_level(0);
  259. }else{
  260. $level = $this->items[$row['parent_item_id']]->get_level()+1;
  261. $this->items[$row['id']]->set_level($level);
  262. if(is_object($this->items[$row['parent_item_id']])){
  263. //items is a list of pointers from item DB ids to item objects
  264. $this->items[$row['parent_item_id']]->add_child($row['id']);
  265. }else{
  266. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - The parent item ('.$row['parent_item_id'].') of item '.$row['id'].' could not be found',0);}
  267. }
  268. }
  269. //get last viewing vars
  270. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  271. //this query should only return one or zero result
  272. $sql = "SELECT * " .
  273. "FROM $lp_item_view_table " .
  274. "WHERE lp_view_id = ".$this->lp_view_id." " .
  275. "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
  276. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
  277. //get the item status
  278. $res2 = api_sql_query($sql, __FILE__, __LINE__);
  279. if(Database::num_rows($res2)>0)
  280. {
  281. //if this learnpath has already been used by this user, get his last attempt count and
  282. //the last item seen back into this object
  283. //$max = 0;
  284. $row2 = Database::fetch_array($res2);
  285. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
  286. $this->items[$row['id']]->set_status($row2['status']);
  287. if(empty($row2['status'])){
  288. $this->items[$row['id']]->set_status($this->default_status);
  289. }
  290. //$this->attempt = $row['view_count'];
  291. //$this->last_item = $row['id'];
  292. }
  293. else //no item found in lp_item_view for this view
  294. {
  295. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  296. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  297. //$this->attempt = 1;
  298. //$this->last_item = 0;
  299. $this->items[$row['id']]->set_status($this->default_status);
  300. //Add that row to the lp_item_view table so that we have something to show in the stats page
  301. $sql_ins = "INSERT INTO $lp_item_view_table " .
  302. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  303. "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
  304. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
  305. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  306. }
  307. //setting the view in the item object
  308. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  309. }
  310. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
  311. $this->max_ordered_items = 0;
  312. foreach($this->ordered_items as $index=>$dummy){
  313. if($index > $this->max_ordered_items AND !empty($dummy)){
  314. $this->max_ordered_items = $index;
  315. }
  316. }
  317. //TODO define the current item better
  318. $this->first();
  319. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
  320. }
  321. /**
  322. * 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
  323. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  324. *
  325. * @param int $parent
  326. * @param int $previous
  327. * @param string $type
  328. * @param int $id
  329. * @param string $title
  330. * @param string $description
  331. * @return int
  332. */
  333. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0)
  334. {
  335. global $charset;
  336. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  337. $tbl_lp_item = Database::get_course_table('lp_item');
  338. $parent = intval($parent);
  339. $previous = intval($previous);
  340. $type = $this->escape_string($type);
  341. $id = intval($id);
  342. $title = $this->escape_string(mb_convert_encoding($title,$this->encoding,$charset));
  343. $description = $this->escape_string(mb_convert_encoding($description,$this->encoding,$charset));
  344. $sql_count = "
  345. SELECT COUNT(id) AS num
  346. FROM " . $tbl_lp_item . "
  347. WHERE
  348. lp_id = " . $this->get_id() . " AND
  349. parent_item_id = " . $parent;
  350. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  351. $row = Database::fetch_array($res_count);
  352. $num = $row['num'];
  353. if($num > 0)
  354. {
  355. if($previous == 0)
  356. {
  357. $sql = "
  358. SELECT
  359. id,
  360. next_item_id,
  361. display_order
  362. FROM " . $tbl_lp_item . "
  363. WHERE
  364. lp_id = " . $this->get_id() . " AND
  365. parent_item_id = " . $parent . " AND
  366. previous_item_id = 0 OR previous_item_id=".$parent;
  367. $result = api_sql_query($sql, __FILE__, __LINE__);
  368. $row = Database::fetch_array($result);
  369. $tmp_previous = 0;
  370. $next = $row['id'];
  371. $display_order = 0;
  372. }
  373. else
  374. {
  375. $previous = (int) $previous;
  376. $sql = "
  377. SELECT
  378. id,
  379. previous_item_id,
  380. next_item_id,
  381. display_order
  382. FROM " . $tbl_lp_item . "
  383. WHERE
  384. lp_id = " . $this->get_id() . " AND
  385. id = " . $previous;
  386. $result = api_sql_query($sql, __FILE__, __LINE__);
  387. $row = Database::fetch_array($result);
  388. $tmp_previous = $row['id'];
  389. $next = $row['next_item_id'];
  390. $display_order = $row['display_order'];
  391. }
  392. }
  393. else
  394. {
  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. {
  403. $sql = 'SELECT SUM(ponderation)
  404. FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
  405. INNER JOIN '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
  406. ON quiz_question.id = quiz_rel_question.question_id
  407. AND quiz_rel_question.exercice_id = '.$id;
  408. $rsQuiz = api_sql_query($sql, __FILE__, __LINE__);
  409. $max_score = Database::result($rsQuiz, 0, 0);
  410. }
  411. else
  412. {
  413. $max_score = 100;
  414. }
  415. if($prerequisites!=0)
  416. {
  417. $sql_ins = "
  418. INSERT INTO " . $tbl_lp_item . " (
  419. lp_id,
  420. item_type,
  421. ref,
  422. title,
  423. description,
  424. path,
  425. max_score,
  426. parent_item_id,
  427. previous_item_id,
  428. next_item_id,
  429. display_order,
  430. prerequisite
  431. ) VALUES (
  432. " . $this->get_id() . ",
  433. '" . $type . "',
  434. '',
  435. '" . $title . "',
  436. '" . $description . "',
  437. '" . $id . "',
  438. '" . $max_score. "',
  439. " . $parent . ",
  440. " . $previous . ",
  441. " . $next . ",
  442. " . ($display_order + 1) . ",
  443. " . $prerequisites . "
  444. )";
  445. }
  446. else
  447. {
  448. //insert new item
  449. $sql_ins = "
  450. INSERT INTO " . $tbl_lp_item . " (
  451. lp_id,
  452. item_type,
  453. ref,
  454. title,
  455. description,
  456. path,
  457. max_score,
  458. parent_item_id,
  459. previous_item_id,
  460. next_item_id,
  461. display_order
  462. ) VALUES (
  463. " . $this->get_id() . ",
  464. '" . $type . "',
  465. '',
  466. '" . $title . "',
  467. '" . $description . "',
  468. '" . $id . "',
  469. '" . $max_score. "',
  470. " . $parent . ",
  471. " . $previous . ",
  472. " . $next . ",
  473. " . ($display_order + 1) . "
  474. )";
  475. }
  476. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  477. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  478. if($res_ins > 0)
  479. {
  480. $new_item_id = Database::get_last_insert_id($res_ins);
  481. //update the item that should come after the new item
  482. $sql_update_next = "
  483. UPDATE " . $tbl_lp_item . "
  484. SET previous_item_id = " . $new_item_id . "
  485. WHERE id = " . $next;
  486. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  487. //update the item that should be before the new item
  488. $sql_update_previous = "
  489. UPDATE " . $tbl_lp_item . "
  490. SET next_item_id = " . $new_item_id . "
  491. WHERE id = " . $tmp_previous;
  492. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  493. //update all the items after the new item
  494. $sql_update_order = "
  495. UPDATE " . $tbl_lp_item . "
  496. SET display_order = display_order + 1
  497. WHERE
  498. lp_id = " . $this->get_id() . " AND
  499. id <> " . $new_item_id . " AND
  500. parent_item_id = " . $parent . " AND
  501. display_order > " . $display_order;
  502. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  503. //update the item that should come after the new item
  504. $sql_update_ref = "
  505. UPDATE " . $tbl_lp_item . "
  506. SET ref = " . $new_item_id . "
  507. WHERE id = " . $new_item_id;
  508. api_sql_query($sql_update_ref, __FILE__, __LINE__);
  509. }
  510. // upload audio
  511. if (!empty($_FILES['mp3']['name']))
  512. {
  513. // create the audio folder if it does not exist yet
  514. global $_course;
  515. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  516. if(!is_dir($filepath.'audio'))
  517. {
  518. $perm = api_get_setting('permissions_for_new_directories');
  519. $perm = octdec(!empty($perm)?$perm:'0770');
  520. mkdir($filepath.'audio',$perm);
  521. $audio_id=add_document($_course,'/audio','folder',0,'audio');
  522. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  523. }
  524. // upload the file in the documents tool
  525. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  526. $file_path = handle_uploaded_document($_course, $_FILES['mp3'],api_get_path('SYS_COURSE_PATH').$_course['path'].'/document','/audio',api_get_user_id(),'','','','','',false);
  527. // getting the filename only
  528. $file_components = explode('/',$file_path);
  529. $file = $file_components[count($file_components)-1];
  530. // store the mp3 file in the lp_item table
  531. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($new_item_id)."'";
  532. api_sql_query($sql_insert_audio, __FILE__, __LINE__);
  533. }
  534. return $new_item_id;
  535. }
  536. /**
  537. * Static admin function allowing addition of a learnpath to a course.
  538. * @param string Course code
  539. * @param string Learnpath name
  540. * @param string Learnpath description string, if provided
  541. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  542. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  543. * @param string Zip file containing the learnpath or directory containing the learnpath
  544. * @return integer The new learnpath ID on success, 0 on failure
  545. */
  546. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  547. {
  548. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  549. //TODO
  550. $tbl_lp = Database::get_course_table('lp');
  551. //check course code exists
  552. //check lp_name doesn't exist, otherwise append something
  553. $i = 0;
  554. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  555. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  556. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  557. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  558. while(Database::num_rows($res_name)){
  559. //there is already one such name, update the current one a bit
  560. $i++;
  561. $name = $name.' - '.$i;
  562. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  563. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  564. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  565. }
  566. //new name does not exist yet; keep it
  567. //escape description
  568. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  569. $type = 1;
  570. switch($learnpath){
  571. case 'guess':
  572. break;
  573. case 'dokeos':
  574. $type = 1;
  575. break;
  576. case 'aicc':
  577. break;
  578. }
  579. switch($origin){
  580. case 'zip':
  581. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  582. break;
  583. case 'manual':
  584. default:
  585. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  586. $res_max = api_sql_query($get_max, __FILE__, __LINE__);
  587. if(Database::num_rows($res_max)<1){
  588. $dsp = 1;
  589. }else{
  590. $row = Database::fetch_array($res_max);
  591. $dsp = $row[0]+1;
  592. }
  593. $sql_insert = "INSERT INTO $tbl_lp " .
  594. "(lp_type,name,description,path,default_view_mod," .
  595. "default_encoding,display_order,content_maker," .
  596. "content_local,js_lib) " .
  597. "VALUES ($type,'$name','$description','','embedded'," .
  598. "'UTF-8','$dsp','Dokeos'," .
  599. "'local','')";
  600. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  601. $res_insert = api_sql_query($sql_insert, __FILE__, __LINE__);
  602. $id = Database::get_last_insert_id();
  603. if($id>0){
  604. //insert into item_property
  605. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$id,'LearnpathAdded',api_get_user_id());
  606. return $id;
  607. }
  608. break;
  609. }
  610. }
  611. /**
  612. * Appends a message to the message attribute
  613. * @param string Message to append.
  614. */
  615. function append_message($string)
  616. {
  617. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  618. $this->message .= $string;
  619. }
  620. /**
  621. * Autocompletes the parents of an item in case it's been completed or passed
  622. * @param integer Optional ID of the item from which to look for parents
  623. */
  624. function autocomplete_parents($item)
  625. {
  626. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  627. if(empty($item)){
  628. $item = $this->current;
  629. }
  630. $parent_id = $this->items[$item]->get_parent();
  631. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  632. if(is_object($this->items[$item]) and !empty($parent_id))
  633. {//if $item points to an object and there is a parent
  634. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  635. $current_item =& $this->items[$item];
  636. $parent =& $this->items[$parent_id]; //get the parent
  637. //new experiment including failed and browsed in completed status
  638. $current_status = $current_item->get_status();
  639. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed')
  640. {
  641. //if the current item is completed or passes or succeeded
  642. $completed = true;
  643. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  644. foreach($parent->get_children() as $child)
  645. {
  646. //check all his brothers (his parent's children) for completion status
  647. if($child!= $item)
  648. {
  649. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  650. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  651. //Trying completing parents of failed and browsed items as well
  652. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  653. {
  654. //keep completion status to true
  655. }else{
  656. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  657. $completed = false;
  658. }
  659. }
  660. }
  661. if($completed == true)
  662. { //if all the children were completed
  663. $parent->set_status('completed');
  664. $parent->save(false,$this->prerequisites_match($parent->get_id()));
  665. $this->update_queue[$parent->get_id()] = $parent->get_status();
  666. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  667. $this->autocomplete_parents($parent->get_id()); //recursive call
  668. }
  669. }else{
  670. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  671. }
  672. }
  673. }
  674. /**
  675. * Autosaves the current results into the database for the whole learnpath
  676. */
  677. function autosave()
  678. {
  679. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  680. //TODO add aditionnal save operations for the learnpath itself
  681. }
  682. /**
  683. * Clears the message attribute
  684. */
  685. function clear_message()
  686. {
  687. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  688. $this->message = '';
  689. }
  690. /**
  691. * Closes the current resource
  692. *
  693. * Stops the timer
  694. * Saves into the database if required
  695. * Clears the current resource data from this object
  696. * @return boolean True on success, false on failure
  697. */
  698. function close()
  699. {
  700. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  701. if(empty($this->lp_id))
  702. {
  703. $this->error = 'Trying to close this learnpath but no ID is set';
  704. return false;
  705. }
  706. $this->current_time_stop = time();
  707. if($this->save)
  708. {
  709. $learnpath_view_table = Database::get_course_table(TABLE_LP_VIEW);
  710. /*
  711. $sql = "UPDATE $learnpath_view_table " .
  712. "SET " .
  713. "stop_time = ".$this->current_time_stop.", " .
  714. "score = ".$this->current_score.", ".
  715. "WHERE learnpath_id = '".$this->lp_id."'";
  716. //$res = Database::query($sql);
  717. $res = api_sql_query($res);
  718. if(mysql_affected_rows($res)<1)
  719. {
  720. $this->error = 'Could not update learnpath_view table while closing learnpath';
  721. return false;
  722. }
  723. */
  724. }
  725. $this->ordered_items = array();
  726. $this->index=0;
  727. unset($this->lp_id);
  728. //unset other stuff
  729. return true;
  730. }
  731. /**
  732. * Static admin function allowing removal of a learnpath
  733. * @param string Course code
  734. * @param integer Learnpath ID
  735. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  736. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  737. */
  738. function delete($course=null,$id=null,$delete='keep')
  739. {
  740. //TODO implement a way of getting this to work when the current object is not set
  741. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  742. //if(empty($course)){$course = api_get_course_id();}
  743. //if(empty($id)){$id = $this->get_id();}
  744. //If an ID is specifically given and the current LP is not the same,
  745. //prevent delete
  746. if(!empty($id) && ($id != $this->lp_id)){return false;}
  747. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  748. foreach($this->items as $id => $dummy)
  749. {
  750. $this->items[$id]->delete();
  751. }
  752. $lp = Database::get_course_table('lp');
  753. $lp_view = Database::get_course_table('lp_view');
  754. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  755. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  756. $res_del_view = api_sql_query($sql_del_view, __FILE__, __LINE__);
  757. $this->toggle_publish($this->lp_id,'i');
  758. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  759. if($this->type == 2 OR $this->type==3){
  760. //this is a scorm learning path, delete the files as well
  761. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  762. $res = api_sql_query($sql, __FILE__, __LINE__);
  763. if(Database::num_rows($res)>0){
  764. $row = Database::fetch_array($res);
  765. $path = $row['path'];
  766. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  767. $res = api_sql_query($sql, __FILE__, __LINE__);
  768. if(Database::num_rows($res)>0)
  769. { //another learning path uses this directory, so don't delete it
  770. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  771. }else{
  772. //no other LP uses that directory, delete it
  773. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  774. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  775. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  776. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  777. exec('rm -rf '.$course_scorm_dir.$path);
  778. }
  779. }
  780. }
  781. }
  782. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  783. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  784. $res_del_lp = api_sql_query($sql_del_lp, __FILE__, __LINE__);
  785. $this->update_display_order();//updates the display order of all lps
  786. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$this->lp_id,'delete',api_get_user_id());
  787. //TODO: also delete items and item-views
  788. }
  789. /**
  790. * Removes all the children of one item - dangerous!
  791. * @param integer Element ID of which children have to be removed
  792. * @return integer Total number of children removed
  793. */
  794. function delete_children_items($id){
  795. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  796. $num = 0;
  797. if(empty($id) || $id != strval(intval($id))){return false;}
  798. $lp_item = Database::get_course_table('lp_item');
  799. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  800. $res = api_sql_query($sql, __FILE__, __LINE__);
  801. while($row = Database::fetch_array($res)){
  802. $num += $this->delete_children_items($row['id']);
  803. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  804. $res_del = api_sql_query($sql_del, __FILE__, __LINE__);
  805. $num++;
  806. }
  807. return $num;
  808. }
  809. /**
  810. * Removes an item from the current learnpath
  811. * @param integer Elem ID (0 if first)
  812. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  813. * @return integer Number of elements moved
  814. * @todo implement resource removal
  815. */
  816. function delete_item($id, $remove='keep')
  817. {
  818. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  819. //TODO - implement the resource removal
  820. if(empty($id) || $id != strval(intval($id))){return false;}
  821. //first select item to get previous, next, and display order
  822. $lp_item = Database::get_course_table('lp_item');
  823. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  824. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  825. if(Database::num_rows($res_sel)<1){return false;}
  826. $row = Database::fetch_array($res_sel);
  827. $previous = $row['previous_item_id'];
  828. $next = $row['next_item_id'];
  829. $display = $row['display_order'];
  830. $parent = $row['parent_item_id'];
  831. $lp = $row['lp_id'];
  832. //delete children items
  833. $num = $this->delete_children_items($id);
  834. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  835. //now delete the item
  836. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  837. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  838. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  839. //now update surrounding items
  840. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  841. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  842. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  843. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  844. //now update all following items with new display order
  845. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  846. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  847. // remove from search engine if enabled
  848. if (api_get_setting('search_enabled') == 'true') {
  849. require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php');
  850. $di = new DokeosIndexer();
  851. $di->remove_document($row['search_did']);
  852. }
  853. }
  854. /**
  855. * Updates an item's content in place
  856. * @param integer Element ID
  857. * @param integer Parent item ID
  858. * @param integer Previous item ID
  859. * @param string Item title
  860. * @param string Item description
  861. * @param string Prerequisites (optional)
  862. * @param string Indexing terms (optional)
  863. * @return boolean True on success, false on error
  864. */
  865. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $terms=NULL)
  866. {
  867. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  868. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  869. $tbl_lp_item = Database::get_course_table('lp_item');
  870. $sql_select = "
  871. SELECT *
  872. FROM " . $tbl_lp_item . "
  873. WHERE id = " . $id;
  874. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  875. $row_select = Database::fetch_array($res_select);
  876. $terms_update_sql='';
  877. if (!is_null($terms)) {
  878. //TODO: validate csv string
  879. $terms_update_sql = ", terms = '". $this->escape_string(htmlentities($terms)) . "'";
  880. // save it to search engine
  881. if (api_get_setting('search_enabled') == 'true') {
  882. require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php');
  883. $di = new DokeosIndexer();
  884. $di->update_terms($row_select['search_did'], explode(',', $terms));
  885. }
  886. }
  887. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  888. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  889. if($same_parent && $same_previous)
  890. {
  891. //only update title and description
  892. $sql_update = "
  893. UPDATE " . $tbl_lp_item . "
  894. SET
  895. title = '" . $this->escape_string(htmlentities($title)) . "',
  896. prerequisite = '".$prerequisites."',
  897. description = '" . $this->escape_string(htmlentities($description)) . "'
  898. ". $terms_update_sql . "
  899. WHERE id = " . $id;
  900. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  901. }
  902. else
  903. {
  904. $old_parent = $row_select['parent_item_id'];
  905. $old_previous = $row_select['previous_item_id'];
  906. $old_next = $row_select['next_item_id'];
  907. $old_order = $row_select['display_order'];
  908. $old_prerequisite= $row_select['prerequisite'];
  909. /* BEGIN -- virtually remove the current item id */
  910. /* for the next and previous item it is like the current item doesn't exist anymore */
  911. if($old_previous != 0)
  912. {
  913. $sql_update_next = "
  914. UPDATE " . $tbl_lp_item . "
  915. SET next_item_id = " . $old_next . "
  916. WHERE id = " . $old_previous;
  917. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  918. //echo '<p>' . $sql_update_next . '</p>';
  919. }
  920. if($old_next != 0)
  921. {
  922. $sql_update_previous = "
  923. UPDATE " . $tbl_lp_item . "
  924. SET previous_item_id = " . $old_previous . "
  925. WHERE id = " . $old_next;
  926. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  927. //echo '<p>' . $sql_update_previous . '</p>';
  928. }
  929. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  930. $sql_update_order = "
  931. UPDATE " . $tbl_lp_item . "
  932. SET display_order = display_order - 1
  933. WHERE
  934. display_order > " . $old_order . " AND
  935. parent_item_id = " . $old_parent;
  936. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  937. //echo '<p>' . $sql_update_order . '</p>';
  938. /* END -- virtually remove the current item id */
  939. /* BEGIN -- update the current item id to his new location */
  940. if($previous == 0)
  941. {
  942. //select the data of the item that should come after the current item
  943. $sql_select_old = "
  944. SELECT
  945. id,
  946. display_order
  947. FROM " . $tbl_lp_item . "
  948. WHERE
  949. lp_id = " . $this->lp_id . " AND
  950. parent_item_id = " . $parent . " AND
  951. previous_item_id = " . $previous;
  952. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  953. $row_select_old = Database::fetch_array($res_select_old);
  954. //echo '<p>' . $sql_select_old . '</p>';
  955. //if the new parent didn't have children before
  956. if(Database::num_rows($res_select_old) == 0)
  957. {
  958. $new_next = 0;
  959. $new_order = 1;
  960. }
  961. else
  962. {
  963. $new_next = $row_select_old['id'];
  964. $new_order = $row_select_old['display_order'];
  965. }
  966. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  967. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  968. //echo 'New display_order of current item: ' . $new_order . '<br />';
  969. }
  970. else
  971. {
  972. //select the data of the item that should come before the current item
  973. $sql_select_old = "
  974. SELECT
  975. next_item_id,
  976. display_order
  977. FROM " . $tbl_lp_item . "
  978. WHERE id = " . $previous;
  979. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  980. $row_select_old = Database::fetch_array($res_select_old);
  981. //echo '<p>' . $sql_select_old . '</p>';
  982. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  983. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  984. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  985. $new_next = $row_select_old['next_item_id'];
  986. $new_order = $row_select_old['display_order'] + 1;
  987. }
  988. //update the current item with the new data
  989. $sql_update = "
  990. UPDATE " . $tbl_lp_item . "
  991. SET
  992. title = '" . $this->escape_string(htmlentities($title)) . "',
  993. description = '" . $this->escape_string(htmlentities($description)) . "',
  994. parent_item_id = " . $parent . ",
  995. previous_item_id = " . $previous . ",
  996. next_item_id = " . $new_next . ",
  997. display_order = " . $new_order . "
  998. ". $terms_update_sql . "
  999. WHERE id = " . $id;
  1000. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  1001. //echo '<p>' . $sql_update . '</p>';
  1002. if($previous != 0)
  1003. {
  1004. //update the previous item's next_item_id
  1005. $sql_update_previous = "
  1006. UPDATE " . $tbl_lp_item . "
  1007. SET next_item_id = " . $id . "
  1008. WHERE id = " . $previous;
  1009. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  1010. //echo '<p>' . $sql_update_previous . '</p>';
  1011. }
  1012. if($new_next != 0)
  1013. {
  1014. //update the next item's previous_item_id
  1015. $sql_update_next = "
  1016. UPDATE " . $tbl_lp_item . "
  1017. SET previous_item_id = " . $id . "
  1018. WHERE id = " . $new_next;
  1019. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1020. //echo '<p>' . $sql_update_next . '</p>';
  1021. }
  1022. if($old_prerequisite!=$prerequisites){
  1023. $sql_update_next = "
  1024. UPDATE " . $tbl_lp_item . "
  1025. SET prerequisite = " . $prerequisites . "
  1026. WHERE id = " . $id;
  1027. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1028. }
  1029. //update all the items with the same or a bigger display_order than
  1030. //the current item
  1031. $sql_update_order = "
  1032. UPDATE " . $tbl_lp_item . "
  1033. SET display_order = display_order + 1
  1034. WHERE
  1035. lp_id = " . $this->get_id() . " AND
  1036. id <> " . $id . " AND
  1037. parent_item_id = " . $parent . " AND
  1038. display_order >= " . $new_order;
  1039. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  1040. //echo '<p>' . $sql_update_order . '</p>';
  1041. /* END -- update the current item id to his new location */
  1042. }
  1043. }
  1044. /**
  1045. * Updates an item's prereq in place
  1046. * @param integer Element ID
  1047. * @param string Prerequisite Element ID
  1048. *
  1049. * @param string Prerequisite item type
  1050. *
  1051. * @param string Prerequisite min score
  1052. *
  1053. * @param string Prerequisite max score
  1054. * @return boolean True on success, false on error
  1055. */
  1056. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
  1057. {
  1058. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')',0);}
  1059. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  1060. $prerequisite_id = $this->escape_string($prerequisite_id);
  1061. $tbl_lp_item = Database::get_course_table('lp_item');
  1062. if(!is_numeric($mastery_score) || $mastery_score < 0)
  1063. $mastery_score = 0;
  1064. if(!is_numeric($max_score) || $max_score < 0)
  1065. $max_score = 100;
  1066. if($mastery_score > $max_score)
  1067. $max_score = $mastery_score;
  1068. if(!is_numeric($prerequisite_id))
  1069. $prerequisite_id = 'NULL';
  1070. $sql_upd = "
  1071. UPDATE " . $tbl_lp_item . "
  1072. SET prerequisite = ".$prerequisite_id." WHERE id = ".$id;
  1073. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1074. if($prerequisite_id!='NULL' && $prerequisite_id!='')
  1075. {
  1076. $sql_upd = " UPDATE ".$tbl_lp_item." SET
  1077. mastery_score = " . $mastery_score .
  1078. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1079. " WHERE ref = '" . $prerequisite_id."'" ; //will this be enough to ensure unicity?
  1080. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1081. }
  1082. //TODO update the item object (can be ignored for now because refreshed)
  1083. return true;
  1084. }
  1085. /**
  1086. * Escapes a string with the available database escape function
  1087. * @param string String to escape
  1088. * @return string String escaped
  1089. */
  1090. function escape_string($string){
  1091. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1092. return Database::escape_string($string);
  1093. }
  1094. /**
  1095. * Static admin function exporting a learnpath into a zip file
  1096. * @param string Export type (scorm, zip, cd)
  1097. * @param string Course code
  1098. * @param integer Learnpath ID
  1099. * @param string Zip file name
  1100. * @return string Zip file path (or false on error)
  1101. */
  1102. function export_lp($type, $course, $id, $zipname)
  1103. {
  1104. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1105. //TODO
  1106. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1107. $url = '';
  1108. switch($type){
  1109. case 'scorm':
  1110. break;
  1111. case 'zip':
  1112. break;
  1113. case 'cdrom':
  1114. break;
  1115. }
  1116. return $url;
  1117. }
  1118. /**
  1119. * Gets all the chapters belonging to the same parent as the item/chapter given
  1120. * Can also be called as abstract method
  1121. * @param integer Item ID
  1122. * @return array A list of all the "brother items" (or an empty array on failure)
  1123. */
  1124. function get_brother_chapters($id){
  1125. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1126. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1127. $lp_item = Database::get_course_table('lp_item');
  1128. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1129. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1130. if(Database::num_rows($res_parent)>0){
  1131. $row_parent = Database::fetch_array($res_parent);
  1132. $parent = $row_parent['parent_item_id'];
  1133. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1134. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1135. $list = array();
  1136. while ($row_bro = Database::fetch_array($res_bros)){
  1137. $list[] = $row_bro;
  1138. }
  1139. return $list;
  1140. }
  1141. return array();
  1142. }
  1143. /**
  1144. * Gets all the items belonging to the same parent as the item given
  1145. * Can also be called as abstract method
  1146. * @param integer Item ID
  1147. * @return array A list of all the "brother items" (or an empty array on failure)
  1148. */
  1149. function get_brother_items($id){
  1150. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1151. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1152. $lp_item = Database::get_course_table('lp_item');
  1153. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1154. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1155. if(Database::num_rows($res_parent)>0){
  1156. $row_parent = Database::fetch_array($res_parent);
  1157. $parent = $row_parent['parent_item_id'];
  1158. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1159. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1160. $list = array();
  1161. while ($row_bro = Database::fetch_array($res_bros)){
  1162. $list[] = $row_bro;
  1163. }
  1164. return $list;
  1165. }
  1166. return array();
  1167. }
  1168. /**
  1169. * Get the index terms shared between all items of this path
  1170. * @return string String of terms, split by a simple comma
  1171. */
  1172. function get_common_index_terms()
  1173. {
  1174. $terms = array();
  1175. $i = 0;
  1176. foreach ( $this->items as $item ) {
  1177. $i_terms = split(',',$item->terms);
  1178. if ( $i == 0 ) { $terms = $i_terms; continue; }
  1179. foreach($terms as $term)
  1180. {
  1181. if ( !in_array($term,$i_terms) )
  1182. {
  1183. $terms = array_diff($terms,array($term)); //remove term from terms array because it is not in the current item's terms (so it is not common to all)
  1184. }
  1185. }
  1186. }
  1187. $s = implode(',',$terms);
  1188. return $s;
  1189. }
  1190. /**
  1191. * Gets the number of items currently completed
  1192. * @return integer The number of items currently completed
  1193. */
  1194. function get_complete_items_count()
  1195. {
  1196. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1197. $i = 0;
  1198. foreach($this->items as $id => $dummy){
  1199. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1200. //Trying failed and browsed considered "progressed" as well
  1201. if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))&&$this->items[$id]->get_type()!='dokeos_chapter'&&$this->items[$id]->get_type()!='dir'){
  1202. $i++;
  1203. }
  1204. }
  1205. return $i;
  1206. }
  1207. /**
  1208. * Gets the current item ID
  1209. * @return integer The current learnpath item id
  1210. */
  1211. function get_current_item_id()
  1212. {
  1213. $current = 0;
  1214. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1215. if(!empty($this->current))
  1216. {
  1217. $current = $this->current;
  1218. }
  1219. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1220. return $current;
  1221. }
  1222. /**
  1223. * Gets the total number of items available for viewing in this SCORM
  1224. * @return integer The total number of items
  1225. */
  1226. function get_total_items_count()
  1227. {
  1228. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1229. return count($this->items);
  1230. }
  1231. /**
  1232. * Gets the total number of items available for viewing in this SCORM but without chapters
  1233. * @return integer The total no-chapters number of items
  1234. */
  1235. function get_total_items_count_without_chapters()
  1236. {
  1237. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1238. $total=0;
  1239. foreach($this->items as $temp=>$temp2){
  1240. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1241. }
  1242. return $total;
  1243. }
  1244. /**
  1245. * Gets the first element URL.
  1246. * @return string URL to load into the viewer
  1247. */
  1248. function first()
  1249. {
  1250. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1251. //test if the last_item_seen exists and is not a dir
  1252. if ( count($this->ordered_items) == 0 ) {
  1253. $this->index = 0;
  1254. }
  1255. if(!empty($this->last_item_seen)
  1256. && !empty($this->items[$this->last_item_seen])
  1257. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1258. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1259. && $this->items[$this->last_item_seen]->is_done() != true
  1260. ){
  1261. if($this->debug>2){error_log('New LP - In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(),0);}
  1262. $index = -1;
  1263. foreach($this->ordered_items as $myindex => $item_id){
  1264. if($item_id == $this->last_item_seen){
  1265. $index = $myindex;
  1266. break;
  1267. }
  1268. }
  1269. if($index==-1){
  1270. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1271. if($this->debug>2){error_log('New LP - Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!',0);}
  1272. return false;
  1273. }else{
  1274. $this->last = $this->last_item_seen;
  1275. $this->current = $this->last_item_seen;
  1276. $this->index = $index;
  1277. }
  1278. }else{
  1279. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1280. $index = 0;
  1281. //loop through all ordered items and stop at the first item that is
  1282. //not a directory *and* that has not been completed yet
  1283. while (!empty($this->ordered_items[$index])
  1284. AND
  1285. is_a($this->items[$this->ordered_items[$index]],'learnpathItem')
  1286. AND
  1287. (
  1288. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1289. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1290. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1291. )
  1292. AND $index < $this->max_ordered_items)
  1293. {
  1294. $index ++;
  1295. }
  1296. $this->last = $this->current;
  1297. //current is
  1298. $this->current = $this->ordered_items[$index];
  1299. $this->index = $index;
  1300. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1301. }
  1302. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1303. }
  1304. /**
  1305. * Gets the information about an item in a format usable as JavaScript to update
  1306. * the JS API by just printing this content into the <head> section of the message frame
  1307. * @param integer Item ID
  1308. * @return string
  1309. */
  1310. function get_js_info($item_id=''){
  1311. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1312. $info = '';
  1313. $item_id = $this->escape_string($item_id);
  1314. if(!empty($item_id) && is_object($this->items[$item_id])){
  1315. //if item is defined, return values from DB
  1316. $oItem = $this->items[$item_id];
  1317. $info .= '<script language="javascript">';
  1318. $info .= "top.set_score(".$oItem->get_score().");\n";
  1319. $info .= "top.set_max(".$oItem->get_max().");\n";
  1320. $info .= "top.set_min(".$oItem->get_min().");\n";
  1321. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1322. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1323. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1324. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1325. $info .= "top.set_flag_synchronized();";
  1326. $info .= '</script>';
  1327. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1328. return $info;
  1329. }else{
  1330. //if item_id is empty, just update to default SCORM data
  1331. $info .= '<script language="javascript">';
  1332. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1333. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1334. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1335. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1336. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1337. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1338. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1339. $info .= "top.set_flag_synchronized();";
  1340. $info .= '</script>';
  1341. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1342. return $info;
  1343. }
  1344. }
  1345. /**
  1346. * Gets the js library from the database
  1347. * @return string The name of the javascript library to be used
  1348. */
  1349. function get_js_lib(){
  1350. $lib = '';
  1351. if(!empty($this->js_lib)){
  1352. $lib = $this->js_lib;
  1353. }
  1354. return $lib;
  1355. }
  1356. /**
  1357. * Gets the learnpath database ID
  1358. * @return integer Learnpath ID in the lp table
  1359. */
  1360. function get_id()
  1361. {
  1362. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1363. if(!empty($this->lp_id))
  1364. {
  1365. return $this->lp_id;
  1366. }else{
  1367. return 0;
  1368. }
  1369. }
  1370. /**
  1371. * Gets the last element URL.
  1372. * @return string URL to load into the viewer
  1373. */
  1374. function get_last()
  1375. {
  1376. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1377. $this->index = count($this->ordered_items)-1;
  1378. return $this->ordered_items[$this->index];
  1379. }
  1380. /**
  1381. * Gets the navigation bar for the learnpath display screen
  1382. * @return string The HTML string to use as a navigation bar
  1383. */
  1384. function get_navigation_bar()
  1385. {
  1386. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1387. //TODO find a good value for the following variables
  1388. $file = '';
  1389. $openDir = '';
  1390. $edoceo = '';
  1391. $time = 0;
  1392. $navbar = '';
  1393. $RequestUri = '';
  1394. $mycurrentitemid = $this->get_current_item_id();
  1395. if($this->mode == 'fullscreen')
  1396. {
  1397. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1398. ' <tr> '."\n" .
  1399. ' <td>'."\n" .
  1400. ' <div class="buttons">'."\n" .
  1401. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('ScormMystatus').'"></a>'."\n" .
  1402. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>'."\n" .
  1403. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>'."\n" .
  1404. //' <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" .
  1405. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1406. ' </div>'."\n" .
  1407. ' </td>'."\n" .
  1408. ' </tr>'."\n" .
  1409. '</table>'."\n" ;
  1410. }else{
  1411. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1412. ' <tr> '."\n" .
  1413. ' <td>'."\n" .
  1414. ' <div class="buttons">'."\n" .
  1415. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('ScormMystatus').'"></a>'."\n" .
  1416. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>'."\n" .
  1417. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>'."\n" .
  1418. // ' <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" .
  1419. ' </div>'."\n" .
  1420. ' </td>'."\n" .
  1421. ' </tr>'."\n" .
  1422. '</table>'."\n" ;
  1423. }
  1424. return $navbar;
  1425. }
  1426. /**
  1427. * Gets the next resource in queue (url).
  1428. * @return string URL to load into the viewer
  1429. */
  1430. function get_next_index()
  1431. {
  1432. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1433. //TODO
  1434. $index = $this->index;
  1435. $index ++;
  1436. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type,0);}
  1437. 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)
  1438. {
  1439. $index ++;
  1440. if($index == $this->max_ordered_items)
  1441. {
  1442. return $this->index;
  1443. }
  1444. }
  1445. if(empty($this->ordered_items[$index])){
  1446. return $this->index;
  1447. }
  1448. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1449. return $index;
  1450. }
  1451. /**
  1452. * Gets item_id for the next element
  1453. * @return integer Next item (DB) ID
  1454. */
  1455. function get_next_item_id()
  1456. {
  1457. if($this->debug>0){error_log('New LP - In learnpath::get_next_item_id()',0);}
  1458. $new_index = $this->get_next_index();
  1459. if(!empty($new_index))
  1460. {
  1461. if(isset($this->ordered_items[$new_index]))
  1462. {
  1463. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index],0);}
  1464. return $this->ordered_items[$new_index];
  1465. }
  1466. }
  1467. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
  1468. return 0;
  1469. }
  1470. /**
  1471. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1472. *
  1473. * Generally, the package provided is in the form of a zip file, so the function
  1474. * has been written to test a zip file. If not a zip, the function will return the
  1475. * default return value: ''
  1476. * @param string the path to the file
  1477. * @param string the original name of the file
  1478. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1479. */
  1480. function get_package_type($file_path,$file_name){
  1481. //get name of the zip file without the extension
  1482. $file_info = pathinfo($file_name);
  1483. $filename = $file_info['basename'];//name including extension
  1484. $extension = $file_info['extension'];//extension only
  1485. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1486. {
  1487. return 'oogie';
  1488. }
  1489. if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
  1490. {
  1491. return 'woogie';
  1492. }
  1493. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1494. $zipFile = new pclZip($file_path);
  1495. // Check the zip content (real size and file extension)
  1496. $zipContentArray = $zipFile->listContent();
  1497. $package_type='';
  1498. $at_root = false;
  1499. $manifest = '';
  1500. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1501. foreach($zipContentArray as $thisContent)
  1502. {
  1503. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1504. {
  1505. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1506. }
  1507. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1508. {
  1509. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1510. $package_type = 'scorm';
  1511. break;//exit the foreach loop
  1512. }
  1513. elseif(preg_match('/aicc\//i',$thisContent['filename'])!=false)
  1514. {//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1515. $package_type='aicc';
  1516. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1517. }
  1518. else
  1519. {
  1520. $package_type = '';
  1521. }
  1522. }
  1523. return $package_type;
  1524. }
  1525. /**
  1526. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1527. * @return string URL to load into the viewer
  1528. */
  1529. function get_previous_index()
  1530. {
  1531. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1532. $index = $this->index;
  1533. if(isset($this->ordered_items[$index-1])){
  1534. $index --;
  1535. 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'))
  1536. {
  1537. $index --;
  1538. if($index < 0){
  1539. return $this->index;
  1540. }
  1541. }
  1542. }else{
  1543. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1544. //no previous item
  1545. }
  1546. return $index;
  1547. }
  1548. /**
  1549. * Gets item_id for the next element
  1550. * @return integer Previous item (DB) ID
  1551. */
  1552. function get_previous_item_id()
  1553. {
  1554. $new_index = $this->get_previous_index();
  1555. return $this->ordered_items[$new_index];
  1556. }
  1557. /**
  1558. * Gets the progress value from the progress_db attribute
  1559. * @return integer Current progress value
  1560. */
  1561. function get_progress()
  1562. {
  1563. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1564. if(!empty($this->progress_db))
  1565. {
  1566. return $this->progress_db;
  1567. }
  1568. return 0;
  1569. }
  1570. /**
  1571. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1572. * @param integer Learnpath ID
  1573. * @param integer User ID
  1574. * @param string Mode of display ('%','abs' or 'both')
  1575. * @param string Course database name (optional, defaults to '')
  1576. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1577. * @return integer Current progress value as found in the database
  1578. */
  1579. function get_db_progress($lp_id,$user_id,$mode='%', $course_db='', $sincere=false)
  1580. {
  1581. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1582. $table = Database::get_course_table('lp_view', $course_db);
  1583. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1584. $res = api_sql_query($sql,__FILE__,__LINE__);
  1585. $view_id = 0;
  1586. if(Database::num_rows($res)>0)
  1587. {
  1588. $row = Database::fetch_array($res);
  1589. $progress = $row['progress'];
  1590. $view_id = $row['id'];
  1591. }
  1592. else
  1593. {
  1594. if($sincere)
  1595. {
  1596. return null;
  1597. }
  1598. }
  1599. if(empty($progress))
  1600. {
  1601. $progress = '0';
  1602. }
  1603. if($mode == '%')
  1604. {
  1605. return $progress.'%';
  1606. }
  1607. else
  1608. {
  1609. //get the number of items completed and the number of items total
  1610. $tbl = Database::get_course_table('lp_item', $course_db);
  1611. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1612. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1613. $res = api_sql_query($sql, __FILE__, __LINE__);
  1614. $row = Database::fetch_array($res);
  1615. $total = $row[0];
  1616. $tbl_item_view = Database::get_course_table('lp_item_view', $course_db);
  1617. $tbl_item = Database::get_course_table('lp_item', $course_db);
  1618. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1619. //trying as also counting browsed and failed items
  1620. $sql = "SELECT count(distinct(lp_item_id))
  1621. FROM $tbl_item_view as item_view
  1622. INNER JOIN $tbl_item as item
  1623. ON item.id = item_view.lp_item_id
  1624. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1625. WHERE lp_view_id = ".$view_id."
  1626. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1627. $res = api_sql_query($sql, __FILE__, __LINE__);
  1628. $row = Database::fetch_array($res);
  1629. $completed = $row[0];
  1630. if($mode == 'abs')
  1631. {
  1632. return $completed.'/'.$total;
  1633. }
  1634. elseif($mode == 'both')
  1635. {
  1636. if($progress<($completed/($total?$total:1)))
  1637. {
  1638. $progress = number_format(($completed/($total?$total:1))*100,0);
  1639. }
  1640. return $progress.'% ('.$completed.'/'.$total.')';
  1641. }
  1642. }
  1643. return $progress;
  1644. }
  1645. function get_mediaplayer()
  1646. {
  1647. global $_course;
  1648. // Database table definition
  1649. $tbl_lp_item = Database::get_course_table('lp_item');
  1650. // getting all the information about the item
  1651. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = '" . $_SESSION['oLP']->current."'";
  1652. $result = api_sql_query($sql, __FILE__, __LINE__);
  1653. $row= mysql_fetch_assoc($result);
  1654. $output='';
  1655. if (!empty($row['audio']))
  1656. {
  1657. // the mp3 player
  1658. $output = '<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
  1659. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1660. $output .= '<script type="text/javascript">
  1661. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1662. s1.addParam("allowscriptaccess","always");
  1663. s1.addParam("flashvars","file='.api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  1664. s1.write("container");
  1665. </script>';
  1666. }
  1667. return $output;
  1668. }
  1669. /**
  1670. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1671. * completed so far.
  1672. * @param string Mode in which we want the values
  1673. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1674. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1675. * @param boolean true if it comes from a Diplay LP view
  1676. * @return string HTML string containing the progress bar
  1677. */
  1678. function get_progress_bar($mode='',$percentage=-1,$text_add='',$from_lp=false)
  1679. {
  1680. global $lp_theme_css;
  1681. // Setting up the CSS path of the current style if exists
  1682. if (!empty($lp_theme_css))
  1683. {
  1684. $css_path=api_get_path(WEB_CODE_PATH).'css/'.$lp_theme_css.'/images/';
  1685. }
  1686. else
  1687. {
  1688. $css_path='../img/';
  1689. }
  1690. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1691. if(isset($this) && is_object($this) && ($percentage=='-1' OR $text_add==''))
  1692. {
  1693. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1694. }
  1695. $text = $percentage.$text_add;
  1696. //Default progress bar config
  1697. // times that will be greater or shorter
  1698. $factor=1.2;
  1699. if ($from_lp)
  1700. $progress_height='26';
  1701. else
  1702. $progress_height='16';
  1703. $size = str_replace('%','',$percentage);
  1704. $output = ''
  1705. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1706. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1707. .'<img id="progress_img_limit_left" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'">'
  1708. .'<img id="progress_img_full" src="'.$css_path.'bar_1u.gif" width="'.$size*$factor.'px" height="'.$progress_height.'" id="full_portion">'
  1709. .'<img id="progress_img_limit_middle" src="'.$css_path.'bar_1m.gif" width="1" height="'.$progress_height.'">';
  1710. if($percentage <= 98)
  1711. {
  1712. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="'.(100-$size)*$factor.'px" height="'.$progress_height.'" id="empty_portion">';
  1713. }
  1714. else
  1715. {
  1716. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="0" height="'.$progress_height.'" id="empty_portion">';
  1717. }
  1718. $output .= '<img id="progress_bar_img_limit_right" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'"></td></tr></table>'
  1719. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1720. return $output;
  1721. }
  1722. /**
  1723. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1724. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1725. * //@param integer Additional steps to fake as completed
  1726. * @return list Percentage or number and symbol (% or /xx)
  1727. */
  1728. function get_progress_bar_text($mode='',$add=0)
  1729. {
  1730. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1731. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1732. $total_items = $this->get_total_items_count_without_chapters();
  1733. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1734. $i = $this->get_complete_items_count();
  1735. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1736. if($add != 0){
  1737. $i += $add;
  1738. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1739. }
  1740. $text = '';
  1741. if($i>$total_items){
  1742. $i = $total_items;
  1743. }
  1744. if($mode == '%'){
  1745. if($total_items>0){
  1746. $percentage = ((float)$i/(float)$total_items)*100;
  1747. }
  1748. else
  1749. {
  1750. $percentage = 0;
  1751. }
  1752. $percentage = number_format($percentage,0);
  1753. $text = '%';
  1754. }elseif($mode == 'abs'){
  1755. $percentage = $i;
  1756. $text = '/'.$total_items;
  1757. }
  1758. return array($percentage,$text);
  1759. }
  1760. /**
  1761. * Gets the progress bar mode
  1762. * @return string The progress bar mode attribute
  1763. */
  1764. function get_progress_bar_mode()
  1765. {
  1766. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1767. if(!empty($this->progress_bar_mode))
  1768. {
  1769. return $this->progress_bar_mode;
  1770. }else{
  1771. return '%';
  1772. }
  1773. }
  1774. /**
  1775. * Gets the learnpath proximity (remote or local)
  1776. * @return string Learnpath proximity
  1777. */
  1778. function get_proximity()
  1779. {
  1780. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1781. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1782. }
  1783. /**
  1784. * Gets the learnpath theme (remote or local)
  1785. * @return string Learnpath theme
  1786. */
  1787. function get_theme()
  1788. {
  1789. if($this->debug>0){error_log('New LP - In learnpath::get_theme()',0);}
  1790. if(!empty($this->theme)){return $this->theme;}else{return '';}
  1791. }
  1792. /**
  1793. * Gets the learnpath image
  1794. * @return string Web URL of the LP image
  1795. */
  1796. function get_preview_image()
  1797. {
  1798. if($this->debug>0){error_log('New LP - In learnpath::get_preview_image()',0);}
  1799. if(!empty($this->preview_image)){return $this->preview_image;}else{return '';}
  1800. }
  1801. /**
  1802. * Gets the learnpath author
  1803. * @return string LP's author
  1804. */
  1805. function get_author()
  1806. {
  1807. if($this->debug>0){error_log('New LP - In learnpath::get_author()',0);}
  1808. if(!empty($this->author)){return $this->author;}else{return '';}
  1809. }
  1810. /**
  1811. * Generate a new prerequisites string for a given item. If this item was a sco and
  1812. * its prerequisites were strings (instead of IDs), then transform those strings into
  1813. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1814. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1815. * same rule as the scorm_export() method
  1816. * @param integer Item ID
  1817. * @return string Prerequisites string ready for the export as SCORM
  1818. */
  1819. function get_scorm_prereq_string($item_id)
  1820. {
  1821. if($this->debug>0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
  1822. if(!is_object($this->items[$item_id])){return false;}
  1823. $oItem = $this->items[$item_id];
  1824. $prereq = $oItem->get_prereq_string();
  1825. if(empty($prereq))
  1826. {
  1827. return '';
  1828. }
  1829. if(preg_match('/^\d+$/',$prereq) && is_object($this->items[$prereq]))
  1830. { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  1831. //then simply return it (with the ITEM_ prefix)
  1832. return 'ITEM_'.$prereq;
  1833. }
  1834. else
  1835. {
  1836. if(isset($this->refs_list[$prereq]))
  1837. {
  1838. //it's a simple string item from which the ID can be found in the refs list
  1839. //so we can transform it directly to an ID for export
  1840. return 'ITEM_'.$this->refs_list[$prereq];
  1841. }
  1842. else
  1843. {
  1844. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  1845. //and replace them, one by one, by the internal IDs (dokeos db)
  1846. //TODO modify the '*' replacement to replace the multiplier in front of it
  1847. //by a space as well
  1848. $find = array('&','|','~','=','<>','{','}','*','(',')');
  1849. $replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
  1850. $prereq_mod = str_replace($find,$replace,$prereq);
  1851. $ids = split(' ',$prereq_mod);
  1852. foreach($ids as $id)
  1853. {
  1854. $id = trim($id);
  1855. if(isset($this->refs_list[$id]))
  1856. {
  1857. $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/','ITEM_'.$this->refs_list[$id],$prereq);
  1858. }
  1859. }
  1860. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '.$prereq,0);
  1861. return $prereq;
  1862. }
  1863. }
  1864. }
  1865. /**
  1866. * Returns the XML DOM document's node
  1867. * @param resource Reference to a list of objects to search for the given ITEM_*
  1868. * @param string The identifier to look for
  1869. * @return mixed The reference to the element found with that identifier. False if not found
  1870. */
  1871. function get_scorm_xml_node(&$children,$id)
  1872. {
  1873. for($i=0;$i<$children->length;$i++){
  1874. $item_temp = $children->item($i);
  1875. if ($item_temp -> nodeName == 'item')
  1876. {
  1877. if($item_temp->getAttribute('identifier') == $id)
  1878. {
  1879. return $item_temp;
  1880. }
  1881. }
  1882. $subchildren = $item_temp->childNodes;
  1883. if($subchildren->length>0)
  1884. {
  1885. $val = $this->get_scorm_xml_node($subchildren,$id);
  1886. if(is_object($val))
  1887. {
  1888. return $val;
  1889. }
  1890. }
  1891. }
  1892. return false;
  1893. }
  1894. /**
  1895. * Returns a usable array of stats related to the current learnpath and user
  1896. * @return array Well-formatted array containing status for the current learnpath
  1897. */
  1898. function get_stats()
  1899. {
  1900. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1901. //TODO
  1902. }
  1903. /**
  1904. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1905. * the given course (for all learnpaths and all users)
  1906. * @param string Course code
  1907. * @return array Well-formatted array containing status for the course's learnpaths
  1908. */
  1909. function get_stats_course($course)
  1910. {
  1911. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1912. //TODO
  1913. }
  1914. /**
  1915. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1916. * the given course and learnpath (for all users)
  1917. * @param string Course code
  1918. * @param integer Learnpath ID
  1919. * @return array Well-formatted array containing status for the specified learnpath
  1920. */
  1921. function get_stats_lp($course,$lp)
  1922. {
  1923. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1924. //TODO
  1925. }
  1926. /**
  1927. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1928. * the given course, learnpath and user.
  1929. * @param string Course code
  1930. * @param integer Learnpath ID
  1931. * @param integer User ID
  1932. * @return array Well-formatted array containing status for the specified learnpath and user
  1933. */
  1934. function get_stats_lp_user($course,$lp,$user)
  1935. {
  1936. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1937. //TODO
  1938. }
  1939. /**
  1940. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1941. * the given course and learnpath (for all users)
  1942. * @param string Course code
  1943. * @param integer User ID
  1944. * @return array Well-formatted array containing status for the user's learnpaths
  1945. */
  1946. function get_stats_user($course,$user)
  1947. {
  1948. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1949. //TODO
  1950. }
  1951. /**
  1952. * Gets the status list for all LP's items
  1953. * @return array Array of [index] => [item ID => current status]
  1954. */
  1955. function get_items_status_list(){
  1956. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1957. $list = array();
  1958. foreach($this->ordered_items as $item_id)
  1959. {
  1960. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1961. }
  1962. return $list;
  1963. }
  1964. /**
  1965. * Return the number of interactions for the given learnpath Item View ID.
  1966. * This method can be used as static.
  1967. * @param integer Item View ID
  1968. * @return integer Number of interactions
  1969. */
  1970. function get_interactions_count_from_db($lp_iv_id=0){
  1971. if(empty($lp_iv_id)){return -1;}
  1972. $table = Database::get_course_table('lp_iv_interaction');
  1973. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1974. $res = api_sql_query($sql,__FILE__,__LINE__);
  1975. $row = Database::fetch_array($res);
  1976. $num = $row[0];
  1977. return $num;
  1978. }
  1979. /**
  1980. * Return the interactions as an array for the given lp_iv_id.
  1981. * This method can be used as static.
  1982. * @param integer Learnpath Item View ID
  1983. * @return array
  1984. * @todo Translate labels
  1985. */
  1986. function get_iv_interactions_array($lp_iv_id=0){
  1987. $list = array();
  1988. $table = Database::get_course_table('lp_iv_interaction');
  1989. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  1990. $res = api_sql_query($sql,__FILE__,__LINE__);
  1991. $num = Database::num_rows($res);
  1992. if($num>0){
  1993. $list[] = array(
  1994. "order_id"=>htmlentities(get_lang('Order')),
  1995. "id"=>htmlentities(get_lang('InteractionID')),
  1996. "type"=>htmlentities(get_lang('Type')),
  1997. "time"=>htmlentities(get_lang('TimeFinished')),
  1998. "correct_responses"=>htmlentities(get_lang('CorrectAnswers')),
  1999. "student_response"=>htmlentities(get_lang('StudentResponse')),
  2000. "result"=>htmlentities(get_lang('Result')),
  2001. "latency"=>htmlentities(get_lang('LatencyTimeSpent')));
  2002. while ($row = Database::fetch_array($res)){
  2003. $list[] = array(
  2004. "order_id"=>($row['order_id']+1),
  2005. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  2006. "type"=>$row['interaction_type'],
  2007. "time"=>$row['completion_time'],
  2008. //"correct_responses"=>$row['correct_responses'],
  2009. //hide correct responses from students
  2010. "correct_responses"=>'',
  2011. "student_response"=>$row['student_response'],
  2012. "result"=>$row['result'],
  2013. "latency"=>$row['latency']);
  2014. }
  2015. }
  2016. return $list;
  2017. }
  2018. /**
  2019. * Return the number of objectives for the given learnpath Item View ID.
  2020. * This method can be used as static.
  2021. * @param integer Item View ID
  2022. * @return integer Number of objectives
  2023. */
  2024. function get_objectives_count_from_db($lp_iv_id=0){
  2025. if(empty($lp_iv_id)){return -1;}
  2026. $table = Database::get_course_table('lp_iv_objective');
  2027. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2028. $res = api_sql_query($sql,__FILE__,__LINE__);
  2029. $row = Database::fetch_array($res);
  2030. $num = $row[0];
  2031. return $num;
  2032. }
  2033. /**
  2034. * Return the objectives as an array for the given lp_iv_id.
  2035. * This method can be used as static.
  2036. * @param integer Learnpath Item View ID
  2037. * @return array
  2038. * @todo Translate labels
  2039. */
  2040. function get_iv_objectives_array($lp_iv_id=0){
  2041. $list = array();
  2042. $table = Database::get_course_table('lp_iv_objective');
  2043. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2044. $res = api_sql_query($sql,__FILE__,__LINE__);
  2045. $num = Database::num_rows($res);
  2046. if($num>0){
  2047. $list[] = array(
  2048. "order_id"=>htmlentities(get_lang('Order')),
  2049. "objective_id"=>htmlentities(get_lang('ObjectiveID')),
  2050. "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')),
  2051. "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')),
  2052. "score_min"=>htmlentities(get_lang('ObjectiveMinScore')),
  2053. "status"=>htmlentities(get_lang('ObjectiveStatus')));
  2054. while ($row = Database::fetch_array($res)){
  2055. $list[] = array(
  2056. "order_id"=>($row['order_id']+1),
  2057. "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
  2058. "score_raw"=>$row['score_raw'],
  2059. "score_max"=>$row['score_max'],
  2060. "score_min"=>$row['score_min'],
  2061. "status"=>$row['status']);
  2062. }
  2063. }
  2064. return $list;
  2065. }
  2066. /**
  2067. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2068. * used by get_html_toc() to be ready to display
  2069. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2070. */
  2071. function get_toc()
  2072. {
  2073. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  2074. $toc = array();
  2075. //echo "<pre>".print_r($this->items,true)."</pre>";
  2076. foreach($this->ordered_items as $item_id)
  2077. {
  2078. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  2079. //TODO change this link generation and use new function instead
  2080. $toc[] = array(
  2081. 'id'=>$item_id,
  2082. 'title'=>$this->items[$item_id]->get_title(),
  2083. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2084. 'status'=>$this->items[$item_id]->get_status(),
  2085. 'level'=>$this->items[$item_id]->get_level(),
  2086. 'type' =>$this->items[$item_id]->get_type(),
  2087. 'description'=>$this->items[$item_id]->get_description(),
  2088. );
  2089. }
  2090. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  2091. return $toc;
  2092. }
  2093. /**
  2094. * Gets the learning path type
  2095. * @param boolean Return the name? If false, return the ID. Default is false.
  2096. * @return mixed Type ID or name, depending on the parameter
  2097. */
  2098. function get_type($get_name = false)
  2099. {
  2100. $res = false;
  2101. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  2102. if(!empty($this->type))
  2103. {
  2104. if($get_name)
  2105. {
  2106. //get it from the lp_type table in main db
  2107. }else{
  2108. $res = $this->type;
  2109. }
  2110. }
  2111. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  2112. return $res;
  2113. }
  2114. /**
  2115. * Gets the learning path type as static method
  2116. * @param boolean Return the name? If false, return the ID. Default is false.
  2117. * @return mixed Type ID or name, depending on the parameter
  2118. */
  2119. function get_type_static($lp_id=0)
  2120. {
  2121. $tbl_lp = Database::get_course_table('lp');
  2122. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '".$lp_id."'";
  2123. $res = api_sql_query($sql, __FILE__, __LINE__);
  2124. if($res===false){ return null;}
  2125. if(Database::num_rows($res)<=0){return null;}
  2126. $row = Database::fetch_array($res);
  2127. return $row['lp_type'];
  2128. }
  2129. /**
  2130. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2131. * This method can be used as abstract and is recursive
  2132. * @param integer Learnpath ID
  2133. * @param integer Parent ID of the items to look for
  2134. * @return mixed Ordered list of item IDs or false on error
  2135. */
  2136. function get_flat_ordered_items_list($lp,$parent=0)
  2137. {
  2138. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2139. $list = array();
  2140. if(empty($lp)){return false;}
  2141. $tbl_lp_item = Database::get_course_table('lp_item');
  2142. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2143. $res = api_sql_query($sql,__FILE__,__LINE__);
  2144. while($row = Database::fetch_array($res)){
  2145. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  2146. $list[] = $row['id'];
  2147. foreach($sublist as $item){
  2148. $list[] = $item;
  2149. }
  2150. }
  2151. return $list;
  2152. }
  2153. /**
  2154. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2155. * @return string HTML TOC ready to display
  2156. */
  2157. /*function get_html_toc()
  2158. {
  2159. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2160. $list = $this->get_toc();
  2161. //echo $this->current;
  2162. //$parent = $this->items[$this->current]->get_parent();
  2163. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2164. $html = '<div class="inner_lp_toc">'."\n" ;
  2165. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2166. require_once('resourcelinker.inc.php');
  2167. //temp variables
  2168. $mycurrentitemid = $this->get_current_item_id();
  2169. foreach($list as $item)
  2170. {
  2171. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2172. //TODO complete this
  2173. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2174. 'incomplete' => '../img/incomplete.gif',
  2175. 'failed' => '../img/failed.gif',
  2176. 'completed' => '../img/completed.gif',
  2177. 'passed' => '../img/passed.gif',
  2178. 'succeeded' => '../img/succeeded.gif',
  2179. 'browsed' => '../img/completed.gif');
  2180. $style = 'scorm_item';
  2181. if($item['id'] == $this->current){
  2182. $style = 'scorm_item_highlight';
  2183. }
  2184. //the anchor will let us center the TOC on the currently viewed item &^D
  2185. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']/2).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
  2186. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2187. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2188. $title = $item['title'];
  2189. if(empty($title)){
  2190. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2191. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2192. }
  2193. if(empty($title))$title = '-';
  2194. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2195. //$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>" ;
  2196. $url = $this->get_link('http',$item['id']);
  2197. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2198. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2199. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2200. $mycurrentitemid.',' .
  2201. $item['id'].');' .
  2202. 'return false;" >'.$title.'</a>' ;
  2203. }else{
  2204. $html .= $title;
  2205. }
  2206. $html .= "</div>\n";
  2207. }
  2208. $html .= "</div>\n";
  2209. return $html;
  2210. }*/
  2211. /**
  2212. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2213. * @return string HTML TOC ready to display
  2214. */
  2215. function get_html_toc()
  2216. {
  2217. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2218. $list = $this->get_toc();
  2219. $mych = api_get_setting('platform_charset');
  2220. //echo $this->current;
  2221. //$parent = $this->items[$this->current]->get_parent();
  2222. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2223. $html= '<div class="scorm_title"><div class="scorm_title_text">'.mb_convert_encoding($this->get_name(),$this->encoding,$mych).'</div></div>';
  2224. // build, display
  2225. if(api_is_allowed_to_edit())
  2226. {
  2227. $html .='<div class="actions_lp">';
  2228. $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').' '.mb_convert_encoding(get_lang('Build'),$this->encoding,$mych)."</a>";
  2229. $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').' '.mb_convert_encoding(get_lang('BasicOverview'),$this->encoding,$mych)."</a>";
  2230. $html .= '<span>'.Display::return_icon('learnpath_view.gif').' '.mb_convert_encoding(get_lang("Display"),$this->encoding,$mych).'</span>';
  2231. $html .= '</div>';
  2232. unset($mych);
  2233. }
  2234. $html.= '<div class="inner_lp_toc">'."\n" ;
  2235. //$html.= '<div class="scorm_title"><div class="scorm_title_text">'.mb_convert_encoding($this->get_name(),$this->encoding,$mych).'</div></div>';
  2236. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2237. require_once('resourcelinker.inc.php');
  2238. //temp variables
  2239. $mycurrentitemid = $this->get_current_item_id();
  2240. $color_counter=0;
  2241. $i=0;
  2242. foreach($list as $item)
  2243. {
  2244. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2245. //TODO complete this
  2246. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2247. 'incomplete' => '../img/incomplete.gif',
  2248. 'failed' => '../img/failed.gif',
  2249. 'completed' => '../img/completed.gif',
  2250. 'passed' => '../img/passed.gif',
  2251. 'succeeded' => '../img/succeeded.gif',
  2252. 'browsed' => '../img/completed.gif');
  2253. $style = 'scorm_item';
  2254. $scorm_color_background='scorm_item';
  2255. $style_item ='scorm_item';
  2256. $current=false;
  2257. if($item['id'] == $this->current)
  2258. {
  2259. $style = 'scorm_item_highlight';
  2260. $scorm_color_background ='scorm_item_highlight';
  2261. }
  2262. else
  2263. if ($color_counter%2==0)
  2264. {
  2265. $scorm_color_background='scorm_item_1';
  2266. }
  2267. else
  2268. {
  2269. $scorm_color_background='scorm_item_2';
  2270. }
  2271. if ($scorm_color_background!='')
  2272. {
  2273. $html .= '<div id="toc_'.$item['id'].'" class="'.$scorm_color_background.'">';
  2274. }
  2275. //the anchor will let us center the TOC on the currently viewed item &^D
  2276. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter')
  2277. {
  2278. $html .= '<a name="atoc_'.$item['id'].'" />';
  2279. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" title="'.$item['description'].'" >';
  2280. }
  2281. else
  2282. {
  2283. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" title="'.$item['description'].'" >';
  2284. }
  2285. $title=$item['title'];
  2286. if(empty($title))
  2287. {
  2288. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2289. }
  2290. $title = html_entity_decode($title,ENT_QUOTES,$this->encoding);
  2291. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module')
  2292. {
  2293. //$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>" ;
  2294. $url = $this->get_link('http',$item['id']);
  2295. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2296. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2297. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;
  2298. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2299. $mycurrentitemid.',' .
  2300. $item['id'].');' .
  2301. 'return false;" >'.stripslashes($title).'</a>' ;
  2302. }
  2303. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter')
  2304. {
  2305. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  2306. }
  2307. elseif($item['type']=='dir')
  2308. {
  2309. $html .= stripslashes($title);
  2310. }
  2311. $html .= "&nbsp;<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' />";
  2312. $html .= "</div>";
  2313. if ($scorm_color_background!='')
  2314. {
  2315. $html .= '</div>';
  2316. }
  2317. $color_counter++;
  2318. }
  2319. $html .= "</div>\n";
  2320. return $html;
  2321. }
  2322. /**
  2323. * Gets the learnpath maker name - generally the editor's name
  2324. * @return string Learnpath maker name
  2325. */
  2326. function get_maker()
  2327. {
  2328. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  2329. if(!empty($this->maker)){return $this->maker;}else{return '';}
  2330. }
  2331. /**
  2332. * Gets the user-friendly message stored in $this->message
  2333. * @return string Message
  2334. */
  2335. function get_message(){
  2336. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  2337. return $this->message;
  2338. }
  2339. /**
  2340. * Gets the learnpath name/title
  2341. * @return string Learnpath name/title
  2342. */
  2343. function get_name()
  2344. {
  2345. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2346. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2347. }
  2348. /**
  2349. * Gets a link to the resource from the present location, depending on item ID.
  2350. * @param string Type of link expected
  2351. * @param integer Learnpath item ID
  2352. * @return string Link to the lp_item resource
  2353. */
  2354. function get_link($type='http',$item_id=null)
  2355. {
  2356. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2357. if(empty($item_id))
  2358. {
  2359. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: '.$this->get_current_item_id(),0);}
  2360. $item_id = $this->get_current_item_id();
  2361. }
  2362. if(empty($item_id)){
  2363. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2364. //still empty, this means there was no item_id given and we are not in an object context or
  2365. //the object property is empty, return empty link
  2366. $item_id = $this->first();
  2367. return '';
  2368. }
  2369. $file = '';
  2370. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2371. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2372. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2373. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2374. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2375. $res = api_sql_query($sel, __FILE__, __LINE__);
  2376. if(Database::num_rows($res)>0)
  2377. {
  2378. $row = Database::fetch_array($res);
  2379. //var_dump($row);
  2380. $lp_type = $row['ltype'];
  2381. $lp_path = $row['lpath'];
  2382. $lp_item_type = $row['litype'];
  2383. $lp_item_path = $row['lipath'];
  2384. $lp_item_params = $row['liparams'];
  2385. if(empty($lp_item_params) && strpos($lp_item_path,'?')!==false)
  2386. {
  2387. list($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
  2388. }
  2389. //$lp_item_params = '?'.$lp_item_params;
  2390. //add ? if none - left commented to give freedom to scorm implementation
  2391. //if(substr($lp_item_params,0,1)!='?'){
  2392. // $lp_item_params = '?'.$lp_item_params;
  2393. //}
  2394. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2395. if($type == 'http'){
  2396. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2397. }else{
  2398. $course_path = $sys_course_path; //system path
  2399. }
  2400. //now go through the specific cases to get the end of the path
  2401. switch($lp_type){
  2402. case 1:
  2403. if($lp_item_type == 'dokeos_chapter'){
  2404. $file = 'lp_content.php?type=dir';
  2405. }else{
  2406. require_once('resourcelinker.inc.php');
  2407. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2408. $tmp_array=explode("/",$file);
  2409. $document_name=$tmp_array[count($tmp_array)-1];
  2410. if(strpos($document_name,'_DELETED_')){
  2411. $file = 'blank.php?error=document_deleted';
  2412. }
  2413. }
  2414. break;
  2415. case 2:
  2416. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2417. if($lp_item_type!='dir'){
  2418. //Quite complex here:
  2419. //we want to make sure 'http://' (and similar) links can
  2420. //be loaded as is (withouth the Dokeos path in front) but
  2421. //some contents use this form: resource.htm?resource=http://blablabla
  2422. //which means we have to find a protocol at the path's start, otherwise
  2423. //it should not be considered as an external URL
  2424. //if($this->prerequisites_match($item_id)){
  2425. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2426. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2427. //distant url, return as is
  2428. $file = $lp_item_path;
  2429. }else{
  2430. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2431. //prevent getting untranslatable urls
  2432. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2433. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2434. //prepare the path
  2435. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2436. //TODO fix this for urls with protocol header
  2437. $file = str_replace('//','/',$file);
  2438. $file = str_replace(':/','://',$file);
  2439. if(substr($lp_path,-1)=='/')
  2440. {
  2441. $lp_path = substr($lp_path,0,-1);
  2442. }
  2443. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path)))
  2444. {//if file not found
  2445. $decoded = html_entity_decode($lp_item_path);
  2446. list($decoded) = explode('?',$decoded);
  2447. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded)))
  2448. {
  2449. require_once('resourcelinker.inc.php');
  2450. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2451. $tmp_array=explode("/",$file);
  2452. $document_name=$tmp_array[count($tmp_array)-1];
  2453. if(strpos($document_name,'_DELETED_')){
  2454. $file = 'blank.php?error=document_deleted';
  2455. }
  2456. }
  2457. else
  2458. {
  2459. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2460. }
  2461. }
  2462. }
  2463. //}else{
  2464. //prerequisites did not match
  2465. //$file = 'blank.php';
  2466. //}
  2467. //We want to use parameters if they were defined in the imsmanifest
  2468. if($file!='blank.php')
  2469. {
  2470. $file.= (strstr($file,'?')===false?'?':'').$lp_item_params;
  2471. }
  2472. }else{
  2473. $file = 'lp_content.php?type=dir';
  2474. }
  2475. break;
  2476. case 3:
  2477. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2478. //formatting AICC HACP append URL
  2479. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2480. if($lp_item_type!='dir'){
  2481. //Quite complex here:
  2482. //we want to make sure 'http://' (and similar) links can
  2483. //be loaded as is (withouth the Dokeos path in front) but
  2484. //some contents use this form: resource.htm?resource=http://blablabla
  2485. //which means we have to find a protocol at the path's start, otherwise
  2486. //it should not be considered as an external URL
  2487. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2488. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2489. //distant url, return as is
  2490. $file = $lp_item_path;
  2491. /*
  2492. if(stristr($file,'<servername>')!==false){
  2493. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2494. }
  2495. */
  2496. $file .= $aicc_append;
  2497. }else{
  2498. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2499. //prevent getting untranslatable urls
  2500. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2501. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2502. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2503. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2504. //TODO fix this for urls with protocol header
  2505. $file = str_replace('//','/',$file);
  2506. $file = str_replace(':/','://',$file);
  2507. $file .= $aicc_append;
  2508. }
  2509. }else{
  2510. $file = 'lp_content.php?type=dir';
  2511. }
  2512. break;
  2513. case 4:
  2514. break;
  2515. default:
  2516. break;
  2517. }
  2518. }
  2519. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2520. return $file;
  2521. }
  2522. /**
  2523. * Gets the latest usable view or generate a new one
  2524. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2525. * @return integer DB lp_view id
  2526. */
  2527. function get_view($attempt_num=0)
  2528. {
  2529. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2530. $search = '';
  2531. //use $attempt_num to enable multi-views management (disabled so far)
  2532. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2533. {
  2534. $search = 'AND view_count = '.$attempt_num;
  2535. }
  2536. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2537. $lp_view_table = Database::get_course_table('lp_view');
  2538. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2539. "WHERE lp_id = ".$this->get_id()." " .
  2540. "AND user_id = ".$this->get_user_id()." " .
  2541. $search .
  2542. " ORDER BY view_count DESC";
  2543. $res = api_sql_query($sql, __FILE__, __LINE__);
  2544. if(Database::num_rows($res)>0)
  2545. {
  2546. $row = Database::fetch_array($res);
  2547. $this->lp_view_id = $row['id'];
  2548. }else{
  2549. //no database record, create one
  2550. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2551. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2552. $res = api_sql_query($sql, __FILE__, __LINE__);
  2553. $id = Database::get_last_insert_id();
  2554. $this->lp_view_id = $id;
  2555. }
  2556. return $this->lp_view_id;
  2557. }
  2558. /**
  2559. * Gets the current view id
  2560. * @return integer View ID (from lp_view)
  2561. */
  2562. function get_view_id()
  2563. {
  2564. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2565. if(!empty($this->lp_view_id))
  2566. {
  2567. return $this->lp_view_id;
  2568. }else{
  2569. return 0;
  2570. }
  2571. }
  2572. /**
  2573. * Gets the update queue
  2574. * @return array Array containing IDs of items to be updated by JavaScript
  2575. */
  2576. function get_update_queue()
  2577. {
  2578. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2579. return $this->update_queue;
  2580. }
  2581. /**
  2582. * Gets the user ID
  2583. * @return integer User ID
  2584. */
  2585. function get_user_id()
  2586. {
  2587. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2588. if(!empty($this->user_id))
  2589. {
  2590. return $this->user_id;
  2591. }else{
  2592. return false;
  2593. }
  2594. }
  2595. /**
  2596. * Logs a message into a file
  2597. * @param string Message to log
  2598. * @return boolean True on success, false on error or if msg empty
  2599. */
  2600. function log($msg)
  2601. {
  2602. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2603. //TODO
  2604. $this->error .= $msg."\n";
  2605. return true;
  2606. }
  2607. /**
  2608. * Moves an item up and down at its level
  2609. * @param integer Item to move up and down
  2610. * @param string Direction 'up' or 'down'
  2611. * @return integer New display order, or false on error
  2612. */
  2613. function move_item($id, $direction){
  2614. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2615. if(empty($id) or empty($direction)){return false;}
  2616. $tbl_lp_item = Database::get_course_table('lp_item');
  2617. $sql_sel = "
  2618. SELECT *
  2619. FROM " . $tbl_lp_item . "
  2620. WHERE id = " . $id;
  2621. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2622. //check if elem exists
  2623. if(Database::num_rows($res_sel)<1){return false;}
  2624. //gather data
  2625. $row = Database::fetch_array($res_sel);
  2626. $previous = $row['previous_item_id'];
  2627. $next = $row['next_item_id'];
  2628. $display = $row['display_order'];
  2629. $parent = $row['parent_item_id'];
  2630. $lp = $row['lp_id'];
  2631. //update the item (switch with previous/next one)
  2632. switch($direction)
  2633. {
  2634. case 'up':
  2635. if($this->debug>2){error_log('Movement up detected',0);}
  2636. if($display <= 1){/*do nothing*/}
  2637. else{
  2638. $sql_sel2 = "SELECT *
  2639. FROM $tbl_lp_item
  2640. WHERE id = $previous";
  2641. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2642. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2643. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2644. //gather data
  2645. $row2 = Database::fetch_array($res_sel2);
  2646. $previous_previous = $row2['previous_item_id'];
  2647. //update previous_previous item (switch "next" with current)
  2648. if($previous_previous != 0)
  2649. {
  2650. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2651. if($this->debug>2){error_log($sql_upd2,0);}
  2652. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2653. }
  2654. //update previous item (switch with current)
  2655. if($previous != 0)
  2656. {
  2657. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2658. if($this->debug>2){error_log($sql_upd2,0);}
  2659. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2660. }
  2661. //update current item (switch with previous)
  2662. if($id != 0){
  2663. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2664. if($this->debug>2){error_log($sql_upd2,0);}
  2665. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2666. }
  2667. //update next item (new previous item)
  2668. if($next != 0){
  2669. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2670. if($this->debug>2){error_log($sql_upd2,0);}
  2671. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2672. }
  2673. $display = $display-1;
  2674. }
  2675. break;
  2676. case 'down':
  2677. if($this->debug>2){error_log('Movement down detected',0);}
  2678. if($next == 0){/*do nothing*/}
  2679. else{
  2680. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2681. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2682. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2683. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2684. //gather data
  2685. $row2 = Database::fetch_array($res_sel2);
  2686. $next_next = $row2['next_item_id'];
  2687. //update previous item (switch with current)
  2688. if($previous != 0)
  2689. {
  2690. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2691. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2692. }
  2693. //update current item (switch with previous)
  2694. if($id != 0)
  2695. {
  2696. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2697. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2698. }
  2699. //update next item (new previous item)
  2700. if($next != 0)
  2701. {
  2702. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2703. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2704. }
  2705. //update next_next item (switch "previous" with current)
  2706. if($next_next != 0)
  2707. {
  2708. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2709. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2710. }
  2711. $display = $display+1;
  2712. }
  2713. break;
  2714. default:
  2715. return false;
  2716. }
  2717. return $display;
  2718. }
  2719. /**
  2720. * Move a learnpath up (display_order)
  2721. * @param integer Learnpath ID
  2722. */
  2723. function move_up($lp_id)
  2724. {
  2725. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2726. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2727. $res = api_sql_query($sql, __FILE__, __LINE__);
  2728. if($res === false) return false;
  2729. $lps = array();
  2730. $lp_order = array();
  2731. $num = Database::num_rows($res);
  2732. //first check the order is correct, globally (might be wrong because
  2733. //of versions < 1.8.4)
  2734. if($num>0)
  2735. {
  2736. $i = 1;
  2737. while($row = Database::fetch_array($res))
  2738. {
  2739. if($row['display_order'] != $i)
  2740. { //if we find a gap in the order, we need to fix it
  2741. $need_fix = true;
  2742. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2743. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2744. }
  2745. $row['display_order'] = $i;
  2746. $lps[$row['id']] = $row;
  2747. $lp_order[$i] = $row['id'];
  2748. $i++;
  2749. }
  2750. }
  2751. if($num>1) //if there's only one element, no need to sort
  2752. {
  2753. $order = $lps[$lp_id]['display_order'];
  2754. if($order>1) //if it's the first element, no need to move up
  2755. {
  2756. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
  2757. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2758. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
  2759. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2760. }
  2761. }
  2762. }
  2763. /**
  2764. * Move a learnpath down (display_order)
  2765. * @param integer Learnpath ID
  2766. */
  2767. function move_down($lp_id)
  2768. {
  2769. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2770. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2771. $res = api_sql_query($sql, __FILE__, __LINE__);
  2772. if($res === false) return false;
  2773. $lps = array();
  2774. $lp_order = array();
  2775. $num = Database::num_rows($res);
  2776. $max = 0;
  2777. //first check the order is correct, globally (might be wrong because
  2778. //of versions < 1.8.4)
  2779. if($num>0)
  2780. {
  2781. $i = 1;
  2782. while($row = Database::fetch_array($res))
  2783. {
  2784. $max = $i;
  2785. if($row['display_order'] != $i)
  2786. { //if we find a gap in the order, we need to fix it
  2787. $need_fix = true;
  2788. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2789. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2790. }
  2791. $row['display_order'] = $i;
  2792. $lps[$row['id']] = $row;
  2793. $lp_order[$i] = $row['id'];
  2794. $i++;
  2795. }
  2796. }
  2797. if($num>1) //if there's only one element, no need to sort
  2798. {
  2799. $order = $lps[$lp_id]['display_order'];
  2800. if($order<$max) //if it's the first element, no need to move up
  2801. {
  2802. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
  2803. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2804. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
  2805. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2806. }
  2807. }
  2808. }
  2809. /**
  2810. * Updates learnpath attributes to point to the next element
  2811. * The last part is similar to set_current_item but processing the other way around
  2812. */
  2813. function next()
  2814. {
  2815. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2816. $this->last = $this->get_current_item_id();
  2817. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2818. $this->autocomplete_parents($this->last);
  2819. $new_index = $this->get_next_index();
  2820. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2821. $this->index = $new_index;
  2822. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2823. $this->current = $this->ordered_items[$new_index];
  2824. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2825. }
  2826. /**
  2827. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2828. * class, this might be redefined to allow several behaviours depending on the document type.
  2829. * @param integer Resource ID
  2830. * @return boolean True on success, false otherwise
  2831. */
  2832. function open($id)
  2833. {
  2834. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2835. //TODO
  2836. //set the current resource attribute to this resource
  2837. //switch on element type (redefine in child class?)
  2838. //set status for this item to "opened"
  2839. //start timer
  2840. //initialise score
  2841. $this->index = 0; //or = the last item seen (see $this->last)
  2842. }
  2843. /**
  2844. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2845. * and the prerequisite string on error.
  2846. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2847. * @param integer Optional item ID. If none given, uses the current open item.
  2848. * @return boolean True if prerequisites are matched, false otherwise
  2849. * @return string Empty string if true returned, prerequisites string otherwise.
  2850. */
  2851. function prerequisites_match($item = null)
  2852. {
  2853. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2854. if(empty($item)){$item = $this->current;}
  2855. if(is_object($this->items[$item]))
  2856. {
  2857. $prereq_string = $this->items[$item]->get_prereq_string();
  2858. if(empty($prereq_string)){return true;}
  2859. //clean spaces
  2860. $prereq_string = str_replace(' ','',$prereq_string);
  2861. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2862. //now send to the parse_prereq() function that will check this component's prerequisites
  2863. $result = $this->items[$item]->parse_prereq($prereq_string,$this->items,$this->refs_list,$this->get_user_id());
  2864. if($result === false)
  2865. {
  2866. $this->set_error_msg($this->items[$item]->prereq_alert);
  2867. }
  2868. }else{
  2869. $result = true;
  2870. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2871. }
  2872. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2873. return $result;
  2874. }
  2875. /**
  2876. * Updates learnpath attributes to point to the previous element
  2877. * The last part is similar to set_current_item but processing the other way around
  2878. */
  2879. function previous()
  2880. {
  2881. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2882. $this->last = $this->get_current_item_id();
  2883. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2884. $this->autocomplete_parents($this->last);
  2885. $new_index = $this->get_previous_index();
  2886. $this->index = $new_index;
  2887. $this->current = $this->ordered_items[$new_index];
  2888. }
  2889. /**
  2890. * Publishes a learnpath. This basically means show or hide the learnpath
  2891. * to normal users.
  2892. * Can be used as abstract
  2893. * @param integer Learnpath ID
  2894. * @param string New visibility
  2895. */
  2896. function toggle_visibility($lp_id,$set_visibility=1)
  2897. {
  2898. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2899. $action = 'visible';
  2900. if($set_visibility != 1)
  2901. {
  2902. $action = 'invisible';
  2903. }
  2904. return api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$lp_id,$action,api_get_user_id());
  2905. }
  2906. /**
  2907. * Publishes a learnpath. This basically means show or hide the learnpath
  2908. * on the course homepage
  2909. * Can be used as abstract
  2910. * @param integer Learnpath ID
  2911. * @param string New visibility
  2912. */
  2913. function toggle_publish($lp_id,$set_visibility='v')
  2914. {
  2915. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  2916. $tbl_lp = Database::get_course_table('lp');
  2917. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2918. $result=api_sql_query($sql,__FILE__,__LINE__);
  2919. $row=Database::fetch_array($result);
  2920. $name=domesticate($row['name']);
  2921. if($set_visibility == 'i') {
  2922. $s=$name." ".get_lang('_no_published');
  2923. $dialogBox=$s;
  2924. $v=0;
  2925. }
  2926. if($set_visibility == 'v')
  2927. {
  2928. $s=$name." ".get_lang('_published');
  2929. $dialogBox=$s;
  2930. $v=1;
  2931. }
  2932. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  2933. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  2934. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  2935. $result=api_sql_query($sql,__FILE__,__LINE__);
  2936. $num=Database::num_rows($result);
  2937. $row2=Database::fetch_array($result);
  2938. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2939. if(($set_visibility == 'i') && ($num>0))
  2940. {
  2941. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2942. }
  2943. elseif(($set_visibility == 'v') && ($num==0))
  2944. {
  2945. $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)";
  2946. }
  2947. else
  2948. {
  2949. //parameter and database incompatible, do nothing
  2950. }
  2951. $result=api_sql_query($sql,__FILE__,__LINE__);
  2952. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  2953. }
  2954. /**
  2955. * Restart the whole learnpath. Return the URL of the first element.
  2956. * Make sure the results are saved with anoter method. This method should probably be
  2957. * redefined in children classes.
  2958. * @return string URL to load in the viewer
  2959. */
  2960. function restart()
  2961. {
  2962. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  2963. //TODO
  2964. //call autosave method to save the current progress
  2965. //$this->index = 0;
  2966. $lp_view_table = Database::get_course_table('lp_view');
  2967. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  2968. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  2969. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  2970. $res = api_sql_query($sql, __FILE__, __LINE__);
  2971. if($view_id = Database::get_last_insert_id($res))
  2972. {
  2973. $this->lp_view_id = $view_id;
  2974. $this->attempt = $this->attempt+1;
  2975. }else{
  2976. $this->error = 'Could not insert into item_view table...';
  2977. return false;
  2978. }
  2979. $this->autocomplete_parents($this->current);
  2980. foreach($this->items as $index=>$dummy){
  2981. $this->items[$index]->restart();
  2982. $this->items[$index]->set_lp_view($this->lp_view_id);
  2983. }
  2984. $this->first();
  2985. return true;
  2986. }
  2987. /**
  2988. * Saves the current item
  2989. * @return boolean
  2990. */
  2991. function save_current(){
  2992. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  2993. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2994. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2995. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  2996. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  2997. if(is_object($this->items[$this->current])){
  2998. //$res = $this->items[$this->current]->save(false);
  2999. $res = $this->items[$this->current]->save(false,$this->prerequisites_match($this->current));
  3000. $this->autocomplete_parents($this->current);
  3001. $status = $this->items[$this->current]->get_status();
  3002. $this->append_message('new_item_status: '.$status);
  3003. $this->update_queue[$this->current] = $status;
  3004. return $res;
  3005. }
  3006. return false;
  3007. }
  3008. /**
  3009. * Saves the given item
  3010. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3011. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3012. * @return boolean
  3013. */
  3014. function save_item($item_id=null,$from_outside=true){
  3015. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  3016. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3017. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3018. if(empty($item_id)){
  3019. $item_id = $this->escape_string($_REQUEST['id']);
  3020. }
  3021. if(empty($item_id))
  3022. {
  3023. $item_id = $this->get_current_item_id();
  3024. }
  3025. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  3026. if(is_object($this->items[$item_id])){
  3027. $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id));
  3028. //$res = $this->items[$item_id]->save($from_outside);
  3029. $this->autocomplete_parents($item_id);
  3030. $status = $this->items[$item_id]->get_status();
  3031. $this->append_message('new_item_status: '.$status);
  3032. $this->update_queue[$item_id] = $status;
  3033. return $res;
  3034. }
  3035. return false;
  3036. }
  3037. /**
  3038. * Saves the last item seen's ID only in case
  3039. */
  3040. function save_last(){
  3041. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  3042. $table = Database::get_course_table('lp_view');
  3043. if(isset($this->current)){
  3044. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  3045. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  3046. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  3047. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  3048. $res = api_sql_query($sql,__FILE__,__LINE__);
  3049. }
  3050. //save progress
  3051. list($progress,$text) = $this->get_progress_bar_text('%');
  3052. if($progress>=0 AND $progress<=100){
  3053. $progress= (int)$progress;
  3054. $sql = "UPDATE $table SET progress = $progress " .
  3055. "WHERE lp_id = ".$this->get_id()." AND " .
  3056. "user_id = ".$this->get_user_id();
  3057. $res = api_sql_query($sql,__FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  3058. $this->progress_db = $progress;
  3059. }
  3060. }
  3061. /**
  3062. * Sets the current item ID (checks if valid and authorized first)
  3063. * @param integer New item ID. If not given or not authorized, defaults to current
  3064. */
  3065. function set_current_item($item_id=null)
  3066. {
  3067. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  3068. if(empty($item_id)){
  3069. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  3070. //do nothing
  3071. }else{
  3072. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  3073. $item_id = $this->escape_string($item_id);
  3074. //TODO check in database here
  3075. $this->last = $this->current;
  3076. $this->current = $item_id;
  3077. //TODO update $this->index as well
  3078. foreach($this->ordered_items as $index => $item)
  3079. {
  3080. if($item == $this->current)
  3081. {
  3082. $this->index = $index;
  3083. break;
  3084. }
  3085. }
  3086. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  3087. }
  3088. }
  3089. /**
  3090. * Sets the encoding
  3091. * @param string New encoding
  3092. */
  3093. function set_encoding($enc='ISO-8859-1'){
  3094. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  3095. $enc = strtoupper($enc);
  3096. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','cp1251','cp1252','KOI8-R','BIG5','GB2312','Shift_JIS','EUC-JP','');
  3097. if(in_array($enc,$encodings)){
  3098. $lp = $this->get_id();
  3099. if($lp!=0){
  3100. $tbl_lp = Database::get_course_table('lp');
  3101. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  3102. $res = api_sql_query($sql, __FILE__, __LINE__);
  3103. return $res;
  3104. }
  3105. }
  3106. return false;
  3107. }
  3108. /**
  3109. * Sets the JS lib setting in the database directly.
  3110. * This is the JavaScript library file this lp needs to load on startup
  3111. * @param string Proximity setting
  3112. */
  3113. function set_jslib($lib=''){
  3114. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  3115. $lp = $this->get_id();
  3116. if($lp!=0){
  3117. $tbl_lp = Database::get_course_table('lp');
  3118. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  3119. $res = api_sql_query($sql, __FILE__, __LINE__);
  3120. return $res;
  3121. }else{
  3122. return false;
  3123. }
  3124. }
  3125. /**
  3126. * Sets the name of the LP maker (publisher) (and save)
  3127. * @param string Optional string giving the new content_maker of this learnpath
  3128. */
  3129. function set_maker($name=''){
  3130. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  3131. if(empty($name))return false;
  3132. $this->maker = $this->escape_string($name);
  3133. $lp_table = Database::get_course_table('lp');
  3134. $lp_id = $this->get_id();
  3135. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  3136. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  3137. //$res = Database::query($sql);
  3138. $res = api_sql_query($sql, __FILE__, __LINE__);
  3139. return true;
  3140. }
  3141. /**
  3142. * Sets the name of the current learnpath (and save)
  3143. * @param string Optional string giving the new name of this learnpath
  3144. */
  3145. function set_name($name=''){
  3146. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  3147. if(empty($name))return false;
  3148. $this->name = $this->escape_string($name);
  3149. $lp_table = Database::get_course_table('lp');
  3150. $lp_id = $this->get_id();
  3151. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  3152. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  3153. //$res = Database::query($sql);
  3154. $res = api_sql_query($sql, __FILE__, __LINE__);
  3155. // if the lp is visible on the homepage, change his name there
  3156. if(mysql_affected_rows())
  3157. {
  3158. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3159. $sql = 'UPDATE '.$table.' SET
  3160. name = "'.$this->name.'"
  3161. WHERE link = "newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'"';
  3162. api_sql_query($sql, __FILE__, __LINE__);
  3163. }
  3164. return true;
  3165. }
  3166. /**
  3167. * Set index terms for all items in this path
  3168. * @param string Comma-separated list of terms
  3169. * @return boolean False on error, true otherwise
  3170. */
  3171. function set_terms($terms) {
  3172. if ( empty($terms) ) return false;
  3173. if ( trim($terms) == trim($this->get_common_index_terms()) ) return false; //indexing is costly, don't re-index if no change
  3174. foreach ( $this->items as $item ) {
  3175. $item->set_terms($terms);
  3176. }
  3177. return true;
  3178. }
  3179. /**
  3180. * Sets the theme of the LP (local/remote) (and save)
  3181. * @param string Optional string giving the new theme of this learnpath
  3182. * @return bool returns true if theme name is not empty
  3183. */
  3184. function set_theme($name=''){
  3185. if($this->debug>0){error_log('New LP - In learnpath::set_theme()',0);}
  3186. $this->theme = $this->escape_string($name);
  3187. $lp_table = Database::get_course_table('lp');
  3188. $lp_id = $this->get_id();
  3189. $sql = "UPDATE $lp_table SET theme = '".$this->theme."' WHERE id = '$lp_id'";
  3190. if($this->debug>2){error_log('New LP - lp updated with new theme : '.$this->theme,0);}
  3191. //$res = Database::query($sql);
  3192. $res = api_sql_query($sql, __FILE__, __LINE__);
  3193. return true;
  3194. }
  3195. /**
  3196. * Sets the image of an LP (and save)
  3197. * @param string Optional string giving the new image of this learnpath
  3198. * @return bool returns true if theme name is not empty
  3199. */
  3200. function set_preview_image($name=''){
  3201. if($this->debug>0){error_log('New LP - In learnpath::set_preview_image()',0);}
  3202. $this->preview_image = $this->escape_string($name);
  3203. $lp_table = Database::get_course_table('lp');
  3204. $lp_id = $this->get_id();
  3205. $sql = "UPDATE $lp_table SET preview_image = '".$this->preview_image."' WHERE id = '$lp_id'";
  3206. if($this->debug>2){error_log('New LP - lp updated with new preview image : '.$this->preview_image,0);}
  3207. $res = api_sql_query($sql, __FILE__, __LINE__);
  3208. return true;
  3209. }
  3210. /**
  3211. * Sets the author of a LP (and save)
  3212. * @param string Optional string giving the new author of this learnpath
  3213. * @return bool returns true if author's name is not empty
  3214. */
  3215. function set_author($name=''){
  3216. if($this->debug>0){error_log('New LP - In learnpath::set_author()',0);}
  3217. $this->author = $this->escape_string($name);
  3218. $lp_table = Database::get_course_table('lp');
  3219. $lp_id = $this->get_id();
  3220. $sql = "UPDATE $lp_table SET author = '".$this->author."' WHERE id = '$lp_id'";
  3221. if($this->debug>2){error_log('New LP - lp updated with new preview author : '.$this->author,0);}
  3222. $res = api_sql_query($sql, __FILE__, __LINE__);
  3223. return true;
  3224. }
  3225. /**
  3226. * Sets the location/proximity of the LP (local/remote) (and save)
  3227. * @param string Optional string giving the new location of this learnpath
  3228. */
  3229. function set_proximity($name=''){
  3230. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  3231. if(empty($name))return false;
  3232. $this->proximity = $this->escape_string($name);
  3233. $lp_table = Database::get_course_table('lp');
  3234. $lp_id = $this->get_id();
  3235. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  3236. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  3237. //$res = Database::query($sql);
  3238. $res = api_sql_query($sql, __FILE__, __LINE__);
  3239. return true;
  3240. }
  3241. /**
  3242. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3243. * @param integer DB ID of the item
  3244. */
  3245. function set_previous_item($id)
  3246. {
  3247. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  3248. $this->last = $id;
  3249. }
  3250. /**
  3251. * Sets the object's error message
  3252. * @param string Error message. If empty, reinits the error string
  3253. * @return void
  3254. */
  3255. function set_error_msg($error='')
  3256. {
  3257. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  3258. if(empty($error)){
  3259. $this->error = '';
  3260. }else{
  3261. $this->error .= $error;
  3262. }
  3263. }
  3264. /**
  3265. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3266. *
  3267. */
  3268. function start_current_item($allow_new_attempt=false){
  3269. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  3270. if($this->current != 0 AND
  3271. is_object($this->items[$this->current]))
  3272. {
  3273. $type = $this->get_type();
  3274. $item_type = $this->items[$this->current]->get_type();
  3275. if(
  3276. ($type == 2 && $item_type!='sco')
  3277. OR
  3278. ($type == 3 && $item_type!='au')
  3279. OR
  3280. ($type == 1 && $item_type!=TOOL_QUIZ && $item_type!=TOOL_HOTPOTATOES)
  3281. )
  3282. {
  3283. $this->items[$this->current]->open($allow_new_attempt);
  3284. $this->autocomplete_parents($this->current);
  3285. $prereq_check = $this->prerequisites_match($this->current);
  3286. $this->items[$this->current]->save(false,$prereq_check);
  3287. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3288. }else{
  3289. //if sco, then it is supposed to have been updated by some other call
  3290. }
  3291. }
  3292. if($this->debug>0){error_log('New LP - End of learnpath::start_current_item()',0);}
  3293. return true;
  3294. }
  3295. /**
  3296. * Stops the processing and counters for the old item (as held in $this->last)
  3297. * @param
  3298. */
  3299. function stop_previous_item(){
  3300. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  3301. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  3302. {
  3303. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  3304. switch($this->get_type()){
  3305. case '3':
  3306. if($this->items[$this->last]->get_type()!='au')
  3307. {
  3308. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  3309. $this->items[$this->last]->close();
  3310. //$this->autocomplete_parents($this->last);
  3311. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3312. }else{
  3313. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  3314. }
  3315. case '2':
  3316. if($this->items[$this->last]->get_type()!='sco')
  3317. {
  3318. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  3319. $this->items[$this->last]->close();
  3320. //$this->autocomplete_parents($this->last);
  3321. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3322. }else{
  3323. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  3324. }
  3325. break;
  3326. case '1':
  3327. default:
  3328. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  3329. $this->items[$this->last]->close();
  3330. break;
  3331. }
  3332. }else{
  3333. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  3334. return false;
  3335. }
  3336. return true;
  3337. }
  3338. /**
  3339. * Updates the default view mode from fullscreen to embedded and inversely
  3340. * @return string The current default view mode ('fullscreen' or 'embedded')
  3341. */
  3342. function update_default_view_mode()
  3343. {
  3344. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  3345. $lp_table = Database::get_course_table('lp');
  3346. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3347. $res = api_sql_query($sql, __FILE__, __LINE__);
  3348. if(Database::num_rows($res)>0){
  3349. $row = Database::fetch_array($res);
  3350. $view_mode = $row['default_view_mod'];
  3351. if($view_mode == 'fullscreen'){
  3352. $view_mode = 'embedded';
  3353. }elseif($view_mode == 'embedded'){
  3354. $view_mode = 'fullscreen';
  3355. }
  3356. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  3357. $res = api_sql_query($sql, __FILE__, __LINE__);
  3358. $this->mode = $view_mode;
  3359. return $view_mode;
  3360. }else{
  3361. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  3362. }
  3363. return -1;
  3364. }
  3365. /**
  3366. * Updates the default behaviour about auto-commiting SCORM updates
  3367. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3368. */
  3369. function update_default_scorm_commit(){
  3370. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  3371. $lp_table = Database::get_course_table('lp');
  3372. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3373. $res = api_sql_query($sql, __FILE__, __LINE__);
  3374. if(Database::num_rows($res)>0){
  3375. $row = Database::fetch_array($res);
  3376. $force = $row['force_commit'];
  3377. if($force == 1){
  3378. $force = 0;
  3379. $force_return = false;
  3380. }elseif($force == 0){
  3381. $force = 1;
  3382. $force_return = true;
  3383. }
  3384. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  3385. $res = api_sql_query($sql, __FILE__, __LINE__);
  3386. $this->force_commit = $force_return;
  3387. return $force_return;
  3388. }else{
  3389. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  3390. }
  3391. return -1;
  3392. }
  3393. /**
  3394. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3395. * @return bool True on success, false on failure
  3396. */
  3397. function update_display_order()
  3398. {
  3399. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  3400. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3401. $res = api_sql_query($sql, __FILE__, __LINE__);
  3402. if($res === false) return false;
  3403. $lps = array();
  3404. $lp_order = array();
  3405. $num = Database::num_rows($res);
  3406. //first check the order is correct, globally (might be wrong because
  3407. //of versions < 1.8.4)
  3408. if($num>0)
  3409. {
  3410. $i = 1;
  3411. while($row = Database::fetch_array($res))
  3412. {
  3413. if($row['display_order'] != $i)
  3414. { //if we find a gap in the order, we need to fix it
  3415. $need_fix = true;
  3416. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  3417. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  3418. }
  3419. $i++;
  3420. }
  3421. }
  3422. return true;
  3423. }
  3424. /**
  3425. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3426. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3427. */
  3428. function update_reinit(){
  3429. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  3430. $lp_table = Database::get_course_table('lp');
  3431. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3432. $res = api_sql_query($sql, __FILE__, __LINE__);
  3433. if(Database::num_rows($res)>0){
  3434. $row = Database::fetch_array($res);
  3435. $force = $row['prevent_reinit'];
  3436. if($force == 1){
  3437. $force = 0;
  3438. }elseif($force == 0){
  3439. $force = 1;
  3440. }
  3441. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  3442. $res = api_sql_query($sql,__FILE__,__LINE__);
  3443. $this->prevent_reinit = $force;
  3444. return $force;
  3445. }else{
  3446. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  3447. }
  3448. return -1;
  3449. }
  3450. /**
  3451. * Updates the "scorm_debug" value that shows or hide the debug window
  3452. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3453. */
  3454. function update_scorm_debug(){
  3455. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  3456. $lp_table = Database::get_course_table('lp');
  3457. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3458. $res = api_sql_query($sql, __FILE__, __LINE__);
  3459. if(Database::num_rows($res)>0){
  3460. $row = Database::fetch_array($res);
  3461. $force = $row['debug'];
  3462. if($force == 1){
  3463. $force = 0;
  3464. }elseif($force == 0){
  3465. $force = 1;
  3466. }
  3467. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  3468. $res = api_sql_query($sql,__FILE__,__LINE__);
  3469. $this->scorm_debug = $force;
  3470. return $force;
  3471. }else{
  3472. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  3473. }
  3474. return -1;
  3475. }
  3476. /**
  3477. * Function that makes a call to the function sort_tree_array and create_tree_array
  3478. *
  3479. * @author Kevin Van Den Haute
  3480. *
  3481. * @param unknown_type $array
  3482. */
  3483. function tree_array($array)
  3484. {
  3485. $array = $this->sort_tree_array($array);
  3486. $this->create_tree_array($array);
  3487. }
  3488. /**
  3489. * Creates an array with the elements of the learning path tree in it
  3490. *
  3491. * @author Kevin Van Den Haute
  3492. *
  3493. * @param array $array
  3494. * @param int $parent
  3495. * @param int $depth
  3496. * @param array $tmp
  3497. */
  3498. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  3499. {
  3500. if(is_array($array))
  3501. {
  3502. for($i = 0; $i < count($array); $i++)
  3503. {
  3504. if($array[$i]['parent_item_id'] == $parent)
  3505. {
  3506. if(!in_array($array[$i]['parent_item_id'], $tmp))
  3507. {
  3508. $tmp[] = $array[$i]['parent_item_id'];
  3509. $depth++;
  3510. }
  3511. $preq = (empty($array[$i]['prerequisite'])?'':$array[$i]['prerequisite']);
  3512. $this->arrMenu[] = array(
  3513. 'id' => $array[$i]['id'],
  3514. 'item_type' => $array[$i]['item_type'],
  3515. 'title' => $array[$i]['title'],
  3516. 'path' => $array[$i]['path'],
  3517. 'description' => $array[$i]['description'],
  3518. 'parent_item_id' => $array[$i]['parent_item_id'],
  3519. 'previous_item_id' => $array[$i]['previous_item_id'],
  3520. 'next_item_id' => $array[$i]['next_item_id'],
  3521. 'min_score' => $array[$i]['min_score'],
  3522. 'max_score' => $array[$i]['max_score'],
  3523. 'mastery_score' => $array[$i]['mastery_score'],
  3524. 'display_order' => $array[$i]['display_order'],
  3525. 'prerequisite' => $preq,
  3526. 'depth' => $depth,
  3527. 'audio' => $array[$i]['audio']
  3528. );
  3529. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3530. }
  3531. }
  3532. }
  3533. }
  3534. /**
  3535. * Sorts a multi dimensional array by parent id and display order
  3536. * @author Kevin Van Den Haute
  3537. *
  3538. * @param array $array (array with al the learning path items in it)
  3539. *
  3540. * @return array
  3541. */
  3542. function sort_tree_array($array)
  3543. {
  3544. foreach($array as $key => $row)
  3545. {
  3546. $parent[$key] = $row['parent_item_id'];
  3547. $position[$key] = $row['display_order'];
  3548. }
  3549. if(count($array) > 0)
  3550. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3551. return $array;
  3552. }
  3553. /**
  3554. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3555. * Also the actions for the modules, chapters and documents are in this table.
  3556. *
  3557. * @author Kevin Van Den Haute
  3558. *
  3559. * @param int $lp_id
  3560. *
  3561. * @return string
  3562. */
  3563. function overview()
  3564. {
  3565. global $charset, $_course;
  3566. $return = '';
  3567. $tbl_lp_item = Database::get_course_table('lp_item');
  3568. $sql = "
  3569. SELECT *
  3570. FROM " . $tbl_lp_item . "
  3571. WHERE
  3572. lp_id = " . $this->lp_id;
  3573. $result = api_sql_query($sql, __FILE__, __LINE__);
  3574. $arrLP = array();
  3575. $mycharset=api_get_setting('platform_charset');
  3576. while($row = Database::fetch_array($result))
  3577. {
  3578. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3579. $arrLP[] = array(
  3580. 'id' => $row['id'],
  3581. 'item_type' => $row['item_type'],
  3582. 'title' => $row['title'],
  3583. 'description' => $row['description'],
  3584. 'parent_item_id' => $row['parent_item_id'],
  3585. 'previous_item_id' => $row['previous_item_id'],
  3586. 'next_item_id' => $row['next_item_id'],
  3587. 'max_score' => $row['max_score'],
  3588. 'min_score' => $row['min_score'],
  3589. 'mastery_score' => $row['mastery_score'],
  3590. 'prerequisite' => $row['prerequisite'],
  3591. 'display_order' => $row['display_order'],
  3592. 'audio' => $row['audio']
  3593. );
  3594. }
  3595. $this->tree_array($arrLP);
  3596. $arrLP = $this->arrMenu;
  3597. unset($this->arrMenu);
  3598. if(api_is_allowed_to_edit())
  3599. {
  3600. $return .= '<div class="actions">';
  3601. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">'.Display::return_icon('learnpath_build.gif').' '.get_lang('Advanced').'</a>';
  3602. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=admin_overview&amp;lp_id=' . $this->lp_id . '">'.Display::return_icon('learnpath_organize.gif').' '.get_lang('BasicOverview').'</a>';
  3603. $return .= '<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$this->lp_id.'">'.Display::return_icon('learnpath_view.gif').' '.get_lang("Display").'</a>';
  3604. $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').'</a>';
  3605. $return .= '</div>';
  3606. }
  3607. // we need to start a form when we want to update all the mp3 files
  3608. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0)
  3609. {
  3610. $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">';
  3611. $return .= Display::display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  3612. }
  3613. $return .= '<table class="data_table">' . "\n";
  3614. $return .= "\t" . '<tr>' . "\n";
  3615. $return .= "\t" . '<th width="75%">'.get_lang("Title").'</th>' . "\n";
  3616. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3617. $return .= "\t" . '<th>'.get_lang("Audio").'</th>' . "\n";
  3618. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3619. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3620. $return .= "\t" . '</tr>' . "\n";
  3621. for($i = 0; $i < count($arrLP); $i++)
  3622. {
  3623. $title=$arrLP[$i]['title'];
  3624. if($arrLP[$i]['description'] == '')
  3625. $arrLP[$i]['description'] = '&nbsp;';
  3626. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3627. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3628. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3629. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3630. // The audio column
  3631. $return .= "\t\t" . '<td>';
  3632. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true')
  3633. {
  3634. if (!empty($arrLP[$i]['audio']))
  3635. {
  3636. $return .= '<span id="container'.$i.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  3637. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  3638. $return .= '<script type="text/javascript">
  3639. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  3640. s1.addParam("allowscriptaccess","always");
  3641. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$arrLP[$i]['audio'].'&image=preview.jpg");
  3642. s1.write("container'.$i.'");
  3643. </script>';
  3644. }
  3645. else
  3646. {
  3647. $return .= ' - ';
  3648. }
  3649. }
  3650. else
  3651. {
  3652. $return .= ' <input type="file" name="mp3file'.$arrLP[$i]['id'].'" id="mp3file" />';
  3653. if (!empty($arrLP[$i]['audio']))
  3654. {
  3655. $return .= '<input type="checkbox" name="removemp3'.$arrLP[$i]['id'].'" id="checkbox'.$arrLP[$i]['id'].'" />'.get_lang('RemoveAudio');
  3656. }
  3657. }
  3658. $return .= '</td>' . "\n";
  3659. if(api_is_allowed_to_edit())
  3660. {
  3661. $return .= "\t\t" . '<td>' . "\n";
  3662. if($arrLP[$i]['previous_item_id'] != 0)
  3663. {
  3664. $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 . '">';
  3665. $return .= '<img alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3666. $return .= '</a>' . "\n";
  3667. }
  3668. else
  3669. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3670. if($arrLP[$i]['next_item_id'] != 0)
  3671. {
  3672. $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 . '">';
  3673. $return .= '<img src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
  3674. $return .= '</a>' . "\n";
  3675. }
  3676. else
  3677. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3678. $return .= "\t\t" . '</td>' . "\n";
  3679. $return .= "\t\t" . '<td>' . "\n";
  3680. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3681. {
  3682. $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 . '">';
  3683. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3684. $return .= '</a>' . "\n";
  3685. }
  3686. else
  3687. {
  3688. $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 . '">';
  3689. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3690. $return .= '</a>' . "\n";
  3691. }
  3692. $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). '\');">';
  3693. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3694. $return .= '</a>' . "\n";
  3695. $return .= "\t\t" . '</td>' . "\n";
  3696. }
  3697. $return .= "\t" . '</tr>' . "\n";
  3698. }
  3699. if(count($arrLP) == 0)
  3700. {
  3701. $return .= "\t" . '<tr>' . "\n";
  3702. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3703. $return .= "\t" . '</tr>' . "\n";
  3704. }
  3705. // we need to close the form when we are updating the mp3 files
  3706. if ($_GET['updateaudio'] == 'true')
  3707. {
  3708. $return .= '<tr><th></th><th><input type="submit" name="save_audio" id="save_audio" value="'.get_lang('SaveAudio').'" /></th><th></th><th></th></tr>';
  3709. }
  3710. $return .= '</table>' . "\n";
  3711. // we need to close the form when we are updating the mp3 files
  3712. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0)
  3713. {
  3714. $return .= '</form>';
  3715. }
  3716. return $return;
  3717. }
  3718. /**
  3719. * This functions builds the LP tree based on data from the database.
  3720. *
  3721. * @return string
  3722. * @uses dtree.js :: necessary javascript for building this tree
  3723. */
  3724. function build_tree()
  3725. {
  3726. $return = "<script type=\"text/javascript\">\n";
  3727. $return .= "\tm = new dTree('m');\n\n";
  3728. $return .= "\tm.config.folderLinks = true;\n";
  3729. $return .= "\tm.config.useCookies = true;\n";
  3730. $return .= "\tm.config.useIcons = true;\n";
  3731. $return .= "\tm.config.useLines = true;\n";
  3732. $return .= "\tm.config.useSelection = true;\n";
  3733. $return .= "\tm.config.useStatustext = false;\n\n";
  3734. $menu = 0;
  3735. $parent = '';
  3736. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3737. $tbl_lp_item = Database::get_course_table('lp_item');
  3738. $sql = "
  3739. SELECT *
  3740. FROM " . $tbl_lp_item . "
  3741. WHERE
  3742. lp_id = " . $this->lp_id;
  3743. $result = api_sql_query($sql, __FILE__, __LINE__);
  3744. $arrLP = array();
  3745. $mycharset=api_get_setting('platform_charset');
  3746. while($row = Database::fetch_array($result))
  3747. {
  3748. if($this->encoding!=$mycharset)
  3749. {
  3750. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3751. }
  3752. $arrLP[] = array(
  3753. 'id' => $row['id'],
  3754. 'item_type' => $row['item_type'],
  3755. 'title' => $row['title'],
  3756. 'path' => $row['path'],
  3757. 'description' => $row['description'],
  3758. 'parent_item_id' => $row['parent_item_id'],
  3759. 'previous_item_id' => $row['previous_item_id'],
  3760. 'next_item_id' => $row['next_item_id'],
  3761. 'max_score' => $row['max_score'],
  3762. 'min_score' => $row['min_score'],
  3763. 'mastery_score' => $row['mastery_score'],
  3764. 'display_order' => $row['display_order']);
  3765. }
  3766. $this->tree_array($arrLP);
  3767. $arrLP = $this->arrMenu;
  3768. unset($this->arrMenu);
  3769. $title='';
  3770. for($i = 0; $i < count($arrLP); $i++)
  3771. {
  3772. $title = addslashes($arrLP[$i]['title']);
  3773. $menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3774. if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".png"))
  3775. {
  3776. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".png', '../img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
  3777. }
  3778. else if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".gif"))
  3779. {
  3780. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif');\n";
  3781. }
  3782. else
  3783. {
  3784. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3785. }
  3786. if($menu < $arrLP[$i]['id'])
  3787. $menu = $arrLP[$i]['id'];
  3788. }
  3789. $return .= "\n\tdocument.write(m);\n";
  3790. $return .= "\t if(!m.selectedNode) m.s(1);";
  3791. $return .= "</script>\n";
  3792. return $return;
  3793. }
  3794. /**
  3795. * Create a new document //still needs some finetuning
  3796. *
  3797. * @param array $_course
  3798. * @return string
  3799. */
  3800. function create_document($_course)
  3801. {
  3802. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3803. if(strstr($dir, '..'))
  3804. $dir = '/';
  3805. if($dir[0] == '.')
  3806. $dir = substr($dir, 1);
  3807. if($dir[0] != '/')
  3808. $dir = '/'.$dir;
  3809. if($dir[strlen($dir) - 1] != '/')
  3810. $dir .= '/';
  3811. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3812. if(!is_dir($filepath))
  3813. {
  3814. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3815. $dir = '/';
  3816. }
  3817. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  3818. //is already escaped twice when it gets here
  3819. $title = replace_dangerous_char(stripslashes($_POST['title']));
  3820. $title = disable_dangerous_file($title);
  3821. $title = replace_accents($title);
  3822. $filename = $title;
  3823. $content = $_POST['content_lp'];
  3824. $tmp_filename = $filename;
  3825. $i=0;
  3826. while(file_exists($filepath . $tmp_filename . '.html'))
  3827. $tmp_filename = $filename . '_' . ++$i;
  3828. $filename = $tmp_filename . '.html';
  3829. $content = stripslashes(text_filter($content));
  3830. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH).'courses/', $content);
  3831. // change the path of mp3 to absolute
  3832. // first regexp deals with ../../../ urls
  3833. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  3834. //second regexp deals with audio/ urls
  3835. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  3836. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  3837. $content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
  3838. if(!file_exists($filepath . $filename))
  3839. {
  3840. if($fp = @fopen($filepath . $filename, 'w'))
  3841. {
  3842. fputs($fp, $content);
  3843. fclose($fp);
  3844. $file_size = filesize($filepath . $filename);
  3845. $save_file_path = $dir . $filename;
  3846. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  3847. if($document_id)
  3848. {
  3849. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  3850. //update parent folders
  3851. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  3852. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  3853. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  3854. if($new_comment || $new_title)
  3855. {
  3856. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3857. $ct = '';
  3858. if($new_comment)
  3859. $ct .= ", comment='" . $new_comment . "'";
  3860. if($new_title)
  3861. $ct .= ", title='" . $new_title . ".html '";
  3862. $sql_update = "
  3863. UPDATE " . $tbl_doc . "
  3864. SET " . substr($ct, 1) . "
  3865. WHERE id = " . $document_id;
  3866. api_sql_query($sql_update, __FILE__, __LINE__);
  3867. }
  3868. }
  3869. return $document_id;
  3870. }
  3871. }
  3872. }
  3873. /**
  3874. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  3875. *
  3876. * @param array $_course array
  3877. * @return void
  3878. */
  3879. function edit_document($_course)
  3880. {
  3881. global $_configuration;
  3882. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3883. if(strstr($dir, '..'))
  3884. $dir = '/';
  3885. if($dir[0] == '.')
  3886. $dir = substr($dir, 1);
  3887. if($dir[0] != '/')
  3888. $dir = '/'.$dir;
  3889. if($dir[strlen($dir) - 1] != '/')
  3890. $dir .= '/';
  3891. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  3892. if(!is_dir($filepath))
  3893. {
  3894. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3895. $dir = '/';
  3896. }
  3897. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  3898. $sql = "
  3899. SELECT path
  3900. FROM " . $table_doc . "
  3901. WHERE id = " . $_POST['path'];
  3902. $res = api_sql_query($sql, __FILE__, __LINE__);
  3903. $row = Database::fetch_array($res);
  3904. $content = stripslashes($_POST['content_lp']);
  3905. $file = $filepath . $row['path'];
  3906. if($fp = @fopen($file, 'w'))
  3907. {
  3908. $content = text_filter($content);
  3909. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  3910. // change the path of mp3 to absolute
  3911. // first regexp deals with ../../../ urls
  3912. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  3913. //second regexp deals with audio/ urls
  3914. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  3915. fputs($fp, $content);
  3916. fclose($fp);
  3917. }
  3918. }
  3919. /**
  3920. * Displays the selected item, with a panel for manipulating the item
  3921. *
  3922. * @param int $item_id
  3923. * @param string $msg
  3924. * @return string
  3925. */
  3926. function display_item($item_id, $iframe = true, $msg = '')
  3927. {
  3928. global $_course; //will disappear
  3929. $return = '';
  3930. if(is_numeric($item_id))
  3931. {
  3932. $tbl_lp_item = Database::get_course_table('lp_item');
  3933. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3934. $sql = "
  3935. SELECT
  3936. lp.*
  3937. FROM " . $tbl_lp_item . " as lp
  3938. WHERE
  3939. lp.id = " . $item_id;
  3940. $result = api_sql_query($sql, __FILE__, __LINE__);
  3941. while($row = Database::fetch_array($result))
  3942. {
  3943. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3944. $return .= '<div style="padding:10px;">';
  3945. if($msg != '')
  3946. $return .= $msg;
  3947. if($this->encoding=='UTF-8')
  3948. {
  3949. $row['title'] = utf8_decode($row['title']);
  3950. }
  3951. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  3952. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  3953. //$return .= '<hr />';
  3954. if($row['item_type'] == TOOL_DOCUMENT)
  3955. {
  3956. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  3957. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  3958. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  3959. $path_file=Database::result($result,0,0);
  3960. $path_parts = pathinfo($path_file);
  3961. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  3962. {
  3963. $return .= $this->display_document($row['path'], true, true);
  3964. }
  3965. }
  3966. $return .= '</div>';
  3967. }
  3968. }
  3969. return $return;
  3970. }
  3971. /**
  3972. * Shows the needed forms for editing a specific item
  3973. *
  3974. * @param int $item_id
  3975. * @return string
  3976. */
  3977. function display_edit_item($item_id)
  3978. {
  3979. global $_course; //will disappear
  3980. $return = '';
  3981. if(is_numeric($item_id))
  3982. {
  3983. $tbl_lp_item = Database::get_course_table('lp_item');
  3984. $sql = "
  3985. SELECT *
  3986. FROM " . $tbl_lp_item . "
  3987. WHERE id = " . $item_id;
  3988. $res = api_sql_query($sql, __FILE__, __LINE__);
  3989. $row = Database::fetch_array($res);
  3990. switch($row['item_type'])
  3991. {
  3992. case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
  3993. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3994. {
  3995. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3996. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  3997. }
  3998. else
  3999. {
  4000. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  4001. }
  4002. break;
  4003. case TOOL_DOCUMENT:
  4004. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4005. $sql_step = "
  4006. SELECT
  4007. lp.*,
  4008. doc.path as dir
  4009. FROM " . $tbl_lp_item . " as lp
  4010. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4011. WHERE
  4012. lp.id = " . $item_id;
  4013. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  4014. $row_step = Database::fetch_array($res_step);
  4015. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4016. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4017. break;
  4018. case TOOL_LINK:
  4019. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4020. $return .= $this->display_link_form('edit', $item_id, $row);
  4021. break;
  4022. case 'dokeos_module':
  4023. if(isset($_GET['view']) && $_GET['view'] == 'build')
  4024. {
  4025. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4026. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  4027. }
  4028. else
  4029. {
  4030. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  4031. }
  4032. break;
  4033. case TOOL_QUIZ:
  4034. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4035. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4036. break;
  4037. case TOOL_HOTPOTATOES:
  4038. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4039. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4040. break;
  4041. case TOOL_STUDENTPUBLICATION:
  4042. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4043. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4044. break;
  4045. case TOOL_FORUM:
  4046. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4047. $return .= $this->display_forum_form('edit', $item_id, $row);
  4048. break;
  4049. case TOOL_THREAD:
  4050. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4051. $return .= $this->display_thread_form('edit', $item_id, $row);
  4052. break;
  4053. }
  4054. }
  4055. return $return;
  4056. }
  4057. /**
  4058. * Function that displays a list with al the resources that could be added to the learning path
  4059. *
  4060. * @return string
  4061. */
  4062. function display_resources()
  4063. {
  4064. global $_course; //TODO: don't use globals
  4065. $return .= '<div class="sectiontitle">'.get_lang('CreateNewStep').'</div>';
  4066. $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 . '">'.get_lang("NewDocument").'</a></div>';
  4067. $return .= '<div class="sectiontitle">'.get_lang('UseAnExistingResource').'</div>';
  4068. $return .= '<div class="sectioncomment">';
  4069. /* get all the docs */
  4070. $return .= $this->get_documents();
  4071. /* get all the exercises */
  4072. $return .= $this->get_exercises();
  4073. /* get all the links */
  4074. $return .= $this->get_links();
  4075. /* get al the student publications */
  4076. $return .= $this->get_student_publications();
  4077. /* get al the forums */
  4078. $return .= $this->get_forums();
  4079. $return .= '</div>';
  4080. return $return;
  4081. }
  4082. /**
  4083. * Returns the extension of a document
  4084. *
  4085. * @param unknown_type $filename
  4086. * @return unknown
  4087. */
  4088. function get_extension($filename)
  4089. {
  4090. $explode = explode('.', $filename);
  4091. return $explode[count($explode) - 1];
  4092. }
  4093. /**
  4094. * Displays a document by id
  4095. *
  4096. * @param unknown_type $id
  4097. * @return unknown
  4098. */
  4099. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  4100. {
  4101. global $_course; //temporary
  4102. $return = '';
  4103. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4104. $sql_doc = "
  4105. SELECT *
  4106. FROM " . $tbl_doc . "
  4107. WHERE id = " . $id;
  4108. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  4109. $row_doc = Database::fetch_array($res_doc);
  4110. //if($show_title)
  4111. //$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>';
  4112. //TODO: add a path filter
  4113. if($iframe){
  4114. $return .= '<iframe id="learnpath_preview_frame" frameborder="0" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F','/',urlencode($row_doc['path'])) . '?'.api_get_cidreq().'"></iframe>';
  4115. }
  4116. else{
  4117. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4118. }
  4119. return $return;
  4120. }
  4121. /**
  4122. * Return HTML form to add/edit a quiz
  4123. *
  4124. * @param string Action (add/edit)
  4125. * @param integer Item ID if already exists
  4126. * @param mixed Extra information (quiz ID if integer)
  4127. * @return string HTML form
  4128. */
  4129. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  4130. {
  4131. global $charset;
  4132. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  4133. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  4134. if($id != 0 && is_array($extra_info))
  4135. {
  4136. $item_title = stripslashes($extra_info['title']);
  4137. $item_description = stripslashes($extra_info['description']);
  4138. }
  4139. elseif(is_numeric($extra_info))
  4140. {
  4141. $sql_quiz = "
  4142. SELECT
  4143. title,
  4144. description
  4145. FROM " . $tbl_quiz . "
  4146. WHERE id = " . $extra_info;
  4147. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  4148. $row = Database::fetch_array($result);
  4149. $item_title = $row['title'];
  4150. $item_description = $row['description'];
  4151. }
  4152. else
  4153. {
  4154. $item_title = '';
  4155. $item_description = '';
  4156. }
  4157. $item_title = mb_convert_encoding($item_title,$charset,$this->encoding);
  4158. $return = '<div class="sectiontitle">';
  4159. if($id != 0 && is_array($extra_info))
  4160. $parent = $extra_info['parent_item_id'];
  4161. else
  4162. $parent = 0;
  4163. $sql = "
  4164. SELECT *
  4165. FROM " . $tbl_lp_item . "
  4166. WHERE
  4167. lp_id = " . $this->lp_id;
  4168. $result = api_sql_query($sql, __FILE__, __LINE__);
  4169. $arrLP = array();
  4170. while($row = Database::fetch_array($result))
  4171. {
  4172. $arrLP[] = array(
  4173. 'id' => $row['id'],
  4174. 'item_type' => $row['item_type'],
  4175. 'title' => $row['title'],
  4176. 'path' => $row['path'],
  4177. 'description' => $row['description'],
  4178. 'parent_item_id' => $row['parent_item_id'],
  4179. 'previous_item_id' => $row['previous_item_id'],
  4180. 'next_item_id' => $row['next_item_id'],
  4181. 'display_order' => $row['display_order'],
  4182. 'max_score' => $row['max_score'],
  4183. 'min_score' => $row['min_score'],
  4184. 'mastery_score' => $row['mastery_score'],
  4185. 'prerequisite' => $row['prerequisite']);
  4186. }
  4187. $this->tree_array($arrLP);
  4188. $arrLP = $this->arrMenu;
  4189. unset($this->arrMenu);
  4190. if($action == 'add')
  4191. $return .= get_lang("CreateTheExercise").'&nbsp;:' . "\n";
  4192. elseif($action == 'move')
  4193. $return .= get_lang("MoveTheCurrentExercise").'&nbsp;:' . "\n";
  4194. else
  4195. $return .= get_lang("EditCurrentExecice").'&nbsp;:' . "\n";
  4196. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4197. {
  4198. $return .= '<div class="warning-message">';
  4199. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4200. $return .= get_lang("WarningEditingDocument");
  4201. $return .= '</div>';
  4202. }
  4203. $return .= '</div>';
  4204. $return .= '<div class="sectioncomment">';
  4205. $return .= '<form method="POST">' . "\n";
  4206. $return .= "\t" . '<table>' . "\n";
  4207. if($action != 'move')
  4208. {
  4209. $return .= "\t\t" . '<tr>' . "\n";
  4210. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").'&nbsp;:</label></td>' . "\n";
  4211. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
  4212. $return .= "\t\t" . '</tr>' . "\n";
  4213. }
  4214. $return .= "\t\t" . '<tr>' . "\n";
  4215. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").'&nbsp;:</label></td>' . "\n";
  4216. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4217. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4218. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4219. $arrHide = array($id);
  4220. for($i = 0; $i < count($arrLP); $i++)
  4221. {
  4222. if($action != 'add')
  4223. {
  4224. 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))
  4225. {
  4226. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4227. }
  4228. else
  4229. {
  4230. $arrHide[] = $arrLP[$i]['id'];
  4231. }
  4232. }
  4233. else
  4234. {
  4235. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4236. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4237. }
  4238. }
  4239. if (is_array($arrLP))
  4240. {
  4241. reset($arrLP);
  4242. }
  4243. $return .= "\t\t\t\t" . '</select>';
  4244. $return .= "\t\t\t" . '</td>' . "\n";
  4245. $return .= "\t\t" . '</tr>' . "\n";
  4246. $return .= "\t\t" . '<tr>' . "\n";
  4247. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").'&nbsp;:</label></td>' . "\n";
  4248. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4249. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" id="idPosition" name="previous" size="1">';
  4250. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4251. for($i = 0; $i < count($arrLP); $i++)
  4252. {
  4253. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4254. {
  4255. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4256. $selected = 'selected="selected" ';
  4257. elseif($action == 'add')
  4258. $selected = 'selected="selected" ';
  4259. else
  4260. $selected = '';
  4261. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  4262. }
  4263. }
  4264. $return .= "\t\t\t\t" . '</select>';
  4265. $return .= "\t\t\t" . '</td>' . "\n";
  4266. $return .= "\t\t" . '</tr>' . "\n";
  4267. if($action != 'move')
  4268. {
  4269. $id_prerequisite=0;
  4270. if (is_array($arrLP ))
  4271. {
  4272. foreach($arrLP as $key=>$value){
  4273. if($value['id']==$id){
  4274. $id_prerequisite=$value['prerequisite'];
  4275. break;
  4276. }
  4277. }
  4278. }
  4279. $arrHide=array();
  4280. for($i = 0; $i < count($arrLP); $i++)
  4281. {
  4282. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4283. {
  4284. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4285. $s_selected_position=$arrLP[$i]['id'];
  4286. elseif($action == 'add')
  4287. $s_selected_position=0;
  4288. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4289. }
  4290. }
  4291. $return .= "\t\t" . '<tr>' . "\n";
  4292. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").'&nbsp;:</label></td>' . "\n";
  4293. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4294. foreach($arrHide as $key => $value){
  4295. if($key==$s_selected_position && $action == 'add'){
  4296. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4297. }
  4298. elseif($key==$id_prerequisite && $action == 'edit'){
  4299. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4300. }
  4301. else{
  4302. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4303. }
  4304. }
  4305. $return .= "</select></td>";
  4306. $return .= "\t\t" . '</tr>' . "\n";
  4307. $return .= "\t\t" . '<tr>' . "\n";
  4308. //Remove temporaly the test description
  4309. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4310. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4311. $return .= "\t\t" . '</tr>' . "\n";
  4312. }
  4313. $return .= "\t\t" . '<tr>' . "\n";
  4314. $return .= "\t\t\t" . '<td>&nbsp;</td><td><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  4315. $return .= "\t\t" . '</tr>' . "\n";
  4316. $return .= "\t" . '</table>' . "\n";
  4317. if($action == 'move')
  4318. {
  4319. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4320. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4321. }
  4322. if(is_numeric($extra_info))
  4323. {
  4324. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4325. }
  4326. elseif(is_array($extra_info))
  4327. {
  4328. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4329. }
  4330. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  4331. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4332. $return .= '</form>' . "\n";
  4333. $return .= '</div>' . "\n";
  4334. return $return;
  4335. }
  4336. /**
  4337. * Addition of Hotpotatoes tests
  4338. * @param string Action
  4339. * @param integer Internal ID of the item
  4340. * @param mixed Extra information - can be an array with title and description indexes
  4341. * @return string HTML structure to display the hotpotatoes addition formular
  4342. */
  4343. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
  4344. {
  4345. global $charset;
  4346. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4347. $tbl_lp_item = Database::get_course_table('lp_item');
  4348. if($id != 0 && is_array($extra_info))
  4349. {
  4350. $item_title = stripslashes($extra_info['title']);
  4351. $item_description = stripslashes($extra_info['description']);
  4352. }
  4353. elseif(is_numeric($extra_info))
  4354. {
  4355. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  4356. $sql_hot = "SELECT * FROM ".$TBL_DOCUMENT."
  4357. WHERE path LIKE '".$uploadPath."/%/%htm%'
  4358. ORDER BY id ASC";
  4359. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  4360. $row = Database::fetch_array($res_hot);
  4361. $item_title = $row['title'];
  4362. $item_description = $row['description'];
  4363. }
  4364. else
  4365. {
  4366. $item_title = '';
  4367. $item_description = '';
  4368. }
  4369. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4370. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4371. $return = '<div style="margin:3px 12px;">';
  4372. if($id != 0 && is_array($extra_info))
  4373. $parent = $extra_info['parent_item_id'];
  4374. else
  4375. $parent = 0;
  4376. $sql = "
  4377. SELECT *
  4378. FROM " . $tbl_lp_item . "
  4379. WHERE
  4380. lp_id = " . $this->lp_id;
  4381. $result = api_sql_query($sql, __FILE__, __LINE__);
  4382. $arrLP = array();
  4383. while($row = Database::fetch_array($result))
  4384. {
  4385. $arrLP[] = array(
  4386. 'id' => $row['id'],
  4387. 'item_type' => $row['item_type'],
  4388. 'title' => $row['title'],
  4389. 'path' => $row['path'],
  4390. 'description' => $row['description'],
  4391. 'parent_item_id' => $row['parent_item_id'],
  4392. 'previous_item_id' => $row['previous_item_id'],
  4393. 'next_item_id' => $row['next_item_id'],
  4394. 'display_order' => $row['display_order'],
  4395. 'max_score' => $row['max_score'],
  4396. 'min_score' => $row['min_score'],
  4397. 'mastery_score' => $row['mastery_score'],
  4398. 'prerequisite' => $row['prerequisite']);
  4399. }
  4400. $this->tree_array($arrLP);
  4401. $arrLP = $this->arrMenu;
  4402. unset($this->arrMenu);
  4403. if($action == 'add')
  4404. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").'&nbsp;:</p>' . "\n";
  4405. elseif($action == 'move')
  4406. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").'&nbsp;:</p>' . "\n";
  4407. else
  4408. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").'&nbsp;:</p>' . "\n";
  4409. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4410. {
  4411. $return .= '<div class="warning-message">';
  4412. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4413. $return .= get_lang("WarningEditingDocument");
  4414. $return .= '</div>';
  4415. }
  4416. $return .= '<form method="POST">' . "\n";
  4417. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4418. $return .= "\t\t" . '<tr>' . "\n";
  4419. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4420. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4421. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4422. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4423. $arrHide = array($id);
  4424. for($i = 0; $i < count($arrLP); $i++)
  4425. {
  4426. if($action != 'add')
  4427. {
  4428. 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))
  4429. {
  4430. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4431. }
  4432. else
  4433. {
  4434. $arrHide[] = $arrLP[$i]['id'];
  4435. }
  4436. }
  4437. else
  4438. {
  4439. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4440. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4441. }
  4442. }
  4443. reset($arrLP);
  4444. $return .= "\t\t\t\t" . '</select>';
  4445. $return .= "\t\t\t" . '</td>' . "\n";
  4446. $return .= "\t\t" . '</tr>' . "\n";
  4447. $return .= "\t\t" . '<tr>' . "\n";
  4448. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4449. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4450. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4451. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4452. for($i = 0; $i < count($arrLP); $i++)
  4453. {
  4454. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4455. {
  4456. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4457. $selected = 'selected="selected" ';
  4458. elseif($action == 'add')
  4459. $selected = 'selected="selected" ';
  4460. else
  4461. $selected = '';
  4462. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  4463. }
  4464. }
  4465. $return .= "\t\t\t\t" . '</select>';
  4466. $return .= "\t\t\t" . '</td>' . "\n";
  4467. $return .= "\t\t" . '</tr>' . "\n";
  4468. if($action != 'move')
  4469. {
  4470. $return .= "\t\t" . '<tr>' . "\n";
  4471. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4472. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4473. $return .= "\t\t" . '</tr>' . "\n";
  4474. $id_prerequisite=0;
  4475. foreach($arrLP as $key=>$value){
  4476. if($value['id']==$id){
  4477. $id_prerequisite=$value['prerequisite'];
  4478. break;
  4479. }
  4480. }
  4481. $arrHide=array();
  4482. for($i = 0; $i < count($arrLP); $i++)
  4483. {
  4484. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4485. {
  4486. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4487. $s_selected_position=$arrLP[$i]['id'];
  4488. elseif($action == 'add')
  4489. $s_selected_position=0;
  4490. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4491. }
  4492. }
  4493. $return .= "\t\t" . '<tr>' . "\n";
  4494. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4495. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4496. foreach($arrHide as $key => $value){
  4497. if($key==$s_selected_position && $action == 'add'){
  4498. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4499. }
  4500. elseif($key==$id_prerequisite && $action == 'edit'){
  4501. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4502. }
  4503. else{
  4504. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4505. }
  4506. }
  4507. $return .= "</select></td>";
  4508. $return .= "\t\t" . '</tr>' . "\n";
  4509. $return .= "\t\t" . '<tr>' . "\n";
  4510. //Remove temporaly the test description
  4511. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4512. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4513. $return .= "\t\t" . '</tr>' . "\n";
  4514. }
  4515. $return .= "\t\t" . '<tr>' . "\n";
  4516. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  4517. $return .= "\t\t" . '</tr>' . "\n";
  4518. $return .= "\t" . '</table>' . "\n";
  4519. if($action == 'move')
  4520. {
  4521. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4522. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4523. }
  4524. if(is_numeric($extra_info))
  4525. {
  4526. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4527. }
  4528. elseif(is_array($extra_info))
  4529. {
  4530. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4531. }
  4532. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />' . "\n";
  4533. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4534. $return .= '</form>' . "\n";
  4535. $return .= '</div>' . "\n";
  4536. return $return;
  4537. }
  4538. //fin du hotpot form
  4539. /**
  4540. * Return the form to display the forum edit/add option
  4541. *
  4542. * @param string Action (add/edit)
  4543. * @param integer ID of the lp_item if already exists
  4544. * @param mixed Forum ID or title
  4545. * @return string HTML form
  4546. */
  4547. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  4548. {
  4549. global $charset;
  4550. $tbl_lp_item = Database::get_course_table('lp_item');
  4551. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  4552. if($id != 0 && is_array($extra_info))
  4553. {
  4554. $item_title = stripslashes($extra_info['title']);
  4555. }
  4556. elseif(is_numeric($extra_info))
  4557. {
  4558. $sql_forum = "
  4559. SELECT
  4560. forum_title as title, forum_comment as comment
  4561. FROM " . $tbl_forum . "
  4562. WHERE forum_id = " . $extra_info;
  4563. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4564. $row = Database::fetch_array($result);
  4565. $item_title = $row['title'];
  4566. $item_description = $row['comment'];
  4567. }
  4568. else
  4569. {
  4570. $item_title = '';
  4571. $item_description = '';
  4572. }
  4573. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4574. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4575. $return = '<div class="sectiontitle">';
  4576. if($id != 0 && is_array($extra_info))
  4577. $parent = $extra_info['parent_item_id'];
  4578. else
  4579. $parent = 0;
  4580. $sql = "
  4581. SELECT *
  4582. FROM " . $tbl_lp_item . "
  4583. WHERE
  4584. lp_id = " . $this->lp_id;
  4585. $result = api_sql_query($sql, __FILE__, __LINE__);
  4586. $arrLP = array();
  4587. while($row = Database::fetch_array($result))
  4588. {
  4589. $arrLP[] = array(
  4590. 'id' => $row['id'],
  4591. 'item_type' => $row['item_type'],
  4592. 'title' => $row['title'],
  4593. 'path' => $row['path'],
  4594. 'description' => $row['description'],
  4595. 'parent_item_id' => $row['parent_item_id'],
  4596. 'previous_item_id' => $row['previous_item_id'],
  4597. 'next_item_id' => $row['next_item_id'],
  4598. 'display_order' => $row['display_order'],
  4599. 'max_score' => $row['max_score'],
  4600. 'min_score' => $row['min_score'],
  4601. 'mastery_score' => $row['mastery_score'],
  4602. 'prerequisite' => $row['prerequisite']);
  4603. }
  4604. $this->tree_array($arrLP);
  4605. $arrLP = $this->arrMenu;
  4606. unset($this->arrMenu);
  4607. if($action == 'add')
  4608. $return .= get_lang("CreateTheForum").'&nbsp;:' . "\n";
  4609. elseif($action == 'move')
  4610. $return .= get_lang("MoveTheCurrentForum").'&nbsp;:' . "\n";
  4611. else
  4612. $return .= get_lang("EditCurrentForum").'&nbsp;:' . "\n";
  4613. $return .= '</div>';
  4614. $return .= '<div class="sectioncomment">';
  4615. $return .= '<form method="POST">' . "\n";
  4616. $return .= "\t" . '<table>' . "\n";
  4617. if($action != 'move')
  4618. {
  4619. $return .= "\t\t" . '<tr>' . "\n";
  4620. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").'&nbsp;:</label></td>' . "\n";
  4621. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  4622. $return .= "\t\t" . '</tr>' . "\n";
  4623. }
  4624. $return .= "\t\t" . '<tr>' . "\n";
  4625. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").'&nbsp;:</label></td>' . "\n";
  4626. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4627. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4628. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4629. $arrHide = array($id);
  4630. for($i = 0; $i < count($arrLP); $i++)
  4631. {
  4632. if($action != 'add')
  4633. {
  4634. 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))
  4635. {
  4636. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4637. }
  4638. else
  4639. {
  4640. $arrHide[] = $arrLP[$i]['id'];
  4641. }
  4642. }
  4643. else
  4644. {
  4645. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4646. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4647. }
  4648. }
  4649. reset($arrLP);
  4650. $return .= "\t\t\t\t" . '</select>';
  4651. $return .= "\t\t\t" . '</td>' . "\n";
  4652. $return .= "\t\t" . '</tr>' . "\n";
  4653. $return .= "\t\t" . '<tr>' . "\n";
  4654. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").'&nbsp;:</label></td>' . "\n";
  4655. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4656. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1" class="learnpath_item_form">';
  4657. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4658. for($i = 0; $i < count($arrLP); $i++)
  4659. {
  4660. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4661. {
  4662. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4663. $selected = 'selected="selected" ';
  4664. elseif($action == 'add')
  4665. $selected = 'selected="selected" ';
  4666. else
  4667. $selected = '';
  4668. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  4669. }
  4670. }
  4671. $return .= "\t\t\t\t" . '</select>';
  4672. $return .= "\t\t\t" . '</td>' . "\n";
  4673. $return .= "\t\t" . '</tr>' . "\n";
  4674. if($action != 'move')
  4675. {
  4676. $return .= "\t\t" . '<tr>' . "\n";
  4677. //Remove temporaly the test description
  4678. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4679. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4680. $return .= "\t\t" . '</tr>' . "\n";
  4681. $id_prerequisite=0;
  4682. foreach($arrLP as $key=>$value){
  4683. if($value['id']==$id){
  4684. $id_prerequisite=$value['prerequisite'];
  4685. break;
  4686. }
  4687. }
  4688. $arrHide=array();
  4689. for($i = 0; $i < count($arrLP); $i++)
  4690. {
  4691. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4692. {
  4693. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4694. $s_selected_position=$arrLP[$i]['id'];
  4695. elseif($action == 'add')
  4696. $s_selected_position=0;
  4697. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4698. }
  4699. }
  4700. $return .= "\t\t" . '<tr>' . "\n";
  4701. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'&nbsp;:</label></td>' . "\n";
  4702. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4703. foreach($arrHide as $key => $value){
  4704. if($key==$s_selected_position && $action == 'add'){
  4705. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4706. }
  4707. elseif($key==$id_prerequisite && $action == 'edit'){
  4708. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4709. }
  4710. else{
  4711. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4712. }
  4713. }
  4714. $return .= "</select></td>";
  4715. $return .= "\t\t" . '</tr>' . "\n";
  4716. }
  4717. $return .= "\t\t" . '<tr>' . "\n";
  4718. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  4719. $return .= "\t\t" . '</tr>' . "\n";
  4720. $return .= "\t" . '</table>' . "\n";
  4721. if($action == 'move')
  4722. {
  4723. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4724. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4725. }
  4726. if(is_numeric($extra_info))
  4727. {
  4728. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4729. }
  4730. elseif(is_array($extra_info))
  4731. {
  4732. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4733. }
  4734. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  4735. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4736. $return .= '</form>' . "\n";
  4737. $return .= '</div>' . "\n";
  4738. return $return;
  4739. }
  4740. /**
  4741. * Return HTML form to add/edit forum threads
  4742. * @param string Action (add/edit)
  4743. * @param integer Item ID if already exists in learning path
  4744. * @param mixed Extra information (thread ID if integer)
  4745. * @return string HTML form
  4746. */
  4747. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  4748. {
  4749. global $charset;
  4750. echo '
  4751. <style>
  4752. div.row div.label {
  4753. width:110px;
  4754. }
  4755. div.row div.formw {
  4756. width: 82%;
  4757. }
  4758. </style>';
  4759. $tbl_lp_item = Database::get_course_table('lp_item');
  4760. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  4761. if($id != 0 && is_array($extra_info))
  4762. {
  4763. $item_title = stripslashes($extra_info['title']);
  4764. }
  4765. elseif(is_numeric($extra_info))
  4766. {
  4767. $sql_forum = "
  4768. SELECT
  4769. thread_title as title
  4770. FROM " . $tbl_forum . "
  4771. WHERE thread_id = " . $extra_info;
  4772. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4773. $row = Database::fetch_array($result);
  4774. $item_title = $row['title'];
  4775. $item_description = '';
  4776. }
  4777. else
  4778. {
  4779. $item_title = '';
  4780. $item_description = '';
  4781. }
  4782. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4783. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4784. $return = '<div style="margin:3px 12px;">';
  4785. if($id != 0 && is_array($extra_info))
  4786. $parent = $extra_info['parent_item_id'];
  4787. else
  4788. $parent = 0;
  4789. $sql = "
  4790. SELECT *
  4791. FROM " . $tbl_lp_item . "
  4792. WHERE
  4793. lp_id = " . $this->lp_id;
  4794. $result = api_sql_query($sql, __FILE__, __LINE__);
  4795. $arrLP = array();
  4796. while($row = Database::fetch_array($result))
  4797. {
  4798. $arrLP[] = array(
  4799. 'id' => $row['id'],
  4800. 'item_type' => $row['item_type'],
  4801. 'title' => $row['title'],
  4802. 'path' => $row['path'],
  4803. 'description' => $row['description'],
  4804. 'parent_item_id' => $row['parent_item_id'],
  4805. 'previous_item_id' => $row['previous_item_id'],
  4806. 'next_item_id' => $row['next_item_id'],
  4807. 'display_order' => $row['display_order'],
  4808. 'max_score' => $row['max_score'],
  4809. 'min_score' => $row['min_score'],
  4810. 'mastery_score' => $row['mastery_score'],
  4811. 'prerequisite' => $row['prerequisite']);
  4812. }
  4813. $this->tree_array($arrLP);
  4814. $arrLP = $this->arrMenu;
  4815. unset($this->arrMenu);
  4816. if($action == 'add')
  4817. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").'&nbsp;:</p>' . "\n";
  4818. elseif($action == 'move')
  4819. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").'&nbsp;:</p>' . "\n";
  4820. else
  4821. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").'&nbsp;:</p>' . "\n";
  4822. $return .= '<form method="POST">' . "\n";
  4823. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4824. $return .= "\t\t" . '<tr>' . "\n";
  4825. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").'&nbsp;:</label></td>' . "\n";
  4826. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4827. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4828. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4829. $arrHide = array($id);
  4830. for($i = 0; $i < count($arrLP); $i++)
  4831. {
  4832. if($action != 'add')
  4833. {
  4834. 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))
  4835. {
  4836. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4837. }
  4838. else
  4839. {
  4840. $arrHide[] = $arrLP[$i]['id'];
  4841. }
  4842. }
  4843. else
  4844. {
  4845. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4846. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4847. }
  4848. }
  4849. reset($arrLP);
  4850. $return .= "\t\t\t\t" . '</select>';
  4851. $return .= "\t\t\t" . '</td>' . "\n";
  4852. $return .= "\t\t" . '</tr>' . "\n";
  4853. $return .= "\t\t" . '<tr>' . "\n";
  4854. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").'&nbsp;:</label></td>' . "\n";
  4855. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4856. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4857. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4858. for($i = 0; $i < count($arrLP); $i++)
  4859. {
  4860. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4861. {
  4862. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4863. $selected = 'selected="selected" ';
  4864. elseif($action == 'add')
  4865. $selected = 'selected="selected" ';
  4866. else
  4867. $selected = '';
  4868. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  4869. }
  4870. }
  4871. $return .= "\t\t\t\t" . '</select>';
  4872. $return .= "\t\t\t" . '</td>' . "\n";
  4873. $return .= "\t\t" . '</tr>' . "\n";
  4874. if($action != 'move')
  4875. {
  4876. $return .= "\t\t" . '<tr>' . "\n";
  4877. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").'&nbsp;:</label></td>' . "\n";
  4878. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4879. $return .= "\t\t" . '</tr>' . "\n";
  4880. $return .= "\t\t" . '<tr>' . "\n";
  4881. //Remove temporaly the test description
  4882. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4883. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4884. $return .= "\t\t" . '</tr>' . "\n";
  4885. $id_prerequisite=0;
  4886. foreach($arrLP as $key=>$value){
  4887. if($value['id']==$id){
  4888. $id_prerequisite=$value['prerequisite'];
  4889. break;
  4890. }
  4891. }
  4892. $arrHide=array();
  4893. for($i = 0; $i < count($arrLP); $i++)
  4894. {
  4895. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4896. {
  4897. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4898. $s_selected_position=$arrLP[$i]['id'];
  4899. elseif($action == 'add')
  4900. $s_selected_position=0;
  4901. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4902. }
  4903. }
  4904. $return .= "\t\t" . '<tr>' . "\n";
  4905. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").'&nbsp;:</label></td>' . "\n";
  4906. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4907. foreach($arrHide as $key => $value){
  4908. if($key==$s_selected_position && $action == 'add'){
  4909. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4910. }
  4911. elseif($key==$id_prerequisite && $action == 'edit'){
  4912. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4913. }
  4914. else{
  4915. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4916. }
  4917. }
  4918. $return .= "</select></td>";
  4919. $return .= "\t\t" . '</tr>' . "\n";
  4920. }
  4921. $return .= "\t\t" . '<tr>' . "\n";
  4922. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  4923. $return .= "\t\t" . '</tr>' . "\n";
  4924. $return .= "\t" . '</table>' . "\n";
  4925. if($action == 'move')
  4926. {
  4927. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4928. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4929. }
  4930. if(is_numeric($extra_info))
  4931. {
  4932. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4933. }
  4934. elseif(is_array($extra_info))
  4935. {
  4936. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4937. }
  4938. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  4939. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4940. $return .= '</form>' . "\n";
  4941. $return .= '</div>' . "\n";
  4942. return $return;
  4943. }
  4944. /**
  4945. * Return the HTML form to display an item (generally a section/module item)
  4946. *
  4947. * @param string Item type (module/dokeos_module)
  4948. * @param string Title (optional, only when creating)
  4949. * @param string Action ('add'/'edit')
  4950. * @param integer lp_item ID
  4951. * @param mixed Extra info
  4952. * @return string HTML form
  4953. */
  4954. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  4955. {
  4956. global $_course;
  4957. global $charset;
  4958. $tbl_lp_item = Database::get_course_table('lp_item');
  4959. if($id != 0 && is_array($extra_info))
  4960. {
  4961. $item_title = $extra_info['title'];
  4962. $item_description = $extra_info['description'];
  4963. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
  4964. }
  4965. else
  4966. {
  4967. $item_title = '';
  4968. $item_description = '';
  4969. }
  4970. $return = '<div class="sectiontitle">';
  4971. if($id != 0 && is_array($extra_info))
  4972. $parent = $extra_info['parent_item_id'];
  4973. else
  4974. $parent = 0;
  4975. $sql = "
  4976. SELECT *
  4977. FROM " . $tbl_lp_item . "
  4978. WHERE lp_id = " . $this->lp_id. " AND id != " . $id. " ";
  4979. if($item_type == 'module')
  4980. $sql .= " AND parent_item_id = 0";
  4981. $result = api_sql_query($sql, __FILE__, __LINE__);
  4982. $arrLP = array();
  4983. while($row = Database::fetch_array($result))
  4984. {
  4985. $arrLP[] = array(
  4986. 'id' => $row['id'],
  4987. 'item_type' => $row['item_type'],
  4988. 'title' => $row['title'],
  4989. 'path' => $row['path'],
  4990. 'description' => $row['description'],
  4991. 'parent_item_id' => $row['parent_item_id'],
  4992. 'previous_item_id' => $row['previous_item_id'],
  4993. 'next_item_id' => $row['next_item_id'],
  4994. 'max_score' => $row['max_score'],
  4995. 'min_score' => $row['min_score'],
  4996. 'mastery_score' => $row['mastery_score'],
  4997. 'prerequisite' => $row['prerequisite'],
  4998. 'display_order' => $row['display_order']);
  4999. }
  5000. $this->tree_array($arrLP);
  5001. $arrLP = $this->arrMenu;
  5002. unset($this->arrMenu);
  5003. $return .= $title . "\n";
  5004. $return .= '</div>';
  5005. $return .= '<div class="sectioncomment">';
  5006. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5007. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  5008. $defaults["title"]=mb_convert_encoding($item_title,$charset,$this->encoding);
  5009. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5010. $form->addElement('html',$return);
  5011. //$arrHide = array($id);
  5012. $arrHide[0]['value']=$this->name;
  5013. $arrHide[0]['padding']=3;
  5014. if($item_type != 'module' && $item_type != 'dokeos_module')
  5015. {
  5016. for($i = 0; $i < count($arrLP); $i++)
  5017. {
  5018. if($action != 'add')
  5019. {
  5020. 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))
  5021. {
  5022. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5023. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5024. if($parent == $arrLP[$i]['id'])
  5025. {
  5026. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5027. }
  5028. }
  5029. }
  5030. else
  5031. {
  5032. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5033. {
  5034. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5035. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5036. if($parent == $arrLP[$i]['id'])
  5037. {
  5038. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5039. }
  5040. }
  5041. }
  5042. }
  5043. if($action != 'move')
  5044. {
  5045. $form->addElement('text','title', get_lang('Title').'&nbsp;:','id="idTitle" class="learnpath_chapter_form"');
  5046. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5047. }
  5048. else
  5049. {
  5050. $form->addElement('hidden','title');
  5051. }
  5052. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")."&nbsp;:", '', 'class="learnpath_chapter_form" id="Parent" onchange="load_cbo(this.value);"');
  5053. foreach($arrHide as $key => $value)
  5054. {
  5055. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5056. }
  5057. $parent_select -> setSelected($s_selected_parent);
  5058. }
  5059. if(is_array($arrLP)) { reset($arrLP); }
  5060. $arrHide=array();
  5061. //POSITION
  5062. for($i = 0; $i < count($arrLP); $i++)
  5063. {
  5064. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5065. {
  5066. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5067. $s_selected_position=$arrLP[$i]['id'];
  5068. elseif($action == 'add')
  5069. $s_selected_position=$arrLP[$i]['id'];
  5070. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5071. }
  5072. }
  5073. $position = &$form->addElement('select', 'previous', get_lang("Position")."&nbsp;:", '', 'id="idPosition" class="learnpath_chapter_form"');
  5074. $position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'.$value['padding'].'px;"');
  5075. foreach($arrHide as $key => $value)
  5076. {
  5077. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5078. }
  5079. if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
  5080. if(is_array($arrLP)) { reset($arrLP); }
  5081. $form->addElement('submit', 'submit_button', get_lang('Ok'));
  5082. if($item_type == 'module' || $item_type == 'dokeos_module')
  5083. {
  5084. $form->addElement('hidden', 'parent', '0');
  5085. }
  5086. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5087. if(($item_type=='asset' || $item_type=='sco') && ($extension == 'html' || $extension == 'htm'))
  5088. {
  5089. if($item_type=='sco')
  5090. {
  5091. $form->addElement('html','<script type="text/javascript">alert("'.get_lang('WarningWhenEditingScorm').'")</script>');
  5092. }
  5093. $renderer = $form->defaultRenderer();
  5094. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5095. $form->addElement('html_editor','content_lp','');
  5096. //$form->addElement('html_editor','content_lp','');
  5097. $defaults["content_lp"]=file_get_contents($item_path);
  5098. }
  5099. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  5100. $form->addElement('hidden', 'post_time', time());
  5101. $form->setDefaults($defaults);
  5102. $form->addElement('html','</div>');
  5103. return $form->return_form();
  5104. }
  5105. /**
  5106. * Returns the form to update or create a document
  5107. *
  5108. * @param string Action (add/edit)
  5109. * @param integer ID of the lp_item (if already exists)
  5110. * @param mixed Integer if document ID, string if info ('new')
  5111. * @return string HTML form
  5112. */
  5113. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  5114. {
  5115. global $charset;
  5116. $tbl_lp_item = Database::get_course_table('lp_item');
  5117. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5118. $path_parts = pathinfo($extra_info['dir']);
  5119. $no_display_edit_textarea=false;
  5120. //If action==edit document
  5121. //We don't display the document form if it's not an editable document (html or txt file)
  5122. if($action=="edit"){
  5123. if(is_array($extra_info)){
  5124. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5125. $no_display_edit_textarea=true;
  5126. }
  5127. }
  5128. }
  5129. $no_display_add=false;
  5130. //If action==add an existing document
  5131. //We don't display the document form if it's not an editable document (html or txt file)
  5132. if($action=="add"){
  5133. if(is_numeric($extra_info)){
  5134. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  5135. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  5136. $path_file=Database::result($result,0,0);
  5137. $path_parts = pathinfo($path_file);
  5138. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5139. $no_display_add=true;
  5140. }
  5141. }
  5142. }
  5143. if($id != 0 && is_array($extra_info))
  5144. {
  5145. $item_title = stripslashes($extra_info['title']);
  5146. $item_description = stripslashes($extra_info['description']);
  5147. $item_terms = stripslashes($extra_info['terms']);
  5148. if(empty($item_title))
  5149. {
  5150. $path_parts = pathinfo($extra_info['path']);
  5151. $item_title = stripslashes($path_parts['filename']);
  5152. }
  5153. }
  5154. elseif(is_numeric($extra_info))
  5155. {
  5156. $sql_doc = "
  5157. SELECT path, title
  5158. FROM " . $tbl_doc . "
  5159. WHERE id = " . $extra_info;
  5160. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  5161. $row = Database::fetch_array($result);
  5162. $explode = explode('.', $row['title']);
  5163. if(count($explode)>1){
  5164. for($i = 0; $i < count($explode) - 1; $i++)
  5165. $item_title .= $explode[$i];
  5166. }
  5167. else{
  5168. $item_title=$row['title'];
  5169. }
  5170. $item_title = str_replace('_', ' ', $item_title);
  5171. if(empty($item_title))
  5172. {
  5173. $path_parts = pathinfo($row['path']);
  5174. $item_title = stripslashes($path_parts['filename']);
  5175. }
  5176. }
  5177. else
  5178. {
  5179. $item_title = '';
  5180. $item_description = '';
  5181. }
  5182. $return = '<div class="sectiontitle">';
  5183. if($id != 0 && is_array($extra_info))
  5184. $parent = $extra_info['parent_item_id'];
  5185. else
  5186. $parent = 0;
  5187. $sql = "
  5188. SELECT *
  5189. FROM " . $tbl_lp_item . "
  5190. WHERE
  5191. lp_id = " . $this->lp_id;
  5192. $result = api_sql_query($sql, __FILE__, __LINE__);
  5193. $arrLP = array();
  5194. while($row = Database::fetch_array($result))
  5195. {
  5196. $arrLP[] = array(
  5197. 'id' => $row['id'],
  5198. 'item_type' => $row['item_type'],
  5199. 'title' => $row['title'],
  5200. 'path' => $row['path'],
  5201. 'description' => $row['description'],
  5202. 'parent_item_id' => $row['parent_item_id'],
  5203. 'previous_item_id' => $row['previous_item_id'],
  5204. 'next_item_id' => $row['next_item_id'],
  5205. 'display_order' => $row['display_order'],
  5206. 'max_score' => $row['max_score'],
  5207. 'min_score' => $row['min_score'],
  5208. 'mastery_score' => $row['mastery_score'],
  5209. 'prerequisite' => $row['prerequisite']);
  5210. }
  5211. $this->tree_array($arrLP);
  5212. $arrLP = $this->arrMenu;
  5213. unset($this->arrMenu);
  5214. if($action == 'add')
  5215. {
  5216. $return .= get_lang("CreateTheDocument") . "\n";
  5217. }
  5218. elseif($action == 'move')
  5219. {
  5220. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5221. }
  5222. else
  5223. {
  5224. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5225. }
  5226. $return .= '</div>';
  5227. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  5228. {
  5229. $return .= '<div class="warning-message">';
  5230. $return .= '<strong>'.get_lang("Warning").' !</strong><br />';
  5231. $return .= get_lang("WarningEditingDocument");
  5232. $return .= '</div>';
  5233. }
  5234. /*
  5235. if($no_display_add==true){
  5236. $return .= '<div class="warning-message">';
  5237. $return .= get_lang("CantEditDocument");
  5238. $return .= '</div>';
  5239. return $return;
  5240. }
  5241. */
  5242. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5243. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"],'','enctype="multipart/form-data"');
  5244. $defaults["title"] = html_entity_decode($item_title);
  5245. $defaults["title"]=mb_convert_encoding($defaults["title"],$charset,$this->encoding);
  5246. if(empty($defaults["title"]))
  5247. {
  5248. $defaults["title"] = html_entity_decode($item_title);
  5249. }
  5250. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5251. $form->addElement('html',$return);
  5252. if($action != 'move')
  5253. {
  5254. $form->addElement('text','title', get_lang('Title').'&nbsp;:','id="idTitle" class="learnpath_item_form"');
  5255. }
  5256. //$arrHide = array($id);
  5257. $arrHide[0]['value']=$this->name;
  5258. $arrHide[0]['padding']=3;
  5259. for($i = 0; $i < count($arrLP); $i++)
  5260. {
  5261. if($action != 'add'){
  5262. 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)){
  5263. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5264. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5265. if($parent == $arrLP[$i]['id']){
  5266. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5267. }
  5268. }
  5269. }
  5270. else{
  5271. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  5272. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5273. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5274. if($parent == $arrLP[$i]['id']){
  5275. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5276. }
  5277. }
  5278. }
  5279. }
  5280. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent")."&nbsp;:", '', 'class="learnpath_item_form" onchange="load_cbo(this.value);"');
  5281. foreach($arrHide as $key => $value)
  5282. {
  5283. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5284. }
  5285. $parent_select -> setSelected($parent);
  5286. if(is_array($arrLP))
  5287. {
  5288. reset($arrLP);
  5289. }
  5290. $arrHide=array();
  5291. //POSITION
  5292. for($i = 0; $i < count($arrLP); $i++)
  5293. {
  5294. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5295. {
  5296. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5297. $s_selected_position=$arrLP[$i]['id'];
  5298. elseif($action == 'add')
  5299. $s_selected_position=$arrLP[$i]['id'];
  5300. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding).'"';
  5301. }
  5302. }
  5303. $position = &$form->addElement('select', 'previous', get_lang("Position")."&nbsp;:", '', 'id="idPosition" class="learnpath_item_form"');
  5304. $position->addOption(get_lang("FirstPosition"),0);
  5305. foreach($arrHide as $key => $value)
  5306. {
  5307. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5308. }
  5309. $position -> setSelected($s_selected_position);
  5310. if(is_array($arrLP))
  5311. {
  5312. reset($arrLP);
  5313. }
  5314. if($action != 'move')
  5315. {
  5316. $id_prerequisite=0;
  5317. if(is_array($arrLP))
  5318. {
  5319. foreach($arrLP as $key=>$value){
  5320. if($value['id']==$id){
  5321. $id_prerequisite=$value['prerequisite'];
  5322. break;
  5323. }
  5324. }
  5325. }
  5326. $select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites').'&nbsp;:', '', 'id="prerequisites" class="learnpath_item_form"');
  5327. $select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5328. // form element for uploading an mp3 file
  5329. $form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5330. $form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5331. if ( api_get_setting('search_enabled') === 'true' )
  5332. {
  5333. //add terms field
  5334. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5335. $terms->setValue($item_terms);
  5336. }
  5337. $arrHide=array();
  5338. for($i = 0; $i < count($arrLP); $i++)
  5339. {
  5340. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5341. {
  5342. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5343. $s_selected_position=$arrLP[$i]['id'];
  5344. elseif($action == 'add')
  5345. $s_selected_position=$arrLP[$i]['id'];
  5346. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5347. }
  5348. }
  5349. foreach($arrHide as $key => $value){
  5350. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5351. if($key==$s_selected_position && $action == 'add'){
  5352. $select_prerequisites -> setSelected(0);
  5353. }
  5354. elseif($key==$id_prerequisite && $action == 'edit'){
  5355. $select_prerequisites -> setSelected($id_prerequisite);
  5356. }
  5357. }
  5358. if(!$no_display_add)
  5359. {
  5360. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  5361. {
  5362. if(isset($_POST['content']))
  5363. $content = stripslashes($_POST['content']);
  5364. elseif(is_array($extra_info)){
  5365. //If it's an html document or a text file
  5366. if(!$no_display_edit_textarea){
  5367. $content = $this->display_document($extra_info['path'], false, false);
  5368. }
  5369. }
  5370. elseif(is_numeric($extra_info))
  5371. $content = $this->display_document($extra_info, false, false);
  5372. else
  5373. $content = '';
  5374. $form->addElement('submit', 'submit_button', get_lang('Ok'));
  5375. if(!$no_display_edit_textarea)
  5376. {
  5377. $renderer = $form->defaultRenderer();
  5378. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5379. $form->addElement('html','<div style="margin:3px 12px">');
  5380. $form->addElement('html_editor','content_lp','');
  5381. $form->addElement('html','</div>');
  5382. $defaults["content_lp"]=$content;
  5383. }
  5384. }
  5385. elseif(is_numeric($extra_info))
  5386. {
  5387. $form->addElement('submit', 'submit_button', get_lang('Ok'));
  5388. $return = $this->display_document($extra_info, true, true, true);
  5389. $form->addElement('html',$return);
  5390. }
  5391. }
  5392. }
  5393. if($action == 'move')
  5394. {
  5395. $form->addElement('hidden', 'title', $item_title);
  5396. $form->addElement('hidden', 'description', $item_description);
  5397. }
  5398. if(is_numeric($extra_info))
  5399. {
  5400. $form->addElement('submit', 'submit_button', get_lang('Ok'));
  5401. $form->addElement('hidden', 'path', $extra_info);
  5402. }
  5403. elseif(is_array($extra_info))
  5404. {
  5405. $form->addElement('submit', 'submit_button', get_lang('Ok'));
  5406. $form->addElement('hidden', 'path', $extra_info['path']);
  5407. }
  5408. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5409. $form->addElement('hidden', 'post_time', time());
  5410. $form->setDefaults($defaults);
  5411. return $form->return_form();
  5412. }
  5413. /**
  5414. * Return HTML form to add/edit a link item
  5415. *
  5416. * @param string Action (add/edit)
  5417. * @param integer Item ID if exists
  5418. * @param mixed Extra info
  5419. * @return string HTML form
  5420. */
  5421. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  5422. {
  5423. global $charset;
  5424. $tbl_lp_item = Database::get_course_table('lp_item');
  5425. $tbl_link = Database::get_course_table(TABLE_LINK);
  5426. if($id != 0 && is_array($extra_info))
  5427. {
  5428. $item_title = stripslashes($extra_info['title']);
  5429. $item_description = stripslashes($extra_info['description']);
  5430. }
  5431. elseif(is_numeric($extra_info))
  5432. {
  5433. $sql_link = "
  5434. SELECT
  5435. title,
  5436. description,
  5437. url
  5438. FROM " . $tbl_link . "
  5439. WHERE id = " . $extra_info;
  5440. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  5441. $row = Database::fetch_array($result);
  5442. $item_title = $row['title'];
  5443. $item_description = $row['description'];
  5444. $item_url = $row['url'];
  5445. }
  5446. else
  5447. {
  5448. $item_title = '';
  5449. $item_description = '';
  5450. }
  5451. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5452. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  5453. $return = '<div class="sectiontitle">';
  5454. if($id != 0 && is_array($extra_info))
  5455. $parent = $extra_info['parent_item_id'];
  5456. else
  5457. $parent = 0;
  5458. $sql = "
  5459. SELECT *
  5460. FROM " . $tbl_lp_item . "
  5461. WHERE
  5462. lp_id = " . $this->lp_id;
  5463. $result = api_sql_query($sql, __FILE__, __LINE__);
  5464. $arrLP = array();
  5465. while($row = Database::fetch_array($result))
  5466. {
  5467. $arrLP[] = array(
  5468. 'id' => $row['id'],
  5469. 'item_type' => $row['item_type'],
  5470. 'title' => $row['title'],
  5471. 'path' => $row['path'],
  5472. 'description' => $row['description'],
  5473. 'parent_item_id' => $row['parent_item_id'],
  5474. 'previous_item_id' => $row['previous_item_id'],
  5475. 'next_item_id' => $row['next_item_id'],
  5476. 'display_order' => $row['display_order'],
  5477. 'max_score' => $row['max_score'],
  5478. 'min_score' => $row['min_score'],
  5479. 'mastery_score' => $row['mastery_score'],
  5480. 'prerequisite' => $row['prerequisite']);
  5481. }
  5482. $this->tree_array($arrLP);
  5483. $arrLP = $this->arrMenu;
  5484. unset($this->arrMenu);
  5485. if($action == 'add')
  5486. $return .= get_lang("CreateTheLink").'&nbsp;:' . "\n";
  5487. elseif($action == 'move')
  5488. $return .= get_lang("MoveCurrentLink").'&nbsp;:' . "\n";
  5489. else
  5490. $return .= get_lang("EditCurrentLink").'&nbsp;:' . "\n";
  5491. $return .= '</div>';
  5492. $return .= '<div class="sectioncomment">';
  5493. $return .= '<form method="POST">' . "\n";
  5494. $return .= "\t" . '<table>' . "\n";
  5495. if($action != 'move')
  5496. {
  5497. $return .= "\t\t" . '<tr>' . "\n";
  5498. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5499. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
  5500. $return .= "\t\t" . '</tr>' . "\n";
  5501. }
  5502. $return .= "\t\t" . '<tr>' . "\n";
  5503. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5504. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5505. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5506. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5507. $arrHide = array($id);
  5508. for($i = 0; $i < count($arrLP); $i++)
  5509. {
  5510. if($action != 'add')
  5511. {
  5512. 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))
  5513. {
  5514. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5515. }
  5516. else
  5517. {
  5518. $arrHide[] = $arrLP[$i]['id'];
  5519. }
  5520. }
  5521. else
  5522. {
  5523. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5524. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5525. }
  5526. }
  5527. reset($arrLP);
  5528. $return .= "\t\t\t\t" . '</select>';
  5529. $return .= "\t\t\t" . '</td>' . "\n";
  5530. $return .= "\t\t" . '</tr>' . "\n";
  5531. $return .= "\t\t" . '<tr>' . "\n";
  5532. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5533. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5534. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1" class="learnpath_item_form">';
  5535. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5536. for($i = 0; $i < count($arrLP); $i++)
  5537. {
  5538. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5539. {
  5540. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5541. $selected = 'selected="selected" ';
  5542. elseif($action == 'add')
  5543. $selected = 'selected="selected" ';
  5544. else
  5545. $selected = '';
  5546. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  5547. }
  5548. }
  5549. $return .= "\t\t\t\t" . '</select>';
  5550. $return .= "\t\t\t" . '</td>' . "\n";
  5551. $return .= "\t\t" . '</tr>' . "\n";
  5552. if($action != 'move')
  5553. {
  5554. $return .= "\t\t" . '<tr>' . "\n";
  5555. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5556. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" class="learnpath_item_form" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5557. $return .= "\t\t" . '</tr>' . "\n";
  5558. $return .= "\t\t" . '<tr>' . "\n";
  5559. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang("Url").' :</label></td>' . "\n";
  5560. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>' . "\n";
  5561. $return .= "\t\t" . '</tr>' . "\n";
  5562. $id_prerequisite=0;
  5563. foreach($arrLP as $key=>$value){
  5564. if($value['id']==$id){
  5565. $id_prerequisite=$value['prerequisite'];
  5566. break;
  5567. }
  5568. }
  5569. $arrHide=array();
  5570. for($i = 0; $i < count($arrLP); $i++)
  5571. {
  5572. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5573. {
  5574. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5575. $s_selected_position=$arrLP[$i]['id'];
  5576. elseif($action == 'add')
  5577. $s_selected_position=0;
  5578. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5579. }
  5580. }
  5581. $return .= "\t\t" . '<tr>' . "\n";
  5582. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5583. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5584. foreach($arrHide as $key => $value)
  5585. {
  5586. if($key==$s_selected_position && $action == 'add')
  5587. {
  5588. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5589. }
  5590. elseif($key==$id_prerequisite && $action == 'edit'){
  5591. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5592. }
  5593. else{
  5594. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5595. }
  5596. }
  5597. $return .= "</select></td>";
  5598. $return .= "\t\t" . '</tr>' . "\n";
  5599. }
  5600. $return .= "\t\t" . '<tr>' . "\n";
  5601. $return .= "\t\t\t" . '<td>&nbsp;</td><td><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5602. $return .= "\t\t" . '</tr>' . "\n";
  5603. $return .= "\t" . '</table>' . "\n";
  5604. if($action == 'move')
  5605. {
  5606. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5607. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5608. }
  5609. if(is_numeric($extra_info))
  5610. {
  5611. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5612. }
  5613. elseif(is_array($extra_info))
  5614. {
  5615. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5616. }
  5617. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  5618. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5619. $return .= '</form>' . "\n";
  5620. $return .= '</div>' . "\n";
  5621. return $return;
  5622. }
  5623. /**
  5624. * Return HTML form to add/edit a student publication (work)
  5625. *
  5626. * @param string Action (add/edit)
  5627. * @param integer Item ID if already exists
  5628. * @param mixed Extra info (work ID if integer)
  5629. * @return string HTML form
  5630. */
  5631. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  5632. {
  5633. global $charset;
  5634. $tbl_lp_item = Database::get_course_table('lp_item');
  5635. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5636. if($id != 0 && is_array($extra_info))
  5637. {
  5638. $item_title = stripslashes($extra_info['title']);
  5639. $item_description = stripslashes($extra_info['description']);
  5640. }
  5641. elseif(is_numeric($extra_info))
  5642. {
  5643. $sql_publication = "
  5644. SELECT
  5645. title,
  5646. description
  5647. FROM " . $tbl_publication . "
  5648. WHERE id = " . $extra_info;
  5649. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  5650. $row = Database::fetch_array($result);
  5651. $item_title = $row['title'];
  5652. }
  5653. else
  5654. {
  5655. $item_title = '';
  5656. }
  5657. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5658. $return = '<div class="sectiontitle">';
  5659. if($id != 0 && is_array($extra_info))
  5660. $parent = $extra_info['parent_item_id'];
  5661. else
  5662. $parent = 0;
  5663. $sql = "
  5664. SELECT *
  5665. FROM " . $tbl_lp_item . "
  5666. WHERE
  5667. lp_id = " . $this->lp_id;
  5668. $result = api_sql_query($sql, __FILE__, __LINE__);
  5669. $arrLP = array();
  5670. while($row = Database::fetch_array($result))
  5671. {
  5672. $arrLP[] = array(
  5673. 'id' => $row['id'],
  5674. 'item_type' => $row['item_type'],
  5675. 'title' => $row['title'],
  5676. 'path' => $row['path'],
  5677. 'description' => $row['description'],
  5678. 'parent_item_id' => $row['parent_item_id'],
  5679. 'previous_item_id' => $row['previous_item_id'],
  5680. 'next_item_id' => $row['next_item_id'],
  5681. 'display_order' => $row['display_order'],
  5682. 'max_score' => $row['max_score'],
  5683. 'min_score' => $row['min_score'],
  5684. 'mastery_score' => $row['mastery_score'],
  5685. 'prerequisite' => $row['prerequisite']);
  5686. }
  5687. $this->tree_array($arrLP);
  5688. $arrLP = $this->arrMenu;
  5689. unset($this->arrMenu);
  5690. if($action == 'add')
  5691. $return .= get_lang("Student_publication").'&nbsp;:' . "\n";
  5692. elseif($action == 'move')
  5693. $return .= get_lang("MoveCurrentStudentPublication").'&nbsp;:' . "\n";
  5694. else
  5695. $return .= get_lang("EditCurrentStudentPublication").'&nbsp;:' . "\n";
  5696. $return .= '</div>';
  5697. $return .= '<div class="sectioncomment">';
  5698. $return .= '<form method="POST">' . "\n";
  5699. $return .= "\t" . '<table>' . "\n";
  5700. if($action != 'move')
  5701. {
  5702. $return .= "\t\t" . '<tr>' . "\n";
  5703. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  5704. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  5705. $return .= "\t\t" . '</tr>' . "\n";
  5706. }
  5707. $return .= "\t\t" . '<tr>' . "\n";
  5708. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  5709. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5710. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5711. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5712. $arrHide = array($id);
  5713. for($i = 0; $i < count($arrLP); $i++)
  5714. {
  5715. if($action != 'add')
  5716. {
  5717. 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))
  5718. {
  5719. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5720. }
  5721. else
  5722. {
  5723. $arrHide[] = $arrLP[$i]['id'];
  5724. }
  5725. }
  5726. else
  5727. {
  5728. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5729. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding). '</option>';
  5730. }
  5731. }
  5732. if(is_array($arrLP))
  5733. {
  5734. reset($arrLP);
  5735. }
  5736. $return .= "\t\t\t\t" . '</select>';
  5737. $return .= "\t\t\t" . '</td>' . "\n";
  5738. $return .= "\t\t" . '</tr>' . "\n";
  5739. $return .= "\t\t" . '<tr>' . "\n";
  5740. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  5741. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5742. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1" class="learnpath_item_form">';
  5743. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5744. for($i = 0; $i < count($arrLP); $i++)
  5745. {
  5746. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5747. {
  5748. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5749. $selected = 'selected="selected" ';
  5750. elseif($action == 'add')
  5751. $selected = 'selected="selected" ';
  5752. else
  5753. $selected = '';
  5754. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  5755. }
  5756. }
  5757. $return .= "\t\t\t\t" . '</select>';
  5758. $return .= "\t\t\t" . '</td>' . "\n";
  5759. $return .= "\t\t" . '</tr>' . "\n";
  5760. if($action != 'move')
  5761. {
  5762. $id_prerequisite=0;
  5763. if(is_array($arrLP))
  5764. {
  5765. foreach($arrLP as $key=>$value){
  5766. if($value['id']==$id){
  5767. $id_prerequisite=$value['prerequisite'];
  5768. break;
  5769. }
  5770. }
  5771. }
  5772. $arrHide=array();
  5773. for($i = 0; $i < count($arrLP); $i++)
  5774. {
  5775. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5776. {
  5777. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5778. $s_selected_position=$arrLP[$i]['id'];
  5779. elseif($action == 'add')
  5780. $s_selected_position=0;
  5781. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5782. }
  5783. }
  5784. $return .= "\t\t" . '<tr>' . "\n";
  5785. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  5786. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5787. foreach($arrHide as $key => $value){
  5788. if($key==$s_selected_position && $action == 'add'){
  5789. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5790. }
  5791. elseif($key==$id_prerequisite && $action == 'edit'){
  5792. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5793. }
  5794. else{
  5795. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5796. }
  5797. }
  5798. $return .= "</select></td>";
  5799. $return .= "\t\t" . '</tr>' . "\n";
  5800. }
  5801. $return .= "\t\t" . '<tr>' . "\n";
  5802. $return .= "\t\t\t" . '<td>&nbsp</td><td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  5803. $return .= "\t\t" . '</tr>' . "\n";
  5804. $return .= "\t" . '</table>' . "\n";
  5805. if($action == 'move')
  5806. {
  5807. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5808. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5809. }
  5810. if(is_numeric($extra_info))
  5811. {
  5812. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5813. }
  5814. elseif(is_array($extra_info))
  5815. {
  5816. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5817. }
  5818. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  5819. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5820. $return .= '</form>' . "\n";
  5821. $return .= '</div>' . "\n";
  5822. return $return;
  5823. }
  5824. /**
  5825. * Displays the menu for manipulating a step
  5826. *
  5827. * @return unknown
  5828. */
  5829. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  5830. {
  5831. global $charset, $_course;
  5832. $return = '<div class="actions">';
  5833. switch($item_type)
  5834. {
  5835. case 'dokeos_chapter':
  5836. case 'chapter':
  5837. $lang = get_lang('TitleManipulateChapter');
  5838. break;
  5839. case 'dokeos_module':
  5840. case 'module':
  5841. $lang = get_lang('TitleManipulateModule');
  5842. break;
  5843. case TOOL_DOCUMENT:
  5844. $lang = get_lang('TitleManipulateDocument');
  5845. break;
  5846. case TOOL_LINK:
  5847. case 'link':
  5848. $lang = get_lang('TitleManipulateLink');
  5849. break;
  5850. case TOOL_QUIZ:
  5851. $lang = get_lang('TitleManipulateQuiz');
  5852. break;
  5853. case TOOL_STUDENTPUBLICATION:
  5854. $lang = get_lang('TitleManipulateStudentPublication');
  5855. break;
  5856. }
  5857. $tbl_lp_item = Database::get_course_table('lp_item');
  5858. $sql = "
  5859. SELECT
  5860. *
  5861. FROM " . $tbl_lp_item . " as lp
  5862. WHERE
  5863. lp.id = " . $item_id;
  5864. $result = api_sql_query($sql, __FILE__, __LINE__);
  5865. $row= mysql_fetch_assoc($result);
  5866. $s_title = $row['title'];
  5867. $s_title=mb_convert_encoding($s_title,$charset,$this->encoding);
  5868. // we display an audio player if needed
  5869. if (!empty($row['audio']))
  5870. {
  5871. $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>';
  5872. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  5873. $return .= '<script type="text/javascript">
  5874. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  5875. s1.addParam("allowscriptaccess","always");
  5876. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  5877. s1.write("container");
  5878. </script>';
  5879. }
  5880. $return .= $lang.': ';
  5881. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Edit the current item"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="Edit the current item" /> '.get_lang("Edit").'</a>';
  5882. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="Move the current item" /> '.get_lang("Move").'</a>';
  5883. // commented for now as prerequisites cannot be added to chapters
  5884. if($item_type != 'dokeos_chapter' && $item_type != 'chapter')
  5885. {
  5886. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="'.get_lang('Prerequisites').'"><img align="absbottom" alt="'.get_lang('Prerequisites').'" src="../img/right.gif" title="'.get_lang('Prerequisites').'" /> '.get_lang('Prerequisites').'</a>';
  5887. }
  5888. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' .addslashes($s_title). '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="Delete the current item" /> '.get_lang("Delete").'</a>';
  5889. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  5890. //$return.="</td><td valign='top'>";
  5891. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  5892. ob_start();
  5893. $audio_recorder_studentview = 'false';
  5894. $audio_recorder_item_id = $item_id;
  5895. if(api_get_setting('service_visio','active')=='true'){
  5896. include('audiorecorder.inc.php');
  5897. }
  5898. $return .= ob_get_contents();
  5899. ob_end_clean();
  5900. // end of audiorecorder include
  5901. $return .= '</div>';
  5902. return $return;
  5903. }
  5904. /**
  5905. * Creates the javascript needed for filling up the checkboxes without page reload
  5906. *
  5907. * @return string
  5908. */
  5909. function create_js()
  5910. {
  5911. $return = '<script language="javascript" type="text/javascript">' . "\n";
  5912. $return .= 'function load_cbo(id){' . "\n";
  5913. $return .= "var cbo = document.getElementById('idPosition');\n";
  5914. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  5915. $return .= 'cbo.options[i] = null;'."\n";
  5916. $return .= 'var k=0;'."\n";
  5917. $return .= 'for(var i = 1; i <= child_name[id].length; i++){'."\n";
  5918. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);'."\n";
  5919. $return .= 'k=i;';
  5920. $return .= '}' . "\n\n";
  5921. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  5922. $return .='}';
  5923. $return .= 'var child_name = new Array();' . "\n";
  5924. $return .= 'var child_value = new Array();' . "\n\n";
  5925. $return .= 'child_name[0] = new Array();' . "\n";
  5926. $return .= 'child_value[0] = new Array();' . "\n\n";
  5927. $tbl_lp_item = Database::get_course_table('lp_item');
  5928. $sql_zero = "
  5929. SELECT *
  5930. FROM " . $tbl_lp_item . "
  5931. WHERE
  5932. lp_id = " . $this->lp_id . " AND
  5933. parent_item_id = 0
  5934. ORDER BY display_order ASC";
  5935. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  5936. global $charset;
  5937. $i = 0;
  5938. while($row_zero = Database::fetch_array($res_zero))
  5939. {
  5940. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_zero['title'],$charset,$this->encoding) . '\"";' . "\n";
  5941. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  5942. }
  5943. $return .= "\n";
  5944. $sql = "
  5945. SELECT *
  5946. FROM " . $tbl_lp_item . "
  5947. WHERE
  5948. lp_id = " . $this->lp_id;
  5949. $res = api_sql_query($sql, __FILE__, __LINE__);
  5950. while($row = Database::fetch_array($res))
  5951. {
  5952. $sql_parent = "
  5953. SELECT *
  5954. FROM " . $tbl_lp_item . "
  5955. WHERE parent_item_id = " . $row['id'] . "
  5956. ORDER BY display_order ASC";
  5957. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  5958. $i = 0;
  5959. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  5960. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  5961. while($row_parent = Database::fetch_array($res_parent))
  5962. {
  5963. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_parent['title'],$charset,$this->encoding) . '\"";' . "\n";
  5964. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  5965. }
  5966. $return .= "\n";
  5967. }
  5968. $return .= '</script>' . "\n";
  5969. return $return;
  5970. }
  5971. /**
  5972. * Display the form to allow moving an item
  5973. *
  5974. * @param integer Item ID
  5975. * @return string HTML form
  5976. */
  5977. function display_move_item($item_id)
  5978. {
  5979. global $_course; //will disappear
  5980. global $charset;
  5981. $return = '';
  5982. if(is_numeric($item_id))
  5983. {
  5984. $tbl_lp_item = Database::get_course_table('lp_item');
  5985. $sql = "
  5986. SELECT *
  5987. FROM " . $tbl_lp_item . "
  5988. WHERE id = " . $item_id;
  5989. $res = api_sql_query($sql, __FILE__, __LINE__);
  5990. $row = Database::fetch_array($res);
  5991. switch($row['item_type'])
  5992. {
  5993. case 'dokeos_chapter': case 'dir' : case 'asset' :
  5994. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5995. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  5996. break;
  5997. case 'dokeos_module':
  5998. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5999. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6000. break;
  6001. case TOOL_DOCUMENT:
  6002. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6003. $return .= $this->display_document_form('move', $item_id, $row);
  6004. break;
  6005. case TOOL_LINK:
  6006. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6007. $return .= $this->display_link_form('move', $item_id, $row);
  6008. break;
  6009. case TOOL_HOTPOTATOES:
  6010. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6011. $return .= $this->display_link_form('move', $item_id, $row);
  6012. break;
  6013. case TOOL_QUIZ:
  6014. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6015. $return .= $this->display_quiz_form('move', $item_id, $row);
  6016. break;
  6017. case TOOL_STUDENTPUBLICATION:
  6018. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6019. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6020. break;
  6021. case TOOL_FORUM :
  6022. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6023. $return .= $this->display_forum_form('move', $item_id, $row);
  6024. }
  6025. }
  6026. return $return;
  6027. }
  6028. /**
  6029. * Displays a basic form on the overview page for changing the item title and the item description.
  6030. *
  6031. * @param string $item_type
  6032. * @param string $title
  6033. * @param array $data
  6034. * @return string
  6035. */
  6036. function display_item_small_form($item_type, $title = '', $data)
  6037. {
  6038. $return .= '<div class="lp_small_form">' . "\n";
  6039. $return .= '<p class="lp_title">' . $title . '</p>';
  6040. $return .= '<form method="post">' . "\n";
  6041. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6042. $return .= "\t\t" . '<tr>' . "\n";
  6043. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6044. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  6045. $return .= "\t\t" . '</tr>' . "\n";
  6046. $return .= "\t\t" . '<tr>' . "\n";
  6047. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6048. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6049. $return .= "\t\t" . '</tr>' . "\n";
  6050. $return .= "\t\t" . '<tr>' . "\n";
  6051. $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  6052. $return .= "\t\t" . '</tr>' . "\n";
  6053. $return .= "\t\t" . '</table>' . "\n";
  6054. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6055. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6056. $return .= '</form>';
  6057. $return .= '</div>';
  6058. return $return;
  6059. }
  6060. /**
  6061. * Return HTML form to allow prerequisites selection
  6062. *
  6063. * @param integer Item ID
  6064. * @return string HTML form
  6065. */
  6066. function display_item_prerequisites_form($item_id)
  6067. {
  6068. global $charset;
  6069. $tbl_lp_item = Database::get_course_table('lp_item');
  6070. /* current prerequisite */
  6071. $sql = "
  6072. SELECT *
  6073. FROM " . $tbl_lp_item . "
  6074. WHERE id = " . $item_id;
  6075. $result = api_sql_query($sql, __FILE__, __LINE__);
  6076. $row = Database::fetch_array($result);
  6077. $preq_id = $row['prerequisite'];
  6078. //$preq_mastery = $row['mastery_score'];
  6079. //$preq_max = $row['max_score'];
  6080. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6081. $return .= '<div class="sectiontitle">';
  6082. $return .= get_lang('AddEditPrerequisites');
  6083. $return .= '</div>';
  6084. $return .= '<div class="sectioncomment">';
  6085. $return .= '<form method="POST">';
  6086. $return .= '<table class="lp_prerequisites">';
  6087. $return .= '<tr>';
  6088. $return .= '<th></th>';
  6089. $return .= '<th >'.get_lang('Minimum').'</th>';
  6090. $return .= '<th>'.get_lang('Maximum').'</th>';
  6091. $return .= '</tr>';
  6092. $return .= '<tr>';
  6093. $return .= '<td class="radio">';
  6094. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6095. $return .= '<label for="idNone">'.get_lang('None').'</label>';
  6096. $return .= '</td><td colspan="2" />';
  6097. $return .= '</tr>';
  6098. $sql = "
  6099. SELECT *
  6100. FROM " . $tbl_lp_item . "
  6101. WHERE
  6102. lp_id = " . $this->lp_id;
  6103. $result = api_sql_query($sql, __FILE__, __LINE__);
  6104. $arrLP = array();
  6105. while($row = Database::fetch_array($result))
  6106. {
  6107. $arrLP[] = array(
  6108. 'id' => $row['id'],
  6109. 'item_type' => $row['item_type'],
  6110. 'title' => mb_convert_encoding($row['title'],$charset,$this->encoding),
  6111. 'ref' => $row['ref'],
  6112. 'description' => $row['description'],
  6113. 'parent_item_id' => $row['parent_item_id'],
  6114. 'previous_item_id' => $row['previous_item_id'],
  6115. 'next_item_id' => $row['next_item_id'],
  6116. 'max_score' => $row['max_score'],
  6117. 'min_score' => $row['min_score'],
  6118. 'mastery_score' => $row['mastery_score'],
  6119. 'prerequisite' => $row['prerequisite'],
  6120. 'next_item_id' => $row['next_item_id'],
  6121. 'display_order' => $row['display_order']);
  6122. if($row['ref'] == $preq_id)
  6123. {
  6124. $preq_mastery = $row['mastery_score'];
  6125. $preq_max = $row['max_score'];
  6126. }
  6127. }
  6128. $this->tree_array($arrLP);
  6129. $arrLP = $this->arrMenu;
  6130. unset($this->arrMenu);
  6131. for($i = 0; $i < count($arrLP); $i++)
  6132. {
  6133. if($arrLP[$i]['id'] == $item_id)
  6134. break;
  6135. $return .= '<tr>';
  6136. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6137. $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'] . '" />';
  6138. $return .= '<img alt="" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  6139. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6140. $return .= '</td>';
  6141. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6142. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  6143. {
  6144. $return .= '<td class="exercise">';
  6145. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6146. $return .= '</td>';
  6147. $return .= '<td class="exercise">';
  6148. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6149. $return .= '</td>';
  6150. }
  6151. if($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES)
  6152. {
  6153. $return .= '<td class="exercise">';
  6154. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6155. $return .= '</td>';
  6156. $return .= '<td class="exercise">';
  6157. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6158. $return .= '</td>';
  6159. }
  6160. $return .='</tr>';
  6161. }
  6162. $return .= '<tr>';
  6163. $return .= '<td colspan="3">';
  6164. $return .= '<input class="button" name="submit_button" type="submit" value="'.get_lang("Ok").'" /></td>' . "\n";
  6165. $return .= '</td>';
  6166. $return .= '</tr>';
  6167. $return .= '</table>';
  6168. $return .= '</form>';
  6169. $return .= '</div>';
  6170. return $return;
  6171. }
  6172. /**
  6173. * Creates a list with all the documents in it
  6174. *
  6175. * @return string
  6176. */
  6177. function get_documents()
  6178. {
  6179. global $_course;
  6180. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6181. $sql_doc = "
  6182. SELECT *
  6183. FROM " . $tbl_doc . "
  6184. WHERE
  6185. path NOT LIKE '%_DELETED_%'
  6186. ORDER BY path ASC";
  6187. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  6188. $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';}\"" . '><img alt="" src="../img/lp_' . TOOL_DOCUMENT . '.gif" style="margin-right:5px;" title="" />'.get_lang("Document").'</div>';
  6189. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6190. $resources=api_store_result($res_doc);
  6191. $resources_sorted = array();
  6192. // if you want to debug it, I advise you to do "echo" on the eval statements
  6193. foreach($resources as $resource)
  6194. {
  6195. $resource_paths = explode('/',$resource['path']);
  6196. array_shift($resource_paths);
  6197. $path_to_eval = $last_path = '';
  6198. $is_file = false;
  6199. foreach($resource_paths as $key => $resource_path)
  6200. {
  6201. if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1)
  6202. { // it's a folder
  6203. $path_to_eval .= '["'.$resource_path.'"]["files"]';
  6204. }
  6205. else if(strpos($resource_path,'.')!==false)
  6206. $is_file = true;
  6207. $last_path = $resource_path;
  6208. }
  6209. if($is_file)
  6210. {
  6211. eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";');
  6212. }
  6213. else
  6214. {
  6215. eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';');
  6216. }
  6217. }
  6218. $return .=$this->write_resources_tree($resources_sorted);
  6219. $return .='</div>';
  6220. if(Database::num_rows($res_doc) == 0)
  6221. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  6222. return $return;
  6223. }
  6224. /**
  6225. * Generate and return an HTML list of resources based on a given array.
  6226. *
  6227. * This list is used to show the course creator a list of available resources to choose from
  6228. * when creating a learning path.
  6229. * @param array Array of elements to add to the list
  6230. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6231. * @return string The HTML list
  6232. */
  6233. function write_resources_tree($resources_sorted, $num=0){
  6234. include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
  6235. if(count($resources_sorted)>0)
  6236. {
  6237. foreach($resources_sorted as $key=>$resource)
  6238. {
  6239. if(is_int($resource['id']))
  6240. { // it's a folder
  6241. $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'].'">';
  6242. $return .= $this->write_resources_tree($resource['files'], $num+1);
  6243. $return .= "</div></div>\r\n";
  6244. }
  6245. else
  6246. {
  6247. // it's a file
  6248. $icon = choose_image($resource);
  6249. $position = strrpos($icon,'.');
  6250. $icon=substr($icon,0,$position).'_small.gif';
  6251. $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";
  6252. }
  6253. }
  6254. }
  6255. return $return;
  6256. }
  6257. /**
  6258. * Creates a list with all the exercises (quiz) in it
  6259. *
  6260. * @return string
  6261. */
  6262. function get_exercises()
  6263. {
  6264. // new for hotpotatoes
  6265. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6266. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6267. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  6268. $sql_quiz = "
  6269. SELECT *
  6270. FROM " . $tbl_quiz . "
  6271. WHERE active<>'-1'
  6272. ORDER BY title ASC";
  6273. $sql_hot = "SELECT * FROM ".$tbl_doc." " .
  6274. " WHERE path LIKE '".$uploadPath."/%/%htm%'" .
  6275. " ORDER BY id ASC";
  6276. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  6277. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  6278. $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>';
  6279. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6280. while ($row_hot = Database::fetch_array($res_hot))
  6281. {
  6282. $return .= '<div class="lp_resource_element">';
  6283. //display quizhotpotatoes
  6284. $return .= '<img alt="" src="../img/jqz.jpg" style="margin-right:5px;" title="" />';
  6285. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_hot['title'] . '</a>';
  6286. //$return .= $row_quiz['title'];
  6287. $return .= '</div>';
  6288. }
  6289. while($row_quiz = Database::fetch_array($res_quiz))
  6290. {
  6291. $return .= '<div class="lp_resource_element">';
  6292. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6293. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
  6294. //$return .= $row_quiz['title'];
  6295. $return .= '</div>';
  6296. }
  6297. if(Database::num_rows($res_quiz) == 0)
  6298. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  6299. $return .= '<div class="lp_resource_element">';
  6300. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6301. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6302. $return .= '</div>';
  6303. $return .= '</div>';
  6304. return $return;
  6305. }
  6306. /**
  6307. * Creates a list with all the links in it
  6308. *
  6309. * @return string
  6310. */
  6311. function get_links()
  6312. {
  6313. $tbl_link = Database::get_course_table(TABLE_LINK);
  6314. $sql_link = "
  6315. SELECT *
  6316. FROM " . $tbl_link . "
  6317. ORDER BY title ASC";
  6318. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  6319. $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>';
  6320. $return .= '<div class="lp_resource_elements" id="resLink">';
  6321. while($row_link = Database::fetch_array($res_link))
  6322. {
  6323. $return .= '<div class="lp_resource_element">';
  6324. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6325. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_LINK . '&amp;file=' . $row_link['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
  6326. $return .= '</div>';
  6327. }
  6328. $return .= '<div class="lp_resource_element">';
  6329. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6330. $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>';
  6331. $return .= '</div>';
  6332. if(Database::num_rows($res_link) == 0)
  6333. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  6334. $return .= '</div>';
  6335. return $return;
  6336. }
  6337. /**
  6338. * Creates a list with all the student publications in it
  6339. *
  6340. * @return unknown
  6341. */
  6342. function get_student_publications()
  6343. {
  6344. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  6345. $sql_student = "
  6346. SELECT *
  6347. FROM " . $tbl_student . "
  6348. ORDER BY title ASC";
  6349. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  6350. $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>';
  6351. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6352. $return .= '<div class="lp_resource_element">';
  6353. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6354. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  6355. $return .= '</div>';
  6356. $return .= '</div>';
  6357. return $return;
  6358. }
  6359. /**
  6360. * Creates a list with all the forums in it
  6361. *
  6362. * @return string
  6363. */
  6364. function get_forums()
  6365. {
  6366. include ('../forum/forumfunction.inc.php');
  6367. include ('../forum/forumconfig.inc.php');
  6368. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  6369. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6370. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6371. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6372. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6373. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6374. $a_forums = get_forums();
  6375. $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>';
  6376. $return .= '<div class="lp_resource_elements" id="forums">';
  6377. foreach($a_forums as $forum)
  6378. {
  6379. $return .= '<div class="lp_resource_element">';
  6380. $return .= '<script type="text/javascript">
  6381. function toggle_forum(forum_id){
  6382. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6383. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6384. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  6385. }
  6386. else {
  6387. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6388. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  6389. }
  6390. }
  6391. </script>
  6392. ';
  6393. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6394. $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>
  6395. <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_'.$forum['forum_id'].'_content">';
  6396. $a_threads = get_threads($forum['forum_id']);
  6397. if(is_array($a_threads)){
  6398. foreach($a_threads as $thread)
  6399. {
  6400. $return .= '<li><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . $thread['thread_title'] . '</a></li>';
  6401. }
  6402. }
  6403. $return .= '</ul></div>';
  6404. }
  6405. $return .= '<div class="lp_resource_element">';
  6406. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6407. $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>';
  6408. $return .= '</div>';
  6409. return $return;
  6410. }
  6411. /**
  6412. * Exports the learning path as a SCORM package. This is the main function that
  6413. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6414. * whole thing and returns the zip.
  6415. *
  6416. * This method needs to be called in PHP5, as it will fail with non-adequate
  6417. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6418. * you need to call it on a learnpath object.
  6419. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6420. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6421. * path has been modified, it should use the generic method here below.
  6422. * @TODO link this function with the export_lp() function in the same class
  6423. * @param string Optional name of zip file. If none, title of learnpath is
  6424. * domesticated and trailed with ".zip"
  6425. * @return string Returns the zip package string, or null if error
  6426. */
  6427. function scorm_export()
  6428. {
  6429. global $_course;
  6430. if (!class_exists('DomDocument'))
  6431. {
  6432. error_log('DOM functions not supported for PHP version below 5.0',0);
  6433. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6434. return null;
  6435. }
  6436. //remove memory and time limits as much as possible as this might be a long process...
  6437. if(function_exists('ini_set'))
  6438. {
  6439. $mem = ini_get('memory_limit');
  6440. if(substr($mem,-1,1)=='M')
  6441. {
  6442. $mem_num = substr($mem,0,-1);
  6443. if($mem_num<128)
  6444. {
  6445. ini_set('memory_limit','128M');
  6446. }
  6447. }
  6448. else
  6449. {
  6450. ini_set('memory_limit','128M');
  6451. }
  6452. ini_set('max_execution_time',600);
  6453. //}else{
  6454. //error_log('Scorm export: could not change memory and time limits',0);
  6455. }
  6456. //Create the zip handler (this will remain available throughout the method)
  6457. $garbage_path = api_get_path(GARBAGE_PATH);
  6458. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6459. $temp_dir_short = uniqid();
  6460. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  6461. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6462. $zip_folder=new PclZip($temp_zip_file);
  6463. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6464. $root_path = $main_path = api_get_path(SYS_PATH);
  6465. $files_cleanup = array();
  6466. //place to temporarily stash the zipfiles
  6467. //create the temp dir if it doesn't exist
  6468. //or do a cleanup befor creating the zipfile
  6469. if(!is_dir($temp_zip_dir))
  6470. {
  6471. mkdir($temp_zip_dir);
  6472. }
  6473. else
  6474. {//cleanup: check the temp dir for old files and delete them
  6475. $handle=opendir($temp_zip_dir);
  6476. while (false!==($file = readdir($handle)))
  6477. {
  6478. if ($file != "." && $file != "..")
  6479. {
  6480. unlink("$temp_zip_dir/$file");
  6481. }
  6482. }
  6483. closedir($handle);
  6484. }
  6485. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6486. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6487. {
  6488. // remove the possible . at the end of the path
  6489. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6490. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6491. $perm = api_get_setting('permissions_for_new_directories');
  6492. $perm = octdec(!empty($perm)?$perm:'0770');
  6493. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6494. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6495. }
  6496. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6497. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6498. //Aggregation Model official document, secion "2.3 Content Packaging"
  6499. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6500. $root = $xmldoc->createElement('manifest');
  6501. $root->setAttribute('identifier','SingleCourseManifest');
  6502. $root->setAttribute('version','1.1');
  6503. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6504. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6505. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6506. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  6507. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  6508. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6509. //Build mandatory sub-root container elements
  6510. $metadata = $xmldoc->createElement('metadata');
  6511. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6512. $metadata->appendChild($md_schema);
  6513. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6514. $metadata->appendChild($md_schemaversion);
  6515. $root->appendChild($metadata);
  6516. $organizations = $xmldoc->createElement('organizations');
  6517. $resources = $xmldoc->createElement('resources');
  6518. //Build the only organization we will use in building our learnpaths
  6519. $organizations->setAttribute('default','dokeos_scorm_export');
  6520. $organization = $xmldoc->createElement('organization');
  6521. $organization->setAttribute('identifier','dokeos_scorm_export');
  6522. //to set the title of the SCORM entity (=organization), we take the name given
  6523. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6524. //learning path charset) as it is the encoding that defines how it is stored
  6525. //in the database. Then we convert it to HTML entities again as the "&" character
  6526. //alone is not authorized in XML (must be &amp;)
  6527. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6528. global $charset;
  6529. $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6530. $organization->appendChild($org_title);
  6531. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6532. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6533. //format
  6534. $link_updates = array();
  6535. foreach($this->items as $index => $item){
  6536. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6537. {
  6538. //get included documents from this item
  6539. if($item->type=='sco')
  6540. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6541. else
  6542. $inc_docs = $item->get_resources_from_source();
  6543. //give a child element <item> to the <organization> element
  6544. $my_item_id = $item->get_id();
  6545. $my_item = $xmldoc->createElement('item');
  6546. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6547. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6548. $my_item->setAttribute('isvisible','true');
  6549. //give a child element <title> to the <item> element
  6550. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6551. $my_item->appendChild($my_title);
  6552. //give a child element <adlcp:prerequisites> to the <item> element
  6553. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6554. $my_prereqs->setAttribute('type','aicc_script');
  6555. $my_item->appendChild($my_prereqs);
  6556. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6557. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6558. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6559. //$xmldoc->createElement('adlcp:timelimitaction','');
  6560. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6561. //$xmldoc->createElement('adlcp:datafromlms','');
  6562. //give a child element <adlcp:masteryscore> to the <item> element
  6563. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6564. $my_item->appendChild($my_masteryscore);
  6565. //attach this item to the organization element or hits parent if there is one
  6566. if(!empty($item->parent) && $item->parent!=0)
  6567. {
  6568. $children = $organization->childNodes;
  6569. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6570. if(is_object($possible_parent))
  6571. {
  6572. $possible_parent->appendChild($my_item);
  6573. }
  6574. else
  6575. {
  6576. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6577. }
  6578. }
  6579. else
  6580. {
  6581. if($this->debug>0){error_log('No parent');}
  6582. $organization->appendChild($my_item);
  6583. }
  6584. //get the path of the file(s) from the course directory root
  6585. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6586. $my_xml_file_path = htmlentities($my_file_path);
  6587. $my_sub_dir = dirname($my_file_path);
  6588. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6589. //give a <resource> child to the <resources> element
  6590. $my_resource = $xmldoc->createElement('resource');
  6591. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6592. $my_resource->setAttribute('type','webcontent');
  6593. $my_resource->setAttribute('href',$my_xml_file_path);
  6594. //adlcp:scormtype can be either 'sco' or 'asset'
  6595. if($item->type=='sco')
  6596. {
  6597. $my_resource->setAttribute('adlcp:scormtype','sco');
  6598. }
  6599. else
  6600. {
  6601. $my_resource->setAttribute('adlcp:scormtype','asset');
  6602. }
  6603. //xml:base is the base directory to find the files declared in this resource
  6604. $my_resource->setAttribute('xml:base','');
  6605. //give a <file> child to the <resource> element
  6606. $my_file = $xmldoc->createElement('file');
  6607. $my_file->setAttribute('href',$my_xml_file_path);
  6608. $my_resource->appendChild($my_file);
  6609. //dependency to other files - not yet supported
  6610. $i = 1;
  6611. foreach($inc_docs as $doc_info)
  6612. {
  6613. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6614. $my_dep = $xmldoc->createElement('resource');
  6615. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6616. $my_dep->setAttribute('identifier',$res_id);
  6617. $my_dep->setAttribute('type','webcontent');
  6618. $my_dep->setAttribute('adlcp:scormtype','asset');
  6619. $my_dep_file = $xmldoc->createElement('file');
  6620. //check type of URL
  6621. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6622. if($doc_info[1] == 'remote')
  6623. { //remote file. Save url as is
  6624. $my_dep_file->setAttribute('href',$doc_info[0]);
  6625. $my_dep->setAttribute('xml:base','');
  6626. }elseif($doc_info[1] == 'local'){
  6627. switch($doc_info[2])
  6628. {
  6629. case 'url': //local URL - save path as url for now, don't zip file
  6630. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6631. $current_dir = dirname($abs_path);
  6632. $file_path = realpath($abs_path);
  6633. $my_dep_file->setAttribute('href',$file_path);
  6634. $my_dep->setAttribute('xml:base','');
  6635. if(strstr($file_path,$main_path) !== false)
  6636. {//the calculated real path is really inside the dokeos root path
  6637. //reduce file path to what's under the DocumentRoot
  6638. $file_path = substr($file_path,strlen($root_path)-1);
  6639. //echo $file_path;echo '<br><br>';
  6640. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6641. $zip_files_abs[] = $file_path;
  6642. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6643. $my_dep_file->setAttribute('href',$file_path);
  6644. $my_dep->setAttribute('xml:base','');
  6645. }
  6646. else if (empty($file_path))
  6647. {
  6648. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6649. if(strpos($document_root,-1)=='/')
  6650. {
  6651. $document_root = substr(0, -1, $document_root);
  6652. }*/
  6653. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6654. $file_path = str_replace('//','/',$file_path);
  6655. if(file_exists($file_path))
  6656. {
  6657. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6658. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6659. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6660. $my_dep_file->setAttribute('href',$file_path);
  6661. $my_dep->setAttribute('xml:base','');
  6662. }
  6663. }
  6664. break;
  6665. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6666. $my_dep_file->setAttribute('href',$doc_info[0]);
  6667. $my_dep->setAttribute('xml:base','');
  6668. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6669. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  6670. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  6671. $abs_img_path_without_subdir = $doc_info[0];
  6672. $relp = api_get_path(REL_PATH); //the url-append config param
  6673. $pos = strpos($abs_img_path_without_subdir,$relp);
  6674. if($pos===0)
  6675. {
  6676. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  6677. }
  6678. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6679. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  6680. $file_path = str_replace('//','/',$file_path);
  6681. //error_log(__LINE__.'Abs path: '.$file_path,0);
  6682. //prepare the current directory path (until just under 'document') with a trailing slash
  6683. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6684. //check if the current document is in that path
  6685. if(strstr($file_path,$cur_path) !== false)
  6686. {
  6687. //the document is in that path, now get the relative path
  6688. //to the containing document
  6689. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  6690. $relative_path ='';
  6691. if(strstr($file_path,$cur_path)!==false)
  6692. {
  6693. $relative_path = substr($file_path,strlen($orig_file_path));
  6694. $file_path = substr($file_path,strlen($cur_path));
  6695. }
  6696. else
  6697. {
  6698. //this case is still a problem as it's difficult to calculate a relative path easily
  6699. //might still generate wrong links
  6700. //$file_path = substr($file_path,strlen($cur_path));
  6701. //calculate the directory path to the current file (without trailing slash)
  6702. $my_relative_path = dirname($file_path);
  6703. $my_relative_file = basename($file_path);
  6704. //calculate the directory path to the containing file (without trailing slash)
  6705. $my_orig_file_path = substr($orig_file_path,0,-1);
  6706. $dotdot = '';
  6707. $subdir = '';
  6708. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  6709. {
  6710. $my_relative_path2 = dirname($my_relative_path);
  6711. $my_orig_file_path = dirname($my_orig_file_path);
  6712. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  6713. $dotdot += '../';
  6714. $my_relative_path = $my_relative_path2;
  6715. }
  6716. $relative_path = $dotdot.$subdir.$my_relative_file;
  6717. }
  6718. //put the current document in the zip (this array is the array
  6719. //that will manage documents already in the course folder - relative)
  6720. $zip_files[] = $file_path;
  6721. //update the links to the current document in the containing document (make them relative)
  6722. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  6723. $my_dep_file->setAttribute('href',$file_path);
  6724. $my_dep->setAttribute('xml:base','');
  6725. }
  6726. elseif(strstr($file_path,$main_path) !== false)
  6727. {//the calculated real path is really inside the dokeos root path
  6728. //reduce file path to what's under the DocumentRoot
  6729. $file_path = substr($file_path,strlen($root_path));
  6730. //echo $file_path;echo '<br><br>';
  6731. //error_log('Reduced path: '.$file_path,0);
  6732. $zip_files_abs[] = $file_path;
  6733. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6734. $my_dep_file->setAttribute('href','document/'.$file_path);
  6735. $my_dep->setAttribute('xml:base','');
  6736. }
  6737. else if (empty($file_path))
  6738. {
  6739. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6740. if(strpos($document_root,-1)=='/')
  6741. {
  6742. $document_root = substr(0, -1, $document_root);
  6743. }*/
  6744. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6745. $file_path = str_replace('//','/',$file_path);
  6746. if(file_exists($file_path))
  6747. {
  6748. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6749. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6750. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6751. $my_dep_file->setAttribute('href','document/'.$file_path);
  6752. $my_dep->setAttribute('xml:base','');
  6753. }
  6754. }
  6755. break;
  6756. 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
  6757. if(substr($doc_info[0],0,2)=='..')
  6758. { //relative path going up
  6759. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6760. $file_path = realpath($current_dir.$doc_info[0]);
  6761. //error_log($file_path.' <-> '.$main_path,0);
  6762. if(strstr($file_path,$main_path) !== false)
  6763. {//the calculated real path is really inside the dokeos root path
  6764. //reduce file path to what's under the DocumentRoot
  6765. $file_path = substr($file_path,strlen($root_path));
  6766. //error_log('Reduced path: '.$file_path,0);
  6767. $zip_files_abs[] = $file_path;
  6768. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6769. $my_dep_file->setAttribute('href','document/'.$file_path);
  6770. $my_dep->setAttribute('xml:base','');
  6771. }
  6772. }else{
  6773. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6774. $my_dep_file->setAttribute('href',$doc_info[0]);
  6775. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6776. }
  6777. break;
  6778. default:
  6779. $my_dep_file->setAttribute('href',$doc_info[0]);
  6780. $my_dep->setAttribute('xml:base','');
  6781. break;
  6782. }
  6783. }
  6784. $my_dep->appendChild($my_dep_file);
  6785. $resources->appendChild($my_dep);
  6786. $dependency = $xmldoc->createElement('dependency');
  6787. $dependency->setAttribute('identifierref',$res_id);
  6788. $my_resource->appendChild($dependency);
  6789. $i++;
  6790. }
  6791. //$my_dependency = $xmldoc->createElement('dependency');
  6792. //$my_dependency->setAttribute('identifierref','');
  6793. $resources->appendChild($my_resource);
  6794. $zip_files[] = $my_file_path;
  6795. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  6796. }
  6797. else
  6798. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  6799. if($item->type == TOOL_LINK)
  6800. {
  6801. $my_item = $xmldoc->createElement('item');
  6802. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6803. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6804. $my_item->setAttribute('isvisible','true');
  6805. //give a child element <title> to the <item> element
  6806. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6807. $my_item->appendChild($my_title);
  6808. //give a child element <adlcp:prerequisites> to the <item> element
  6809. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6810. $my_prereqs->setAttribute('type','aicc_script');
  6811. $my_item->appendChild($my_prereqs);
  6812. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6813. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6814. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6815. //$xmldoc->createElement('adlcp:timelimitaction','');
  6816. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6817. //$xmldoc->createElement('adlcp:datafromlms','');
  6818. //give a child element <adlcp:masteryscore> to the <item> element
  6819. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6820. $my_item->appendChild($my_masteryscore);
  6821. //attach this item to the organization element or its parent if there is one
  6822. if(!empty($item->parent) && $item->parent!=0)
  6823. {
  6824. $children = $organization->childNodes;
  6825. for($i=0;$i<$children->length;$i++){
  6826. $item_temp = $children->item($i);
  6827. if ($item_temp -> nodeName == 'item')
  6828. {
  6829. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6830. {
  6831. $item_temp -> appendChild($my_item);
  6832. }
  6833. }
  6834. }
  6835. }
  6836. else
  6837. {
  6838. $organization->appendChild($my_item);
  6839. }
  6840. $my_file_path = 'link_'.$item->get_id().'.html';
  6841. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  6842. $rs = api_sql_query($sql, __FILE__, __LINE__);
  6843. if($link = Database :: fetch_array($rs))
  6844. {
  6845. $url = $link['url'];
  6846. $title = stripslashes($link['title']);
  6847. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  6848. $my_xml_file_path = htmlentities($my_file_path);
  6849. $my_sub_dir = dirname($my_file_path);
  6850. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6851. //give a <resource> child to the <resources> element
  6852. $my_resource = $xmldoc->createElement('resource');
  6853. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6854. $my_resource->setAttribute('type','webcontent');
  6855. $my_resource->setAttribute('href',$my_xml_file_path);
  6856. //adlcp:scormtype can be either 'sco' or 'asset'
  6857. $my_resource->setAttribute('adlcp:scormtype','asset');
  6858. //xml:base is the base directory to find the files declared in this resource
  6859. $my_resource->setAttribute('xml:base','');
  6860. //give a <file> child to the <resource> element
  6861. $my_file = $xmldoc->createElement('file');
  6862. $my_file->setAttribute('href',$my_xml_file_path);
  6863. $my_resource->appendChild($my_file);
  6864. $resources->appendChild($my_resource);
  6865. }
  6866. }
  6867. elseif($item->type == TOOL_QUIZ)
  6868. {
  6869. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  6870. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  6871. $exe = new Exercise();
  6872. $exe->read($exe_id);
  6873. $my_item = $xmldoc->createElement('item');
  6874. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6875. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6876. $my_item->setAttribute('isvisible','true');
  6877. //give a child element <title> to the <item> element
  6878. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6879. $my_item->appendChild($my_title);
  6880. //give a child element <adlcp:prerequisites> to the <item> element
  6881. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6882. $my_prereqs->setAttribute('type','aicc_script');
  6883. $my_item->appendChild($my_prereqs);
  6884. //give a child element <adlcp:masteryscore> to the <item> element
  6885. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6886. $my_item->appendChild($my_masteryscore);
  6887. //attach this item to the organization element or hits parent if there is one
  6888. if(!empty($item->parent) && $item->parent!=0)
  6889. {
  6890. $children = $organization->childNodes;
  6891. for($i=0;$i<$children->length;$i++){
  6892. $item_temp = $children->item($i);
  6893. if ($item_temp -> nodeName == 'item')
  6894. {
  6895. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6896. {
  6897. $item_temp -> appendChild($my_item);
  6898. }
  6899. }
  6900. }
  6901. }
  6902. else
  6903. {
  6904. $organization->appendChild($my_item);
  6905. }
  6906. //include export scripts
  6907. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  6908. //get the path of the file(s) from the course directory root
  6909. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6910. $my_file_path = 'quiz_'.$item->get_id().'.html';
  6911. //write the contents of the exported exercise into a (big) html file
  6912. //to later pack it into the exported SCORM. The file will be removed afterwards
  6913. $contents = export_exercise($exe_id,true);
  6914. $tmp_file_path = $garbage_path.$temp_dir_short.'/'.$my_file_path;
  6915. $res = file_put_contents($tmp_file_path,$contents);
  6916. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  6917. $files_cleanup[] = $tmp_file_path;
  6918. //error_log($tmp_path);die();
  6919. $my_xml_file_path = htmlentities($my_file_path);
  6920. $my_sub_dir = dirname($my_file_path);
  6921. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6922. //give a <resource> child to the <resources> element
  6923. $my_resource = $xmldoc->createElement('resource');
  6924. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6925. $my_resource->setAttribute('type','webcontent');
  6926. $my_resource->setAttribute('href',$my_xml_file_path);
  6927. //adlcp:scormtype can be either 'sco' or 'asset'
  6928. $my_resource->setAttribute('adlcp:scormtype','sco');
  6929. //xml:base is the base directory to find the files declared in this resource
  6930. $my_resource->setAttribute('xml:base','');
  6931. //give a <file> child to the <resource> element
  6932. $my_file = $xmldoc->createElement('file');
  6933. $my_file->setAttribute('href',$my_xml_file_path);
  6934. $my_resource->appendChild($my_file);
  6935. //get included docs
  6936. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  6937. //dependency to other files - not yet supported
  6938. $i = 1;
  6939. foreach($inc_docs as $doc_info)
  6940. {
  6941. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6942. $my_dep = $xmldoc->createElement('resource');
  6943. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6944. $my_dep->setAttribute('identifier',$res_id);
  6945. $my_dep->setAttribute('type','webcontent');
  6946. $my_dep->setAttribute('adlcp:scormtype','asset');
  6947. $my_dep_file = $xmldoc->createElement('file');
  6948. //check type of URL
  6949. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6950. if($doc_info[1] == 'remote')
  6951. { //remote file. Save url as is
  6952. $my_dep_file->setAttribute('href',$doc_info[0]);
  6953. $my_dep->setAttribute('xml:base','');
  6954. }elseif($doc_info[1] == 'local'){
  6955. switch($doc_info[2])
  6956. {
  6957. case 'url': //local URL - save path as url for now, don't zip file
  6958. //save file but as local file (retrieve from URL)
  6959. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6960. $current_dir = dirname($abs_path);
  6961. $file_path = realpath($abs_path);
  6962. $my_dep_file->setAttribute('href','document/'.$file_path);
  6963. $my_dep->setAttribute('xml:base','');
  6964. if(strstr($file_path,$main_path) !== false)
  6965. {//the calculated real path is really inside the dokeos root path
  6966. //reduce file path to what's under the DocumentRoot
  6967. $file_path = substr($file_path,strlen($root_path));
  6968. //echo $file_path;echo '<br><br>';
  6969. //error_log('Reduced path: '.$file_path,0);
  6970. $zip_files_abs[] = $file_path;
  6971. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6972. $my_dep_file->setAttribute('href','document/'.$file_path);
  6973. $my_dep->setAttribute('xml:base','');
  6974. }
  6975. else if (empty($file_path))
  6976. {
  6977. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6978. if(strpos($document_root,-1)=='/')
  6979. {
  6980. $document_root = substr(0, -1, $document_root);
  6981. }*/
  6982. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6983. $file_path = str_replace('//','/',$file_path);
  6984. if(file_exists($file_path))
  6985. {
  6986. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6987. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6988. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  6989. $my_dep_file->setAttribute('href','document/'.$file_path);
  6990. $my_dep->setAttribute('xml:base','');
  6991. }
  6992. }
  6993. break;
  6994. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6995. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6996. $file_path = realpath($doc_info[0]);
  6997. $my_dep_file->setAttribute('href',$file_path);
  6998. $my_dep->setAttribute('xml:base','');
  6999. if(strstr($file_path,$main_path) !== false)
  7000. {//the calculated real path is really inside the dokeos root path
  7001. //reduce file path to what's under the DocumentRoot
  7002. $file_path = substr($file_path,strlen($root_path));
  7003. //echo $file_path;echo '<br><br>';
  7004. //error_log('Reduced path: '.$file_path,0);
  7005. $zip_files_abs[] = $file_path;
  7006. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7007. $my_dep_file->setAttribute('href','document/'.$file_path);
  7008. $my_dep->setAttribute('xml:base','');
  7009. }
  7010. else if (empty($file_path))
  7011. {
  7012. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7013. if(strpos($document_root,-1)=='/')
  7014. {
  7015. $document_root = substr(0, -1, $document_root);
  7016. }*/
  7017. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7018. $file_path = str_replace('//','/',$file_path);
  7019. if(file_exists($file_path))
  7020. {
  7021. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7022. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7023. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7024. $my_dep_file->setAttribute('href','document/'.$file_path);
  7025. $my_dep->setAttribute('xml:base','');
  7026. }
  7027. }
  7028. break;
  7029. 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
  7030. if(substr($doc_info[0],0,2)=='..')
  7031. { //relative path going up
  7032. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7033. $file_path = realpath($current_dir.$doc_info[0]);
  7034. //error_log($file_path.' <-> '.$main_path,0);
  7035. if(strstr($file_path,$main_path) !== false)
  7036. {//the calculated real path is really inside the dokeos root path
  7037. //reduce file path to what's under the DocumentRoot
  7038. $file_path = substr($file_path,strlen($root_path));
  7039. //error_log('Reduced path: '.$file_path,0);
  7040. $zip_files_abs[] = $file_path;
  7041. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7042. $my_dep_file->setAttribute('href','document/'.$file_path);
  7043. $my_dep->setAttribute('xml:base','');
  7044. }
  7045. }else{
  7046. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7047. $my_dep_file->setAttribute('href',$doc_info[0]);
  7048. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7049. }
  7050. break;
  7051. default:
  7052. $my_dep_file->setAttribute('href',$doc_info[0]);
  7053. $my_dep->setAttribute('xml:base','');
  7054. break;
  7055. }
  7056. }
  7057. $my_dep->appendChild($my_dep_file);
  7058. $resources->appendChild($my_dep);
  7059. $dependency = $xmldoc->createElement('dependency');
  7060. $dependency->setAttribute('identifierref',$res_id);
  7061. $my_resource->appendChild($dependency);
  7062. $i++;
  7063. }
  7064. $resources->appendChild($my_resource);
  7065. $zip_files[] = $my_file_path;
  7066. }
  7067. else
  7068. {
  7069. //get the path of the file(s) from the course directory root
  7070. $my_file_path = 'non_exportable.html';
  7071. $my_xml_file_path = htmlentities($my_file_path);
  7072. $my_sub_dir = dirname($my_file_path);
  7073. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7074. //give a <resource> child to the <resources> element
  7075. $my_resource = $xmldoc->createElement('resource');
  7076. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7077. $my_resource->setAttribute('type','webcontent');
  7078. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7079. //adlcp:scormtype can be either 'sco' or 'asset'
  7080. $my_resource->setAttribute('adlcp:scormtype','asset');
  7081. //xml:base is the base directory to find the files declared in this resource
  7082. $my_resource->setAttribute('xml:base','');
  7083. //give a <file> child to the <resource> element
  7084. $my_file = $xmldoc->createElement('file');
  7085. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7086. $my_resource->appendChild($my_file);
  7087. $resources->appendChild($my_resource);
  7088. }
  7089. }
  7090. }
  7091. $organizations->appendChild($organization);
  7092. $root->appendChild($organizations);
  7093. $root->appendChild($resources);
  7094. $xmldoc->appendChild($root);
  7095. //todo: add a readme file here, with a short description and a link to the Reload player
  7096. //then add the file to the zip, then destroy the file (this is done automatically)
  7097. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7098. //error_log(print_r($zip_files,true),0);
  7099. foreach($zip_files as $file_path)
  7100. {
  7101. if(empty($file_path)){continue;}
  7102. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7103. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  7104. $this->create_path($dest_file);
  7105. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  7106. //echo $main_path.$file_path.'<br>';
  7107. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7108. //check if the file needs a link update
  7109. if(in_array($file_path,array_keys($link_updates))){
  7110. $string = file_get_contents($dest_file);
  7111. unlink($dest_file);
  7112. foreach($link_updates[$file_path] as $old_new)
  7113. {
  7114. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7115. //this is an ugly hack that allows .flv files to be found by the flv player that
  7116. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7117. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7118. // ../../.. to return from inc/lib/flv_player to the document/main path
  7119. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7120. {
  7121. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7122. }
  7123. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7124. {
  7125. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7126. }
  7127. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7128. }
  7129. file_put_contents($dest_file,$string);
  7130. }
  7131. }
  7132. foreach($zip_files_abs as $file_path)
  7133. {
  7134. if(empty($file_path)){continue;}
  7135. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7136. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7137. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7138. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  7139. $this->create_path($dest_file);
  7140. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  7141. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  7142. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7143. copy($main_path.$file_path,$dest_file);
  7144. //check if the file needs a link update
  7145. if(in_array($file_path,array_keys($link_updates)))
  7146. {
  7147. $string = file_get_contents($dest_file);
  7148. unlink($dest_file);
  7149. foreach($link_updates[$file_path] as $old_new)
  7150. {
  7151. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7152. //this is an ugly hack that allows .flv files to be found by the flv player that
  7153. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7154. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7155. // ../../.. to return from inc/lib/flv_player to the document/main path
  7156. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7157. {
  7158. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7159. }
  7160. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7161. }
  7162. file_put_contents($dest_file,$string);
  7163. }
  7164. }
  7165. if(is_array($links_to_create))
  7166. {
  7167. foreach($links_to_create as $file=>$link)
  7168. {
  7169. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7170. file_put_contents($garbage_path.$temp_dir_short.'/'.$file, $file_content);
  7171. }
  7172. }
  7173. // add non exportable message explanation
  7174. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7175. $file_content =
  7176. <<<EOD
  7177. <html>
  7178. <head>
  7179. <style>
  7180. .error-message {
  7181. font-family: arial, verdana, helvetica, sans-serif;
  7182. border-width: 1px;
  7183. border-style: solid;
  7184. left: 50%;
  7185. margin: 10px auto;
  7186. min-height: 30px;
  7187. padding: 5px;
  7188. right: 50%;
  7189. width: 500px;
  7190. background-color: #FFD1D1;
  7191. border-color: #FF0000;
  7192. color: #000;
  7193. }
  7194. </style>
  7195. <body>
  7196. <div class="error-message">
  7197. $lang_not_exportable
  7198. </div>
  7199. </body>
  7200. </html>
  7201. EOD;
  7202. if(!is_dir($garbage_path.$temp_dir_short.'/document'))
  7203. {
  7204. @mkdir($garbage_path.$temp_dir_short.'/document');
  7205. }
  7206. file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7207. //Add the extra files that go along with a SCORM package
  7208. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7209. $extra_files = scandir($main_code_path);
  7210. foreach($extra_files as $extra_file)
  7211. {
  7212. if(strpos($extra_file,'.')===0) continue;
  7213. else
  7214. {
  7215. $dest_file = $garbage_path.$temp_dir_short.'/'.$extra_file;
  7216. $this->create_path($dest_file);
  7217. copy($main_code_path.$extra_file,$dest_file);
  7218. }
  7219. }
  7220. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7221. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7222. $zip_folder->add($garbage_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/'.$temp_dir_short.'/');
  7223. //clean possible temporary files
  7224. foreach($files_cleanup as $file)
  7225. {
  7226. $res = unlink($file);
  7227. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7228. }
  7229. //Send file to client
  7230. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7231. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7232. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7233. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7234. }
  7235. /**
  7236. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7237. * if it doesn't exist
  7238. */
  7239. function create_path($path){
  7240. $path_bits = split('/',dirname($path));
  7241. $path_built = '/';
  7242. foreach($path_bits as $bit){
  7243. if(!empty($bit)){
  7244. $new_path = $path_built.$bit;
  7245. if(is_dir($new_path)){
  7246. $path_built = $new_path.'/';
  7247. }
  7248. else
  7249. {
  7250. mkdir($new_path);
  7251. $path_built = $new_path.'/';
  7252. }
  7253. }
  7254. }
  7255. }
  7256. /**
  7257. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7258. * @return boolean The results of the unlink function, or false if there was no image to start with
  7259. */
  7260. function delete_lp_image()
  7261. {
  7262. $img = $this->get_preview_image();
  7263. if ($img!='')
  7264. {
  7265. $del_file = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$img;
  7266. $this->set_preview_image('');
  7267. return @unlink($del_file);
  7268. }
  7269. else
  7270. {
  7271. return false;
  7272. }
  7273. }
  7274. /**
  7275. * Uploads an author image to the upload/learning_path/images directory
  7276. * @param array The image array, coming from the $_FILES superglobal
  7277. * @return boolean True on success, false on error
  7278. */
  7279. function upload_image($image_array)
  7280. {
  7281. $image_moved=false;
  7282. if(!empty($image_array['name']))
  7283. {
  7284. $upload_ok = process_uploaded_file($image_array);
  7285. $has_attachment=true;
  7286. }
  7287. else
  7288. {
  7289. $image_moved=true;
  7290. }
  7291. if($upload_ok)
  7292. {
  7293. if ($has_attachment)
  7294. {
  7295. $courseDir = api_get_course_path().'/upload/learning_path/images';
  7296. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7297. $updir = $sys_course_path.$courseDir;
  7298. // Try to add an extension to the file if it hasn't one
  7299. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7300. if (!filter_extension($new_file_name))
  7301. {
  7302. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7303. $image_moved=false;
  7304. }
  7305. else
  7306. {
  7307. $file_extension = explode('.', $image_array['name']);
  7308. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7309. $new_file_name = uniqid('').'.'.$file_extension;
  7310. $new_path=$updir.'/'.$new_file_name;
  7311. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7312. // resize the image
  7313. include_once (api_get_path(LIBRARY_PATH).'image.lib.php');
  7314. $temp = new image($image_array['tmp_name']);
  7315. $picture_infos=getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7316. if ($picture_infos[0]>240)
  7317. $thumbwidth=240;
  7318. else
  7319. $thumbwidth=$picture_infos[0];
  7320. if ($picture_infos[1]>100)
  7321. $new_height=100;
  7322. else
  7323. $new_height = $picture_infos[1];
  7324. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7325. $temp->resize($thumbwidth,$new_height,0);
  7326. $type=$picture_infos[2];
  7327. $result=false;
  7328. switch ($type)
  7329. {
  7330. case 2 :
  7331. $result=$temp->send_image('JPG',$new_path);
  7332. break;
  7333. case 3 :
  7334. $result=$temp->send_image('PNG',$new_path);
  7335. break;
  7336. case 1 :
  7337. $result=$temp->send_image('GIF',$new_path);
  7338. break;
  7339. }
  7340. // Storing the image filename
  7341. if ($result)
  7342. {
  7343. $image_moved=true;
  7344. $this->set_preview_image($new_file_name);
  7345. return true;
  7346. }
  7347. }
  7348. }
  7349. }
  7350. return false;
  7351. }
  7352. }
  7353. ?>