learnpath.class.php 333 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040
  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 = 1; //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, $max_time_allowed=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. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  343. if (empty($max_time_allowed)) { $max_time_allowed = 0; }
  344. $title=htmlspecialchars($title,ENT_QUOTES);
  345. $title = $this->escape_string(mb_convert_encoding($title,$this->encoding,$charset));
  346. $description = $this->escape_string(mb_convert_encoding($description,$this->encoding,$charset));
  347. $sql_count = "
  348. SELECT COUNT(id) AS num
  349. FROM " . $tbl_lp_item . "
  350. WHERE
  351. lp_id = " . $this->get_id() . " AND
  352. parent_item_id = " . $parent;
  353. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  354. $row = Database::fetch_array($res_count);
  355. $num = $row['num'];
  356. if($num > 0) {
  357. if($previous == 0) {
  358. $sql = "
  359. SELECT
  360. id,
  361. next_item_id,
  362. display_order
  363. FROM " . $tbl_lp_item . "
  364. WHERE
  365. lp_id = " . $this->get_id() . " AND
  366. parent_item_id = " . $parent . " AND
  367. previous_item_id = 0 OR previous_item_id=".$parent;
  368. $result = api_sql_query($sql, __FILE__, __LINE__);
  369. $row = Database::fetch_array($result);
  370. $tmp_previous = 0;
  371. $next = $row['id'];
  372. $display_order = 0;
  373. } else {
  374. $previous = (int) $previous;
  375. $sql = "
  376. SELECT
  377. id,
  378. previous_item_id,
  379. next_item_id,
  380. display_order
  381. FROM " . $tbl_lp_item . "
  382. WHERE
  383. lp_id = " . $this->get_id() . " AND
  384. id = " . $previous;
  385. $result = api_sql_query($sql, __FILE__, __LINE__);
  386. $row = Database::fetch_array($result);
  387. $tmp_previous = $row['id'];
  388. $next = $row['next_item_id'];
  389. $display_order = $row['display_order'];
  390. }
  391. } else {
  392. $tmp_previous = 0;
  393. $next = 0;
  394. $display_order = 0;
  395. }
  396. $new_item_id = -1;
  397. $id = $this->escape_string($id);
  398. if($type == 'quiz') {
  399. $sql = 'SELECT SUM(ponderation)
  400. FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
  401. INNER JOIN '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
  402. ON quiz_question.id = quiz_rel_question.question_id
  403. AND quiz_rel_question.exercice_id = '.$id;
  404. $rsQuiz = api_sql_query($sql, __FILE__, __LINE__);
  405. $max_score = Database::result($rsQuiz, 0, 0);
  406. } else {
  407. $max_score = 100;
  408. }
  409. if($prerequisites!=0) {
  410. $sql_ins = "
  411. INSERT INTO " . $tbl_lp_item . " (
  412. lp_id,
  413. item_type,
  414. ref,
  415. title,
  416. description,
  417. path,
  418. max_score,
  419. parent_item_id,
  420. previous_item_id,
  421. next_item_id,
  422. display_order,
  423. prerequisite,
  424. max_time_allowed
  425. ) VALUES (
  426. " . $this->get_id() . ",
  427. '" . $type . "',
  428. '',
  429. '" . $title . "',
  430. '" . $description . "',
  431. '" . $id . "',
  432. '" . $max_score. "',
  433. " . $parent . ",
  434. " . $previous . ",
  435. " . $next . ",
  436. " . ($display_order + 1) . ",
  437. " . $prerequisites . ",
  438. " . $max_time_allowed . "
  439. )";
  440. } else {
  441. //insert new item
  442. $sql_ins = "
  443. INSERT INTO " . $tbl_lp_item . " (
  444. lp_id,
  445. item_type,
  446. ref,
  447. title,
  448. description,
  449. path,
  450. max_score,
  451. parent_item_id,
  452. previous_item_id,
  453. next_item_id,
  454. display_order,
  455. max_time_allowed
  456. ) VALUES (
  457. " . $this->get_id() . ",
  458. '" . $type . "',
  459. '',
  460. '" . $title . "',
  461. '" . $description . "',
  462. '" . $id . "',
  463. '" . $max_score. "',
  464. " . $parent . ",
  465. " . $previous . ",
  466. " . $next . ",
  467. " . ($display_order + 1) . ",
  468. " . $max_time_allowed . "
  469. )";
  470. }
  471. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  472. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  473. if($res_ins > 0)
  474. {
  475. $new_item_id = Database::get_last_insert_id($res_ins);
  476. //update the item that should come after the new item
  477. $sql_update_next = "
  478. UPDATE " . $tbl_lp_item . "
  479. SET previous_item_id = " . $new_item_id . "
  480. WHERE id = " . $next;
  481. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  482. //update the item that should be before the new item
  483. $sql_update_previous = "
  484. UPDATE " . $tbl_lp_item . "
  485. SET next_item_id = " . $new_item_id . "
  486. WHERE id = " . $tmp_previous;
  487. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  488. //update all the items after the new item
  489. $sql_update_order = "
  490. UPDATE " . $tbl_lp_item . "
  491. SET display_order = display_order + 1
  492. WHERE
  493. lp_id = " . $this->get_id() . " AND
  494. id <> " . $new_item_id . " AND
  495. parent_item_id = " . $parent . " AND
  496. display_order > " . $display_order;
  497. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  498. //update the item that should come after the new item
  499. $sql_update_ref = "
  500. UPDATE " . $tbl_lp_item . "
  501. SET ref = " . $new_item_id . "
  502. WHERE id = " . $new_item_id;
  503. api_sql_query($sql_update_ref, __FILE__, __LINE__);
  504. }
  505. // upload audio
  506. if (!empty($_FILES['mp3']['name'])) {
  507. // create the audio folder if it does not exist yet
  508. global $_course;
  509. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  510. if(!is_dir($filepath.'audio')) {
  511. $perm = api_get_setting('permissions_for_new_directories');
  512. $perm = octdec(!empty($perm)?$perm:'0770');
  513. mkdir($filepath.'audio',$perm);
  514. $audio_id=add_document($_course,'/audio','folder',0,'audio');
  515. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  516. }
  517. // upload the file in the documents tool
  518. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  519. $file_path = handle_uploaded_document($_course, $_FILES['mp3'],api_get_path('SYS_COURSE_PATH').$_course['path'].'/document','/audio',api_get_user_id(),'','','','','',false);
  520. // getting the filename only
  521. $file_components = explode('/',$file_path);
  522. $file = $file_components[count($file_components)-1];
  523. // store the mp3 file in the lp_item table
  524. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($new_item_id)."'";
  525. api_sql_query($sql_insert_audio, __FILE__, __LINE__);
  526. }
  527. return $new_item_id;
  528. }
  529. /**
  530. * Static admin function allowing addition of a learnpath to a course.
  531. * @param string Course code
  532. * @param string Learnpath name
  533. * @param string Learnpath description string, if provided
  534. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  535. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  536. * @param string Zip file containing the learnpath or directory containing the learnpath
  537. * @return integer The new learnpath ID on success, 0 on failure
  538. */
  539. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  540. {
  541. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  542. //TODO
  543. $tbl_lp = Database::get_course_table('lp');
  544. //check course code exists
  545. //check lp_name doesn't exist, otherwise append something
  546. $i = 0;
  547. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  548. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  549. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  550. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  551. while(Database::num_rows($res_name)){
  552. //there is already one such name, update the current one a bit
  553. $i++;
  554. $name = $name.' - '.$i;
  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. }
  559. //new name does not exist yet; keep it
  560. //escape description
  561. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  562. $type = 1;
  563. switch($learnpath){
  564. case 'guess':
  565. break;
  566. case 'dokeos':
  567. $type = 1;
  568. break;
  569. case 'aicc':
  570. break;
  571. }
  572. switch($origin){
  573. case 'zip':
  574. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  575. break;
  576. case 'manual':
  577. default:
  578. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  579. $res_max = api_sql_query($get_max, __FILE__, __LINE__);
  580. if(Database::num_rows($res_max)<1){
  581. $dsp = 1;
  582. }else{
  583. $row = Database::fetch_array($res_max);
  584. $dsp = $row[0]+1;
  585. }
  586. $sql_insert = "INSERT INTO $tbl_lp " .
  587. "(lp_type,name,description,path,default_view_mod," .
  588. "default_encoding,display_order,content_maker," .
  589. "content_local,js_lib) " .
  590. "VALUES ($type,'$name','$description','','embedded'," .
  591. "'UTF-8','$dsp','Dokeos'," .
  592. "'local','')";
  593. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  594. $res_insert = api_sql_query($sql_insert, __FILE__, __LINE__);
  595. $id = Database::get_last_insert_id();
  596. if($id>0){
  597. //insert into item_property
  598. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$id,'LearnpathAdded',api_get_user_id());
  599. return $id;
  600. }
  601. break;
  602. }
  603. }
  604. /**
  605. * Appends a message to the message attribute
  606. * @param string Message to append.
  607. */
  608. function append_message($string)
  609. {
  610. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  611. $this->message .= $string;
  612. }
  613. /**
  614. * Autocompletes the parents of an item in case it's been completed or passed
  615. * @param integer Optional ID of the item from which to look for parents
  616. */
  617. function autocomplete_parents($item)
  618. {
  619. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  620. if(empty($item)){
  621. $item = $this->current;
  622. }
  623. $parent_id = $this->items[$item]->get_parent();
  624. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  625. if(is_object($this->items[$item]) and !empty($parent_id))
  626. {//if $item points to an object and there is a parent
  627. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  628. $current_item =& $this->items[$item];
  629. $parent =& $this->items[$parent_id]; //get the parent
  630. //new experiment including failed and browsed in completed status
  631. $current_status = $current_item->get_status();
  632. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed')
  633. {
  634. //if the current item is completed or passes or succeeded
  635. $completed = true;
  636. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  637. foreach($parent->get_children() as $child)
  638. {
  639. //check all his brothers (his parent's children) for completion status
  640. if($child!= $item)
  641. {
  642. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  643. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  644. //Trying completing parents of failed and browsed items as well
  645. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  646. {
  647. //keep completion status to true
  648. }else{
  649. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  650. $completed = false;
  651. }
  652. }
  653. }
  654. if($completed == true)
  655. { //if all the children were completed
  656. $parent->set_status('completed');
  657. $parent->save(false,$this->prerequisites_match($parent->get_id()));
  658. $this->update_queue[$parent->get_id()] = $parent->get_status();
  659. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  660. $this->autocomplete_parents($parent->get_id()); //recursive call
  661. }
  662. }else{
  663. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  664. }
  665. }
  666. }
  667. /**
  668. * Autosaves the current results into the database for the whole learnpath
  669. */
  670. function autosave()
  671. {
  672. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  673. //TODO add aditionnal save operations for the learnpath itself
  674. }
  675. /**
  676. * Clears the message attribute
  677. */
  678. function clear_message()
  679. {
  680. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  681. $this->message = '';
  682. }
  683. /**
  684. * Closes the current resource
  685. *
  686. * Stops the timer
  687. * Saves into the database if required
  688. * Clears the current resource data from this object
  689. * @return boolean True on success, false on failure
  690. */
  691. function close()
  692. {
  693. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  694. if(empty($this->lp_id))
  695. {
  696. $this->error = 'Trying to close this learnpath but no ID is set';
  697. return false;
  698. }
  699. $this->current_time_stop = time();
  700. if($this->save)
  701. {
  702. $learnpath_view_table = Database::get_course_table(TABLE_LP_VIEW);
  703. /*
  704. $sql = "UPDATE $learnpath_view_table " .
  705. "SET " .
  706. "stop_time = ".$this->current_time_stop.", " .
  707. "score = ".$this->current_score.", ".
  708. "WHERE learnpath_id = '".$this->lp_id."'";
  709. //$res = Database::query($sql);
  710. $res = api_sql_query($res);
  711. if(mysql_affected_rows($res)<1)
  712. {
  713. $this->error = 'Could not update learnpath_view table while closing learnpath';
  714. return false;
  715. }
  716. */
  717. }
  718. $this->ordered_items = array();
  719. $this->index=0;
  720. unset($this->lp_id);
  721. //unset other stuff
  722. return true;
  723. }
  724. /**
  725. * Static admin function allowing removal of a learnpath
  726. * @param string Course code
  727. * @param integer Learnpath ID
  728. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  729. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  730. */
  731. function delete($course=null,$id=null,$delete='keep')
  732. {
  733. //TODO implement a way of getting this to work when the current object is not set
  734. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  735. //if(empty($course)){$course = api_get_course_id();}
  736. //if(empty($id)){$id = $this->get_id();}
  737. //If an ID is specifically given and the current LP is not the same,
  738. //prevent delete
  739. if(!empty($id) && ($id != $this->lp_id)){return false;}
  740. $lp = Database::get_course_table('lp');
  741. $lp_view = Database::get_course_table('lp_view');
  742. $lp_item_view = Database::get_course_table('lp_item_view');
  743. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  744. //delete lp item id
  745. foreach($this->items as $id => $dummy) {
  746. //$this->items[$id]->delete();
  747. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '".$id."'";
  748. $res_del_item_view=api_sql_query($sql_del_view,__FILE__,__LINE__);
  749. }
  750. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  751. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  752. $res_del_view = api_sql_query($sql_del_view, __FILE__, __LINE__);
  753. $this->toggle_publish($this->lp_id,'i');
  754. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  755. if($this->type == 2 OR $this->type==3){
  756. //this is a scorm learning path, delete the files as well
  757. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  758. $res = api_sql_query($sql, __FILE__, __LINE__);
  759. if(Database::num_rows($res)>0){
  760. $row = Database::fetch_array($res);
  761. $path = $row['path'];
  762. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  763. $res = api_sql_query($sql, __FILE__, __LINE__);
  764. if(Database::num_rows($res)>0)
  765. { //another learning path uses this directory, so don't delete it
  766. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  767. }else{
  768. //no other LP uses that directory, delete it
  769. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  770. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  771. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  772. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  773. exec('rm -rf '.$course_scorm_dir.$path);
  774. }
  775. }
  776. }
  777. }
  778. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  779. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  780. $res_del_lp = api_sql_query($sql_del_lp, __FILE__, __LINE__);
  781. $this->update_display_order();//updates the display order of all lps
  782. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$this->lp_id,'delete',api_get_user_id());
  783. require_once '../gradebook/lib/be.inc.php';
  784. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  785. //delete link of gradebook tool
  786. $sql='SELECT gl.id FROM '.$tbl_grade_link.' gl WHERE gl.type="4" AND gl.ref_id="'.$id.'";';
  787. $result=api_sql_query($sql,__FILE__,__LINE__);
  788. $row=Database::fetch_array($result,'ASSOC');
  789. $link= LinkFactory :: load($row['id']);
  790. if ($link[0] != null) {
  791. $link[0]->delete();
  792. }
  793. //TODO: also delete items and item-views
  794. if (api_get_setting('search_enabled') == 'true') {
  795. require_once(api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php');
  796. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  797. }
  798. }
  799. /**
  800. * Removes all the children of one item - dangerous!
  801. * @param integer Element ID of which children have to be removed
  802. * @return integer Total number of children removed
  803. */
  804. function delete_children_items($id){
  805. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  806. $num = 0;
  807. if(empty($id) || $id != strval(intval($id))){return false;}
  808. $lp_item = Database::get_course_table('lp_item');
  809. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  810. $res = api_sql_query($sql, __FILE__, __LINE__);
  811. while($row = Database::fetch_array($res)){
  812. $num += $this->delete_children_items($row['id']);
  813. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  814. $res_del = api_sql_query($sql_del, __FILE__, __LINE__);
  815. $num++;
  816. }
  817. return $num;
  818. }
  819. /**
  820. * Removes an item from the current learnpath
  821. * @param integer Elem ID (0 if first)
  822. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  823. * @return integer Number of elements moved
  824. * @todo implement resource removal
  825. */
  826. function delete_item($id, $remove='keep')
  827. {
  828. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  829. //TODO - implement the resource removal
  830. if(empty($id) || $id != strval(intval($id))){return false;}
  831. //first select item to get previous, next, and display order
  832. $lp_item = Database::get_course_table('lp_item');
  833. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  834. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  835. if(Database::num_rows($res_sel)<1){return false;}
  836. $row = Database::fetch_array($res_sel);
  837. $previous = $row['previous_item_id'];
  838. $next = $row['next_item_id'];
  839. $display = $row['display_order'];
  840. $parent = $row['parent_item_id'];
  841. $lp = $row['lp_id'];
  842. //delete children items
  843. $num = $this->delete_children_items($id);
  844. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  845. //now delete the item
  846. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  847. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  848. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  849. //now update surrounding items
  850. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  851. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  852. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  853. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  854. //now update all following items with new display order
  855. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  856. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  857. // remove from search engine if enabled
  858. if (api_get_setting('search_enabled') == 'true') {
  859. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  860. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  861. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  862. $res = api_sql_query($sql, __FILE__, __LINE__);
  863. if (Database::num_rows($res) > 0) {
  864. $row2 = Database::fetch_array($res);
  865. require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php');
  866. $di = new DokeosIndexer();
  867. $di->remove_document((int)$row2['search_did']);
  868. }
  869. $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  870. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  871. api_sql_query($sql, __FILE__, __LINE__);
  872. }
  873. }
  874. /**
  875. * Updates an item's content in place
  876. * @param integer Element ID
  877. * @param integer Parent item ID
  878. * @param integer Previous item ID
  879. * @param string Item title
  880. * @param string Item description
  881. * @param string Prerequisites (optional)
  882. * @param string Indexing terms (optional)
  883. * @param array The array resulting of the $_FILES[mp3] element
  884. * @return boolean True on success, false on error
  885. */
  886. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $audio=NULL, $max_time_allowed=0) {
  887. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  888. if(empty($max_time_allowed)) { $max_time_allowed = 0;}
  889. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  890. $tbl_lp_item = Database::get_course_table('lp_item');
  891. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  892. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  893. $row_select = Database::fetch_array($res_select);
  894. $audio_update_sql = '';
  895. if (is_array($audio) && !empty($audio['tmp_name']) && $audio['error']===0) {
  896. // create the audio folder if it does not exist yet
  897. global $_course;
  898. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  899. if(!is_dir($filepath.'audio')) {
  900. $perm = api_get_setting('permissions_for_new_directories');
  901. $perm = octdec(!empty($perm)?$perm:'0770');
  902. mkdir($filepath.'audio',$perm);
  903. $audio_id=add_document($_course,'/audio','folder',0,'audio');
  904. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  905. }
  906. //upload file in documents
  907. $pi = pathinfo($audio['name']);
  908. if ($pi['extension'] == 'mp3') {
  909. $c_det = api_get_course_info($this->cc);
  910. $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document';
  911. $path = handle_uploaded_document($c_det,$audio,$bp,'/audio',api_get_user_id(),0,null,'',0,'rename',false,0);
  912. $path = substr($path,7);
  913. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  914. $audio_update_sql = ", audio = '".Database::escape_string($path)."' ";
  915. }
  916. }
  917. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  918. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  919. if($same_parent && $same_previous) {
  920. //only update title and description
  921. $sql_update = "
  922. UPDATE " . $tbl_lp_item . "
  923. SET
  924. title = '" . $this->escape_string(htmlspecialchars($title,ENT_QUOTES)) . "',
  925. prerequisite = '".$prerequisites."',
  926. description = '" . $this->escape_string(htmlentities($description)) . "'
  927. ". $audio_update_sql . ",
  928. max_time_allowed = '" . $this->escape_string(htmlentities($max_time_allowed)) . "'
  929. WHERE id = " . $id;
  930. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  931. }
  932. else
  933. {
  934. $old_parent = $row_select['parent_item_id'];
  935. $old_previous = $row_select['previous_item_id'];
  936. $old_next = $row_select['next_item_id'];
  937. $old_order = $row_select['display_order'];
  938. $old_prerequisite = $row_select['prerequisite'];
  939. $old_max_time_allowed = $row_select['max_time_allowed'];
  940. /* BEGIN -- virtually remove the current item id */
  941. /* for the next and previous item it is like the current item doesn't exist anymore */
  942. if($old_previous != 0)
  943. {
  944. $sql_update_next = "
  945. UPDATE " . $tbl_lp_item . "
  946. SET next_item_id = " . $old_next . "
  947. WHERE id = " . $old_previous;
  948. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  949. //echo '<p>' . $sql_update_next . '</p>';
  950. }
  951. if($old_next != 0)
  952. {
  953. $sql_update_previous = "
  954. UPDATE " . $tbl_lp_item . "
  955. SET previous_item_id = " . $old_previous . "
  956. WHERE id = " . $old_next;
  957. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  958. //echo '<p>' . $sql_update_previous . '</p>';
  959. }
  960. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  961. $sql_update_order = "
  962. UPDATE " . $tbl_lp_item . "
  963. SET display_order = display_order - 1
  964. WHERE
  965. display_order > " . $old_order . " AND
  966. parent_item_id = " . $old_parent;
  967. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  968. //echo '<p>' . $sql_update_order . '</p>';
  969. /* END -- virtually remove the current item id */
  970. /* BEGIN -- update the current item id to his new location */
  971. if($previous == 0)
  972. {
  973. //select the data of the item that should come after the current item
  974. $sql_select_old = "
  975. SELECT
  976. id,
  977. display_order
  978. FROM " . $tbl_lp_item . "
  979. WHERE
  980. lp_id = " . $this->lp_id . " AND
  981. parent_item_id = " . $parent . " AND
  982. previous_item_id = " . $previous;
  983. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  984. $row_select_old = Database::fetch_array($res_select_old);
  985. //echo '<p>' . $sql_select_old . '</p>';
  986. //if the new parent didn't have children before
  987. if(Database::num_rows($res_select_old) == 0)
  988. {
  989. $new_next = 0;
  990. $new_order = 1;
  991. }
  992. else
  993. {
  994. $new_next = $row_select_old['id'];
  995. $new_order = $row_select_old['display_order'];
  996. }
  997. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  998. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  999. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1000. }
  1001. else
  1002. {
  1003. //select the data of the item that should come before the current item
  1004. $sql_select_old = "
  1005. SELECT
  1006. next_item_id,
  1007. display_order
  1008. FROM " . $tbl_lp_item . "
  1009. WHERE id = " . $previous;
  1010. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  1011. $row_select_old = Database::fetch_array($res_select_old);
  1012. //echo '<p>' . $sql_select_old . '</p>';
  1013. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1014. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1015. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1016. $new_next = $row_select_old['next_item_id'];
  1017. $new_order = $row_select_old['display_order'] + 1;
  1018. }
  1019. //update the current item with the new data
  1020. $sql_update = "
  1021. UPDATE " . $tbl_lp_item . "
  1022. SET
  1023. title = '" . $this->escape_string(htmlspecialchars($title,ENT_QUOTES)) . "',
  1024. description = '" . $this->escape_string(htmlentities($description)) . "',
  1025. parent_item_id = " . $parent . ",
  1026. previous_item_id = " . $previous . ",
  1027. next_item_id = " . $new_next . ",
  1028. display_order = " . $new_order . "
  1029. ". $audio_update_sql . "
  1030. WHERE id = " . $id;
  1031. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  1032. //echo '<p>' . $sql_update . '</p>';
  1033. if($previous != 0)
  1034. {
  1035. //update the previous item's next_item_id
  1036. $sql_update_previous = "
  1037. UPDATE " . $tbl_lp_item . "
  1038. SET next_item_id = " . $id . "
  1039. WHERE id = " . $previous;
  1040. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  1041. //echo '<p>' . $sql_update_previous . '</p>';
  1042. }
  1043. if($new_next != 0)
  1044. {
  1045. //update the next item's previous_item_id
  1046. $sql_update_next = "
  1047. UPDATE " . $tbl_lp_item . "
  1048. SET previous_item_id = " . $id . "
  1049. WHERE id = " . $new_next;
  1050. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1051. //echo '<p>' . $sql_update_next . '</p>';
  1052. }
  1053. if($old_prerequisite!=$prerequisites){
  1054. $sql_update_next = "
  1055. UPDATE " . $tbl_lp_item . "
  1056. SET prerequisite = " . $prerequisites . "
  1057. WHERE id = " . $id;
  1058. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1059. }
  1060. if($old_max_time_allowed!=$max_time_allowed){
  1061. $sql_update_max_time_allowed = "
  1062. UPDATE " . $tbl_lp_item . "
  1063. SET max_time_allowed = " . $max_time_allowed . "
  1064. WHERE id = " . $id;
  1065. $res_update_max_time_allowed = api_sql_query($sql_update_max_time_allowed, __FILE__, __LINE__);
  1066. }
  1067. //update all the items with the same or a bigger display_order than
  1068. //the current item
  1069. $sql_update_order = "
  1070. UPDATE " . $tbl_lp_item . "
  1071. SET display_order = display_order + 1
  1072. WHERE
  1073. lp_id = " . $this->get_id() . " AND
  1074. id <> " . $id . " AND
  1075. parent_item_id = " . $parent . " AND
  1076. display_order >= " . $new_order;
  1077. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  1078. //echo '<p>' . $sql_update_order . '</p>';
  1079. /* END -- update the current item id to his new location */
  1080. }
  1081. }
  1082. /**
  1083. * Updates an item's prereq in place
  1084. * @param integer Element ID
  1085. * @param string Prerequisite Element ID
  1086. *
  1087. * @param string Prerequisite item type
  1088. *
  1089. * @param string Prerequisite min score
  1090. *
  1091. * @param string Prerequisite max score
  1092. * @return boolean True on success, false on error
  1093. */
  1094. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
  1095. {
  1096. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')',0);}
  1097. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  1098. $prerequisite_id = $this->escape_string($prerequisite_id);
  1099. $tbl_lp_item = Database::get_course_table('lp_item');
  1100. if(!is_numeric($mastery_score) || $mastery_score < 0)
  1101. $mastery_score = 0;
  1102. if(!is_numeric($max_score) || $max_score < 0)
  1103. $max_score = 100;
  1104. if($mastery_score > $max_score)
  1105. $max_score = $mastery_score;
  1106. if(!is_numeric($prerequisite_id))
  1107. $prerequisite_id = 'NULL';
  1108. $sql_upd = "
  1109. UPDATE " . $tbl_lp_item . "
  1110. SET prerequisite = ".$prerequisite_id." WHERE id = ".$id;
  1111. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1112. if($prerequisite_id!='NULL' && $prerequisite_id!='')
  1113. {
  1114. $sql_upd = " UPDATE ".$tbl_lp_item." SET
  1115. mastery_score = " . $mastery_score .
  1116. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1117. " WHERE ref = '" . $prerequisite_id."'" ; //will this be enough to ensure unicity?
  1118. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1119. }
  1120. //TODO update the item object (can be ignored for now because refreshed)
  1121. return true;
  1122. }
  1123. /**
  1124. * Escapes a string with the available database escape function
  1125. * @param string String to escape
  1126. * @return string String escaped
  1127. */
  1128. function escape_string($string){
  1129. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1130. return Database::escape_string($string);
  1131. }
  1132. /**
  1133. * Static admin function exporting a learnpath into a zip file
  1134. * @param string Export type (scorm, zip, cd)
  1135. * @param string Course code
  1136. * @param integer Learnpath ID
  1137. * @param string Zip file name
  1138. * @return string Zip file path (or false on error)
  1139. */
  1140. function export_lp($type, $course, $id, $zipname)
  1141. {
  1142. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1143. //TODO
  1144. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1145. $url = '';
  1146. switch($type){
  1147. case 'scorm':
  1148. break;
  1149. case 'zip':
  1150. break;
  1151. case 'cdrom':
  1152. break;
  1153. }
  1154. return $url;
  1155. }
  1156. /**
  1157. * Gets all the chapters belonging to the same parent as the item/chapter given
  1158. * Can also be called as abstract method
  1159. * @param integer Item ID
  1160. * @return array A list of all the "brother items" (or an empty array on failure)
  1161. */
  1162. function get_brother_chapters($id){
  1163. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1164. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1165. $lp_item = Database::get_course_table('lp_item');
  1166. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1167. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1168. if(Database::num_rows($res_parent)>0){
  1169. $row_parent = Database::fetch_array($res_parent);
  1170. $parent = $row_parent['parent_item_id'];
  1171. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1172. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1173. $list = array();
  1174. while ($row_bro = Database::fetch_array($res_bros)){
  1175. $list[] = $row_bro;
  1176. }
  1177. return $list;
  1178. }
  1179. return array();
  1180. }
  1181. /**
  1182. * Gets all the items belonging to the same parent as the item given
  1183. * Can also be called as abstract method
  1184. * @param integer Item ID
  1185. * @return array A list of all the "brother items" (or an empty array on failure)
  1186. */
  1187. function get_brother_items($id){
  1188. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1189. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1190. $lp_item = Database::get_course_table('lp_item');
  1191. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1192. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1193. if(Database::num_rows($res_parent)>0){
  1194. $row_parent = Database::fetch_array($res_parent);
  1195. $parent = $row_parent['parent_item_id'];
  1196. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1197. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1198. $list = array();
  1199. while ($row_bro = Database::fetch_array($res_bros)){
  1200. $list[] = $row_bro;
  1201. }
  1202. return $list;
  1203. }
  1204. return array();
  1205. }
  1206. /**
  1207. * Get the specific prefix index terms of this learning path
  1208. * @return array Array of terms
  1209. */
  1210. function get_common_index_terms_by_prefix($prefix)
  1211. {
  1212. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  1213. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1214. $prefix_terms = array();
  1215. foreach($terms as $term)
  1216. {
  1217. $prefix_terms[] = $term['value'];
  1218. }
  1219. return $prefix_terms;
  1220. }
  1221. /**
  1222. * Gets the number of items currently completed
  1223. * @return integer The number of items currently completed
  1224. */
  1225. function get_complete_items_count()
  1226. {
  1227. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1228. $i = 0;
  1229. foreach($this->items as $id => $dummy){
  1230. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1231. //Trying failed and browsed considered "progressed" as well
  1232. 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'){
  1233. $i++;
  1234. }
  1235. }
  1236. return $i;
  1237. }
  1238. /**
  1239. * Gets the current item ID
  1240. * @return integer The current learnpath item id
  1241. */
  1242. function get_current_item_id()
  1243. {
  1244. $current = 0;
  1245. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1246. if(!empty($this->current))
  1247. {
  1248. $current = $this->current;
  1249. }
  1250. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1251. return $current;
  1252. }
  1253. /** Force to get the first learnpath item id
  1254. * @return integer The current learnpath item id
  1255. */
  1256. function get_first_item_id()
  1257. {
  1258. $current = 0;
  1259. if (is_array($this->ordered_items)) {
  1260. $current = $this->ordered_items[0];
  1261. }
  1262. return $current;
  1263. }
  1264. /**
  1265. * Gets the total number of items available for viewing in this SCORM
  1266. * @return integer The total number of items
  1267. */
  1268. function get_total_items_count()
  1269. {
  1270. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1271. return count($this->items);
  1272. }
  1273. /**
  1274. * Gets the total number of items available for viewing in this SCORM but without chapters
  1275. * @return integer The total no-chapters number of items
  1276. */
  1277. function get_total_items_count_without_chapters()
  1278. {
  1279. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1280. $total=0;
  1281. foreach($this->items as $temp=>$temp2){
  1282. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1283. }
  1284. return $total;
  1285. }
  1286. /**
  1287. * Gets the first element URL.
  1288. * @return string URL to load into the viewer
  1289. */
  1290. function first()
  1291. {
  1292. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1293. //test if the last_item_seen exists and is not a dir
  1294. if ( count($this->ordered_items) == 0 ) {
  1295. $this->index = 0;
  1296. }
  1297. if(!empty($this->last_item_seen)
  1298. && !empty($this->items[$this->last_item_seen])
  1299. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1300. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1301. && $this->items[$this->last_item_seen]->is_done() != true
  1302. ){
  1303. 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);}
  1304. $index = -1;
  1305. foreach($this->ordered_items as $myindex => $item_id){
  1306. if($item_id == $this->last_item_seen){
  1307. $index = $myindex;
  1308. break;
  1309. }
  1310. }
  1311. if($index==-1){
  1312. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1313. 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);}
  1314. return false;
  1315. }else{
  1316. $this->last = $this->last_item_seen;
  1317. $this->current = $this->last_item_seen;
  1318. $this->index = $index;
  1319. }
  1320. }else{
  1321. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1322. $index = 0;
  1323. //loop through all ordered items and stop at the first item that is
  1324. //not a directory *and* that has not been completed yet
  1325. while (!empty($this->ordered_items[$index])
  1326. AND
  1327. is_a($this->items[$this->ordered_items[$index]],'learnpathItem')
  1328. AND
  1329. (
  1330. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1331. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1332. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1333. )
  1334. AND $index < $this->max_ordered_items)
  1335. {
  1336. $index ++;
  1337. }
  1338. $this->last = $this->current;
  1339. //current is
  1340. $this->current = $this->ordered_items[$index];
  1341. $this->index = $index;
  1342. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1343. }
  1344. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1345. }
  1346. /**
  1347. * Gets the information about an item in a format usable as JavaScript to update
  1348. * the JS API by just printing this content into the <head> section of the message frame
  1349. * @param integer Item ID
  1350. * @return string
  1351. */
  1352. function get_js_info($item_id=''){
  1353. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1354. $info = '';
  1355. $item_id = $this->escape_string($item_id);
  1356. if(!empty($item_id) && is_object($this->items[$item_id])){
  1357. //if item is defined, return values from DB
  1358. $oItem = $this->items[$item_id];
  1359. $info .= '<script language="javascript">';
  1360. $info .= "top.set_score(".$oItem->get_score().");\n";
  1361. $info .= "top.set_max(".$oItem->get_max().");\n";
  1362. $info .= "top.set_min(".$oItem->get_min().");\n";
  1363. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1364. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1365. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1366. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1367. $info .= "top.set_flag_synchronized();";
  1368. $info .= '</script>';
  1369. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1370. return $info;
  1371. }else{
  1372. //if item_id is empty, just update to default SCORM data
  1373. $info .= '<script language="javascript">';
  1374. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1375. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1376. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1377. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1378. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1379. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1380. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1381. $info .= "top.set_flag_synchronized();";
  1382. $info .= '</script>';
  1383. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1384. return $info;
  1385. }
  1386. }
  1387. /**
  1388. * Gets the js library from the database
  1389. * @return string The name of the javascript library to be used
  1390. */
  1391. function get_js_lib(){
  1392. $lib = '';
  1393. if(!empty($this->js_lib)){
  1394. $lib = $this->js_lib;
  1395. }
  1396. return $lib;
  1397. }
  1398. /**
  1399. * Gets the learnpath database ID
  1400. * @return integer Learnpath ID in the lp table
  1401. */
  1402. function get_id()
  1403. {
  1404. //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1405. if(!empty($this->lp_id))
  1406. {
  1407. return $this->lp_id;
  1408. }else{
  1409. return 0;
  1410. }
  1411. }
  1412. /**
  1413. * Gets the last element URL.
  1414. * @return string URL to load into the viewer
  1415. */
  1416. function get_last()
  1417. {
  1418. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1419. $this->index = count($this->ordered_items)-1;
  1420. return $this->ordered_items[$this->index];
  1421. }
  1422. /**
  1423. * Gets the navigation bar for the learnpath display screen
  1424. * @return string The HTML string to use as a navigation bar
  1425. */
  1426. function get_navigation_bar()
  1427. {
  1428. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1429. //TODO find a good value for the following variables
  1430. $file = '';
  1431. $openDir = '';
  1432. $edoceo = '';
  1433. $time = 0;
  1434. $navbar = '';
  1435. $RequestUri = '';
  1436. $mycurrentitemid = $this->get_current_item_id();
  1437. if($this->mode == 'fullscreen')
  1438. {
  1439. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1440. ' <tr> '."\n" .
  1441. ' <td>'."\n" .
  1442. ' <div class="buttons">'."\n" .
  1443. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('Reporting').'"></a>'."\n" .
  1444. ' <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" .
  1445. ' <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" .
  1446. //' <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" .
  1447. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1448. ' </div>'."\n" .
  1449. ' </td>'."\n" .
  1450. ' </tr>'."\n" .
  1451. '</table>'."\n" ;
  1452. }else{
  1453. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1454. ' <tr> '."\n" .
  1455. ' <td>'."\n" .
  1456. ' <div class="buttons">'."\n" .
  1457. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('Reporting').'"></a>'."\n" .
  1458. ' <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" .
  1459. ' <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" .
  1460. // ' <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" .
  1461. ' </div>'."\n" .
  1462. ' </td>'."\n" .
  1463. ' </tr>'."\n" .
  1464. '</table>'."\n" ;
  1465. }
  1466. return $navbar;
  1467. }
  1468. /**
  1469. * Gets the next resource in queue (url).
  1470. * @return string URL to load into the viewer
  1471. */
  1472. function get_next_index()
  1473. {
  1474. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1475. //TODO
  1476. $index = $this->index;
  1477. $index ++;
  1478. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type,0);}
  1479. 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)
  1480. {
  1481. $index ++;
  1482. if($index == $this->max_ordered_items)
  1483. {
  1484. return $this->index;
  1485. }
  1486. }
  1487. if(empty($this->ordered_items[$index])){
  1488. return $this->index;
  1489. }
  1490. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1491. return $index;
  1492. }
  1493. /**
  1494. * Gets item_id for the next element
  1495. * @return integer Next item (DB) ID
  1496. */
  1497. function get_next_item_id()
  1498. {
  1499. if($this->debug>0){error_log('New LP - In learnpath::get_next_item_id()',0);}
  1500. $new_index = $this->get_next_index();
  1501. if(!empty($new_index))
  1502. {
  1503. if(isset($this->ordered_items[$new_index]))
  1504. {
  1505. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index],0);}
  1506. return $this->ordered_items[$new_index];
  1507. }
  1508. }
  1509. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
  1510. return 0;
  1511. }
  1512. /**
  1513. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1514. *
  1515. * Generally, the package provided is in the form of a zip file, so the function
  1516. * has been written to test a zip file. If not a zip, the function will return the
  1517. * default return value: ''
  1518. * @param string the path to the file
  1519. * @param string the original name of the file
  1520. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1521. */
  1522. function get_package_type($file_path,$file_name){
  1523. //get name of the zip file without the extension
  1524. $file_info = pathinfo($file_name);
  1525. $filename = $file_info['basename'];//name including extension
  1526. $extension = $file_info['extension'];//extension only
  1527. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1528. {
  1529. return 'oogie';
  1530. }
  1531. if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
  1532. {
  1533. return 'woogie';
  1534. }
  1535. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1536. $zipFile = new pclZip($file_path);
  1537. // Check the zip content (real size and file extension)
  1538. $zipContentArray = $zipFile->listContent();
  1539. $package_type='';
  1540. $at_root = false;
  1541. $manifest = '';
  1542. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1543. if (is_array($zipContentArray) && count($zipContentArray)>0) {
  1544. foreach($zipContentArray as $thisContent)
  1545. {
  1546. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1547. {
  1548. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1549. }
  1550. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1551. {
  1552. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1553. $package_type = 'scorm';
  1554. break;//exit the foreach loop
  1555. }
  1556. elseif(preg_match('/aicc\//i',$thisContent['filename'])!=false)
  1557. {//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1558. $package_type='aicc';
  1559. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1560. }
  1561. else
  1562. {
  1563. $package_type = '';
  1564. }
  1565. }
  1566. }
  1567. return $package_type;
  1568. }
  1569. /**
  1570. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1571. * @return string URL to load into the viewer
  1572. */
  1573. function get_previous_index()
  1574. {
  1575. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1576. $index = $this->index;
  1577. if(isset($this->ordered_items[$index-1])){
  1578. $index --;
  1579. 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'))
  1580. {
  1581. $index --;
  1582. if($index < 0){
  1583. return $this->index;
  1584. }
  1585. }
  1586. }else{
  1587. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1588. //no previous item
  1589. }
  1590. return $index;
  1591. }
  1592. /**
  1593. * Gets item_id for the next element
  1594. * @return integer Previous item (DB) ID
  1595. */
  1596. function get_previous_item_id()
  1597. {
  1598. if($this->debug>0){error_log('New LP - In learnpath::get_previous_item_id()',0);}
  1599. $new_index = $this->get_previous_index();
  1600. return $this->ordered_items[$new_index];
  1601. }
  1602. /**
  1603. * Gets the progress value from the progress_db attribute
  1604. * @return integer Current progress value
  1605. */
  1606. function get_progress()
  1607. {
  1608. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1609. if(!empty($this->progress_db))
  1610. {
  1611. return $this->progress_db;
  1612. }
  1613. return 0;
  1614. }
  1615. /**
  1616. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1617. * @param integer Learnpath ID
  1618. * @param integer User ID
  1619. * @param string Mode of display ('%','abs' or 'both')
  1620. * @param string Course database name (optional, defaults to '')
  1621. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1622. * @return integer Current progress value as found in the database
  1623. */
  1624. function get_db_progress($lp_id,$user_id,$mode='%', $course_db='', $sincere=false)
  1625. {
  1626. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1627. $table = Database::get_course_table('lp_view', $course_db);
  1628. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1629. $res = api_sql_query($sql,__FILE__,__LINE__);
  1630. $view_id = 0;
  1631. if(Database::num_rows($res)>0)
  1632. {
  1633. $row = Database::fetch_array($res);
  1634. $progress = $row['progress'];
  1635. $view_id = $row['id'];
  1636. }
  1637. else
  1638. {
  1639. if($sincere)
  1640. {
  1641. return null;
  1642. }
  1643. }
  1644. if(empty($progress))
  1645. {
  1646. $progress = '0';
  1647. }
  1648. if($mode == '%')
  1649. {
  1650. return $progress.'%';
  1651. }
  1652. else
  1653. {
  1654. //get the number of items completed and the number of items total
  1655. $tbl = Database::get_course_table('lp_item', $course_db);
  1656. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1657. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1658. $res = api_sql_query($sql, __FILE__, __LINE__);
  1659. $row = Database::fetch_array($res);
  1660. $total = $row[0];
  1661. $tbl_item_view = Database::get_course_table('lp_item_view', $course_db);
  1662. $tbl_item = Database::get_course_table('lp_item', $course_db);
  1663. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1664. //trying as also counting browsed and failed items
  1665. $sql = "SELECT count(distinct(lp_item_id))
  1666. FROM $tbl_item_view as item_view
  1667. INNER JOIN $tbl_item as item
  1668. ON item.id = item_view.lp_item_id
  1669. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1670. WHERE lp_view_id = ".$view_id."
  1671. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1672. $res = api_sql_query($sql, __FILE__, __LINE__);
  1673. $row = Database::fetch_array($res);
  1674. $completed = $row[0];
  1675. if($mode == 'abs')
  1676. {
  1677. return $completed.'/'.$total;
  1678. }
  1679. elseif($mode == 'both')
  1680. {
  1681. if($progress<($completed/($total?$total:1)))
  1682. {
  1683. $progress = number_format(($completed/($total?$total:1))*100,0);
  1684. }
  1685. return $progress.'% ('.$completed.'/'.$total.')';
  1686. }
  1687. }
  1688. return $progress;
  1689. }
  1690. function get_mediaplayer()
  1691. {
  1692. global $_course;
  1693. // Database table definition
  1694. $tbl_lp_item = Database::get_course_table('lp_item');
  1695. // getting all the information about the item
  1696. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = '" . $_SESSION['oLP']->current."'";
  1697. $result = api_sql_query($sql, __FILE__, __LINE__);
  1698. $row= mysql_fetch_assoc($result);
  1699. $output='';
  1700. if (!empty($row['audio']))
  1701. {
  1702. // the mp3 player
  1703. $output = '<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
  1704. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1705. $output .= '<script type="text/javascript">
  1706. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1707. s1.addParam("allowscriptaccess","always");
  1708. s1.addParam("flashvars","file='.api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  1709. s1.write("container");
  1710. </script>';
  1711. }
  1712. return $output;
  1713. }
  1714. /**
  1715. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1716. * completed so far.
  1717. * @param string Mode in which we want the values
  1718. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1719. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1720. * @param boolean true if it comes from a Diplay LP view
  1721. * @return string HTML string containing the progress bar
  1722. */
  1723. function get_progress_bar($mode='',$percentage=-1,$text_add='',$from_lp=false)
  1724. {
  1725. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1726. global $lp_theme_css;
  1727. // Setting up the CSS path of the current style if exists
  1728. if (!empty($lp_theme_css))
  1729. {
  1730. $css_path=api_get_path(WEB_CODE_PATH).'css/'.$lp_theme_css.'/images/';
  1731. }
  1732. else
  1733. {
  1734. $css_path='../img/';
  1735. }
  1736. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1737. if(isset($this) && is_object($this) && ($percentage=='-1' OR $text_add==''))
  1738. {
  1739. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1740. }
  1741. $text = $percentage.$text_add;
  1742. //Default progress bar config
  1743. // times that will be greater or shorter
  1744. $factor=1.2;
  1745. if ($from_lp)
  1746. $progress_height='26';
  1747. else
  1748. $progress_height='16';
  1749. $size = str_replace('%','',$percentage);
  1750. $output = ''
  1751. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1752. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1753. .'<img id="progress_img_limit_left" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'">'
  1754. .'<img id="progress_img_full" src="'.$css_path.'bar_1u.gif" width="'.$size*$factor.'px" height="'.$progress_height.'" id="full_portion">'
  1755. .'<img id="progress_img_limit_middle" src="'.$css_path.'bar_1m.gif" width="1" height="'.$progress_height.'">';
  1756. if($percentage <= 98)
  1757. {
  1758. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="'.(100-$size)*$factor.'px" height="'.$progress_height.'" id="empty_portion">';
  1759. }
  1760. else
  1761. {
  1762. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="0" height="'.$progress_height.'" id="empty_portion">';
  1763. }
  1764. $output .= '<img id="progress_bar_img_limit_right" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'"></td></tr></table>'
  1765. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1766. return $output;
  1767. }
  1768. /**
  1769. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1770. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1771. * //@param integer Additional steps to fake as completed
  1772. * @return list Percentage or number and symbol (% or /xx)
  1773. */
  1774. function get_progress_bar_text($mode='',$add=0)
  1775. {
  1776. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1777. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1778. $total_items = $this->get_total_items_count_without_chapters();
  1779. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1780. $i = $this->get_complete_items_count();
  1781. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1782. if($add != 0){
  1783. $i += $add;
  1784. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1785. }
  1786. $text = '';
  1787. if($i>$total_items){
  1788. $i = $total_items;
  1789. }
  1790. if($mode == '%'){
  1791. if($total_items>0){
  1792. $percentage = ((float)$i/(float)$total_items)*100;
  1793. }
  1794. else
  1795. {
  1796. $percentage = 0;
  1797. }
  1798. $percentage = number_format($percentage,0);
  1799. $text = '%';
  1800. }elseif($mode == 'abs'){
  1801. $percentage = $i;
  1802. $text = '/'.$total_items;
  1803. }
  1804. return array($percentage,$text);
  1805. }
  1806. /**
  1807. * Gets the progress bar mode
  1808. * @return string The progress bar mode attribute
  1809. */
  1810. function get_progress_bar_mode()
  1811. {
  1812. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1813. if(!empty($this->progress_bar_mode))
  1814. {
  1815. return $this->progress_bar_mode;
  1816. }else{
  1817. return '%';
  1818. }
  1819. }
  1820. /**
  1821. * Gets the learnpath proximity (remote or local)
  1822. * @return string Learnpath proximity
  1823. */
  1824. function get_proximity()
  1825. {
  1826. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1827. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1828. }
  1829. /**
  1830. * Gets the learnpath theme (remote or local)
  1831. * @return string Learnpath theme
  1832. */
  1833. function get_theme()
  1834. {
  1835. if($this->debug>0){error_log('New LP - In learnpath::get_theme()',0);}
  1836. if(!empty($this->theme)){return $this->theme;}else{return '';}
  1837. }
  1838. /**
  1839. * Gets the learnpath image
  1840. * @return string Web URL of the LP image
  1841. */
  1842. function get_preview_image()
  1843. {
  1844. if($this->debug>0){error_log('New LP - In learnpath::get_preview_image()',0);}
  1845. if(!empty($this->preview_image)){return $this->preview_image;}else{return '';}
  1846. }
  1847. /**
  1848. * Gets the learnpath author
  1849. * @return string LP's author
  1850. */
  1851. function get_author()
  1852. {
  1853. if($this->debug>0){error_log('New LP - In learnpath::get_author()',0);}
  1854. if(!empty($this->author)){return $this->author;}else{return '';}
  1855. }
  1856. /**
  1857. * Generate a new prerequisites string for a given item. If this item was a sco and
  1858. * its prerequisites were strings (instead of IDs), then transform those strings into
  1859. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1860. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1861. * same rule as the scorm_export() method
  1862. * @param integer Item ID
  1863. * @return string Prerequisites string ready for the export as SCORM
  1864. */
  1865. function get_scorm_prereq_string($item_id)
  1866. {
  1867. if($this->debug>0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
  1868. if(!is_object($this->items[$item_id])){return false;}
  1869. $oItem = $this->items[$item_id];
  1870. $prereq = $oItem->get_prereq_string();
  1871. if(empty($prereq))
  1872. {
  1873. return '';
  1874. }
  1875. if(preg_match('/^\d+$/',$prereq) && is_object($this->items[$prereq]))
  1876. { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  1877. //then simply return it (with the ITEM_ prefix)
  1878. return 'ITEM_'.$prereq;
  1879. }
  1880. else
  1881. {
  1882. if(isset($this->refs_list[$prereq]))
  1883. {
  1884. //it's a simple string item from which the ID can be found in the refs list
  1885. //so we can transform it directly to an ID for export
  1886. return 'ITEM_'.$this->refs_list[$prereq];
  1887. }
  1888. else
  1889. {
  1890. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  1891. //and replace them, one by one, by the internal IDs (dokeos db)
  1892. //TODO modify the '*' replacement to replace the multiplier in front of it
  1893. //by a space as well
  1894. $find = array('&','|','~','=','<>','{','}','*','(',')');
  1895. $replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
  1896. $prereq_mod = str_replace($find,$replace,$prereq);
  1897. $ids = split(' ',$prereq_mod);
  1898. foreach($ids as $id)
  1899. {
  1900. $id = trim($id);
  1901. if(isset($this->refs_list[$id]))
  1902. {
  1903. $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/','ITEM_'.$this->refs_list[$id],$prereq);
  1904. }
  1905. }
  1906. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '.$prereq,0);
  1907. return $prereq;
  1908. }
  1909. }
  1910. }
  1911. /**
  1912. * Returns the XML DOM document's node
  1913. * @param resource Reference to a list of objects to search for the given ITEM_*
  1914. * @param string The identifier to look for
  1915. * @return mixed The reference to the element found with that identifier. False if not found
  1916. */
  1917. function get_scorm_xml_node(&$children,$id)
  1918. {
  1919. for($i=0;$i<$children->length;$i++){
  1920. $item_temp = $children->item($i);
  1921. if ($item_temp -> nodeName == 'item')
  1922. {
  1923. if($item_temp->getAttribute('identifier') == $id)
  1924. {
  1925. return $item_temp;
  1926. }
  1927. }
  1928. $subchildren = $item_temp->childNodes;
  1929. if($subchildren->length>0)
  1930. {
  1931. $val = $this->get_scorm_xml_node($subchildren,$id);
  1932. if(is_object($val))
  1933. {
  1934. return $val;
  1935. }
  1936. }
  1937. }
  1938. return false;
  1939. }
  1940. /**
  1941. * Returns a usable array of stats related to the current learnpath and user
  1942. * @return array Well-formatted array containing status for the current learnpath
  1943. */
  1944. function get_stats()
  1945. {
  1946. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1947. //TODO
  1948. }
  1949. /**
  1950. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1951. * the given course (for all learnpaths and all users)
  1952. * @param string Course code
  1953. * @return array Well-formatted array containing status for the course's learnpaths
  1954. */
  1955. function get_stats_course($course)
  1956. {
  1957. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1958. //TODO
  1959. }
  1960. /**
  1961. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1962. * the given course and learnpath (for all users)
  1963. * @param string Course code
  1964. * @param integer Learnpath ID
  1965. * @return array Well-formatted array containing status for the specified learnpath
  1966. */
  1967. function get_stats_lp($course,$lp)
  1968. {
  1969. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1970. //TODO
  1971. }
  1972. /**
  1973. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1974. * the given course, learnpath and user.
  1975. * @param string Course code
  1976. * @param integer Learnpath ID
  1977. * @param integer User ID
  1978. * @return array Well-formatted array containing status for the specified learnpath and user
  1979. */
  1980. function get_stats_lp_user($course,$lp,$user)
  1981. {
  1982. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1983. //TODO
  1984. }
  1985. /**
  1986. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1987. * the given course and learnpath (for all users)
  1988. * @param string Course code
  1989. * @param integer User ID
  1990. * @return array Well-formatted array containing status for the user's learnpaths
  1991. */
  1992. function get_stats_user($course,$user)
  1993. {
  1994. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1995. //TODO
  1996. }
  1997. /**
  1998. * Gets the status list for all LP's items
  1999. * @return array Array of [index] => [item ID => current status]
  2000. */
  2001. function get_items_status_list(){
  2002. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  2003. $list = array();
  2004. foreach($this->ordered_items as $item_id)
  2005. {
  2006. $list[]= array($item_id => $this->items[$item_id]->get_status());
  2007. }
  2008. return $list;
  2009. }
  2010. /**
  2011. * Return the number of interactions for the given learnpath Item View ID.
  2012. * This method can be used as static.
  2013. * @param integer Item View ID
  2014. * @return integer Number of interactions
  2015. */
  2016. function get_interactions_count_from_db($lp_iv_id=0){
  2017. if(empty($lp_iv_id)){return -1;}
  2018. $table = Database::get_course_table('lp_iv_interaction');
  2019. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2020. $res = api_sql_query($sql,__FILE__,__LINE__);
  2021. $row = Database::fetch_array($res);
  2022. $num = $row[0];
  2023. return $num;
  2024. }
  2025. /**
  2026. * Return the interactions as an array for the given lp_iv_id.
  2027. * This method can be used as static.
  2028. * @param integer Learnpath Item View ID
  2029. * @return array
  2030. * @todo Translate labels
  2031. */
  2032. function get_iv_interactions_array($lp_iv_id=0){
  2033. $list = array();
  2034. $table = Database::get_course_table('lp_iv_interaction');
  2035. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2036. $res = api_sql_query($sql,__FILE__,__LINE__);
  2037. $num = Database::num_rows($res);
  2038. if($num>0){
  2039. $list[] = array(
  2040. "order_id"=>htmlentities(get_lang('Order')),
  2041. "id"=>htmlentities(get_lang('InteractionID')),
  2042. "type"=>htmlentities(get_lang('Type')),
  2043. "time"=>htmlentities(get_lang('TimeFinished')),
  2044. "correct_responses"=>htmlentities(get_lang('CorrectAnswers')),
  2045. "student_response"=>htmlentities(get_lang('StudentResponse')),
  2046. "result"=>htmlentities(get_lang('Result')),
  2047. "latency"=>htmlentities(get_lang('LatencyTimeSpent')));
  2048. while ($row = Database::fetch_array($res)){
  2049. $list[] = array(
  2050. "order_id"=>($row['order_id']+1),
  2051. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  2052. "type"=>$row['interaction_type'],
  2053. "time"=>$row['completion_time'],
  2054. //"correct_responses"=>$row['correct_responses'],
  2055. //hide correct responses from students
  2056. "correct_responses"=>'',
  2057. "student_response"=>$row['student_response'],
  2058. "result"=>$row['result'],
  2059. "latency"=>$row['latency']);
  2060. }
  2061. }
  2062. return $list;
  2063. }
  2064. /**
  2065. * Return the number of objectives for the given learnpath Item View ID.
  2066. * This method can be used as static.
  2067. * @param integer Item View ID
  2068. * @return integer Number of objectives
  2069. */
  2070. function get_objectives_count_from_db($lp_iv_id=0){
  2071. if(empty($lp_iv_id)){return -1;}
  2072. $table = Database::get_course_table('lp_iv_objective');
  2073. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2074. $res = api_sql_query($sql,__FILE__,__LINE__);
  2075. $row = Database::fetch_array($res);
  2076. $num = $row[0];
  2077. return $num;
  2078. }
  2079. /**
  2080. * Return the objectives as an array for the given lp_iv_id.
  2081. * This method can be used as static.
  2082. * @param integer Learnpath Item View ID
  2083. * @return array
  2084. * @todo Translate labels
  2085. */
  2086. function get_iv_objectives_array($lp_iv_id=0){
  2087. $list = array();
  2088. $table = Database::get_course_table('lp_iv_objective');
  2089. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2090. $res = api_sql_query($sql,__FILE__,__LINE__);
  2091. $num = Database::num_rows($res);
  2092. if($num>0){
  2093. $list[] = array(
  2094. "order_id"=>htmlentities(get_lang('Order')),
  2095. "objective_id"=>htmlentities(get_lang('ObjectiveID')),
  2096. "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')),
  2097. "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')),
  2098. "score_min"=>htmlentities(get_lang('ObjectiveMinScore')),
  2099. "status"=>htmlentities(get_lang('ObjectiveStatus')));
  2100. while ($row = Database::fetch_array($res)){
  2101. $list[] = array(
  2102. "order_id"=>($row['order_id']+1),
  2103. "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
  2104. "score_raw"=>$row['score_raw'],
  2105. "score_max"=>$row['score_max'],
  2106. "score_min"=>$row['score_min'],
  2107. "status"=>$row['status']);
  2108. }
  2109. }
  2110. return $list;
  2111. }
  2112. /**
  2113. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2114. * used by get_html_toc() to be ready to display
  2115. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2116. */
  2117. function get_toc()
  2118. {
  2119. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  2120. $toc = array();
  2121. //echo "<pre>".print_r($this->items,true)."</pre>";
  2122. foreach($this->ordered_items as $item_id)
  2123. {
  2124. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  2125. //TODO change this link generation and use new function instead
  2126. $toc[] = array(
  2127. 'id'=>$item_id,
  2128. 'title'=>$this->items[$item_id]->get_title(),
  2129. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2130. 'status'=>$this->items[$item_id]->get_status(),
  2131. 'level'=>$this->items[$item_id]->get_level(),
  2132. 'type' =>$this->items[$item_id]->get_type(),
  2133. 'description'=>$this->items[$item_id]->get_description(),
  2134. 'path'=>$this->items[$item_id]->get_path(),
  2135. );
  2136. }
  2137. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  2138. return $toc;
  2139. }
  2140. /**
  2141. * Gets the learning path type
  2142. * @param boolean Return the name? If false, return the ID. Default is false.
  2143. * @return mixed Type ID or name, depending on the parameter
  2144. */
  2145. function get_type($get_name = false)
  2146. {
  2147. $res = false;
  2148. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  2149. if(!empty($this->type))
  2150. {
  2151. if($get_name)
  2152. {
  2153. //get it from the lp_type table in main db
  2154. }else{
  2155. $res = $this->type;
  2156. }
  2157. }
  2158. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  2159. return $res;
  2160. }
  2161. /**
  2162. * Gets the learning path type as static method
  2163. * @param boolean Return the name? If false, return the ID. Default is false.
  2164. * @return mixed Type ID or name, depending on the parameter
  2165. */
  2166. function get_type_static($lp_id=0)
  2167. {
  2168. $tbl_lp = Database::get_course_table('lp');
  2169. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '".$lp_id."'";
  2170. $res = api_sql_query($sql, __FILE__, __LINE__);
  2171. if($res===false){ return null;}
  2172. if(Database::num_rows($res)<=0){return null;}
  2173. $row = Database::fetch_array($res);
  2174. return $row['lp_type'];
  2175. }
  2176. /**
  2177. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2178. * This method can be used as abstract and is recursive
  2179. * @param integer Learnpath ID
  2180. * @param integer Parent ID of the items to look for
  2181. * @return mixed Ordered list of item IDs or false on error
  2182. */
  2183. function get_flat_ordered_items_list($lp,$parent=0)
  2184. {
  2185. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2186. $list = array();
  2187. if(empty($lp)){return false;}
  2188. $tbl_lp_item = Database::get_course_table('lp_item');
  2189. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2190. $res = api_sql_query($sql,__FILE__,__LINE__);
  2191. while($row = Database::fetch_array($res)){
  2192. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  2193. $list[] = $row['id'];
  2194. foreach($sublist as $item){
  2195. $list[] = $item;
  2196. }
  2197. }
  2198. return $list;
  2199. }
  2200. /**
  2201. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2202. * @return string HTML TOC ready to display
  2203. */
  2204. /*function get_html_toc()
  2205. {
  2206. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2207. $list = $this->get_toc();
  2208. //echo $this->current;
  2209. //$parent = $this->items[$this->current]->get_parent();
  2210. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2211. $html = '<div class="inner_lp_toc">'."\n" ;
  2212. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2213. require_once('resourcelinker.inc.php');
  2214. //temp variables
  2215. $mycurrentitemid = $this->get_current_item_id();
  2216. foreach($list as $item)
  2217. {
  2218. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2219. //TODO complete this
  2220. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2221. 'incomplete' => '../img/incomplete.gif',
  2222. 'failed' => '../img/failed.gif',
  2223. 'completed' => '../img/completed.gif',
  2224. 'passed' => '../img/passed.gif',
  2225. 'succeeded' => '../img/succeeded.gif',
  2226. 'browsed' => '../img/completed.gif');
  2227. $style = 'scorm_item';
  2228. if($item['id'] == $this->current){
  2229. $style = 'scorm_item_highlight';
  2230. }
  2231. //the anchor will let us center the TOC on the currently viewed item &^D
  2232. $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'].'" >' .
  2233. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2234. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2235. $title = $item['title'];
  2236. if(empty($title)){
  2237. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2238. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2239. }
  2240. if(empty($title))$title = '-';
  2241. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2242. //$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>" ;
  2243. $url = $this->get_link('http',$item['id']);
  2244. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2245. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2246. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2247. $mycurrentitemid.',' .
  2248. $item['id'].');' .
  2249. 'return false;" >'.$title.'</a>' ;
  2250. }else{
  2251. $html .= $title;
  2252. }
  2253. $html .= "</div>\n";
  2254. }
  2255. $html .= "</div>\n";
  2256. return $html;
  2257. }*/
  2258. /**
  2259. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2260. * @return string HTML TOC ready to display
  2261. */
  2262. function get_html_toc()
  2263. {
  2264. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2265. $list = $this->get_toc();
  2266. $mych = api_get_setting('platform_charset');
  2267. //echo $this->current;
  2268. //$parent = $this->items[$this->current]->get_parent();
  2269. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2270. $html= '<div class="scorm_title"><div class="scorm_title_text">'.$this->get_name().'</div></div>';
  2271. // build, display
  2272. if(api_is_allowed_to_edit())
  2273. {
  2274. $gradebook=Security::remove_XSS($_GET['gradebook']);
  2275. $html .='<div class="actions_lp">';
  2276. //the icon it was removed in display (build)
  2277. //$html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;action=build&amp;lp_id=".$this->lp_id."' target='_parent'>".Display::return_icon('learnpath_build.gif', get_lang('Build')).' '.mb_convert_encoding(get_lang('Build'),$this->encoding,$mych)."</a>";
  2278. $html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;gradebook=$gradebook&amp;action=build&amp;lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang('Build'),$this->encoding,$mych)."</a>";
  2279. //the icon it was removed in display (organize)
  2280. //$html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;action=admin_view&amp;lp_id=".$this->lp_id."' target='_parent'>".Display::return_icon('learnpath_organize.gif', get_lang('BasicOverview')).' '.mb_convert_encoding(get_lang('BasicOverview'),$this->encoding,$mych)."</a>";
  2281. $html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;action=admin_view&amp;lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang('BasicOverview'),$this->encoding,$mych)."</a>";
  2282. //the icon it was removed in display (display)
  2283. //$html .= '<span>'.Display::return_icon('learnpath_view.gif', get_lang("Display")).' '.mb_convert_encoding(get_lang("Display"),$this->encoding,$mych).'</span>';
  2284. $html .= '<span>'.mb_convert_encoding(get_lang("Display"),$this->encoding,$mych).'</span>';
  2285. $html .= '</div>';
  2286. unset($mych);
  2287. }
  2288. $html.= '<div id="inner_lp_toc" class="inner_lp_toc">'."\n" ;
  2289. //$html.= '<div class="scorm_title"><div class="scorm_title_text">'.mb_convert_encoding($this->get_name(),$this->encoding,$mych).'</div></div>';
  2290. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2291. require_once('resourcelinker.inc.php');
  2292. //temp variables
  2293. $mycurrentitemid = $this->get_current_item_id();
  2294. $color_counter=0;
  2295. $i=0;
  2296. foreach($list as $item)
  2297. {
  2298. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2299. //TODO complete this
  2300. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2301. 'incomplete' => '../img/incomplete.gif',
  2302. 'failed' => '../img/failed.gif',
  2303. 'completed' => '../img/completed.gif',
  2304. 'passed' => '../img/passed.gif',
  2305. 'succeeded' => '../img/succeeded.gif',
  2306. 'browsed' => '../img/completed.gif');
  2307. $style = 'scorm_item';
  2308. $scorm_color_background='scorm_item';
  2309. $style_item ='scorm_item';
  2310. $current=false;
  2311. if($item['id'] == $this->current)
  2312. {
  2313. $style = 'scorm_item_highlight';
  2314. $scorm_color_background ='scorm_item_highlight';
  2315. }
  2316. else
  2317. if ($color_counter%2==0)
  2318. {
  2319. $scorm_color_background='scorm_item_1';
  2320. }
  2321. else
  2322. {
  2323. $scorm_color_background='scorm_item_2';
  2324. }
  2325. if ($scorm_color_background!='')
  2326. {
  2327. $html .= '<div id="toc_'.$item['id'].'" class="'.$scorm_color_background.'">';
  2328. }
  2329. //the anchor will let us center the TOC on the currently viewed item &^D
  2330. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter')
  2331. {
  2332. $html .= '<a name="atoc_'.$item['id'].'" />';
  2333. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" title="'.$item['description'].'" >';
  2334. }
  2335. else
  2336. {
  2337. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" title="'.$item['description'].'" >';
  2338. }
  2339. $title=$item['title'];
  2340. if(empty($title))
  2341. {
  2342. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2343. }
  2344. $title = utf8_decode(html_entity_decode($title,ENT_QUOTES,$this->encoding));
  2345. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module')
  2346. {
  2347. //$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>" ;
  2348. $url = $this->get_link('http',$item['id']);
  2349. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2350. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2351. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2352. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2353. $mycurrentitemid.',' .
  2354. $item['id'].');' .
  2355. 'return false;" >'.stripslashes($title).'</a>' ;
  2356. }
  2357. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter')
  2358. {
  2359. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  2360. }
  2361. elseif($item['type']=='dir')
  2362. {
  2363. $html .= stripslashes($title);
  2364. }
  2365. $tbl_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2366. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  2367. $user_id = api_get_user_id();
  2368. $course_id = api_get_course_id();
  2369. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2370. WHERE path = '".$item['path']."' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2371. $result = api_sql_query($sql,__FILE__,__LINE__);
  2372. $count = Database::num_rows($result);
  2373. if ($item['type']=='quiz') {
  2374. if ($item['status']=='completed') {
  2375. $html .= "&nbsp;<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' width='12' height='12' />";
  2376. }
  2377. } else {
  2378. if ($item['type']!='dokeos_chapter' && $item['type']!='dokeos_module' && $item['type']!='dir') {
  2379. $html .= "&nbsp;<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' width='12' height='12' />";
  2380. }
  2381. }
  2382. $html .= "</div>";
  2383. if ($scorm_color_background!='')
  2384. {
  2385. $html .= '</div>';
  2386. }
  2387. $color_counter++;
  2388. }
  2389. $html .= "</div>\n";
  2390. return $html;
  2391. }
  2392. /**
  2393. * Gets the learnpath maker name - generally the editor's name
  2394. * @return string Learnpath maker name
  2395. */
  2396. function get_maker()
  2397. {
  2398. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  2399. if(!empty($this->maker)){return $this->maker;}else{return '';}
  2400. }
  2401. /**
  2402. * Gets the user-friendly message stored in $this->message
  2403. * @return string Message
  2404. */
  2405. function get_message(){
  2406. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  2407. return $this->message;
  2408. }
  2409. /**
  2410. * Gets the learnpath name/title
  2411. * @return string Learnpath name/title
  2412. */
  2413. function get_name()
  2414. {
  2415. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2416. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2417. }
  2418. /**
  2419. * Gets a link to the resource from the present location, depending on item ID.
  2420. * @param string Type of link expected
  2421. * @param integer Learnpath item ID
  2422. * @return string Link to the lp_item resource
  2423. */
  2424. function get_link($type='http',$item_id=null)
  2425. {
  2426. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2427. if(empty($item_id))
  2428. {
  2429. 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);}
  2430. $item_id = $this->get_current_item_id();
  2431. }
  2432. if(empty($item_id)){
  2433. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2434. //still empty, this means there was no item_id given and we are not in an object context or
  2435. //the object property is empty, return empty link
  2436. $item_id = $this->first();
  2437. return '';
  2438. }
  2439. $file = '';
  2440. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2441. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2442. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  2443. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2444. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2445. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2446. $res = api_sql_query($sel, __FILE__, __LINE__);
  2447. if(Database::num_rows($res)>0)
  2448. {
  2449. $row = Database::fetch_array($res);
  2450. //var_dump($row);
  2451. $lp_type = $row['ltype'];
  2452. $lp_path = $row['lpath'];
  2453. $lp_item_type = $row['litype'];
  2454. $lp_item_path = $row['lipath'];
  2455. $lp_item_params = $row['liparams'];
  2456. if(empty($lp_item_params) && strpos($lp_item_path,'?')!==false)
  2457. {
  2458. list($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
  2459. }
  2460. //$lp_item_params = '?'.$lp_item_params;
  2461. //add ? if none - left commented to give freedom to scorm implementation
  2462. //if(substr($lp_item_params,0,1)!='?'){
  2463. // $lp_item_params = '?'.$lp_item_params;
  2464. //}
  2465. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2466. if($type == 'http'){
  2467. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2468. }else{
  2469. $course_path = $sys_course_path; //system path
  2470. }
  2471. //now go through the specific cases to get the end of the path
  2472. switch($lp_type){
  2473. case 1:
  2474. if($lp_item_type == 'dokeos_chapter'){
  2475. $file = 'lp_content.php?type=dir';
  2476. }else{
  2477. require_once('resourcelinker.inc.php');
  2478. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2479. // check how much attempts of a exercise exits in lp
  2480. $lp_item_id = $this->get_current_item_id();
  2481. $lp_view_id = $this->get_view_id();
  2482. $prevent_reinit = $this->items[$this->current]->prevent_reinit;
  2483. $list = $this->get_toc();
  2484. $type_quiz = false;
  2485. foreach($list as $toc) {
  2486. if ($toc['id'] == $lp_item_id && ($toc['type']=='quiz') ) {
  2487. $type_quiz = true;
  2488. }
  2489. }
  2490. if ($type_quiz) {
  2491. $lp_item_id = Database::escape_string($lp_item_id);
  2492. $lp_view_id = Database::escape_string($lp_view_id);
  2493. $sql = "SELECT count(*) FROM $lp_item_view_table WHERE lp_item_id='".(int)$lp_item_id."' AND lp_view_id ='".(int)$lp_view_id."' AND status='completed'";
  2494. $result = api_sql_query($sql,__FILE__,__LINE__);
  2495. $row_count = Database::fetch_row($result);
  2496. $count_item_view = (int)$row_count[0];
  2497. $not_multiple_attempt = 0;
  2498. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2499. $not_multiple_attempt = 1;
  2500. }
  2501. $file .= '&not_multiple_attempt='.$not_multiple_attempt;
  2502. }
  2503. $tmp_array=explode("/",$file);
  2504. $document_name=$tmp_array[count($tmp_array)-1];
  2505. if(strpos($document_name,'_DELETED_')){
  2506. $file = 'blank.php?error=document_deleted';
  2507. }
  2508. }
  2509. break;
  2510. case 2:
  2511. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2512. if($lp_item_type!='dir'){
  2513. //Quite complex here:
  2514. //we want to make sure 'http://' (and similar) links can
  2515. //be loaded as is (withouth the Dokeos path in front) but
  2516. //some contents use this form: resource.htm?resource=http://blablabla
  2517. //which means we have to find a protocol at the path's start, otherwise
  2518. //it should not be considered as an external URL
  2519. //if($this->prerequisites_match($item_id)){
  2520. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2521. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2522. //distant url, return as is
  2523. $file = $lp_item_path;
  2524. }else{
  2525. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2526. //prevent getting untranslatable urls
  2527. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2528. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2529. //prepare the path
  2530. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2531. //TODO fix this for urls with protocol header
  2532. $file = str_replace('//','/',$file);
  2533. $file = str_replace(':/','://',$file);
  2534. if(substr($lp_path,-1)=='/')
  2535. {
  2536. $lp_path = substr($lp_path,0,-1);
  2537. }
  2538. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path)))
  2539. {//if file not found
  2540. $decoded = html_entity_decode($lp_item_path);
  2541. list($decoded) = explode('?',$decoded);
  2542. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded)))
  2543. {
  2544. require_once('resourcelinker.inc.php');
  2545. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2546. $tmp_array=explode("/",$file);
  2547. $document_name=$tmp_array[count($tmp_array)-1];
  2548. if(strpos($document_name,'_DELETED_')){
  2549. $file = 'blank.php?error=document_deleted';
  2550. }
  2551. }
  2552. else
  2553. {
  2554. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2555. }
  2556. }
  2557. }
  2558. //}else{
  2559. //prerequisites did not match
  2560. //$file = 'blank.php';
  2561. //}
  2562. //We want to use parameters if they were defined in the imsmanifest
  2563. if($file!='blank.php')
  2564. {
  2565. $file.= (strstr($file,'?')===false?'?':'').$lp_item_params;
  2566. }
  2567. }else{
  2568. $file = 'lp_content.php?type=dir';
  2569. }
  2570. break;
  2571. case 3:
  2572. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2573. //formatting AICC HACP append URL
  2574. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2575. if($lp_item_type!='dir'){
  2576. //Quite complex here:
  2577. //we want to make sure 'http://' (and similar) links can
  2578. //be loaded as is (withouth the Dokeos path in front) but
  2579. //some contents use this form: resource.htm?resource=http://blablabla
  2580. //which means we have to find a protocol at the path's start, otherwise
  2581. //it should not be considered as an external URL
  2582. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2583. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2584. //distant url, return as is
  2585. $file = $lp_item_path;
  2586. /*
  2587. if(stristr($file,'<servername>')!==false){
  2588. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2589. }
  2590. */
  2591. $file .= $aicc_append;
  2592. }else{
  2593. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2594. //prevent getting untranslatable urls
  2595. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2596. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2597. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2598. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2599. //TODO fix this for urls with protocol header
  2600. $file = str_replace('//','/',$file);
  2601. $file = str_replace(':/','://',$file);
  2602. $file .= $aicc_append;
  2603. }
  2604. }else{
  2605. $file = 'lp_content.php?type=dir';
  2606. }
  2607. break;
  2608. case 4:
  2609. break;
  2610. default:
  2611. break;
  2612. }
  2613. }
  2614. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2615. return $file;
  2616. }
  2617. /**
  2618. * Gets the latest usable view or generate a new one
  2619. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2620. * @return integer DB lp_view id
  2621. */
  2622. function get_view($attempt_num=0)
  2623. {
  2624. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2625. $search = '';
  2626. //use $attempt_num to enable multi-views management (disabled so far)
  2627. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2628. {
  2629. $search = 'AND view_count = '.$attempt_num;
  2630. }
  2631. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2632. $lp_view_table = Database::get_course_table('lp_view');
  2633. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2634. "WHERE lp_id = ".$this->get_id()." " .
  2635. "AND user_id = ".$this->get_user_id()." " .
  2636. $search .
  2637. " ORDER BY view_count DESC";
  2638. $res = api_sql_query($sql, __FILE__, __LINE__);
  2639. if(Database::num_rows($res)>0)
  2640. {
  2641. $row = Database::fetch_array($res);
  2642. $this->lp_view_id = $row['id'];
  2643. }else{
  2644. //no database record, create one
  2645. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2646. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2647. $res = api_sql_query($sql, __FILE__, __LINE__);
  2648. $id = Database::get_last_insert_id();
  2649. $this->lp_view_id = $id;
  2650. }
  2651. return $this->lp_view_id;
  2652. }
  2653. /**
  2654. * Gets the current view id
  2655. * @return integer View ID (from lp_view)
  2656. */
  2657. function get_view_id()
  2658. {
  2659. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2660. if(!empty($this->lp_view_id))
  2661. {
  2662. return $this->lp_view_id;
  2663. }else{
  2664. return 0;
  2665. }
  2666. }
  2667. /**
  2668. * Gets the update queue
  2669. * @return array Array containing IDs of items to be updated by JavaScript
  2670. */
  2671. function get_update_queue()
  2672. {
  2673. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2674. return $this->update_queue;
  2675. }
  2676. /**
  2677. * Gets the user ID
  2678. * @return integer User ID
  2679. */
  2680. function get_user_id()
  2681. {
  2682. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2683. if(!empty($this->user_id))
  2684. {
  2685. return $this->user_id;
  2686. }else{
  2687. return false;
  2688. }
  2689. }
  2690. /**
  2691. * Checks if any of the items has an audio element attached
  2692. * @return bool True or false
  2693. */
  2694. function has_audio() {
  2695. if($this->debug>1){error_log('New LP - In learnpath::has_audio()',0);}
  2696. $has = false;
  2697. foreach ($this->items as $i=>$item) {
  2698. if (!empty($this->items[$i]->audio)) {
  2699. $has = true;
  2700. break;
  2701. }
  2702. }
  2703. return $has;
  2704. }
  2705. /**
  2706. * Logs a message into a file
  2707. * @param string Message to log
  2708. * @return boolean True on success, false on error or if msg empty
  2709. */
  2710. function log($msg)
  2711. {
  2712. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2713. //TODO
  2714. $this->error .= $msg."\n";
  2715. return true;
  2716. }
  2717. /**
  2718. * Moves an item up and down at its level
  2719. * @param integer Item to move up and down
  2720. * @param string Direction 'up' or 'down'
  2721. * @return integer New display order, or false on error
  2722. */
  2723. function move_item($id, $direction){
  2724. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2725. if(empty($id) or empty($direction)){return false;}
  2726. $tbl_lp_item = Database::get_course_table('lp_item');
  2727. $sql_sel = "
  2728. SELECT *
  2729. FROM " . $tbl_lp_item . "
  2730. WHERE id = " . $id;
  2731. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2732. //check if elem exists
  2733. if(Database::num_rows($res_sel)<1){return false;}
  2734. //gather data
  2735. $row = Database::fetch_array($res_sel);
  2736. $previous = $row['previous_item_id'];
  2737. $next = $row['next_item_id'];
  2738. $display = $row['display_order'];
  2739. $parent = $row['parent_item_id'];
  2740. $lp = $row['lp_id'];
  2741. //update the item (switch with previous/next one)
  2742. switch($direction)
  2743. {
  2744. case 'up':
  2745. if($this->debug>2){error_log('Movement up detected',0);}
  2746. if($display <= 1){/*do nothing*/}
  2747. else{
  2748. $sql_sel2 = "SELECT *
  2749. FROM $tbl_lp_item
  2750. WHERE id = $previous";
  2751. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2752. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2753. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2754. //gather data
  2755. $row2 = Database::fetch_array($res_sel2);
  2756. $previous_previous = $row2['previous_item_id'];
  2757. //update previous_previous item (switch "next" with current)
  2758. if($previous_previous != 0)
  2759. {
  2760. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2761. if($this->debug>2){error_log($sql_upd2,0);}
  2762. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2763. }
  2764. //update previous item (switch with current)
  2765. if($previous != 0)
  2766. {
  2767. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2768. if($this->debug>2){error_log($sql_upd2,0);}
  2769. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2770. }
  2771. //update current item (switch with previous)
  2772. if($id != 0){
  2773. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2774. if($this->debug>2){error_log($sql_upd2,0);}
  2775. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2776. }
  2777. //update next item (new previous item)
  2778. if($next != 0){
  2779. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2780. if($this->debug>2){error_log($sql_upd2,0);}
  2781. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2782. }
  2783. $display = $display-1;
  2784. }
  2785. break;
  2786. case 'down':
  2787. if($this->debug>2){error_log('Movement down detected',0);}
  2788. if($next == 0){/*do nothing*/}
  2789. else{
  2790. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2791. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2792. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2793. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2794. //gather data
  2795. $row2 = Database::fetch_array($res_sel2);
  2796. $next_next = $row2['next_item_id'];
  2797. //update previous item (switch with current)
  2798. if($previous != 0)
  2799. {
  2800. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2801. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2802. }
  2803. //update current item (switch with previous)
  2804. if($id != 0)
  2805. {
  2806. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2807. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2808. }
  2809. //update next item (new previous item)
  2810. if($next != 0)
  2811. {
  2812. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2813. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2814. }
  2815. //update next_next item (switch "previous" with current)
  2816. if($next_next != 0)
  2817. {
  2818. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2819. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2820. }
  2821. $display = $display+1;
  2822. }
  2823. break;
  2824. default:
  2825. return false;
  2826. }
  2827. return $display;
  2828. }
  2829. /**
  2830. * Move a learnpath up (display_order)
  2831. * @param integer Learnpath ID
  2832. */
  2833. function move_up($lp_id)
  2834. {
  2835. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2836. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2837. $res = api_sql_query($sql, __FILE__, __LINE__);
  2838. if($res === false) return false;
  2839. $lps = array();
  2840. $lp_order = array();
  2841. $num = Database::num_rows($res);
  2842. //first check the order is correct, globally (might be wrong because
  2843. //of versions < 1.8.4)
  2844. if($num>0)
  2845. {
  2846. $i = 1;
  2847. while($row = Database::fetch_array($res))
  2848. {
  2849. if($row['display_order'] != $i)
  2850. { //if we find a gap in the order, we need to fix it
  2851. $need_fix = true;
  2852. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2853. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2854. }
  2855. $row['display_order'] = $i;
  2856. $lps[$row['id']] = $row;
  2857. $lp_order[$i] = $row['id'];
  2858. $i++;
  2859. }
  2860. }
  2861. if($num>1) //if there's only one element, no need to sort
  2862. {
  2863. $order = $lps[$lp_id]['display_order'];
  2864. if($order>1) //if it's the first element, no need to move up
  2865. {
  2866. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
  2867. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2868. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
  2869. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2870. }
  2871. }
  2872. }
  2873. /**
  2874. * Move a learnpath down (display_order)
  2875. * @param integer Learnpath ID
  2876. */
  2877. function move_down($lp_id)
  2878. {
  2879. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2880. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2881. $res = api_sql_query($sql, __FILE__, __LINE__);
  2882. if($res === false) return false;
  2883. $lps = array();
  2884. $lp_order = array();
  2885. $num = Database::num_rows($res);
  2886. $max = 0;
  2887. //first check the order is correct, globally (might be wrong because
  2888. //of versions < 1.8.4)
  2889. if($num>0)
  2890. {
  2891. $i = 1;
  2892. while($row = Database::fetch_array($res))
  2893. {
  2894. $max = $i;
  2895. if($row['display_order'] != $i)
  2896. { //if we find a gap in the order, we need to fix it
  2897. $need_fix = true;
  2898. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2899. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2900. }
  2901. $row['display_order'] = $i;
  2902. $lps[$row['id']] = $row;
  2903. $lp_order[$i] = $row['id'];
  2904. $i++;
  2905. }
  2906. }
  2907. if($num>1) //if there's only one element, no need to sort
  2908. {
  2909. $order = $lps[$lp_id]['display_order'];
  2910. if($order<$max) //if it's the first element, no need to move up
  2911. {
  2912. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
  2913. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2914. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
  2915. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2916. }
  2917. }
  2918. }
  2919. /**
  2920. * Updates learnpath attributes to point to the next element
  2921. * The last part is similar to set_current_item but processing the other way around
  2922. */
  2923. function next()
  2924. {
  2925. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2926. $this->last = $this->get_current_item_id();
  2927. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2928. $this->autocomplete_parents($this->last);
  2929. $new_index = $this->get_next_index();
  2930. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2931. $this->index = $new_index;
  2932. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2933. $this->current = $this->ordered_items[$new_index];
  2934. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2935. }
  2936. /**
  2937. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2938. * class, this might be redefined to allow several behaviours depending on the document type.
  2939. * @param integer Resource ID
  2940. * @return boolean True on success, false otherwise
  2941. */
  2942. function open($id)
  2943. {
  2944. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2945. //TODO
  2946. //set the current resource attribute to this resource
  2947. //switch on element type (redefine in child class?)
  2948. //set status for this item to "opened"
  2949. //start timer
  2950. //initialise score
  2951. $this->index = 0; //or = the last item seen (see $this->last)
  2952. }
  2953. /**
  2954. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2955. * and the prerequisite string on error.
  2956. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2957. * @param integer Optional item ID. If none given, uses the current open item.
  2958. * @return boolean True if prerequisites are matched, false otherwise
  2959. * @return string Empty string if true returned, prerequisites string otherwise.
  2960. */
  2961. function prerequisites_match($item = null)
  2962. {
  2963. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2964. if(empty($item)){$item = $this->current;}
  2965. if(is_object($this->items[$item]))
  2966. {
  2967. $prereq_string = $this->items[$item]->get_prereq_string();
  2968. if(empty($prereq_string)){return true;}
  2969. //clean spaces
  2970. $prereq_string = str_replace(' ','',$prereq_string);
  2971. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2972. //now send to the parse_prereq() function that will check this component's prerequisites
  2973. $result = $this->items[$item]->parse_prereq($prereq_string,$this->items,$this->refs_list,$this->get_user_id());
  2974. if($result === false)
  2975. {
  2976. $this->set_error_msg($this->items[$item]->prereq_alert);
  2977. }
  2978. }else{
  2979. $result = true;
  2980. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2981. }
  2982. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2983. return $result;
  2984. }
  2985. /**
  2986. * Updates learnpath attributes to point to the previous element
  2987. * The last part is similar to set_current_item but processing the other way around
  2988. */
  2989. function previous()
  2990. {
  2991. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2992. $this->last = $this->get_current_item_id();
  2993. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2994. $this->autocomplete_parents($this->last);
  2995. $new_index = $this->get_previous_index();
  2996. $this->index = $new_index;
  2997. $this->current = $this->ordered_items[$new_index];
  2998. }
  2999. /**
  3000. * Publishes a learnpath. This basically means show or hide the learnpath
  3001. * to normal users.
  3002. * Can be used as abstract
  3003. * @param integer Learnpath ID
  3004. * @param string New visibility
  3005. */
  3006. function toggle_visibility($lp_id,$set_visibility=1)
  3007. {
  3008. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  3009. $action = 'visible';
  3010. if($set_visibility != 1)
  3011. {
  3012. $action = 'invisible';
  3013. }
  3014. return api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$lp_id,$action,api_get_user_id());
  3015. }
  3016. /**
  3017. * Publishes a learnpath. This basically means show or hide the learnpath
  3018. * on the course homepage
  3019. * Can be used as abstract
  3020. * @param integer Learnpath ID
  3021. * @param string New visibility
  3022. */
  3023. function toggle_publish($lp_id,$set_visibility='v')
  3024. {
  3025. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  3026. $tbl_lp = Database::get_course_table('lp');
  3027. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  3028. $result=api_sql_query($sql,__FILE__,__LINE__);
  3029. $row=Database::fetch_array($result);
  3030. $name=domesticate($row['name']);
  3031. if($set_visibility == 'i') {
  3032. $s=$name." ".get_lang('_no_published');
  3033. $dialogBox=$s;
  3034. $v=0;
  3035. }
  3036. if($set_visibility == 'v')
  3037. {
  3038. $s=$name." ".get_lang('_published');
  3039. $dialogBox=$s;
  3040. $v=1;
  3041. }
  3042. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  3043. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  3044. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  3045. $result=api_sql_query($sql,__FILE__,__LINE__);
  3046. $num=Database::num_rows($result);
  3047. $row2=Database::fetch_array($result);
  3048. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  3049. if(($set_visibility == 'i') && ($num>0))
  3050. {
  3051. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  3052. }
  3053. elseif(($set_visibility == 'v') && ($num==0))
  3054. {
  3055. $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)";
  3056. }
  3057. else
  3058. {
  3059. //parameter and database incompatible, do nothing
  3060. }
  3061. $result=api_sql_query($sql,__FILE__,__LINE__);
  3062. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3063. }
  3064. /**
  3065. * Restart the whole learnpath. Return the URL of the first element.
  3066. * Make sure the results are saved with anoter method. This method should probably be
  3067. * redefined in children classes.
  3068. * To use a similar method statically, use the create_new_attempt() method
  3069. * @return string URL to load in the viewer
  3070. */
  3071. function restart()
  3072. {
  3073. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  3074. //TODO
  3075. //call autosave method to save the current progress
  3076. //$this->index = 0;
  3077. $lp_view_table = Database::get_course_table('lp_view');
  3078. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  3079. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  3080. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  3081. $res = api_sql_query($sql, __FILE__, __LINE__);
  3082. if($view_id = Database::get_last_insert_id($res))
  3083. {
  3084. $this->lp_view_id = $view_id;
  3085. $this->attempt = $this->attempt+1;
  3086. }else{
  3087. $this->error = 'Could not insert into item_view table...';
  3088. return false;
  3089. }
  3090. $this->autocomplete_parents($this->current);
  3091. foreach($this->items as $index=>$dummy){
  3092. $this->items[$index]->restart();
  3093. $this->items[$index]->set_lp_view($this->lp_view_id);
  3094. }
  3095. $this->first();
  3096. return true;
  3097. }
  3098. /**
  3099. * Saves the current item
  3100. * @return boolean
  3101. */
  3102. function save_current(){
  3103. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  3104. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3105. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3106. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  3107. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  3108. if(is_object($this->items[$this->current])){
  3109. //$res = $this->items[$this->current]->save(false);
  3110. $res = $this->items[$this->current]->save(false,$this->prerequisites_match($this->current));
  3111. $this->autocomplete_parents($this->current);
  3112. $status = $this->items[$this->current]->get_status();
  3113. $this->append_message('new_item_status: '.$status);
  3114. $this->update_queue[$this->current] = $status;
  3115. return $res;
  3116. }
  3117. return false;
  3118. }
  3119. /**
  3120. * Saves the given item
  3121. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3122. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3123. * @return boolean
  3124. */
  3125. function save_item($item_id=null,$from_outside=true){
  3126. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  3127. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3128. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3129. if(empty($item_id)){
  3130. $item_id = $this->escape_string($_REQUEST['id']);
  3131. }
  3132. if(empty($item_id))
  3133. {
  3134. $item_id = $this->get_current_item_id();
  3135. }
  3136. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  3137. if(is_object($this->items[$item_id])){
  3138. $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id));
  3139. //$res = $this->items[$item_id]->save($from_outside);
  3140. $this->autocomplete_parents($item_id);
  3141. $status = $this->items[$item_id]->get_status();
  3142. $this->append_message('new_item_status: '.$status);
  3143. $this->update_queue[$item_id] = $status;
  3144. return $res;
  3145. }
  3146. return false;
  3147. }
  3148. /**
  3149. * Saves the last item seen's ID only in case
  3150. */
  3151. function save_last(){
  3152. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  3153. $table = Database::get_course_table('lp_view');
  3154. if(isset($this->current)){
  3155. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  3156. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  3157. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  3158. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  3159. $res = api_sql_query($sql,__FILE__,__LINE__);
  3160. }
  3161. //save progress
  3162. list($progress,$text) = $this->get_progress_bar_text('%');
  3163. if($progress>=0 AND $progress<=100){
  3164. $progress= (int)$progress;
  3165. $sql = "UPDATE $table SET progress = $progress " .
  3166. "WHERE lp_id = ".$this->get_id()." AND " .
  3167. "user_id = ".$this->get_user_id();
  3168. $res = api_sql_query($sql,__FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  3169. $this->progress_db = $progress;
  3170. }
  3171. }
  3172. /**
  3173. * Sets the current item ID (checks if valid and authorized first)
  3174. * @param integer New item ID. If not given or not authorized, defaults to current
  3175. */
  3176. function set_current_item($item_id=null)
  3177. {
  3178. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  3179. if(empty($item_id)){
  3180. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  3181. //do nothing
  3182. }else{
  3183. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  3184. $item_id = $this->escape_string($item_id);
  3185. //TODO check in database here
  3186. $this->last = $this->current;
  3187. $this->current = $item_id;
  3188. //TODO update $this->index as well
  3189. foreach($this->ordered_items as $index => $item)
  3190. {
  3191. if($item == $this->current)
  3192. {
  3193. $this->index = $index;
  3194. break;
  3195. }
  3196. }
  3197. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  3198. }
  3199. }
  3200. /**
  3201. * Sets the encoding
  3202. * @param string New encoding
  3203. */
  3204. function set_encoding($enc='ISO-8859-1'){
  3205. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  3206. $enc = strtoupper($enc);
  3207. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','cp1251','cp1252','KOI8-R','BIG5','GB2312','Shift_JIS','EUC-JP','');
  3208. if(in_array($enc,$encodings)){
  3209. $lp = $this->get_id();
  3210. if($lp!=0){
  3211. $tbl_lp = Database::get_course_table('lp');
  3212. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  3213. $res = api_sql_query($sql, __FILE__, __LINE__);
  3214. return $res;
  3215. }
  3216. }
  3217. return false;
  3218. }
  3219. /**
  3220. * Sets the JS lib setting in the database directly.
  3221. * This is the JavaScript library file this lp needs to load on startup
  3222. * @param string Proximity setting
  3223. */
  3224. function set_jslib($lib=''){
  3225. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  3226. $lp = $this->get_id();
  3227. if($lp!=0){
  3228. $tbl_lp = Database::get_course_table('lp');
  3229. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  3230. $res = api_sql_query($sql, __FILE__, __LINE__);
  3231. return $res;
  3232. }else{
  3233. return false;
  3234. }
  3235. }
  3236. /**
  3237. * Sets the name of the LP maker (publisher) (and save)
  3238. * @param string Optional string giving the new content_maker of this learnpath
  3239. */
  3240. function set_maker($name=''){
  3241. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  3242. if(empty($name))return false;
  3243. $this->maker = $this->escape_string($name);
  3244. $lp_table = Database::get_course_table('lp');
  3245. $lp_id = $this->get_id();
  3246. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  3247. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  3248. //$res = Database::query($sql);
  3249. $res = api_sql_query($sql, __FILE__, __LINE__);
  3250. return true;
  3251. }
  3252. /**
  3253. * Sets the name of the current learnpath (and save)
  3254. * @param string Optional string giving the new name of this learnpath
  3255. */
  3256. function set_name($name=''){
  3257. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  3258. if(empty($name))return false;
  3259. $this->name = $this->escape_string($name);
  3260. $lp_table = Database::get_course_table('lp');
  3261. $lp_id = $this->get_id();
  3262. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  3263. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  3264. //$res = Database::query($sql);
  3265. $res = api_sql_query($sql, __FILE__, __LINE__);
  3266. // if the lp is visible on the homepage, change his name there
  3267. if(mysql_affected_rows())
  3268. {
  3269. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3270. $sql = 'UPDATE '.$table.' SET
  3271. name = "'.$this->name.'"
  3272. WHERE link = "newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'"';
  3273. api_sql_query($sql, __FILE__, __LINE__);
  3274. }
  3275. return true;
  3276. }
  3277. /**
  3278. * Set index specified prefix terms for all items in this path
  3279. * @param string Comma-separated list of terms
  3280. * @param char Xapian term prefix
  3281. * @return boolean False on error, true otherwise
  3282. */
  3283. function set_terms_by_prefix($terms_string, $prefix) {
  3284. if (api_get_setting('search_enabled') !== 'true')
  3285. return FALSE;
  3286. $terms_string = trim($terms_string);
  3287. $terms = explode(',', $terms_string);
  3288. array_walk($terms, 'trim_value');
  3289. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3290. //var_dump($stored_terms);
  3291. //var_dump($terms);
  3292. // don't do anything if no change, verify only at DB, not the search engine
  3293. if ( (count(array_diff($terms, $stored_terms))==0) && (count(array_diff($stored_terms, $terms))==0) )
  3294. return FALSE;
  3295. require_once('xapian.php'); //TODO try catch every xapian use or make wrappers on api
  3296. require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php');
  3297. require_once(api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php');
  3298. require_once(api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php');
  3299. $items_table = Database::get_course_table('lp_item');
  3300. //TODO: make query secure agains XSS : use member attr instead of post var
  3301. $lp_id = $_POST['lp_id'];
  3302. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3303. $result = api_sql_query($sql);
  3304. $di = new DokeosIndexer();
  3305. while($lp_item = Database::fetch_array($result))
  3306. {
  3307. // get search_did
  3308. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3309. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  3310. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3311. $res = api_sql_query($sql, __FILE__, __LINE__);
  3312. $se_ref = Database::fetch_array($res);
  3313. // compare terms
  3314. $doc = $di->get_document($se_ref['search_did']);
  3315. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3316. //var_dump($xapian_terms);
  3317. $xterms = array();
  3318. foreach ($xapian_terms as $xapian_term) $xterms[] = substr($xapian_term['name'],1);
  3319. $dterms = $terms;
  3320. //var_dump($xterms);
  3321. //var_dump($dterms);
  3322. $missing_terms = array_diff($dterms, $xterms);
  3323. $deprecated_terms = array_diff($xterms, $dterms);
  3324. // save it to search engine
  3325. foreach ($missing_terms as $term)
  3326. {
  3327. $doc->add_term($prefix. $term, 1);
  3328. }
  3329. foreach ($deprecated_terms as $term)
  3330. {
  3331. $doc->remove_term($prefix.$term);
  3332. }
  3333. $di->getDb()->replace_document((int)$se_ref['search_did'], $doc);
  3334. $di->getDb()->flush();
  3335. }
  3336. return true;
  3337. }
  3338. /**
  3339. * Sets the theme of the LP (local/remote) (and save)
  3340. * @param string Optional string giving the new theme of this learnpath
  3341. * @return bool returns true if theme name is not empty
  3342. */
  3343. function set_theme($name=''){
  3344. if($this->debug>0){error_log('New LP - In learnpath::set_theme()',0);}
  3345. $this->theme = $this->escape_string($name);
  3346. $lp_table = Database::get_course_table('lp');
  3347. $lp_id = $this->get_id();
  3348. $sql = "UPDATE $lp_table SET theme = '".$this->theme."' WHERE id = '$lp_id'";
  3349. if($this->debug>2){error_log('New LP - lp updated with new theme : '.$this->theme,0);}
  3350. //$res = Database::query($sql);
  3351. $res = api_sql_query($sql, __FILE__, __LINE__);
  3352. return true;
  3353. }
  3354. /**
  3355. * Sets the image of an LP (and save)
  3356. * @param string Optional string giving the new image of this learnpath
  3357. * @return bool returns true if theme name is not empty
  3358. */
  3359. function set_preview_image($name=''){
  3360. if($this->debug>0){error_log('New LP - In learnpath::set_preview_image()',0);}
  3361. $this->preview_image = $this->escape_string($name);
  3362. $lp_table = Database::get_course_table('lp');
  3363. $lp_id = $this->get_id();
  3364. $sql = "UPDATE $lp_table SET preview_image = '".$this->preview_image."' WHERE id = '$lp_id'";
  3365. if($this->debug>2){error_log('New LP - lp updated with new preview image : '.$this->preview_image,0);}
  3366. $res = api_sql_query($sql, __FILE__, __LINE__);
  3367. return true;
  3368. }
  3369. /**
  3370. * Sets the author of a LP (and save)
  3371. * @param string Optional string giving the new author of this learnpath
  3372. * @return bool returns true if author's name is not empty
  3373. */
  3374. function set_author($name=''){
  3375. if($this->debug>0){error_log('New LP - In learnpath::set_author()',0);}
  3376. $this->author = $this->escape_string($name);
  3377. $lp_table = Database::get_course_table('lp');
  3378. $lp_id = $this->get_id();
  3379. $sql = "UPDATE $lp_table SET author = '".$this->author."' WHERE id = '$lp_id'";
  3380. if($this->debug>2){error_log('New LP - lp updated with new preview author : '.$this->author,0);}
  3381. $res = api_sql_query($sql, __FILE__, __LINE__);
  3382. return true;
  3383. }
  3384. /**
  3385. * Sets the location/proximity of the LP (local/remote) (and save)
  3386. * @param string Optional string giving the new location of this learnpath
  3387. */
  3388. function set_proximity($name=''){
  3389. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  3390. if(empty($name))return false;
  3391. $this->proximity = $this->escape_string($name);
  3392. $lp_table = Database::get_course_table('lp');
  3393. $lp_id = $this->get_id();
  3394. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  3395. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  3396. //$res = Database::query($sql);
  3397. $res = api_sql_query($sql, __FILE__, __LINE__);
  3398. return true;
  3399. }
  3400. /**
  3401. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3402. * @param integer DB ID of the item
  3403. */
  3404. function set_previous_item($id)
  3405. {
  3406. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  3407. $this->last = $id;
  3408. }
  3409. /**
  3410. * Sets the object's error message
  3411. * @param string Error message. If empty, reinits the error string
  3412. * @return void
  3413. */
  3414. function set_error_msg($error='')
  3415. {
  3416. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  3417. if(empty($error)){
  3418. $this->error = '';
  3419. }else{
  3420. $this->error .= $error;
  3421. }
  3422. }
  3423. /**
  3424. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3425. *
  3426. */
  3427. function start_current_item($allow_new_attempt=false){
  3428. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  3429. if($this->current != 0 AND
  3430. is_object($this->items[$this->current]))
  3431. {
  3432. $type = $this->get_type();
  3433. $item_type = $this->items[$this->current]->get_type();
  3434. if(
  3435. ($type == 2 && $item_type!='sco')
  3436. OR
  3437. ($type == 3 && $item_type!='au')
  3438. OR
  3439. ($type == 1 && $item_type!=TOOL_QUIZ && $item_type!=TOOL_HOTPOTATOES)
  3440. )
  3441. {
  3442. $this->items[$this->current]->open($allow_new_attempt);
  3443. $this->autocomplete_parents($this->current);
  3444. $prereq_check = $this->prerequisites_match($this->current);
  3445. $this->items[$this->current]->save(false,$prereq_check);
  3446. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3447. }else{
  3448. //if sco, then it is supposed to have been updated by some other call
  3449. }
  3450. if ($item_type=='sco') {
  3451. $this->items[$this->current]->restart();
  3452. }
  3453. }
  3454. if($this->debug>0){error_log('New LP - End of learnpath::start_current_item()',0);}
  3455. return true;
  3456. }
  3457. /**
  3458. * Stops the processing and counters for the old item (as held in $this->last)
  3459. * @param
  3460. */
  3461. function stop_previous_item(){
  3462. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  3463. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  3464. {
  3465. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  3466. switch($this->get_type()){
  3467. case '3':
  3468. if($this->items[$this->last]->get_type()!='au')
  3469. {
  3470. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  3471. $this->items[$this->last]->close();
  3472. //$this->autocomplete_parents($this->last);
  3473. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3474. }else{
  3475. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  3476. }
  3477. case '2':
  3478. if($this->items[$this->last]->get_type()!='sco')
  3479. {
  3480. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  3481. $this->items[$this->last]->close();
  3482. //$this->autocomplete_parents($this->last);
  3483. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3484. }else{
  3485. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  3486. }
  3487. break;
  3488. case '1':
  3489. default:
  3490. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  3491. $this->items[$this->last]->close();
  3492. break;
  3493. }
  3494. }else{
  3495. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  3496. return false;
  3497. }
  3498. return true;
  3499. }
  3500. /**
  3501. * Updates the default view mode from fullscreen to embedded and inversely
  3502. * @return string The current default view mode ('fullscreen' or 'embedded')
  3503. */
  3504. function update_default_view_mode()
  3505. {
  3506. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  3507. $lp_table = Database::get_course_table('lp');
  3508. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3509. $res = api_sql_query($sql, __FILE__, __LINE__);
  3510. if(Database::num_rows($res)>0){
  3511. $row = Database::fetch_array($res);
  3512. $view_mode = $row['default_view_mod'];
  3513. if($view_mode == 'fullscreen'){
  3514. $view_mode = 'embedded';
  3515. }elseif($view_mode == 'embedded'){
  3516. $view_mode = 'fullscreen';
  3517. }
  3518. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  3519. $res = api_sql_query($sql, __FILE__, __LINE__);
  3520. $this->mode = $view_mode;
  3521. return $view_mode;
  3522. }else{
  3523. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  3524. }
  3525. return -1;
  3526. }
  3527. /**
  3528. * Updates the default behaviour about auto-commiting SCORM updates
  3529. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3530. */
  3531. function update_default_scorm_commit(){
  3532. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  3533. $lp_table = Database::get_course_table('lp');
  3534. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3535. $res = api_sql_query($sql, __FILE__, __LINE__);
  3536. if(Database::num_rows($res)>0){
  3537. $row = Database::fetch_array($res);
  3538. $force = $row['force_commit'];
  3539. if($force == 1){
  3540. $force = 0;
  3541. $force_return = false;
  3542. }elseif($force == 0){
  3543. $force = 1;
  3544. $force_return = true;
  3545. }
  3546. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  3547. $res = api_sql_query($sql, __FILE__, __LINE__);
  3548. $this->force_commit = $force_return;
  3549. return $force_return;
  3550. }else{
  3551. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  3552. }
  3553. return -1;
  3554. }
  3555. /**
  3556. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3557. * @return bool True on success, false on failure
  3558. */
  3559. function update_display_order()
  3560. {
  3561. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  3562. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3563. $res = api_sql_query($sql, __FILE__, __LINE__);
  3564. if($res === false) return false;
  3565. $lps = array();
  3566. $lp_order = array();
  3567. $num = Database::num_rows($res);
  3568. //first check the order is correct, globally (might be wrong because
  3569. //of versions < 1.8.4)
  3570. if($num>0)
  3571. {
  3572. $i = 1;
  3573. while($row = Database::fetch_array($res))
  3574. {
  3575. if($row['display_order'] != $i)
  3576. { //if we find a gap in the order, we need to fix it
  3577. $need_fix = true;
  3578. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  3579. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  3580. }
  3581. $i++;
  3582. }
  3583. }
  3584. return true;
  3585. }
  3586. /**
  3587. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3588. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3589. */
  3590. function update_reinit(){
  3591. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  3592. $lp_table = Database::get_course_table('lp');
  3593. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3594. $res = api_sql_query($sql, __FILE__, __LINE__);
  3595. if(Database::num_rows($res)>0){
  3596. $row = Database::fetch_array($res);
  3597. $force = $row['prevent_reinit'];
  3598. if($force == 1){
  3599. $force = 0;
  3600. }elseif($force == 0){
  3601. $force = 1;
  3602. }
  3603. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  3604. $res = api_sql_query($sql,__FILE__,__LINE__);
  3605. $this->prevent_reinit = $force;
  3606. return $force;
  3607. }else{
  3608. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  3609. }
  3610. return -1;
  3611. }
  3612. /**
  3613. * Updates the "scorm_debug" value that shows or hide the debug window
  3614. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3615. */
  3616. function update_scorm_debug(){
  3617. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  3618. $lp_table = Database::get_course_table('lp');
  3619. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3620. $res = api_sql_query($sql, __FILE__, __LINE__);
  3621. if(Database::num_rows($res)>0){
  3622. $row = Database::fetch_array($res);
  3623. $force = $row['debug'];
  3624. if($force == 1){
  3625. $force = 0;
  3626. }elseif($force == 0){
  3627. $force = 1;
  3628. }
  3629. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  3630. $res = api_sql_query($sql,__FILE__,__LINE__);
  3631. $this->scorm_debug = $force;
  3632. return $force;
  3633. }else{
  3634. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  3635. }
  3636. return -1;
  3637. }
  3638. /**
  3639. * Function that makes a call to the function sort_tree_array and create_tree_array
  3640. *
  3641. * @author Kevin Van Den Haute
  3642. *
  3643. * @param unknown_type $array
  3644. */
  3645. function tree_array($array)
  3646. {
  3647. if($this->debug>1){error_log('New LP - In learnpath::tree_array()',0);}
  3648. $array = $this->sort_tree_array($array);
  3649. $this->create_tree_array($array);
  3650. }
  3651. /**
  3652. * Creates an array with the elements of the learning path tree in it
  3653. *
  3654. * @author Kevin Van Den Haute
  3655. *
  3656. * @param array $array
  3657. * @param int $parent
  3658. * @param int $depth
  3659. * @param array $tmp
  3660. */
  3661. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  3662. {
  3663. if($this->debug>1){error_log('New LP - In learnpath::create_tree_array())',0);}
  3664. if(is_array($array))
  3665. {
  3666. for($i = 0; $i < count($array); $i++)
  3667. {
  3668. if($array[$i]['parent_item_id'] == $parent)
  3669. {
  3670. if(!in_array($array[$i]['parent_item_id'], $tmp))
  3671. {
  3672. $tmp[] = $array[$i]['parent_item_id'];
  3673. $depth++;
  3674. }
  3675. $preq = (empty($array[$i]['prerequisite'])?'':$array[$i]['prerequisite']);
  3676. $this->arrMenu[] = array(
  3677. 'id' => $array[$i]['id'],
  3678. 'item_type' => $array[$i]['item_type'],
  3679. 'title' => $array[$i]['title'],
  3680. 'path' => $array[$i]['path'],
  3681. 'description' => $array[$i]['description'],
  3682. 'parent_item_id' => $array[$i]['parent_item_id'],
  3683. 'previous_item_id' => $array[$i]['previous_item_id'],
  3684. 'next_item_id' => $array[$i]['next_item_id'],
  3685. 'min_score' => $array[$i]['min_score'],
  3686. 'max_score' => $array[$i]['max_score'],
  3687. 'mastery_score' => $array[$i]['mastery_score'],
  3688. 'display_order' => $array[$i]['display_order'],
  3689. 'prerequisite' => $preq,
  3690. 'depth' => $depth,
  3691. 'audio' => $array[$i]['audio']
  3692. );
  3693. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3694. }
  3695. }
  3696. }
  3697. }
  3698. /**
  3699. * Sorts a multi dimensional array by parent id and display order
  3700. * @author Kevin Van Den Haute
  3701. *
  3702. * @param array $array (array with al the learning path items in it)
  3703. *
  3704. * @return array
  3705. */
  3706. function sort_tree_array($array)
  3707. {
  3708. foreach($array as $key => $row)
  3709. {
  3710. $parent[$key] = $row['parent_item_id'];
  3711. $position[$key] = $row['display_order'];
  3712. }
  3713. if(count($array) > 0)
  3714. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3715. return $array;
  3716. }
  3717. /**
  3718. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3719. * Also the actions for the modules, chapters and documents are in this table.
  3720. *
  3721. * @author Kevin Van Den Haute
  3722. *
  3723. * @param int $lp_id
  3724. *
  3725. * @return string
  3726. */
  3727. function overview()
  3728. {
  3729. if($this->debug>0){error_log('New LP - In learnpath::overview()',0);}
  3730. global $charset, $_course;
  3731. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  3732. $return = '';
  3733. $tbl_lp_item = Database::get_course_table('lp_item');
  3734. $sql = "
  3735. SELECT *
  3736. FROM " . $tbl_lp_item . "
  3737. WHERE
  3738. lp_id = " . $this->lp_id;
  3739. $result = api_sql_query($sql, __FILE__, __LINE__);
  3740. $arrLP = array();
  3741. $mycharset=api_get_setting('platform_charset');
  3742. while($row = Database::fetch_array($result))
  3743. {
  3744. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3745. $arrLP[] = array(
  3746. 'id' => $row['id'],
  3747. 'item_type' => $row['item_type'],
  3748. 'title' => $row['title'],
  3749. 'path' => $row['path'],
  3750. 'description' => $row['description'],
  3751. 'parent_item_id' => $row['parent_item_id'],
  3752. 'previous_item_id' => $row['previous_item_id'],
  3753. 'next_item_id' => $row['next_item_id'],
  3754. 'max_score' => $row['max_score'],
  3755. 'min_score' => $row['min_score'],
  3756. 'mastery_score' => $row['mastery_score'],
  3757. 'prerequisite' => $row['prerequisite'],
  3758. 'display_order' => $row['display_order'],
  3759. 'audio' => $row['audio']
  3760. );
  3761. }
  3762. $this->tree_array($arrLP);
  3763. $arrLP = $this->arrMenu;
  3764. unset($this->arrMenu);
  3765. if (api_is_allowed_to_edit()) {
  3766. $gradebook=Security::remove_XSS($_GET['gradebook']);
  3767. $return .= '<div class="actions">';
  3768. //$return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;gradebook='.$gradebook.'&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="'.get_lang("Build").'">'.Display::return_icon('learnpath_build.gif', get_lang('Build')).' '.get_lang('Build').'</a>';
  3769. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;gradebook='.$gradebook.'&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="'.get_lang("Build").'"><img alt="'.get_lang("Build").'" src="../img/learnpath_build.png" title="'.get_lang("Build").'" />'.get_lang("Build").'</a>';
  3770. //$return .= '<span>'.Display::return_icon('learnpath_organize.gif', get_lang("BasicOverview")).' '.get_lang("BasicOverview").'</span>';
  3771. $return .= '<span><img alt="'.get_lang("BasicOverview").'" src="../img/learnpath_organize.png" title="'.get_lang("BasicOverview").'" />'.' '.get_lang('BasicOverview').'</span>';
  3772. $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")).' '.get_lang("Display").'</a>';
  3773. $return .= '<a href="'.api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&amp;action='.Security::remove_XSS($_GET['action']).'&amp;lp_id='.Security::remove_XSS($_GET['lp_id']).'&amp;updateaudio=true">'.Display::return_icon('audio.gif', get_lang('UpdateAllAudioFragments')).' '.get_lang('UpdateAllAudioFragments').'</a>';
  3774. $return .= '</div>';
  3775. }
  3776. // we need to start a form when we want to update all the mp3 files
  3777. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  3778. $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">';
  3779. $return .= Display::display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  3780. }
  3781. $return .= '<table class="data_table">' . "\n";
  3782. $return .= "\t" . '<tr>' . "\n";
  3783. $return .= "\t" . '<th width="60%">'.get_lang("Title").'</th>' . "\n";
  3784. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3785. $return .= "\t" . '<th>'.get_lang("Audio").'</th>' . "\n";
  3786. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3787. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3788. $return .= "\t" . '</tr>' . "\n";
  3789. for($i = 0; $i < count($arrLP); $i++)
  3790. {
  3791. $title=$arrLP[$i]['title'];
  3792. if($arrLP[$i]['description'] == '')
  3793. $arrLP[$i]['description'] = '&nbsp;';
  3794. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3795. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3796. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  3797. if (file_exists("../img/lp_" . $icon_name . ".png"))
  3798. {
  3799. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3800. }
  3801. else if(file_exists("../img/lp_" . $icon_name . ".gif"))
  3802. {
  3803. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3804. }
  3805. else
  3806. {
  3807. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_document.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3808. }
  3809. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3810. // The audio column
  3811. $return .= "\t\t" . '<td align="center">';
  3812. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true')
  3813. {
  3814. if (!empty($arrLP[$i]['audio']))
  3815. {
  3816. $return .= '<span id="container'.$i.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  3817. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  3818. $return .= '<script type="text/javascript">
  3819. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  3820. s1.addParam("allowscriptaccess","always");
  3821. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$arrLP[$i]['audio'].'&image=preview.jpg");
  3822. s1.write("container'.$i.'");
  3823. </script>';
  3824. }
  3825. else
  3826. {
  3827. $return .= ' - ';
  3828. }
  3829. }
  3830. else
  3831. {
  3832. if ($arrLP[$i]['item_type']!='dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  3833. $return .= ' <input type="file" name="mp3file'.$arrLP[$i]['id'].'" id="mp3file" />';
  3834. if (!empty($arrLP[$i]['audio']))
  3835. {
  3836. $return .= '<br /><input type="checkbox" name="removemp3'.$arrLP[$i]['id'].'" id="checkbox'.$arrLP[$i]['id'].'" />'.get_lang('RemoveAudio');
  3837. }
  3838. }
  3839. }
  3840. $return .= '</td>' . "\n";
  3841. if(api_is_allowed_to_edit())
  3842. {
  3843. $return .= "\t\t" . '<td align="center">' . "\n";
  3844. if($arrLP[$i]['previous_item_id'] != 0)
  3845. {
  3846. $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 . '">';
  3847. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3). '.gif" title="' . get_lang('MoveUp') .'"/>';
  3848. $return .= '</a>' . "\n";
  3849. }
  3850. else
  3851. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3852. if($arrLP[$i]['next_item_id'] != 0)
  3853. {
  3854. $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 . '">';
  3855. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  3856. $return .= '</a>' . "\n";
  3857. }
  3858. else
  3859. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3860. $return .= "\t\t" . '</td>' . "\n";
  3861. $return .= "\t\t" . '<td align="center">' . "\n";
  3862. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3863. {
  3864. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item='.$arrLP[$i]['path'].'">';
  3865. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3866. $return .= '</a>' . "\n";
  3867. }
  3868. else
  3869. {
  3870. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item='.$arrLP[$i]['path'].'">';
  3871. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3872. $return .= '</a>' . "\n";
  3873. }
  3874. $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). '\');">';
  3875. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3876. $return .= '</a>' . "\n";
  3877. $return .= "\t\t" . '</td>' . "\n";
  3878. }
  3879. $return .= "\t" . '</tr>' . "\n";
  3880. }
  3881. if(count($arrLP) == 0)
  3882. {
  3883. $return .= "\t" . '<tr>' . "\n";
  3884. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3885. $return .= "\t" . '</tr>' . "\n";
  3886. }
  3887. $return .= '</table>' . "\n";
  3888. // we need to close the form when we are updating the mp3 files
  3889. if ($_GET['updateaudio'] == 'true')
  3890. {
  3891. $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">'.get_lang('Save audio and organization').'</button></div>';
  3892. }
  3893. // we need to close the form when we are updating the mp3 files
  3894. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0)
  3895. {
  3896. $return .= '</form>';
  3897. }
  3898. return $return;
  3899. }
  3900. /**
  3901. * This function builds the action menu
  3902. *
  3903. * */
  3904. function build_action_menu() {
  3905. $gradebook = Security::remove_XSS($_GET['gradebook']);
  3906. echo '<div class="actions">';
  3907. //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  3908. echo '<span><img alt="'.get_lang("Build").'" src="../img/learnpath_build.png" title="'.get_lang("Build").'" />'.' '.get_lang('Build').'</span>';
  3909. //echo '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.Display::return_icon('learnpath_organize.gif').' '.get_lang("BasicOverview").'</a>';
  3910. echo '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang("BasicOverview").'"><img alt="'.get_lang("BasicOverview").'" src="../img/learnpath_organize.png" title="'.get_lang("BasicOverview").'" />'.get_lang("BasicOverview").'</a>';
  3911. //echo '<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']).'&amp;gradebook='.$gradebook.'&action=view&lp_id='.$_SESSION['oLP']->lp_id.'">'.Display::return_icon('learnpath_view.gif').' '.get_lang('Display').'</a>';
  3912. echo '<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']).'&amp;gradebook='.$gradebook.'&action=view&lp_id='.$_SESSION['oLP']->lp_id.'" title="'.get_lang("Display").'"><img alt="'.get_lang("Display").'" src="../img/learnpath_view.gif" title="'.get_lang("Display").'" />'.get_lang("Display").'</a>';
  3913. echo '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang("NewChapter").'"><img alt="'.get_lang("NewChapter").'" src="../img/lp_dokeos_chapter_add.gif" title="'.get_lang("NewChapter").'" />'.get_lang("NewChapter").'</a>';
  3914. echo '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;gradebook='.$gradebook.'&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang("NewStep").'"><img alt="'.get_lang("NewStep").'" src="../img/new_test.gif" title="'.get_lang("NewStep").'" />'.get_lang("NewStep").'</a>';
  3915. echo '</div>';
  3916. }
  3917. /**
  3918. * This functions builds the LP tree based on data from the database.
  3919. *
  3920. * @return string
  3921. * @uses dtree.js :: necessary javascript for building this tree
  3922. */
  3923. function build_tree()
  3924. {
  3925. $return = "<script type=\"text/javascript\">\n";
  3926. $return .= "\tm = new dTree('m');\n\n";
  3927. $return .= "\tm.config.folderLinks = true;\n";
  3928. $return .= "\tm.config.useCookies = true;\n";
  3929. $return .= "\tm.config.useIcons = true;\n";
  3930. $return .= "\tm.config.useLines = true;\n";
  3931. $return .= "\tm.config.useSelection = true;\n";
  3932. $return .= "\tm.config.useStatustext = false;\n\n";
  3933. $menu = 0;
  3934. $parent = '';
  3935. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3936. $tbl_lp_item = Database::get_course_table('lp_item');
  3937. $sql = "
  3938. SELECT *
  3939. FROM " . $tbl_lp_item . "
  3940. WHERE
  3941. lp_id = " . $this->lp_id;
  3942. $result = api_sql_query($sql, __FILE__, __LINE__);
  3943. $arrLP = array();
  3944. $mycharset=api_get_setting('platform_charset');
  3945. while($row = Database::fetch_array($result))
  3946. {
  3947. if($this->encoding!=$mycharset)
  3948. {
  3949. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3950. }
  3951. $arrLP[] = array(
  3952. 'id' => $row['id'],
  3953. 'item_type' => $row['item_type'],
  3954. 'title' => $row['title'],
  3955. 'path' => $row['path'],
  3956. 'description' => $row['description'],
  3957. 'parent_item_id' => $row['parent_item_id'],
  3958. 'previous_item_id' => $row['previous_item_id'],
  3959. 'next_item_id' => $row['next_item_id'],
  3960. 'max_score' => $row['max_score'],
  3961. 'min_score' => $row['min_score'],
  3962. 'mastery_score' => $row['mastery_score'],
  3963. 'display_order' => $row['display_order']);
  3964. }
  3965. $this->tree_array($arrLP);
  3966. $arrLP = $this->arrMenu;
  3967. unset($this->arrMenu);
  3968. $title='';
  3969. for($i = 0; $i < count($arrLP); $i++)
  3970. {
  3971. $title = addslashes($arrLP[$i]['title']);
  3972. $menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3973. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  3974. if (file_exists("../img/lp_" . $icon_name . ".png"))
  3975. {
  3976. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".png', '../img/lp_" . $icon_name . ".png');\n";
  3977. }
  3978. else if(file_exists("../img/lp_" . $icon_name . ".gif"))
  3979. {
  3980. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".gif', '../img/lp_" . $icon_name . ".gif');\n";
  3981. }
  3982. else
  3983. {
  3984. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3985. }
  3986. if($menu < $arrLP[$i]['id'])
  3987. $menu = $arrLP[$i]['id'];
  3988. }
  3989. $return .= "\n\tdocument.write(m);\n";
  3990. $return .= "\t if(!m.selectedNode) m.s(1);";
  3991. $return .= "</script>\n";
  3992. return $return;
  3993. }
  3994. /**
  3995. * Create a new document //still needs some finetuning
  3996. *
  3997. * @param array $_course
  3998. * @return string
  3999. */
  4000. function create_document($_course)
  4001. {
  4002. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4003. if(strstr($dir, '..'))
  4004. $dir = '/';
  4005. if($dir[0] == '.')
  4006. $dir = substr($dir, 1);
  4007. if($dir[0] != '/')
  4008. $dir = '/'.$dir;
  4009. if($dir[strlen($dir) - 1] != '/')
  4010. $dir .= '/';
  4011. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4012. if(!is_dir($filepath))
  4013. {
  4014. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4015. $dir = '/';
  4016. }
  4017. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  4018. //is already escaped twice when it gets here
  4019. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4020. $title = disable_dangerous_file($title);
  4021. $title = replace_accents($title);
  4022. $filename = $title;
  4023. $content = $_POST['content_lp'];
  4024. $tmp_filename = $filename;
  4025. $i=0;
  4026. while(file_exists($filepath . $tmp_filename . '.html'))
  4027. $tmp_filename = $filename . '_' . ++$i;
  4028. $filename = $tmp_filename . '.html';
  4029. $content = stripslashes(text_filter($content));
  4030. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH).'courses/', $content);
  4031. // change the path of mp3 to absolute
  4032. // first regexp deals with ../../../ urls
  4033. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  4034. //second regexp deals with audio/ urls
  4035. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  4036. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  4037. $content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
  4038. if(!file_exists($filepath . $filename))
  4039. {
  4040. if($fp = @fopen($filepath . $filename, 'w'))
  4041. {
  4042. fputs($fp, $content);
  4043. fclose($fp);
  4044. $file_size = filesize($filepath . $filename);
  4045. $save_file_path = $dir . $filename;
  4046. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4047. if($document_id)
  4048. {
  4049. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  4050. //update parent folders
  4051. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4052. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4053. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4054. if($new_comment || $new_title)
  4055. {
  4056. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4057. $ct = '';
  4058. if($new_comment)
  4059. $ct .= ", comment='" . $new_comment . "'";
  4060. if($new_title)
  4061. $ct .= ", title='" . Database::escape_string(htmlspecialchars($new_title,ENT_QUOTES)) . ".html '";
  4062. $sql_update = "
  4063. UPDATE " . $tbl_doc . "
  4064. SET " . substr($ct, 1) . "
  4065. WHERE id = " . $document_id;
  4066. api_sql_query($sql_update, __FILE__, __LINE__);
  4067. }
  4068. }
  4069. return $document_id;
  4070. }
  4071. }
  4072. }
  4073. /**
  4074. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4075. *
  4076. * @param array $_course array
  4077. * @return void
  4078. */
  4079. function edit_document($_course)
  4080. {
  4081. global $_configuration;
  4082. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4083. if(strstr($dir, '..'))
  4084. $dir = '/';
  4085. if($dir[0] == '.')
  4086. $dir = substr($dir, 1);
  4087. if($dir[0] != '/')
  4088. $dir = '/'.$dir;
  4089. if($dir[strlen($dir) - 1] != '/')
  4090. $dir .= '/';
  4091. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  4092. if(!is_dir($filepath))
  4093. {
  4094. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4095. $dir = '/';
  4096. }
  4097. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  4098. $sql = "
  4099. SELECT path
  4100. FROM " . $table_doc . "
  4101. WHERE id = " . $_POST['path'];
  4102. $res = api_sql_query($sql, __FILE__, __LINE__);
  4103. $row = Database::fetch_array($res);
  4104. $content = stripslashes($_POST['content_lp']);
  4105. $file = $filepath . $row['path'];
  4106. if($fp = @fopen($file, 'w'))
  4107. {
  4108. $content = text_filter($content);
  4109. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  4110. // change the path of mp3 to absolute
  4111. // first regexp deals with ../../../ urls
  4112. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  4113. //second regexp deals with audio/ urls
  4114. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  4115. fputs($fp, $content);
  4116. fclose($fp);
  4117. }
  4118. }
  4119. /**
  4120. * Displays the selected item, with a panel for manipulating the item
  4121. *
  4122. * @param int $item_id
  4123. * @param string $msg
  4124. * @return string
  4125. */
  4126. function display_item($item_id, $iframe = true, $msg = '')
  4127. {
  4128. global $_course; //will disappear
  4129. $return = '';
  4130. if(is_numeric($item_id))
  4131. {
  4132. $tbl_lp_item = Database::get_course_table('lp_item');
  4133. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4134. $sql = "
  4135. SELECT
  4136. lp.*
  4137. FROM " . $tbl_lp_item . " as lp
  4138. WHERE
  4139. lp.id = " . $item_id;
  4140. $result = api_sql_query($sql, __FILE__, __LINE__);
  4141. while($row = Database::fetch_array($result))
  4142. {
  4143. $_SESSION['parent_item_id'] = ($row['item_type']=='dokeos_chapter' || $row['item_type']=='dokeos_module' || $row['item_type']=='dir')?$item_id:0;
  4144. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4145. $return .= '<div style="padding:10px;">';
  4146. if($msg != '')
  4147. $return .= $msg;
  4148. if($this->encoding=='UTF-8')
  4149. {
  4150. $row['title'] = utf8_decode($row['title']);
  4151. }
  4152. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  4153. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4154. //$return .= '<hr />';
  4155. if($row['item_type'] == TOOL_DOCUMENT)
  4156. {
  4157. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4158. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  4159. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  4160. $path_file=Database::result($result,0,0);
  4161. $path_parts = pathinfo($path_file);
  4162. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  4163. {
  4164. $return .= $this->display_document($row['path'], true, true);
  4165. }
  4166. }
  4167. $return .= '</div>';
  4168. }
  4169. }
  4170. return $return;
  4171. }
  4172. /**
  4173. * Shows the needed forms for editing a specific item
  4174. *
  4175. * @param int $item_id
  4176. * @return string
  4177. */
  4178. function display_edit_item($item_id)
  4179. {
  4180. global $_course; //will disappear
  4181. $return = '';
  4182. if(is_numeric($item_id))
  4183. {
  4184. $tbl_lp_item = Database::get_course_table('lp_item');
  4185. $sql = "
  4186. SELECT *
  4187. FROM " . $tbl_lp_item . "
  4188. WHERE id = " . $item_id;
  4189. $res = api_sql_query($sql, __FILE__, __LINE__);
  4190. $row = Database::fetch_array($res);
  4191. switch($row['item_type'])
  4192. {
  4193. case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
  4194. if(isset($_GET['view']) && $_GET['view'] == 'build')
  4195. {
  4196. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4197. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  4198. }
  4199. else
  4200. {
  4201. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  4202. }
  4203. break;
  4204. case TOOL_DOCUMENT:
  4205. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4206. $sql_step = "
  4207. SELECT
  4208. lp.*,
  4209. doc.path as dir
  4210. FROM " . $tbl_lp_item . " as lp
  4211. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4212. WHERE
  4213. lp.id = " . $item_id;
  4214. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  4215. $row_step = Database::fetch_array($res_step);
  4216. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4217. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4218. break;
  4219. case TOOL_LINK:
  4220. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4221. $return .= $this->display_link_form('edit', $item_id, $row);
  4222. break;
  4223. case 'dokeos_module':
  4224. if(isset($_GET['view']) && $_GET['view'] == 'build')
  4225. {
  4226. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4227. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  4228. }
  4229. else
  4230. {
  4231. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  4232. }
  4233. break;
  4234. case TOOL_QUIZ:
  4235. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4236. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4237. break;
  4238. case TOOL_HOTPOTATOES:
  4239. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4240. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4241. break;
  4242. case TOOL_STUDENTPUBLICATION:
  4243. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4244. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4245. break;
  4246. case TOOL_FORUM:
  4247. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4248. $return .= $this->display_forum_form('edit', $item_id, $row);
  4249. break;
  4250. case TOOL_THREAD:
  4251. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4252. $return .= $this->display_thread_form('edit', $item_id, $row);
  4253. break;
  4254. }
  4255. }
  4256. return $return;
  4257. }
  4258. /**
  4259. * Function that displays a list with al the resources that could be added to the learning path
  4260. *
  4261. * @return string
  4262. */
  4263. function display_resources()
  4264. {
  4265. global $_course; //TODO: don't use globals
  4266. $return .= '<div class="sectiontitle">'.get_lang('CreateNewStep').'</div>';
  4267. $return .= '<div class="sectioncomment"><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.'<img title="Nuevo documento" src="../img/new_doc.gif" alt="Nuevo documento"/> '.get_lang("NewDocument").'</a></div>';
  4268. $return .= '<div class="sectiontitle">'.get_lang('UseAnExistingResource').'</div>';
  4269. $return .= '<div class="sectioncomment">';
  4270. /* get all the docs */
  4271. $return .= $this->get_documents();
  4272. /* get all the exercises */
  4273. $return .= $this->get_exercises();
  4274. /* get all the links */
  4275. $return .= $this->get_links();
  4276. /* get al the student publications */
  4277. $return .= $this->get_student_publications();
  4278. /* get al the forums */
  4279. $return .= $this->get_forums();
  4280. $return .= '</div>';
  4281. return $return;
  4282. }
  4283. /**
  4284. * Returns the extension of a document
  4285. *
  4286. * @param unknown_type $filename
  4287. * @return unknown
  4288. */
  4289. function get_extension($filename)
  4290. {
  4291. $explode = explode('.', $filename);
  4292. return $explode[count($explode) - 1];
  4293. }
  4294. /**
  4295. * Displays a document by id
  4296. *
  4297. * @param unknown_type $id
  4298. * @return unknown
  4299. */
  4300. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  4301. {
  4302. global $_course; //temporary
  4303. $return = '';
  4304. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4305. $sql_doc = "
  4306. SELECT *
  4307. FROM " . $tbl_doc . "
  4308. WHERE id = " . $id;
  4309. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  4310. $row_doc = Database::fetch_array($res_doc);
  4311. //if($show_title)
  4312. //$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>';
  4313. //TODO: add a path filter
  4314. if($iframe){
  4315. $return .= '<iframe id="learnpath_preview_frame" frameborder="0" height="400" width="100%" scrolling="auto" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F','/',urlencode($row_doc['path'])) . '?'.api_get_cidreq().'"></iframe>';
  4316. }
  4317. else{
  4318. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4319. }
  4320. return $return;
  4321. }
  4322. /**
  4323. * Return HTML form to add/edit a quiz
  4324. *
  4325. * @param string Action (add/edit)
  4326. * @param integer Item ID if already exists
  4327. * @param mixed Extra information (quiz ID if integer)
  4328. * @return string HTML form
  4329. */
  4330. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  4331. {
  4332. global $charset;
  4333. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  4334. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  4335. if($id != 0 && is_array($extra_info)) {
  4336. $item_title = stripslashes($extra_info['title']);
  4337. $item_description = stripslashes($extra_info['description']);
  4338. } elseif(is_numeric($extra_info)) {
  4339. $sql_quiz = "
  4340. SELECT
  4341. title,
  4342. description
  4343. FROM " . $tbl_quiz . "
  4344. WHERE id = " . $extra_info;
  4345. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  4346. $row = Database::fetch_array($result);
  4347. $item_title = $row['title'];
  4348. $item_description = $row['description'];
  4349. } else {
  4350. $item_title = '';
  4351. $item_description = '';
  4352. }
  4353. $item_title = mb_convert_encoding($item_title,$charset,$this->encoding);
  4354. $return = '<div class="sectiontitle">';
  4355. if($id != 0 && is_array($extra_info))
  4356. $parent = $extra_info['parent_item_id'];
  4357. else
  4358. $parent = 0;
  4359. $sql = "
  4360. SELECT *
  4361. FROM " . $tbl_lp_item . "
  4362. WHERE
  4363. lp_id = " . $this->lp_id;
  4364. $result = api_sql_query($sql, __FILE__, __LINE__);
  4365. $arrLP = array();
  4366. while($row = Database::fetch_array($result)) {
  4367. $arrLP[] = array(
  4368. 'id' => $row['id'],
  4369. 'item_type' => $row['item_type'],
  4370. 'title' => $row['title'],
  4371. 'path' => $row['path'],
  4372. 'description' => $row['description'],
  4373. 'parent_item_id' => $row['parent_item_id'],
  4374. 'previous_item_id' => $row['previous_item_id'],
  4375. 'next_item_id' => $row['next_item_id'],
  4376. 'display_order' => $row['display_order'],
  4377. 'max_score' => $row['max_score'],
  4378. 'min_score' => $row['min_score'],
  4379. 'mastery_score' => $row['mastery_score'],
  4380. 'prerequisite' => $row['prerequisite'],
  4381. 'max_time_allowed' => $row['max_time_allowed']);
  4382. }
  4383. $this->tree_array($arrLP);
  4384. $arrLP = $this->arrMenu;
  4385. unset($this->arrMenu);
  4386. if($action == 'add')
  4387. $return .= get_lang("CreateTheExercise").'&nbsp;:' . "\n";
  4388. elseif($action == 'move')
  4389. $return .= get_lang("MoveTheCurrentExercise").'&nbsp;:' . "\n";
  4390. else
  4391. $return .= get_lang("EditCurrentExecice").'&nbsp;:' . "\n";
  4392. if(isset($_GET['edit']) && $_GET['edit'] == 'true') {
  4393. $return .= '<div class="warning-message">';
  4394. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4395. $return .= get_lang("WarningEditingDocument");
  4396. $return .= '</div>';
  4397. }
  4398. $return .= '</div>';
  4399. $return .= '<div class="sectioncomment">';
  4400. $return .= '<form method="POST">' . "\n";
  4401. $return .= "\t" . '<table>' . "\n";
  4402. if($action != 'move') {
  4403. $return .= "\t\t" . '<tr>' . "\n";
  4404. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  4405. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
  4406. $return .= "\t\t" . '</tr>' . "\n";
  4407. }
  4408. $return .= "\t\t" . '<tr>' . "\n";
  4409. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  4410. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4411. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4412. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4413. $arrHide = array($id);
  4414. $parent_item_id = $_SESSION['parent_item_id'];
  4415. for($i = 0; $i < count($arrLP); $i++) {
  4416. if($action != 'add') {
  4417. 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)) {
  4418. $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>';
  4419. } else {
  4420. $arrHide[] = $arrLP[$i]['id'];
  4421. }
  4422. } else {
  4423. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4424. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4425. }
  4426. }
  4427. if (is_array($arrLP)) {
  4428. reset($arrLP);
  4429. }
  4430. $return .= "\t\t\t\t" . '</select>';
  4431. $return .= "\t\t\t" . '</td>' . "\n";
  4432. $return .= "\t\t" . '</tr>' . "\n";
  4433. $return .= "\t\t" . '<tr>' . "\n";
  4434. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  4435. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4436. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4437. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4438. for($i = 0; $i < count($arrLP); $i++) {
  4439. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4440. {
  4441. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4442. $selected = 'selected="selected" ';
  4443. elseif($action == 'add')
  4444. $selected = 'selected="selected" ';
  4445. else
  4446. $selected = '';
  4447. $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>';
  4448. }
  4449. }
  4450. $return .= "\t\t\t\t" . '</select>';
  4451. $return .= "\t\t\t" . '</td>' . "\n";
  4452. $return .= "\t\t" . '</tr>' . "\n";
  4453. if($action != 'move') {
  4454. $id_prerequisite=0;
  4455. if (is_array($arrLP )) {
  4456. foreach($arrLP as $key=>$value){
  4457. if($value['id']==$id){
  4458. $id_prerequisite=$value['prerequisite'];
  4459. break;
  4460. }
  4461. }
  4462. }
  4463. $arrHide=array();
  4464. for($i = 0; $i < count($arrLP); $i++) {
  4465. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4466. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4467. $s_selected_position=$arrLP[$i]['id'];
  4468. elseif($action == 'add')
  4469. $s_selected_position=0;
  4470. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4471. }
  4472. }
  4473. /*//comented the prerequisites, only visible in edit (exercise)
  4474. $return .= "\t\t" . '<tr>' . "\n";
  4475. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4476. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4477. foreach($arrHide as $key => $value){
  4478. if($key==$s_selected_position && $action == 'add'){
  4479. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4480. }
  4481. elseif($key==$id_prerequisite && $action == 'edit'){
  4482. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4483. }
  4484. else{
  4485. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4486. }
  4487. }
  4488. $return .= "</select></td>";
  4489. */
  4490. $return .= "\t\t" . '</tr>' . "\n";
  4491. $return .= "\t\t" . '<tr>' . "\n";
  4492. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">'.get_lang('MaxTimeAllowed').'</label></td>' . "\n";
  4493. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4494. //Remove temporaly the test description
  4495. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4496. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4497. $return .= "\t\t" . '</tr>' . "\n";
  4498. }
  4499. $return .= "\t\t" . '<tr>' . "\n";
  4500. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">'.get_lang('AddExercise').'</button></td>' . "\n";
  4501. $return .= "\t\t" . '</tr>' . "\n";
  4502. $return .= "\t" . '</table>' . "\n";
  4503. if($action == 'move') {
  4504. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4505. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4506. }
  4507. if(is_numeric($extra_info)) {
  4508. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4509. } elseif(is_array($extra_info)) {
  4510. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4511. }
  4512. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  4513. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4514. $return .= '</form>' . "\n";
  4515. $return .= '</div>' . "\n";
  4516. return $return;
  4517. }
  4518. /**
  4519. * Addition of Hotpotatoes tests
  4520. * @param string Action
  4521. * @param integer Internal ID of the item
  4522. * @param mixed Extra information - can be an array with title and description indexes
  4523. * @return string HTML structure to display the hotpotatoes addition formular
  4524. */
  4525. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
  4526. {
  4527. global $charset;
  4528. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4529. $tbl_lp_item = Database::get_course_table('lp_item');
  4530. if($id != 0 && is_array($extra_info))
  4531. {
  4532. $item_title = stripslashes($extra_info['title']);
  4533. $item_description = stripslashes($extra_info['description']);
  4534. }
  4535. elseif(is_numeric($extra_info))
  4536. {
  4537. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  4538. $sql_hot = "SELECT * FROM ".$TBL_DOCUMENT."
  4539. WHERE path LIKE '".$uploadPath."/%/%htm%'
  4540. AND id = ".(int)$extra_info." ORDER BY id ASC";
  4541. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  4542. $row = Database::fetch_array($res_hot);
  4543. $item_title = $row['title'];
  4544. $item_description = $row['description'];
  4545. if(!empty($row['comment'])) {
  4546. $item_title = $row['comment'];
  4547. }
  4548. }
  4549. else
  4550. {
  4551. $item_title = '';
  4552. $item_description = '';
  4553. }
  4554. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4555. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4556. $return = '<div style="margin:3px 12px;">';
  4557. if($id != 0 && is_array($extra_info))
  4558. $parent = $extra_info['parent_item_id'];
  4559. else
  4560. $parent = 0;
  4561. $sql = "
  4562. SELECT *
  4563. FROM " . $tbl_lp_item . "
  4564. WHERE
  4565. lp_id = " . $this->lp_id;
  4566. $result = api_sql_query($sql, __FILE__, __LINE__);
  4567. $arrLP = array();
  4568. while($row = Database::fetch_array($result))
  4569. {
  4570. $arrLP[] = array(
  4571. 'id' => $row['id'],
  4572. 'item_type' => $row['item_type'],
  4573. 'title' => $row['title'],
  4574. 'path' => $row['path'],
  4575. 'description' => $row['description'],
  4576. 'parent_item_id' => $row['parent_item_id'],
  4577. 'previous_item_id' => $row['previous_item_id'],
  4578. 'next_item_id' => $row['next_item_id'],
  4579. 'display_order' => $row['display_order'],
  4580. 'max_score' => $row['max_score'],
  4581. 'min_score' => $row['min_score'],
  4582. 'mastery_score' => $row['mastery_score'],
  4583. 'prerequisite' => $row['prerequisite'],
  4584. 'max_time_allowed' => $row['max_time_allowed']);
  4585. }
  4586. $this->tree_array($arrLP);
  4587. $arrLP = $this->arrMenu;
  4588. unset($this->arrMenu);
  4589. if($action == 'add')
  4590. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").'&nbsp;:</p>' . "\n";
  4591. elseif($action == 'move')
  4592. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").'&nbsp;:</p>' . "\n";
  4593. else
  4594. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").'&nbsp;:</p>' . "\n";
  4595. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4596. {
  4597. $return .= '<div class="warning-message">';
  4598. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4599. $return .= get_lang("WarningEditingDocument");
  4600. $return .= '</div>';
  4601. }
  4602. $return .= '<form method="POST">' . "\n";
  4603. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4604. $return .= "\t\t" . '<tr>' . "\n";
  4605. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4606. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4607. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4608. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4609. $arrHide = array($id);
  4610. for($i = 0; $i < count($arrLP); $i++)
  4611. {
  4612. if($action != 'add')
  4613. {
  4614. 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))
  4615. {
  4616. $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>';
  4617. }
  4618. else
  4619. {
  4620. $arrHide[] = $arrLP[$i]['id'];
  4621. }
  4622. }
  4623. else
  4624. {
  4625. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4626. $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>';
  4627. }
  4628. }
  4629. reset($arrLP);
  4630. $return .= "\t\t\t\t" . '</select>';
  4631. $return .= "\t\t\t" . '</td>' . "\n";
  4632. $return .= "\t\t" . '</tr>' . "\n";
  4633. $return .= "\t\t" . '<tr>' . "\n";
  4634. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4635. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4636. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4637. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4638. for($i = 0; $i < count($arrLP); $i++)
  4639. {
  4640. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4641. {
  4642. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4643. $selected = 'selected="selected" ';
  4644. elseif($action == 'add')
  4645. $selected = 'selected="selected" ';
  4646. else
  4647. $selected = '';
  4648. $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>';
  4649. }
  4650. }
  4651. $return .= "\t\t\t\t" . '</select>';
  4652. $return .= "\t\t\t" . '</td>' . "\n";
  4653. $return .= "\t\t" . '</tr>' . "\n";
  4654. if($action != 'move')
  4655. {
  4656. $return .= "\t\t" . '<tr>' . "\n";
  4657. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4658. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4659. $return .= "\t\t" . '</tr>' . "\n";
  4660. $id_prerequisite=0;
  4661. foreach($arrLP as $key=>$value){
  4662. if($value['id']==$id){
  4663. $id_prerequisite=$value['prerequisite'];
  4664. break;
  4665. }
  4666. }
  4667. $arrHide=array();
  4668. for($i = 0; $i < count($arrLP); $i++)
  4669. {
  4670. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4671. {
  4672. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4673. $s_selected_position=$arrLP[$i]['id'];
  4674. elseif($action == 'add')
  4675. $s_selected_position=0;
  4676. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4677. }
  4678. }
  4679. $return .= "\t\t" . '<tr>' . "\n";
  4680. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4681. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4682. foreach($arrHide as $key => $value){
  4683. if($key==$s_selected_position && $action == 'add'){
  4684. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4685. }
  4686. elseif($key==$id_prerequisite && $action == 'edit'){
  4687. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4688. }
  4689. else{
  4690. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4691. }
  4692. }
  4693. $return .= "</select></td>";
  4694. $return .= "\t\t" . '</tr>' . "\n";
  4695. $return .= "\t\t" . '<tr>' . "\n";
  4696. //Remove temporaly the test description
  4697. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4698. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4699. $return .= "\t\t" . '</tr>' . "\n";
  4700. }
  4701. $return .= "\t\t" . '<tr>' . "\n";
  4702. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  4703. $return .= "\t\t" . '</tr>' . "\n";
  4704. $return .= "\t" . '</table>' . "\n";
  4705. if($action == 'move')
  4706. {
  4707. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4708. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4709. }
  4710. if(is_numeric($extra_info))
  4711. {
  4712. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4713. }
  4714. elseif(is_array($extra_info))
  4715. {
  4716. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4717. }
  4718. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />' . "\n";
  4719. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4720. $return .= '</form>' . "\n";
  4721. $return .= '</div>' . "\n";
  4722. return $return;
  4723. }
  4724. //fin du hotpot form
  4725. /**
  4726. * Return the form to display the forum edit/add option
  4727. *
  4728. * @param string Action (add/edit)
  4729. * @param integer ID of the lp_item if already exists
  4730. * @param mixed Forum ID or title
  4731. * @return string HTML form
  4732. */
  4733. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  4734. {
  4735. global $charset;
  4736. $tbl_lp_item = Database::get_course_table('lp_item');
  4737. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  4738. if($id != 0 && is_array($extra_info)) {
  4739. $item_title = stripslashes($extra_info['title']);
  4740. } elseif(is_numeric($extra_info)) {
  4741. $sql_forum = "
  4742. SELECT
  4743. forum_title as title, forum_comment as comment
  4744. FROM " . $tbl_forum . "
  4745. WHERE forum_id = " . $extra_info;
  4746. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4747. $row = Database::fetch_array($result);
  4748. $item_title = $row['title'];
  4749. $item_description = $row['comment'];
  4750. } else {
  4751. $item_title = '';
  4752. $item_description = '';
  4753. }
  4754. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4755. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4756. $return = '<div class="sectiontitle">';
  4757. if($id != 0 && is_array($extra_info))
  4758. $parent = $extra_info['parent_item_id'];
  4759. else
  4760. $parent = 0;
  4761. $sql = "
  4762. SELECT *
  4763. FROM " . $tbl_lp_item . "
  4764. WHERE
  4765. lp_id = " . $this->lp_id;
  4766. $result = api_sql_query($sql, __FILE__, __LINE__);
  4767. $arrLP = array();
  4768. while($row = Database::fetch_array($result)) {
  4769. $arrLP[] = array(
  4770. 'id' => $row['id'],
  4771. 'item_type' => $row['item_type'],
  4772. 'title' => $row['title'],
  4773. 'path' => $row['path'],
  4774. 'description' => $row['description'],
  4775. 'parent_item_id' => $row['parent_item_id'],
  4776. 'previous_item_id' => $row['previous_item_id'],
  4777. 'next_item_id' => $row['next_item_id'],
  4778. 'display_order' => $row['display_order'],
  4779. 'max_score' => $row['max_score'],
  4780. 'min_score' => $row['min_score'],
  4781. 'mastery_score' => $row['mastery_score'],
  4782. 'prerequisite' => $row['prerequisite']);
  4783. }
  4784. $this->tree_array($arrLP);
  4785. $arrLP = $this->arrMenu;
  4786. unset($this->arrMenu);
  4787. if($action == 'add')
  4788. $return .= get_lang("CreateTheForum").'&nbsp;:' . "\n";
  4789. elseif($action == 'move')
  4790. $return .= get_lang("MoveTheCurrentForum").'&nbsp;:' . "\n";
  4791. else
  4792. $return .= get_lang("EditCurrentForum").'&nbsp;:' . "\n";
  4793. $return .= '</div>';
  4794. $return .= '<div class="sectioncomment">';
  4795. $return .= '<form method="POST">' . "\n";
  4796. $return .= "\t" . '<table>' . "\n";
  4797. if($action != 'move') {
  4798. $return .= "\t\t" . '<tr>' . "\n";
  4799. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  4800. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  4801. $return .= "\t\t" . '</tr>' . "\n";
  4802. }
  4803. $return .= "\t\t" . '<tr>' . "\n";
  4804. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  4805. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4806. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4807. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4808. $arrHide = array($id);
  4809. $parent_item_id = $_SESSION['parent_item_id'];
  4810. for($i = 0; $i < count($arrLP); $i++)
  4811. {
  4812. if($action != 'add')
  4813. {
  4814. 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))
  4815. {
  4816. $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>';
  4817. }
  4818. else
  4819. {
  4820. $arrHide[] = $arrLP[$i]['id'];
  4821. }
  4822. }
  4823. else
  4824. {
  4825. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4826. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4827. }
  4828. }
  4829. if (is_array($arrLP)) {
  4830. reset($arrLP);
  4831. }
  4832. $return .= "\t\t\t\t" . '</select>';
  4833. $return .= "\t\t\t" . '</td>' . "\n";
  4834. $return .= "\t\t" . '</tr>' . "\n";
  4835. $return .= "\t\t" . '<tr>' . "\n";
  4836. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  4837. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4838. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  4839. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4840. for($i = 0; $i < count($arrLP); $i++)
  4841. {
  4842. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4843. {
  4844. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4845. $selected = 'selected="selected" ';
  4846. elseif($action == 'add')
  4847. $selected = 'selected="selected" ';
  4848. else
  4849. $selected = '';
  4850. $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>';
  4851. }
  4852. }
  4853. $return .= "\t\t\t\t" . '</select>';
  4854. $return .= "\t\t\t" . '</td>' . "\n";
  4855. $return .= "\t\t" . '</tr>' . "\n";
  4856. if($action != 'move')
  4857. {
  4858. $return .= "\t\t" . '<tr>' . "\n";
  4859. //Remove temporaly the test description
  4860. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4861. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4862. $return .= "\t\t" . '</tr>' . "\n";
  4863. $id_prerequisite=0;
  4864. if (is_array($arrLP)) {
  4865. foreach($arrLP as $key=>$value){
  4866. if($value['id']==$id){
  4867. $id_prerequisite=$value['prerequisite'];
  4868. break;
  4869. }
  4870. }
  4871. }
  4872. $arrHide=array();
  4873. for($i = 0; $i < count($arrLP); $i++) {
  4874. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4875. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4876. $s_selected_position=$arrLP[$i]['id'];
  4877. elseif($action == 'add')
  4878. $s_selected_position=0;
  4879. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4880. }
  4881. }
  4882. /* //comented the prerequisites, only visible in edit (forum)
  4883. $return .= "\t\t" . '<tr>' . "\n";
  4884. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4885. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4886. foreach($arrHide as $key => $value) {
  4887. if($key==$s_selected_position && $action == 'add') {
  4888. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4889. }elseif($key==$id_prerequisite && $action == 'edit') {
  4890. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4891. } else {
  4892. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4893. }
  4894. }
  4895. $return .= "</select></td>";
  4896. */
  4897. $return .= "\t\t" . '</tr>' . "\n";
  4898. }
  4899. $return .= "\t\t" . '<tr>' . "\n";
  4900. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> '.get_lang('AddForumToCourse').' </button></td>' . "\n";
  4901. $return .= "\t\t" . '</tr>' . "\n";
  4902. $return .= "\t" . '</table>' . "\n";
  4903. if($action == 'move') {
  4904. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4905. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4906. }
  4907. if(is_numeric($extra_info)) {
  4908. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4909. } elseif(is_array($extra_info)) {
  4910. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4911. }
  4912. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  4913. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4914. $return .= '</form>' . "\n";
  4915. $return .= '</div>' . "\n";
  4916. return $return;
  4917. }
  4918. /**
  4919. * Return HTML form to add/edit forum threads
  4920. * @param string Action (add/edit)
  4921. * @param integer Item ID if already exists in learning path
  4922. * @param mixed Extra information (thread ID if integer)
  4923. * @return string HTML form
  4924. */
  4925. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  4926. {
  4927. global $charset;
  4928. echo '
  4929. <style>
  4930. div.row div.label {
  4931. width:110px;
  4932. }
  4933. div.row div.formw {
  4934. width: 82%;
  4935. }
  4936. </style>';
  4937. $tbl_lp_item = Database::get_course_table('lp_item');
  4938. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  4939. if($id != 0 && is_array($extra_info))
  4940. {
  4941. $item_title = stripslashes($extra_info['title']);
  4942. }
  4943. elseif(is_numeric($extra_info))
  4944. {
  4945. $sql_forum = "
  4946. SELECT
  4947. thread_title as title
  4948. FROM " . $tbl_forum . "
  4949. WHERE thread_id = " . $extra_info;
  4950. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4951. $row = Database::fetch_array($result);
  4952. $item_title = $row['title'];
  4953. $item_description = '';
  4954. }
  4955. else
  4956. {
  4957. $item_title = '';
  4958. $item_description = '';
  4959. }
  4960. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4961. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4962. $return = '<div style="margin:3px 12px;">';
  4963. if($id != 0 && is_array($extra_info))
  4964. $parent = $extra_info['parent_item_id'];
  4965. else
  4966. $parent = 0;
  4967. $sql = "
  4968. SELECT *
  4969. FROM " . $tbl_lp_item . "
  4970. WHERE
  4971. lp_id = " . $this->lp_id;
  4972. $result = api_sql_query($sql, __FILE__, __LINE__);
  4973. $arrLP = array();
  4974. while($row = Database::fetch_array($result))
  4975. {
  4976. $arrLP[] = array(
  4977. 'id' => $row['id'],
  4978. 'item_type' => $row['item_type'],
  4979. 'title' => $row['title'],
  4980. 'path' => $row['path'],
  4981. 'description' => $row['description'],
  4982. 'parent_item_id' => $row['parent_item_id'],
  4983. 'previous_item_id' => $row['previous_item_id'],
  4984. 'next_item_id' => $row['next_item_id'],
  4985. 'display_order' => $row['display_order'],
  4986. 'max_score' => $row['max_score'],
  4987. 'min_score' => $row['min_score'],
  4988. 'mastery_score' => $row['mastery_score'],
  4989. 'prerequisite' => $row['prerequisite']);
  4990. }
  4991. $this->tree_array($arrLP);
  4992. $arrLP = $this->arrMenu;
  4993. unset($this->arrMenu);
  4994. if($action == 'add')
  4995. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").'&nbsp;:</p>' . "\n";
  4996. elseif($action == 'move')
  4997. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").'&nbsp;:</p>' . "\n";
  4998. else
  4999. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").'&nbsp;:</p>' . "\n";
  5000. $return .= '<form method="POST">' . "\n";
  5001. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5002. $return .= "\t\t" . '<tr>' . "\n";
  5003. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").'&nbsp;:</label></td>' . "\n";
  5004. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5005. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5006. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5007. $arrHide = array($id);
  5008. for($i = 0; $i < count($arrLP); $i++)
  5009. {
  5010. if($action != 'add')
  5011. {
  5012. 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))
  5013. {
  5014. $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>';
  5015. }
  5016. else
  5017. {
  5018. $arrHide[] = $arrLP[$i]['id'];
  5019. }
  5020. }
  5021. else
  5022. {
  5023. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5024. $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>';
  5025. }
  5026. }
  5027. if ($arrLP!=null) {
  5028. reset($arrLP);
  5029. }
  5030. $return .= "\t\t\t\t" . '</select>';
  5031. $return .= "\t\t\t" . '</td>' . "\n";
  5032. $return .= "\t\t" . '</tr>' . "\n";
  5033. $return .= "\t\t" . '<tr>' . "\n";
  5034. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").'&nbsp;:</label></td>' . "\n";
  5035. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5036. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5037. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  5038. for($i = 0; $i < count($arrLP); $i++)
  5039. {
  5040. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5041. {
  5042. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5043. $selected = 'selected="selected" ';
  5044. elseif($action == 'add')
  5045. $selected = 'selected="selected" ';
  5046. else
  5047. $selected = '';
  5048. $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>';
  5049. }
  5050. }
  5051. $return .= "\t\t\t\t" . '</select>';
  5052. $return .= "\t\t\t" . '</td>' . "\n";
  5053. $return .= "\t\t" . '</tr>' . "\n";
  5054. if($action != 'move')
  5055. {
  5056. $return .= "\t\t" . '<tr>' . "\n";
  5057. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").'&nbsp;:</label></td>' . "\n";
  5058. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5059. $return .= "\t\t" . '</tr>' . "\n";
  5060. $return .= "\t\t" . '<tr>' . "\n";
  5061. //Remove temporaly the test description
  5062. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5063. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5064. $return .= "\t\t" . '</tr>' . "\n";
  5065. $id_prerequisite=0;
  5066. if ($arrLP!=null) {
  5067. foreach($arrLP as $key=>$value){
  5068. if($value['id']==$id){
  5069. $id_prerequisite=$value['prerequisite'];
  5070. break;
  5071. }
  5072. }
  5073. }
  5074. $arrHide=array();
  5075. for($i = 0; $i < count($arrLP); $i++)
  5076. {
  5077. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5078. {
  5079. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5080. $s_selected_position=$arrLP[$i]['id'];
  5081. elseif($action == 'add')
  5082. $s_selected_position=0;
  5083. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5084. }
  5085. }
  5086. $return .= "\t\t" . '<tr>' . "\n";
  5087. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").'&nbsp;:</label></td>' . "\n";
  5088. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5089. foreach($arrHide as $key => $value){
  5090. if($key==$s_selected_position && $action == 'add'){
  5091. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5092. }
  5093. elseif($key==$id_prerequisite && $action == 'edit'){
  5094. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5095. }
  5096. else{
  5097. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5098. }
  5099. }
  5100. $return .= "</select></td>";
  5101. $return .= "\t\t" . '</tr>' . "\n";
  5102. }
  5103. $return .= "\t\t" . '<tr>' . "\n";
  5104. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  5105. $return .= "\t\t" . '</tr>' . "\n";
  5106. $return .= "\t" . '</table>' . "\n";
  5107. if($action == 'move')
  5108. {
  5109. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5110. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5111. }
  5112. if(is_numeric($extra_info))
  5113. {
  5114. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5115. }
  5116. elseif(is_array($extra_info))
  5117. {
  5118. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5119. }
  5120. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  5121. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5122. $return .= '</form>' . "\n";
  5123. $return .= '</div>' . "\n";
  5124. return $return;
  5125. }
  5126. /**
  5127. * Return the HTML form to display an item (generally a section/module item)
  5128. *
  5129. * @param string Item type (module/dokeos_module)
  5130. * @param string Title (optional, only when creating)
  5131. * @param string Action ('add'/'edit')
  5132. * @param integer lp_item ID
  5133. * @param mixed Extra info
  5134. * @return string HTML form
  5135. */
  5136. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  5137. {
  5138. global $_course;
  5139. global $charset;
  5140. $tbl_lp_item = Database::get_course_table('lp_item');
  5141. if($id != 0 && is_array($extra_info))
  5142. {
  5143. $item_title = $extra_info['title'];
  5144. $item_description = $extra_info['description'];
  5145. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
  5146. }
  5147. else
  5148. {
  5149. $item_title = '';
  5150. $item_description = '';
  5151. }
  5152. $return = '<div class="sectiontitle">';
  5153. if($id != 0 && is_array($extra_info))
  5154. $parent = $extra_info['parent_item_id'];
  5155. else
  5156. $parent = 0;
  5157. $sql = "
  5158. SELECT *
  5159. FROM " . $tbl_lp_item . "
  5160. WHERE lp_id = " . $this->lp_id. " AND id != " . $id. " ";
  5161. if($item_type == 'module')
  5162. $sql .= " AND parent_item_id = 0";
  5163. $result = api_sql_query($sql, __FILE__, __LINE__);
  5164. $arrLP = array();
  5165. while($row = Database::fetch_array($result))
  5166. {
  5167. $arrLP[] = array(
  5168. 'id' => $row['id'],
  5169. 'item_type' => $row['item_type'],
  5170. 'title' => $row['title'],
  5171. 'path' => $row['path'],
  5172. 'description' => $row['description'],
  5173. 'parent_item_id' => $row['parent_item_id'],
  5174. 'previous_item_id' => $row['previous_item_id'],
  5175. 'next_item_id' => $row['next_item_id'],
  5176. 'max_score' => $row['max_score'],
  5177. 'min_score' => $row['min_score'],
  5178. 'mastery_score' => $row['mastery_score'],
  5179. 'prerequisite' => $row['prerequisite'],
  5180. 'display_order' => $row['display_order']);
  5181. }
  5182. $this->tree_array($arrLP);
  5183. $arrLP = $this->arrMenu;
  5184. unset($this->arrMenu);
  5185. $return .= $title . "\n";
  5186. $return .= '</div>';
  5187. $return .= '<div class="sectioncomment">';
  5188. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5189. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  5190. $defaults["title"]=mb_convert_encoding($item_title,$charset,$this->encoding);
  5191. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5192. $form->addElement('html',$return);
  5193. //$arrHide = array($id);
  5194. $arrHide[0]['value']=$this->name;
  5195. $arrHide[0]['padding']=3;
  5196. if($item_type != 'module' && $item_type != 'dokeos_module')
  5197. {
  5198. for($i = 0; $i < count($arrLP); $i++)
  5199. {
  5200. if($action != 'add')
  5201. {
  5202. 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))
  5203. {
  5204. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5205. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5206. if($parent == $arrLP[$i]['id'])
  5207. {
  5208. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5209. }
  5210. }
  5211. }
  5212. else
  5213. {
  5214. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5215. {
  5216. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5217. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5218. if($parent == $arrLP[$i]['id'])
  5219. {
  5220. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5221. }
  5222. }
  5223. }
  5224. }
  5225. if($action != 'move')
  5226. {
  5227. $form->addElement('text','title', get_lang('Title'),'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5228. $form->applyFilter('title', 'html_filter');
  5229. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5230. }
  5231. else
  5232. {
  5233. $form->addElement('hidden','title');
  5234. }
  5235. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
  5236. foreach($arrHide as $key => $value)
  5237. {
  5238. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5239. }
  5240. $parent_select -> setSelected($s_selected_parent);
  5241. }
  5242. if(is_array($arrLP)) { reset($arrLP); }
  5243. $arrHide=array();
  5244. //POSITION
  5245. for($i = 0; $i < count($arrLP); $i++)
  5246. {
  5247. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5248. {
  5249. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5250. $s_selected_position=$arrLP[$i]['id'];
  5251. elseif($action == 'add')
  5252. $s_selected_position=$arrLP[$i]['id'];
  5253. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5254. }
  5255. }
  5256. $position = &$form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5257. $position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'.$value['padding'].'px;"');
  5258. foreach($arrHide as $key => $value)
  5259. {
  5260. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5261. }
  5262. if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
  5263. if(is_array($arrLP)) { reset($arrLP); }
  5264. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'),'class="save"');
  5265. if($item_type == 'module' || $item_type == 'dokeos_module')
  5266. {
  5267. $form->addElement('hidden', 'parent', '0');
  5268. }
  5269. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5270. if(($item_type=='asset' || $item_type=='sco') && ($extension == 'html' || $extension == 'htm'))
  5271. {
  5272. if($item_type=='sco')
  5273. {
  5274. $form->addElement('html','<script type="text/javascript">alert("'.get_lang('WarningWhenEditingScorm').'")</script>');
  5275. }
  5276. $renderer = $form->defaultRenderer();
  5277. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5278. $form->addElement('html_editor','content_lp','');
  5279. //$form->addElement('html_editor','content_lp','');
  5280. $defaults["content_lp"]=file_get_contents($item_path);
  5281. }
  5282. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  5283. $form->addElement('hidden', 'post_time', time());
  5284. $form->setDefaults($defaults);
  5285. $form->addElement('html','</div>');
  5286. return $form->return_form();
  5287. }
  5288. /**
  5289. * Returns the form to update or create a document
  5290. *
  5291. * @param string Action (add/edit)
  5292. * @param integer ID of the lp_item (if already exists)
  5293. * @param mixed Integer if document ID, string if info ('new')
  5294. * @return string HTML form
  5295. */
  5296. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  5297. {
  5298. global $charset;
  5299. $tbl_lp_item = Database::get_course_table('lp_item');
  5300. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5301. $path_parts = pathinfo($extra_info['dir']);
  5302. $no_display_edit_textarea=false;
  5303. //If action==edit document
  5304. //We don't display the document form if it's not an editable document (html or txt file)
  5305. if($action=="edit"){
  5306. if(is_array($extra_info)){
  5307. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5308. $no_display_edit_textarea=true;
  5309. }
  5310. }
  5311. }
  5312. $no_display_add=false;
  5313. //If action==add an existing document
  5314. //We don't display the document form if it's not an editable document (html or txt file)
  5315. if($action=="add"){
  5316. if(is_numeric($extra_info)){
  5317. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  5318. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  5319. $path_file=Database::result($result,0,0);
  5320. $path_parts = pathinfo($path_file);
  5321. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5322. $no_display_add=true;
  5323. }
  5324. }
  5325. }
  5326. if($id != 0 && is_array($extra_info))
  5327. {
  5328. $item_title = stripslashes($extra_info['title']);
  5329. $item_description = stripslashes($extra_info['description']);
  5330. $item_terms = stripslashes($extra_info['terms']);
  5331. if(empty($item_title))
  5332. {
  5333. $path_parts = pathinfo($extra_info['path']);
  5334. $item_title = stripslashes($path_parts['filename']);
  5335. }
  5336. }
  5337. elseif(is_numeric($extra_info))
  5338. {
  5339. $sql_doc = "
  5340. SELECT path, title
  5341. FROM " . $tbl_doc . "
  5342. WHERE id = " . $extra_info;
  5343. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  5344. $row = Database::fetch_array($result);
  5345. $explode = explode('.', $row['title']);
  5346. if(count($explode)>1){
  5347. for($i = 0; $i < count($explode) - 1; $i++)
  5348. $item_title .= $explode[$i];
  5349. }
  5350. else{
  5351. $item_title=$row['title'];
  5352. }
  5353. $item_title = str_replace('_', ' ', $item_title);
  5354. if(empty($item_title))
  5355. {
  5356. $path_parts = pathinfo($row['path']);
  5357. $item_title = stripslashes($path_parts['filename']);
  5358. }
  5359. }
  5360. else
  5361. {
  5362. $item_title = '';
  5363. $item_description = '';
  5364. }
  5365. $return = '<div class="sectiontitle">';
  5366. if($id != 0 && is_array($extra_info))
  5367. $parent = $extra_info['parent_item_id'];
  5368. else
  5369. $parent = 0;
  5370. $sql = "
  5371. SELECT *
  5372. FROM " . $tbl_lp_item . "
  5373. WHERE
  5374. lp_id = " . $this->lp_id;
  5375. $result = api_sql_query($sql, __FILE__, __LINE__);
  5376. $arrLP = array();
  5377. while($row = Database::fetch_array($result))
  5378. {
  5379. $arrLP[] = array(
  5380. 'id' => $row['id'],
  5381. 'item_type' => $row['item_type'],
  5382. 'title' => $row['title'],
  5383. 'path' => $row['path'],
  5384. 'description' => $row['description'],
  5385. 'parent_item_id' => $row['parent_item_id'],
  5386. 'previous_item_id' => $row['previous_item_id'],
  5387. 'next_item_id' => $row['next_item_id'],
  5388. 'display_order' => $row['display_order'],
  5389. 'max_score' => $row['max_score'],
  5390. 'min_score' => $row['min_score'],
  5391. 'mastery_score' => $row['mastery_score'],
  5392. 'prerequisite' => $row['prerequisite']);
  5393. }
  5394. $this->tree_array($arrLP);
  5395. $arrLP = $this->arrMenu;
  5396. unset($this->arrMenu);
  5397. if($action == 'add')
  5398. {
  5399. $return .= get_lang("CreateTheDocument") . "\n";
  5400. }
  5401. elseif($action == 'move')
  5402. {
  5403. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5404. }
  5405. else
  5406. {
  5407. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5408. }
  5409. $return .= '</div>';
  5410. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  5411. {
  5412. $return .= '<div class="warning-message">';
  5413. $return .= '<strong>'.get_lang("Warning").' !</strong><br />';
  5414. $return .= get_lang("WarningEditingDocument");
  5415. $return .= '</div>';
  5416. }
  5417. /*
  5418. if($no_display_add==true){
  5419. $return .= '<div class="warning-message">';
  5420. $return .= get_lang("CantEditDocument");
  5421. $return .= '</div>';
  5422. return $return;
  5423. }
  5424. */
  5425. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5426. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"],'','enctype="multipart/form-data"');
  5427. $defaults["title"] = html_entity_decode($item_title);
  5428. $defaults["title"]=mb_convert_encoding($defaults["title"],$charset,$this->encoding);
  5429. if(empty($defaults["title"]))
  5430. {
  5431. $defaults["title"] = html_entity_decode($item_title);
  5432. }
  5433. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5434. $form->addElement('html',$return);
  5435. if($action != 'move')
  5436. {
  5437. $form->addElement('text','title', get_lang('Title'),'id="idTitle" class="learnpath_item_form" size=44%');
  5438. $form->applyFilter('title', 'html_filter');
  5439. }
  5440. //$arrHide = array($id);
  5441. $arrHide[0]['value']=$this->name;
  5442. $arrHide[0]['padding']=3;
  5443. for($i = 0; $i < count($arrLP); $i++)
  5444. {
  5445. if($action != 'add'){
  5446. 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)){
  5447. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5448. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5449. if($parent == $arrLP[$i]['id']){
  5450. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5451. }
  5452. }
  5453. }
  5454. else{
  5455. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  5456. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5457. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5458. if($parent == $arrLP[$i]['id']){
  5459. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5460. }
  5461. }
  5462. }
  5463. }
  5464. $parent_select = &$form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
  5465. foreach($arrHide as $key => $value) {
  5466. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5467. }
  5468. if (!empty($id)) {
  5469. $parent_select -> setSelected($parent);
  5470. } else {
  5471. $parent_item_id = $_SESSION['parent_item_id'];
  5472. $parent_select -> setSelected($parent_item_id);
  5473. }
  5474. if(is_array($arrLP)) {
  5475. reset($arrLP);
  5476. }
  5477. $arrHide=array();
  5478. //POSITION
  5479. for($i = 0; $i < count($arrLP); $i++) {
  5480. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5481. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5482. $s_selected_position=$arrLP[$i]['id'];
  5483. elseif($action == 'add')
  5484. $s_selected_position=$arrLP[$i]['id'];
  5485. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding).'"';
  5486. }
  5487. }
  5488. $position = &$form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5489. $position->addOption(get_lang("FirstPosition"),0);
  5490. foreach($arrHide as $key => $value) {
  5491. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5492. }
  5493. $position -> setSelected($s_selected_position);
  5494. if(is_array($arrLP)) {
  5495. reset($arrLP);
  5496. }
  5497. if($action != 'move') {
  5498. $id_prerequisite=0;
  5499. if(is_array($arrLP)) {
  5500. foreach($arrLP as $key=>$value){
  5501. if($value['id']==$id){
  5502. $id_prerequisite=$value['prerequisite'];
  5503. break;
  5504. }
  5505. }
  5506. }
  5507. //comented the prerequisites, only visible in edit (new document)
  5508. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5509. //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5510. // form element for uploading an mp3 file
  5511. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5512. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5513. /* Code deprecated - moved to lp level (not lp-item)
  5514. if ( api_get_setting('search_enabled') === 'true' )
  5515. {
  5516. //add terms field
  5517. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5518. $terms->setValue($item_terms);
  5519. }
  5520. */
  5521. $arrHide=array();
  5522. for($i = 0; $i < count($arrLP); $i++)
  5523. {
  5524. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5525. {
  5526. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5527. $s_selected_position=$arrLP[$i]['id'];
  5528. elseif($action == 'add')
  5529. $s_selected_position=$arrLP[$i]['id'];
  5530. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5531. }
  5532. }
  5533. /* foreach($arrHide as $key => $value){
  5534. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5535. if($key==$s_selected_position && $action == 'add'){
  5536. $select_prerequisites -> setSelected(0);
  5537. }
  5538. elseif($key==$id_prerequisite && $action == 'edit'){
  5539. $select_prerequisites -> setSelected($id_prerequisite);
  5540. }
  5541. }
  5542. */
  5543. if(!$no_display_add)
  5544. {
  5545. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  5546. {
  5547. if(isset($_POST['content']))
  5548. $content = stripslashes($_POST['content']);
  5549. elseif(is_array($extra_info)){
  5550. //If it's an html document or a text file
  5551. if(!$no_display_edit_textarea){
  5552. $content = $this->display_document($extra_info['path'], false, false);
  5553. }
  5554. }
  5555. elseif(is_numeric($extra_info))
  5556. $content = $this->display_document($extra_info, false, false);
  5557. else
  5558. $content = '';
  5559. if(!$no_display_edit_textarea)
  5560. {
  5561. // We need to claculate here some specific settings for the online editor.
  5562. // The calculated settings work for documents in the Documents tool
  5563. // (on the root or in subfolders).
  5564. // For documents in native scorm packages it is unclear whether the
  5565. // online editor should be activated or not.
  5566. global $fck_attribute;
  5567. $fck_attribute['Width'] = '100%';
  5568. $fck_attribute['Height'] = '700';
  5569. $fck_attribute['ToolbarSet'] = 'LearnPath';
  5570. $fck_attribute['Config']['FullPage'] = true;
  5571. $relative_path = $extra_info['dir'];
  5572. if ($relative_path == 'n/')
  5573. {
  5574. // A new document, it is in the root of the repository.
  5575. $relative_path = '';
  5576. $relative_prefix = '';
  5577. }
  5578. else
  5579. {
  5580. // The document already exists. Whe have to determine its relative path towards the repository root.
  5581. $relative_path = explode('/', $relative_path);
  5582. $cnt = count($relative_path) - 2;
  5583. if ($cnt < 0) { $cnt = 0; }
  5584. $relative_prefix = str_repeat('../', $cnt);
  5585. $relative_path = array_slice($relative_path, 1, $cnt);
  5586. $relative_path = implode('/', $relative_path);
  5587. if (strlen($relative_path) > 0)
  5588. {
  5589. $relative_path = $relative_path.'/';
  5590. }
  5591. }
  5592. $fck_attribute['Config']['CreateDocumentDir'] = $relative_prefix;
  5593. $fck_attribute['Config']['CreateDocumentWebDir'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/';
  5594. $fck_attribute['Config']['BaseHref'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/'.$relative_path;
  5595. if ($_GET['action']=='add_item'){
  5596. $class='add';
  5597. $text=get_lang('LPCreateDocument');
  5598. } else if ($_GET['action']=='edit_item'){
  5599. $class='save';
  5600. $text=get_lang('SaveDocument');
  5601. }
  5602. $form->addElement('style_submit_button', 'submit_button', $text,'class="'.$class.'"');
  5603. $renderer = $form->defaultRenderer();
  5604. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5605. $form->addElement('html','<div style="margin:3px 12px">');
  5606. $form->addElement('html_editor','content_lp','');
  5607. $form->addElement('html','</div>');
  5608. $defaults["content_lp"]=$content;
  5609. }
  5610. }
  5611. elseif(is_numeric($extra_info))
  5612. {
  5613. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5614. $return = $this->display_document($extra_info, true, true, true);
  5615. $form->addElement('html',$return);
  5616. }
  5617. }
  5618. }
  5619. if($action == 'move')
  5620. {
  5621. $form->addElement('hidden', 'title', $item_title);
  5622. $form->addElement('hidden', 'description', $item_description);
  5623. }
  5624. if(is_numeric($extra_info))
  5625. {
  5626. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5627. $form->addElement('hidden', 'path', $extra_info);
  5628. }
  5629. elseif(is_array($extra_info))
  5630. {
  5631. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5632. $form->addElement('hidden', 'path', $extra_info['path']);
  5633. }
  5634. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5635. $form->addElement('hidden', 'post_time', time());
  5636. $form->setDefaults($defaults);
  5637. return $form->return_form();
  5638. }
  5639. /**
  5640. * Return HTML form to add/edit a link item
  5641. *
  5642. * @param string Action (add/edit)
  5643. * @param integer Item ID if exists
  5644. * @param mixed Extra info
  5645. * @return string HTML form
  5646. */
  5647. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  5648. {
  5649. global $charset;
  5650. $tbl_lp_item = Database::get_course_table('lp_item');
  5651. $tbl_link = Database::get_course_table(TABLE_LINK);
  5652. if($id != 0 && is_array($extra_info)) {
  5653. $item_title = stripslashes($extra_info['title']);
  5654. $item_description = stripslashes($extra_info['description']);
  5655. } elseif(is_numeric($extra_info)) {
  5656. $sql_link = "
  5657. SELECT
  5658. title,
  5659. description,
  5660. url
  5661. FROM " . $tbl_link . "
  5662. WHERE id = " . $extra_info;
  5663. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  5664. $row = Database::fetch_array($result);
  5665. $item_title = $row['title'];
  5666. $item_description = $row['description'];
  5667. $item_url = $row['url'];
  5668. } else {
  5669. $item_title = '';
  5670. $item_description = '';
  5671. }
  5672. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5673. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  5674. $return = '<div class="sectiontitle">';
  5675. if($id != 0 && is_array($extra_info))
  5676. $parent = $extra_info['parent_item_id'];
  5677. else
  5678. $parent = 0;
  5679. $sql = "
  5680. SELECT *
  5681. FROM " . $tbl_lp_item . "
  5682. WHERE
  5683. lp_id = " . $this->lp_id;
  5684. $result = api_sql_query($sql, __FILE__, __LINE__);
  5685. $arrLP = array();
  5686. while($row = Database::fetch_array($result)) {
  5687. $arrLP[] = array(
  5688. 'id' => $row['id'],
  5689. 'item_type' => $row['item_type'],
  5690. 'title' => $row['title'],
  5691. 'path' => $row['path'],
  5692. 'description' => $row['description'],
  5693. 'parent_item_id' => $row['parent_item_id'],
  5694. 'previous_item_id' => $row['previous_item_id'],
  5695. 'next_item_id' => $row['next_item_id'],
  5696. 'display_order' => $row['display_order'],
  5697. 'max_score' => $row['max_score'],
  5698. 'min_score' => $row['min_score'],
  5699. 'mastery_score' => $row['mastery_score'],
  5700. 'prerequisite' => $row['prerequisite']);
  5701. }
  5702. $this->tree_array($arrLP);
  5703. $arrLP = $this->arrMenu;
  5704. unset($this->arrMenu);
  5705. if($action == 'add')
  5706. $return .= get_lang("CreateTheLink").'&nbsp;:' . "\n";
  5707. elseif($action == 'move')
  5708. $return .= get_lang("MoveCurrentLink").'&nbsp;:' . "\n";
  5709. else
  5710. $return .= get_lang("EditCurrentLink").'&nbsp;:' . "\n";
  5711. $return .= '</div>';
  5712. $return .= '<div class="sectioncomment">';
  5713. $return .= '<form method="POST">' . "\n";
  5714. $return .= "\t" . '<table>' . "\n";
  5715. if($action != 'move') {
  5716. $return .= "\t\t" . '<tr>' . "\n";
  5717. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  5718. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
  5719. $return .= "\t\t" . '</tr>' . "\n";
  5720. }
  5721. $return .= "\t\t" . '<tr>' . "\n";
  5722. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  5723. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5724. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5725. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5726. $arrHide = array($id);
  5727. $parent_item_id = $_SESSION['parent_item_id'];
  5728. for($i = 0; $i < count($arrLP); $i++) {
  5729. if($action != 'add') {
  5730. 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))
  5731. {
  5732. $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>';
  5733. } else {
  5734. $arrHide[] = $arrLP[$i]['id'];
  5735. }
  5736. } else {
  5737. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5738. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5739. }
  5740. }
  5741. if(is_array($arrLP)) {
  5742. reset($arrLP);
  5743. }
  5744. $return .= "\t\t\t\t" . '</select>';
  5745. $return .= "\t\t\t" . '</td>' . "\n";
  5746. $return .= "\t\t" . '</tr>' . "\n";
  5747. $return .= "\t\t" . '<tr>' . "\n";
  5748. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  5749. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5750. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5751. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5752. for($i = 0; $i < count($arrLP); $i++)
  5753. {
  5754. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5755. {
  5756. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5757. $selected = 'selected="selected" ';
  5758. elseif($action == 'add')
  5759. $selected = 'selected="selected" ';
  5760. else
  5761. $selected = '';
  5762. $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>';
  5763. }
  5764. }
  5765. $return .= "\t\t\t\t" . '</select>';
  5766. $return .= "\t\t\t" . '</td>' . "\n";
  5767. $return .= "\t\t" . '</tr>' . "\n";
  5768. if($action != 'move') {
  5769. //Description filed is commentd for link
  5770. /*$return .= "\t\t" . '<tr>' . "\n";
  5771. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
  5772. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" style="width:100%;" name="description" class="learnpath_item_form" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5773. $return .= "\t\t" . '</tr>' . "\n";*/
  5774. $return .= "\t\t" . '<tr>' . "\n";
  5775. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang('Url').'</label></td>' . "\n";
  5776. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>' . "\n";
  5777. $return .= "\t\t" . '</tr>' . "\n";
  5778. $id_prerequisite=0;
  5779. if (is_array($arrLP)){
  5780. foreach($arrLP as $key=>$value){
  5781. if($value['id']==$id){
  5782. $id_prerequisite=$value['prerequisite'];
  5783. break;
  5784. }
  5785. }
  5786. }
  5787. $arrHide=array();
  5788. for($i = 0; $i < count($arrLP); $i++) {
  5789. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5790. {
  5791. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5792. $s_selected_position=$arrLP[$i]['id'];
  5793. elseif($action == 'add')
  5794. $s_selected_position=0;
  5795. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5796. }
  5797. }
  5798. /*//comented the prerequisites, only visible in edit (link)
  5799. $return .= "\t\t" . '<tr>' . "\n";
  5800. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5801. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5802. foreach($arrHide as $key => $value)
  5803. {
  5804. if($key==$s_selected_position && $action == 'add')
  5805. {
  5806. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5807. }
  5808. elseif($key==$id_prerequisite && $action == 'edit'){
  5809. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5810. }
  5811. else{
  5812. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5813. }
  5814. }
  5815. $return .= "</select></td>";
  5816. */
  5817. $return .= "\t\t" . '</tr>' . "\n";
  5818. }
  5819. $return .= "\t\t" . '<tr>' . "\n";
  5820. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">'.get_lang("AddLinkToCourse").'</button></td>' . "\n";
  5821. $return .= "\t\t" . '</tr>' . "\n";
  5822. $return .= "\t" . '</table>' . "\n";
  5823. if($action == 'move')
  5824. {
  5825. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5826. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5827. }
  5828. if(is_numeric($extra_info))
  5829. {
  5830. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5831. }
  5832. elseif(is_array($extra_info))
  5833. {
  5834. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5835. }
  5836. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  5837. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5838. $return .= '</form>' . "\n";
  5839. $return .= '</div>' . "\n";
  5840. return $return;
  5841. }
  5842. /**
  5843. * Return HTML form to add/edit a student publication (work)
  5844. *
  5845. * @param string Action (add/edit)
  5846. * @param integer Item ID if already exists
  5847. * @param mixed Extra info (work ID if integer)
  5848. * @return string HTML form
  5849. */
  5850. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  5851. {
  5852. global $charset;
  5853. $tbl_lp_item = Database::get_course_table('lp_item');
  5854. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5855. if($id != 0 && is_array($extra_info)) {
  5856. $item_title = stripslashes($extra_info['title']);
  5857. $item_description = stripslashes($extra_info['description']);
  5858. } elseif(is_numeric($extra_info)) {
  5859. $sql_publication = "
  5860. SELECT
  5861. title,
  5862. description
  5863. FROM " . $tbl_publication . "
  5864. WHERE id = " . $extra_info;
  5865. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  5866. $row = Database::fetch_array($result);
  5867. $item_title = $row['title'];
  5868. } else {
  5869. $item_title = '';
  5870. }
  5871. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5872. $return = '<div class="sectiontitle">';
  5873. if($id != 0 && is_array($extra_info))
  5874. $parent = $extra_info['parent_item_id'];
  5875. else
  5876. $parent = 0;
  5877. $sql = "
  5878. SELECT *
  5879. FROM " . $tbl_lp_item . "
  5880. WHERE
  5881. lp_id = " . $this->lp_id;
  5882. $result = api_sql_query($sql, __FILE__, __LINE__);
  5883. $arrLP = array();
  5884. while($row = Database::fetch_array($result)) {
  5885. $arrLP[] = array(
  5886. 'id' => $row['id'],
  5887. 'item_type' => $row['item_type'],
  5888. 'title' => $row['title'],
  5889. 'path' => $row['path'],
  5890. 'description' => $row['description'],
  5891. 'parent_item_id' => $row['parent_item_id'],
  5892. 'previous_item_id' => $row['previous_item_id'],
  5893. 'next_item_id' => $row['next_item_id'],
  5894. 'display_order' => $row['display_order'],
  5895. 'max_score' => $row['max_score'],
  5896. 'min_score' => $row['min_score'],
  5897. 'mastery_score' => $row['mastery_score'],
  5898. 'prerequisite' => $row['prerequisite']);
  5899. }
  5900. $this->tree_array($arrLP);
  5901. $arrLP = $this->arrMenu;
  5902. unset($this->arrMenu);
  5903. if($action == 'add')
  5904. $return .= get_lang("Student_publication").'&nbsp;:' . "\n";
  5905. elseif($action == 'move')
  5906. $return .= get_lang("MoveCurrentStudentPublication").'&nbsp;:' . "\n";
  5907. else
  5908. $return .= get_lang("EditCurrentStudentPublication").'&nbsp;:' . "\n";
  5909. $return .= '</div>';
  5910. $return .= '<div class="sectioncomment">';
  5911. $return .= '<form method="POST">' . "\n";
  5912. $return .= "\t" . '<table>' . "\n";
  5913. if($action != 'move')
  5914. {
  5915. $return .= "\t\t" . '<tr>' . "\n";
  5916. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  5917. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  5918. $return .= "\t\t" . '</tr>' . "\n";
  5919. }
  5920. $return .= "\t\t" . '<tr>' . "\n";
  5921. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  5922. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5923. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5924. $parent_item_id = $_SESSION['parent_item_id'];
  5925. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5926. $arrHide = array($id);
  5927. for($i = 0; $i < count($arrLP); $i++)
  5928. {
  5929. if($action != 'add')
  5930. {
  5931. 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))
  5932. {
  5933. $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>';
  5934. }
  5935. else
  5936. {
  5937. $arrHide[] = $arrLP[$i]['id'];
  5938. }
  5939. }
  5940. else
  5941. {
  5942. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5943. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding). '</option>';
  5944. }
  5945. }
  5946. if(is_array($arrLP))
  5947. {
  5948. reset($arrLP);
  5949. }
  5950. $return .= "\t\t\t\t" . '</select>';
  5951. $return .= "\t\t\t" . '</td>' . "\n";
  5952. $return .= "\t\t" . '</tr>' . "\n";
  5953. $return .= "\t\t" . '<tr>' . "\n";
  5954. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  5955. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5956. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5957. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5958. for($i = 0; $i < count($arrLP); $i++)
  5959. {
  5960. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5961. {
  5962. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5963. $selected = 'selected="selected" ';
  5964. elseif($action == 'add')
  5965. $selected = 'selected="selected" ';
  5966. else
  5967. $selected = '';
  5968. $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>';
  5969. }
  5970. }
  5971. $return .= "\t\t\t\t" . '</select>';
  5972. $return .= "\t\t\t" . '</td>' . "\n";
  5973. $return .= "\t\t" . '</tr>' . "\n";
  5974. if($action != 'move')
  5975. {
  5976. $id_prerequisite=0;
  5977. if(is_array($arrLP))
  5978. {
  5979. foreach($arrLP as $key=>$value){
  5980. if($value['id']==$id){
  5981. $id_prerequisite=$value['prerequisite'];
  5982. break;
  5983. }
  5984. }
  5985. }
  5986. $arrHide=array();
  5987. for($i = 0; $i < count($arrLP); $i++)
  5988. {
  5989. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5990. {
  5991. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5992. $s_selected_position=$arrLP[$i]['id'];
  5993. elseif($action == 'add')
  5994. $s_selected_position=0;
  5995. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5996. }
  5997. }
  5998. //comented the prerequisites, only visible in edit (work)
  5999. /*
  6000. $return .= "\t\t" . '<tr>' . "\n";
  6001. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6002. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  6003. foreach($arrHide as $key => $value){
  6004. if($key==$s_selected_position && $action == 'add'){
  6005. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6006. }
  6007. elseif($key==$id_prerequisite && $action == 'edit'){
  6008. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6009. }
  6010. else{
  6011. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6012. }
  6013. }
  6014. $return .= "</select></td>";
  6015. */
  6016. $return .= "\t\t" . '</tr>' . "\n";
  6017. }
  6018. $return .= "\t\t" . '<tr>' . "\n";
  6019. $return .= "\t\t\t" . '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">'.get_lang("AddAssignmentToCourse").'</button></td>' . "\n";
  6020. $return .= "\t\t" . '</tr>' . "\n";
  6021. $return .= "\t" . '</table>' . "\n";
  6022. if($action == 'move')
  6023. {
  6024. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6025. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6026. }
  6027. if(is_numeric($extra_info))
  6028. {
  6029. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6030. }
  6031. elseif(is_array($extra_info))
  6032. {
  6033. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6034. }
  6035. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  6036. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6037. $return .= '</form>' . "\n";
  6038. $return .= '</div>' . "\n";
  6039. return $return;
  6040. }
  6041. /**
  6042. * Displays the menu for manipulating a step
  6043. *
  6044. * @return unknown
  6045. */
  6046. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  6047. {
  6048. global $charset, $_course;
  6049. $return = '<div class="actions">';
  6050. switch($item_type)
  6051. {
  6052. case 'dokeos_chapter':
  6053. case 'chapter':
  6054. //comented the message cause should not show it
  6055. //$lang = get_lang('TitleManipulateChapter');
  6056. break;
  6057. case 'dokeos_module':
  6058. case 'module':
  6059. //comented the message cause should not show it
  6060. //$lang = get_lang('TitleManipulateModule');
  6061. break;
  6062. case TOOL_DOCUMENT:
  6063. //comented the message cause should not show it
  6064. //$lang = get_lang('TitleManipulateDocument');
  6065. break;
  6066. case TOOL_LINK:
  6067. case 'link':
  6068. //comented the message cause should not show it
  6069. //$lang = get_lang('TitleManipulateLink');
  6070. break;
  6071. case TOOL_QUIZ:
  6072. //comented the message cause should not show it
  6073. //$lang = get_lang('TitleManipulateQuiz');
  6074. break;
  6075. case TOOL_STUDENTPUBLICATION:
  6076. //comented the message cause should not show it
  6077. //$lang = get_lang('TitleManipulateStudentPublication');
  6078. break;
  6079. }
  6080. $tbl_lp_item = Database::get_course_table('lp_item');
  6081. $sql = "
  6082. SELECT
  6083. *
  6084. FROM " . $tbl_lp_item . " as lp
  6085. WHERE
  6086. lp.id = " . $item_id;
  6087. $result = api_sql_query($sql, __FILE__, __LINE__);
  6088. $row= mysql_fetch_assoc($result);
  6089. $s_title = $row['title'];
  6090. $s_title=mb_convert_encoding($s_title,$charset,$this->encoding);
  6091. // we display an audio player if needed
  6092. if (!empty($row['audio']))
  6093. {
  6094. $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>';
  6095. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6096. $return .= '<script type="text/javascript">
  6097. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6098. s1.addParam("allowscriptaccess","always");
  6099. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  6100. s1.write("container");
  6101. </script>';
  6102. }
  6103. //commented ":" for message in step
  6104. //$return .= $lang.': ';
  6105. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '&path_item='.$row['path'].'" title="'.get_lang('Edit').'"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="'.get_lang("Edit").'" /> '.get_lang("Edit").'</a>';
  6106. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="'.get_lang("Move").'" /> '.get_lang("Move").'</a>';
  6107. // commented for now as prerequisites cannot be added to chapters
  6108. if($item_type != 'dokeos_chapter' && $item_type != 'chapter')
  6109. {
  6110. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="'.get_lang('Prerequisites').'"><img align="absbottom" alt="'.get_lang('Prerequisites').'" src="../img/right.gif" title="'.get_lang('Prerequisites').'" /> '.get_lang('Prerequisites').'</a>';
  6111. }
  6112. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' .addslashes($s_title). '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="'.get_lang("Delete").'" /> '.get_lang("Delete").'</a>';
  6113. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  6114. //$return.="</td><td valign='top'>";
  6115. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  6116. ob_start();
  6117. $audio_recorder_studentview = 'false';
  6118. $audio_recorder_item_id = $item_id;
  6119. if(api_get_setting('service_visio','active')=='true'){
  6120. include('audiorecorder.inc.php');
  6121. }
  6122. $return .= ob_get_contents();
  6123. ob_end_clean();
  6124. // end of audiorecorder include
  6125. $return .= '</div>';
  6126. return $return;
  6127. }
  6128. /**
  6129. * Creates the javascript needed for filling up the checkboxes without page reload
  6130. *
  6131. * @return string
  6132. */
  6133. function create_js()
  6134. {
  6135. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6136. $return .= 'function load_cbo(id){' . "\n";
  6137. $return .= "var cbo = document.getElementById('idPosition');\n";
  6138. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6139. $return .= 'cbo.options[i] = null;'."\n";
  6140. $return .= 'var k=0;'."\n";
  6141. $return .= 'for(var i = 1; i <= child_name[id].length; i++){'."\n";
  6142. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);'."\n";
  6143. $return .= 'k=i;';
  6144. $return .= '}' . "\n\n";
  6145. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6146. $return .='}';
  6147. $return .= 'var child_name = new Array();' . "\n";
  6148. $return .= 'var child_value = new Array();' . "\n\n";
  6149. $return .= 'child_name[0] = new Array();' . "\n";
  6150. $return .= 'child_value[0] = new Array();' . "\n\n";
  6151. $tbl_lp_item = Database::get_course_table('lp_item');
  6152. $sql_zero = "
  6153. SELECT *
  6154. FROM " . $tbl_lp_item . "
  6155. WHERE
  6156. lp_id = " . $this->lp_id . " AND
  6157. parent_item_id = 0
  6158. ORDER BY display_order ASC";
  6159. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  6160. global $charset;
  6161. $i = 0;
  6162. while($row_zero = Database::fetch_array($res_zero))
  6163. {
  6164. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_zero['title'],$charset,$this->encoding) . '\"";' . "\n";
  6165. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6166. }
  6167. $return .= "\n";
  6168. $sql = "
  6169. SELECT *
  6170. FROM " . $tbl_lp_item . "
  6171. WHERE
  6172. lp_id = " . $this->lp_id;
  6173. $res = api_sql_query($sql, __FILE__, __LINE__);
  6174. while($row = Database::fetch_array($res))
  6175. {
  6176. $sql_parent = "
  6177. SELECT *
  6178. FROM " . $tbl_lp_item . "
  6179. WHERE parent_item_id = " . $row['id'] . "
  6180. ORDER BY display_order ASC";
  6181. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  6182. $i = 0;
  6183. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6184. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6185. while($row_parent = Database::fetch_array($res_parent))
  6186. {
  6187. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_parent['title'],$charset,$this->encoding) . '\"";' . "\n";
  6188. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6189. }
  6190. $return .= "\n";
  6191. }
  6192. $return .= '</script>' . "\n";
  6193. return $return;
  6194. }
  6195. /**
  6196. * Display the form to allow moving an item
  6197. *
  6198. * @param integer Item ID
  6199. * @return string HTML form
  6200. */
  6201. function display_move_item($item_id)
  6202. {
  6203. global $_course; //will disappear
  6204. global $charset;
  6205. $return = '';
  6206. if(is_numeric($item_id))
  6207. {
  6208. $tbl_lp_item = Database::get_course_table('lp_item');
  6209. $sql = "
  6210. SELECT *
  6211. FROM " . $tbl_lp_item . "
  6212. WHERE id = " . $item_id;
  6213. $res = api_sql_query($sql, __FILE__, __LINE__);
  6214. $row = Database::fetch_array($res);
  6215. switch($row['item_type'])
  6216. {
  6217. case 'dokeos_chapter': case 'dir' : case 'asset' :
  6218. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6219. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6220. break;
  6221. case 'dokeos_module':
  6222. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6223. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6224. break;
  6225. case TOOL_DOCUMENT:
  6226. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6227. $return .= $this->display_document_form('move', $item_id, $row);
  6228. break;
  6229. case TOOL_LINK:
  6230. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6231. $return .= $this->display_link_form('move', $item_id, $row);
  6232. break;
  6233. case TOOL_HOTPOTATOES:
  6234. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6235. $return .= $this->display_link_form('move', $item_id, $row);
  6236. break;
  6237. case TOOL_QUIZ:
  6238. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6239. $return .= $this->display_quiz_form('move', $item_id, $row);
  6240. break;
  6241. case TOOL_STUDENTPUBLICATION:
  6242. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6243. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6244. break;
  6245. case TOOL_FORUM :
  6246. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6247. $return .= $this->display_forum_form('move', $item_id, $row);
  6248. }
  6249. }
  6250. return $return;
  6251. }
  6252. /**
  6253. * Displays a basic form on the overview page for changing the item title and the item description.
  6254. *
  6255. * @param string $item_type
  6256. * @param string $title
  6257. * @param array $data
  6258. * @return string
  6259. */
  6260. function display_item_small_form($item_type, $title = '', $data)
  6261. {
  6262. $return .= '<div class="lp_small_form">' . "\n";
  6263. $return .= '<p class="lp_title">' . $title . '</p>';
  6264. $return .= '<form method="post">' . "\n";
  6265. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6266. $return .= "\t\t" . '<tr>' . "\n";
  6267. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6268. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  6269. $return .= "\t\t" . '</tr>' . "\n";
  6270. $return .= "\t\t" . '<tr>' . "\n";
  6271. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6272. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6273. $return .= "\t\t" . '</tr>' . "\n";
  6274. $return .= "\t\t" . '<tr>' . "\n";
  6275. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">'.get_lang('Save').'</button></td>' . "\n";
  6276. $return .= "\t\t" . '</tr>' . "\n";
  6277. $return .= "\t\t" . '</table>' . "\n";
  6278. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6279. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6280. $return .= '</form>';
  6281. $return .= '</div>';
  6282. return $return;
  6283. }
  6284. /**
  6285. * Return HTML form to allow prerequisites selection
  6286. *
  6287. * @param integer Item ID
  6288. * @return string HTML form
  6289. */
  6290. function display_item_prerequisites_form($item_id)
  6291. {
  6292. global $charset;
  6293. $tbl_lp_item = Database::get_course_table('lp_item');
  6294. /* current prerequisite */
  6295. $sql = "
  6296. SELECT *
  6297. FROM " . $tbl_lp_item . "
  6298. WHERE id = " . $item_id;
  6299. $result = api_sql_query($sql, __FILE__, __LINE__);
  6300. $row = Database::fetch_array($result);
  6301. $preq_id = $row['prerequisite'];
  6302. //$preq_mastery = $row['mastery_score'];
  6303. //$preq_max = $row['max_score'];
  6304. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6305. $return .= '<div class="sectiontitle">';
  6306. $return .= get_lang('AddEditPrerequisites');
  6307. $return .= '</div>';
  6308. $return .= '<div class="sectioncomment">';
  6309. $return .= '<form method="POST">';
  6310. $return .= '<table class="lp_prerequisites">';
  6311. $return .= '<tr>';
  6312. $return .= '<th></th>';
  6313. $return .= '<th >'.get_lang('Minimum').'</th>';
  6314. $return .= '<th>'.get_lang('Maximum').'</th>';
  6315. $return .= '</tr>';
  6316. $return .= '<tr>';
  6317. $return .= '<td class="radio">';
  6318. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6319. $return .= '<label for="idNone">'.get_lang('None').'</label>';
  6320. $return .= '</td><td colspan="2" />';
  6321. $return .= '</tr>';
  6322. $sql = "
  6323. SELECT *
  6324. FROM " . $tbl_lp_item . "
  6325. WHERE
  6326. lp_id = " . $this->lp_id;
  6327. $result = api_sql_query($sql, __FILE__, __LINE__);
  6328. $arrLP = array();
  6329. while($row = Database::fetch_array($result))
  6330. {
  6331. $arrLP[] = array(
  6332. 'id' => $row['id'],
  6333. 'item_type' => $row['item_type'],
  6334. 'title' => mb_convert_encoding($row['title'],$charset,$this->encoding),
  6335. 'ref' => $row['ref'],
  6336. 'description' => $row['description'],
  6337. 'parent_item_id' => $row['parent_item_id'],
  6338. 'previous_item_id' => $row['previous_item_id'],
  6339. 'next_item_id' => $row['next_item_id'],
  6340. 'max_score' => $row['max_score'],
  6341. 'min_score' => $row['min_score'],
  6342. 'mastery_score' => $row['mastery_score'],
  6343. 'prerequisite' => $row['prerequisite'],
  6344. 'next_item_id' => $row['next_item_id'],
  6345. 'display_order' => $row['display_order']);
  6346. if($row['ref'] == $preq_id)
  6347. {
  6348. $preq_mastery = $row['mastery_score'];
  6349. $preq_max = $row['max_score'];
  6350. }
  6351. }
  6352. $this->tree_array($arrLP);
  6353. $arrLP = $this->arrMenu;
  6354. unset($this->arrMenu);
  6355. for($i = 0; $i < count($arrLP); $i++)
  6356. {
  6357. if($arrLP[$i]['id'] == $item_id)
  6358. break;
  6359. $return .= '<tr>';
  6360. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6361. $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'] . '" />';
  6362. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6363. if (file_exists("../img/lp_" . $icon_name . ".png"))
  6364. {
  6365. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6366. }
  6367. else if(file_exists("../img/lp_" . $icon_name . ".gif"))
  6368. {
  6369. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6370. }
  6371. else
  6372. {
  6373. $return .= '<img alt="" src="../img/lp_document.png" style="margin-right:5px;" title="" />';
  6374. }
  6375. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6376. $return .= '</td>';
  6377. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6378. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  6379. {
  6380. $return .= '<td class="exercise">';
  6381. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6382. $return .= '</td>';
  6383. $return .= '<td class="exercise">';
  6384. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6385. $return .= '</td>';
  6386. }
  6387. if($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES)
  6388. {
  6389. $return .= '<td class="exercise">';
  6390. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6391. $return .= '</td>';
  6392. $return .= '<td class="exercise">';
  6393. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6394. $return .= '</td>';
  6395. }
  6396. $return .='</tr>';
  6397. }
  6398. $return .= '<tr>';
  6399. $return .= '<td colspan="3">';
  6400. $return .= '<button class="save" name="submit_button" type="submit">'.get_lang("ModifyPrerequisites").' </button></td>' . "\n";
  6401. $return .= '</td>';
  6402. $return .= '</tr>';
  6403. $return .= '</table>';
  6404. $return .= '</form>';
  6405. $return .= '</div>';
  6406. return $return;
  6407. }
  6408. /**
  6409. * Creates a list with all the documents in it
  6410. *
  6411. * @return string
  6412. */
  6413. function get_documents()
  6414. {
  6415. global $_course;
  6416. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6417. $sql_doc = "
  6418. SELECT *
  6419. FROM " . $tbl_doc . "
  6420. WHERE
  6421. path NOT LIKE '%_DELETED_%'
  6422. ORDER BY path ASC";
  6423. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  6424. $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("Documents").'</div>';
  6425. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6426. $resources=api_store_result($res_doc);
  6427. $resources_sorted = array();
  6428. // if you want to debug it, I advise you to do "echo" on the eval statements
  6429. foreach($resources as $resource)
  6430. {
  6431. $resource_paths = explode('/',$resource['path']);
  6432. array_shift($resource_paths);
  6433. $path_to_eval = $last_path = '';
  6434. $is_file = false;
  6435. foreach($resource_paths as $key => $resource_path)
  6436. {
  6437. if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1)
  6438. { // it's a folder
  6439. $path_to_eval .= '["'.$resource_path.'"]["files"]';
  6440. }
  6441. else if(strpos($resource_path,'.')!==false)
  6442. $is_file = true;
  6443. $last_path = $resource_path;
  6444. }
  6445. if($is_file)
  6446. {
  6447. eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";');
  6448. }
  6449. else
  6450. {
  6451. eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';');
  6452. }
  6453. }
  6454. $return .=$this->write_resources_tree($resources_sorted);
  6455. $return .='</div>';
  6456. if(Database::num_rows($res_doc) == 0)
  6457. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  6458. return $return;
  6459. }
  6460. /**
  6461. * Generate and return an HTML list of resources based on a given array.
  6462. *
  6463. * This list is used to show the course creator a list of available resources to choose from
  6464. * when creating a learning path.
  6465. * @param array Array of elements to add to the list
  6466. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6467. * @return string The HTML list
  6468. */
  6469. function write_resources_tree($resources_sorted, $num=0){
  6470. include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
  6471. if(count($resources_sorted)>0)
  6472. {
  6473. foreach($resources_sorted as $key=>$resource)
  6474. {
  6475. if(is_int($resource['id']))
  6476. { // it's a folder
  6477. $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'].'">';
  6478. $return .= $this->write_resources_tree($resource['files'], $num+1);
  6479. $return .= "</div></div>\r\n";
  6480. }
  6481. else
  6482. {
  6483. // it's a file
  6484. $icon = choose_image($resource);
  6485. $position = strrpos($icon,'.');
  6486. $icon=substr($icon,0,$position).'_small.gif';
  6487. $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";
  6488. }
  6489. }
  6490. }
  6491. return $return;
  6492. }
  6493. /**
  6494. * Creates a list with all the exercises (quiz) in it
  6495. *
  6496. * @return string
  6497. */
  6498. function get_exercises()
  6499. {
  6500. // new for hotpotatoes
  6501. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6502. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6503. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  6504. $sql_quiz = "
  6505. SELECT *
  6506. FROM " . $tbl_quiz . "
  6507. WHERE active<>'-1'
  6508. ORDER BY title ASC";
  6509. $sql_hot = "SELECT * FROM ".$tbl_doc." " .
  6510. " WHERE path LIKE '".$uploadPath."/%/%htm%'" .
  6511. " ORDER BY id ASC";
  6512. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  6513. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  6514. $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>';
  6515. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6516. while ($row_hot = Database::fetch_array($res_hot)) {
  6517. $return .= '<div class="lp_resource_element">';
  6518. //display quizhotpotatoes
  6519. $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
  6520. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . ((!empty($row_hot['comment']))?$row_hot['comment']:$row_hot['title']). '</a>';
  6521. //$return .= $row_quiz['title'];
  6522. $return .= '</div>';
  6523. }
  6524. while($row_quiz = Database::fetch_array($res_quiz)) {
  6525. $return .= '<div class="lp_resource_element">';
  6526. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6527. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
  6528. //$return .= $row_quiz['title'];
  6529. $return .= '</div>';
  6530. }
  6531. if(Database::num_rows($res_quiz) == 0)
  6532. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  6533. $return .= '<div class="lp_resource_element">';
  6534. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6535. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6536. $return .= '</div>';
  6537. $return .= '</div>';
  6538. return $return;
  6539. }
  6540. /**
  6541. * Creates a list with all the links in it
  6542. *
  6543. * @return string
  6544. */
  6545. function get_links()
  6546. {
  6547. $tbl_link = Database::get_course_table(TABLE_LINK);
  6548. $sql_link = "
  6549. SELECT *
  6550. FROM " . $tbl_link . "
  6551. ORDER BY title ASC";
  6552. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  6553. $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>';
  6554. $return .= '<div class="lp_resource_elements" id="resLink">';
  6555. while($row_link = Database::fetch_array($res_link))
  6556. {
  6557. $return .= '<div class="lp_resource_element">';
  6558. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6559. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_LINK . '&amp;file=' . $row_link['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
  6560. $return .= '</div>';
  6561. }
  6562. $return .= '<div class="lp_resource_element">';
  6563. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6564. $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>';
  6565. $return .= '</div>';
  6566. if(Database::num_rows($res_link) == 0)
  6567. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  6568. $return .= '</div>';
  6569. return $return;
  6570. }
  6571. /**
  6572. * Creates a list with all the student publications in it
  6573. *
  6574. * @return unknown
  6575. */
  6576. function get_student_publications()
  6577. {
  6578. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  6579. $sql_student = "
  6580. SELECT *
  6581. FROM " . $tbl_student . "
  6582. ORDER BY title ASC";
  6583. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  6584. $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>';
  6585. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6586. $return .= '<div class="lp_resource_element">';
  6587. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6588. $return .= '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  6589. $return .= '</div>';
  6590. $return .= '</div>';
  6591. return $return;
  6592. }
  6593. /**
  6594. * Creates a list with all the forums in it
  6595. *
  6596. * @return string
  6597. */
  6598. function get_forums()
  6599. {
  6600. include ('../forum/forumfunction.inc.php');
  6601. include ('../forum/forumconfig.inc.php');
  6602. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  6603. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6604. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6605. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6606. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6607. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6608. $a_forums = get_forums();
  6609. $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>';
  6610. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6611. foreach($a_forums as $forum)
  6612. {
  6613. $return .= '<div class="lp_resource_element">';
  6614. $return .= '<script type="text/javascript">
  6615. function toggle_forum(forum_id){
  6616. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6617. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6618. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  6619. }
  6620. else {
  6621. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6622. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  6623. }
  6624. }
  6625. </script>
  6626. ';
  6627. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6628. $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>
  6629. <a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_'.$forum['forum_id'].'_content">';
  6630. $a_threads = get_threads($forum['forum_id']);
  6631. if(is_array($a_threads)){
  6632. foreach($a_threads as $thread)
  6633. {
  6634. $return .= '<li><a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . $thread['thread_title'] . '</a></li>';
  6635. }
  6636. }
  6637. $return .= '</ul></div>';
  6638. }
  6639. $return .= '<div class="lp_resource_element">';
  6640. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6641. $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>';
  6642. $return .= '</div>';
  6643. return $return;
  6644. }
  6645. /**
  6646. * Exports the learning path as a SCORM package. This is the main function that
  6647. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6648. * whole thing and returns the zip.
  6649. *
  6650. * This method needs to be called in PHP5, as it will fail with non-adequate
  6651. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6652. * you need to call it on a learnpath object.
  6653. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6654. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6655. * path has been modified, it should use the generic method here below.
  6656. * @TODO link this function with the export_lp() function in the same class
  6657. * @param string Optional name of zip file. If none, title of learnpath is
  6658. * domesticated and trailed with ".zip"
  6659. * @return string Returns the zip package string, or null if error
  6660. */
  6661. function scorm_export()
  6662. {
  6663. global $_course;
  6664. if (!class_exists('DomDocument'))
  6665. {
  6666. error_log('DOM functions not supported for PHP version below 5.0',0);
  6667. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6668. return null;
  6669. }
  6670. //remove memory and time limits as much as possible as this might be a long process...
  6671. if(function_exists('ini_set'))
  6672. {
  6673. $mem = ini_get('memory_limit');
  6674. if(substr($mem,-1,1)=='M')
  6675. {
  6676. $mem_num = substr($mem,0,-1);
  6677. if($mem_num<128)
  6678. {
  6679. ini_set('memory_limit','128M');
  6680. }
  6681. }
  6682. else
  6683. {
  6684. ini_set('memory_limit','128M');
  6685. }
  6686. ini_set('max_execution_time',600);
  6687. //}else{
  6688. //error_log('Scorm export: could not change memory and time limits',0);
  6689. }
  6690. //Create the zip handler (this will remain available throughout the method)
  6691. $garbage_path = api_get_path(GARBAGE_PATH);
  6692. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6693. $temp_dir_short = uniqid();
  6694. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  6695. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6696. $zip_folder=new PclZip($temp_zip_file);
  6697. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6698. $root_path = $main_path = api_get_path(SYS_PATH);
  6699. $files_cleanup = array();
  6700. //place to temporarily stash the zipfiles
  6701. //create the temp dir if it doesn't exist
  6702. //or do a cleanup befor creating the zipfile
  6703. if(!is_dir($temp_zip_dir))
  6704. {
  6705. mkdir($temp_zip_dir);
  6706. }
  6707. else
  6708. {//cleanup: check the temp dir for old files and delete them
  6709. $handle=opendir($temp_zip_dir);
  6710. while (false!==($file = readdir($handle)))
  6711. {
  6712. if ($file != "." && $file != "..")
  6713. {
  6714. unlink("$temp_zip_dir/$file");
  6715. }
  6716. }
  6717. closedir($handle);
  6718. }
  6719. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6720. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6721. {
  6722. // remove the possible . at the end of the path
  6723. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6724. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6725. $perm = api_get_setting('permissions_for_new_directories');
  6726. $perm = octdec(!empty($perm)?$perm:'0770');
  6727. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6728. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6729. }
  6730. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6731. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6732. //Aggregation Model official document, secion "2.3 Content Packaging"
  6733. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6734. $root = $xmldoc->createElement('manifest');
  6735. $root->setAttribute('identifier','SingleCourseManifest');
  6736. $root->setAttribute('version','1.1');
  6737. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6738. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6739. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6740. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  6741. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  6742. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6743. //Build mandatory sub-root container elements
  6744. $metadata = $xmldoc->createElement('metadata');
  6745. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6746. $metadata->appendChild($md_schema);
  6747. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6748. $metadata->appendChild($md_schemaversion);
  6749. $root->appendChild($metadata);
  6750. $organizations = $xmldoc->createElement('organizations');
  6751. $resources = $xmldoc->createElement('resources');
  6752. //Build the only organization we will use in building our learnpaths
  6753. $organizations->setAttribute('default','dokeos_scorm_export');
  6754. $organization = $xmldoc->createElement('organization');
  6755. $organization->setAttribute('identifier','dokeos_scorm_export');
  6756. //to set the title of the SCORM entity (=organization), we take the name given
  6757. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6758. //learning path charset) as it is the encoding that defines how it is stored
  6759. //in the database. Then we convert it to HTML entities again as the "&" character
  6760. //alone is not authorized in XML (must be &amp;)
  6761. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6762. global $charset;
  6763. $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6764. $organization->appendChild($org_title);
  6765. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6766. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6767. //format
  6768. $link_updates = array();
  6769. foreach($this->items as $index => $item){
  6770. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6771. {
  6772. //get included documents from this item
  6773. if($item->type=='sco')
  6774. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6775. else
  6776. $inc_docs = $item->get_resources_from_source();
  6777. //give a child element <item> to the <organization> element
  6778. $my_item_id = $item->get_id();
  6779. $my_item = $xmldoc->createElement('item');
  6780. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6781. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6782. $my_item->setAttribute('isvisible','true');
  6783. //give a child element <title> to the <item> element
  6784. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6785. $my_item->appendChild($my_title);
  6786. //give a child element <adlcp:prerequisites> to the <item> element
  6787. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6788. $my_prereqs->setAttribute('type','aicc_script');
  6789. $my_item->appendChild($my_prereqs);
  6790. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6791. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6792. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6793. //$xmldoc->createElement('adlcp:timelimitaction','');
  6794. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6795. //$xmldoc->createElement('adlcp:datafromlms','');
  6796. //give a child element <adlcp:masteryscore> to the <item> element
  6797. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6798. $my_item->appendChild($my_masteryscore);
  6799. //attach this item to the organization element or hits parent if there is one
  6800. if(!empty($item->parent) && $item->parent!=0)
  6801. {
  6802. $children = $organization->childNodes;
  6803. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6804. if(is_object($possible_parent))
  6805. {
  6806. $possible_parent->appendChild($my_item);
  6807. }
  6808. else
  6809. {
  6810. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6811. }
  6812. }
  6813. else
  6814. {
  6815. if($this->debug>0){error_log('No parent');}
  6816. $organization->appendChild($my_item);
  6817. }
  6818. //get the path of the file(s) from the course directory root
  6819. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6820. $my_xml_file_path = htmlentities($my_file_path);
  6821. $my_sub_dir = dirname($my_file_path);
  6822. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6823. //give a <resource> child to the <resources> element
  6824. $my_resource = $xmldoc->createElement('resource');
  6825. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6826. $my_resource->setAttribute('type','webcontent');
  6827. $my_resource->setAttribute('href',$my_xml_file_path);
  6828. //adlcp:scormtype can be either 'sco' or 'asset'
  6829. if($item->type=='sco')
  6830. {
  6831. $my_resource->setAttribute('adlcp:scormtype','sco');
  6832. }
  6833. else
  6834. {
  6835. $my_resource->setAttribute('adlcp:scormtype','asset');
  6836. }
  6837. //xml:base is the base directory to find the files declared in this resource
  6838. $my_resource->setAttribute('xml:base','');
  6839. //give a <file> child to the <resource> element
  6840. $my_file = $xmldoc->createElement('file');
  6841. $my_file->setAttribute('href',$my_xml_file_path);
  6842. $my_resource->appendChild($my_file);
  6843. //dependency to other files - not yet supported
  6844. $i = 1;
  6845. foreach($inc_docs as $doc_info)
  6846. {
  6847. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6848. $my_dep = $xmldoc->createElement('resource');
  6849. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6850. $my_dep->setAttribute('identifier',$res_id);
  6851. $my_dep->setAttribute('type','webcontent');
  6852. $my_dep->setAttribute('adlcp:scormtype','asset');
  6853. $my_dep_file = $xmldoc->createElement('file');
  6854. //check type of URL
  6855. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6856. if($doc_info[1] == 'remote')
  6857. { //remote file. Save url as is
  6858. $my_dep_file->setAttribute('href',$doc_info[0]);
  6859. $my_dep->setAttribute('xml:base','');
  6860. }elseif($doc_info[1] == 'local'){
  6861. switch($doc_info[2])
  6862. {
  6863. case 'url': //local URL - save path as url for now, don't zip file
  6864. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6865. $current_dir = dirname($abs_path);
  6866. $file_path = realpath($abs_path);
  6867. $my_dep_file->setAttribute('href',$file_path);
  6868. $my_dep->setAttribute('xml:base','');
  6869. if(strstr($file_path,$main_path) !== false)
  6870. {//the calculated real path is really inside the dokeos root path
  6871. //reduce file path to what's under the DocumentRoot
  6872. $file_path = substr($file_path,strlen($root_path)-1);
  6873. //echo $file_path;echo '<br><br>';
  6874. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6875. $zip_files_abs[] = $file_path;
  6876. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6877. $my_dep_file->setAttribute('href',$file_path);
  6878. $my_dep->setAttribute('xml:base','');
  6879. }
  6880. else if (empty($file_path))
  6881. {
  6882. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6883. if(strpos($document_root,-1)=='/')
  6884. {
  6885. $document_root = substr(0, -1, $document_root);
  6886. }*/
  6887. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6888. $file_path = str_replace('//','/',$file_path);
  6889. if(file_exists($file_path))
  6890. {
  6891. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6892. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6893. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6894. $my_dep_file->setAttribute('href',$file_path);
  6895. $my_dep->setAttribute('xml:base','');
  6896. }
  6897. }
  6898. break;
  6899. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6900. $my_dep_file->setAttribute('href',$doc_info[0]);
  6901. $my_dep->setAttribute('xml:base','');
  6902. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6903. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  6904. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  6905. $abs_img_path_without_subdir = $doc_info[0];
  6906. $relp = api_get_path(REL_PATH); //the url-append config param
  6907. $pos = strpos($abs_img_path_without_subdir,$relp);
  6908. if($pos===0)
  6909. {
  6910. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  6911. }
  6912. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6913. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  6914. $file_path = str_replace('\\','/',$file_path);
  6915. $file_path = str_replace('//','/',$file_path);
  6916. //error_log(__LINE__.'Abs path: '.$file_path,0);
  6917. //prepare the current directory path (until just under 'document') with a trailing slash
  6918. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6919. //check if the current document is in that path
  6920. if(strstr($file_path,$cur_path) !== false)
  6921. {
  6922. //the document is in that path, now get the relative path
  6923. //to the containing document
  6924. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  6925. $relative_path ='';
  6926. if(strstr($file_path,$cur_path)!==false)
  6927. {
  6928. $relative_path = substr($file_path,strlen($orig_file_path));
  6929. $file_path = substr($file_path,strlen($cur_path));
  6930. }
  6931. else
  6932. {
  6933. //this case is still a problem as it's difficult to calculate a relative path easily
  6934. //might still generate wrong links
  6935. //$file_path = substr($file_path,strlen($cur_path));
  6936. //calculate the directory path to the current file (without trailing slash)
  6937. $my_relative_path = dirname($file_path);
  6938. $my_relative_file = basename($file_path);
  6939. //calculate the directory path to the containing file (without trailing slash)
  6940. $my_orig_file_path = substr($orig_file_path,0,-1);
  6941. $dotdot = '';
  6942. $subdir = '';
  6943. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  6944. {
  6945. $my_relative_path2 = dirname($my_relative_path);
  6946. $my_orig_file_path = dirname($my_orig_file_path);
  6947. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  6948. $dotdot += '../';
  6949. $my_relative_path = $my_relative_path2;
  6950. }
  6951. $relative_path = $dotdot.$subdir.$my_relative_file;
  6952. }
  6953. //put the current document in the zip (this array is the array
  6954. //that will manage documents already in the course folder - relative)
  6955. $zip_files[] = $file_path;
  6956. //update the links to the current document in the containing document (make them relative)
  6957. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  6958. $my_dep_file->setAttribute('href',$file_path);
  6959. $my_dep->setAttribute('xml:base','');
  6960. }
  6961. elseif(strstr($file_path,$main_path) !== false)
  6962. {//the calculated real path is really inside the dokeos root path
  6963. //reduce file path to what's under the DocumentRoot
  6964. $file_path = substr($file_path,strlen($root_path));
  6965. //echo $file_path;echo '<br><br>';
  6966. //error_log('Reduced path: '.$file_path,0);
  6967. $zip_files_abs[] = $file_path;
  6968. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6969. $my_dep_file->setAttribute('href','document/'.$file_path);
  6970. $my_dep->setAttribute('xml:base','');
  6971. }
  6972. else if (empty($file_path))
  6973. {
  6974. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6975. if(strpos($document_root,-1)=='/')
  6976. {
  6977. $document_root = substr(0, -1, $document_root);
  6978. }*/
  6979. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6980. $file_path = str_replace('//','/',$file_path);
  6981. if(file_exists($file_path))
  6982. {
  6983. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6984. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6985. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6986. $my_dep_file->setAttribute('href','document/'.$file_path);
  6987. $my_dep->setAttribute('xml:base','');
  6988. }
  6989. }
  6990. break;
  6991. 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
  6992. if(substr($doc_info[0],0,2)=='..')
  6993. { //relative path going up
  6994. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6995. $file_path = realpath($current_dir.$doc_info[0]);
  6996. //error_log($file_path.' <-> '.$main_path,0);
  6997. if(strstr($file_path,$main_path) !== false)
  6998. {//the calculated real path is really inside the dokeos root path
  6999. //reduce file path to what's under the DocumentRoot
  7000. $file_path = substr($file_path,strlen($root_path));
  7001. //error_log('Reduced path: '.$file_path,0);
  7002. $zip_files_abs[] = $file_path;
  7003. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7004. $my_dep_file->setAttribute('href','document/'.$file_path);
  7005. $my_dep->setAttribute('xml:base','');
  7006. }
  7007. }else{
  7008. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7009. $my_dep_file->setAttribute('href',$doc_info[0]);
  7010. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7011. }
  7012. break;
  7013. default:
  7014. $my_dep_file->setAttribute('href',$doc_info[0]);
  7015. $my_dep->setAttribute('xml:base','');
  7016. break;
  7017. }
  7018. }
  7019. $my_dep->appendChild($my_dep_file);
  7020. $resources->appendChild($my_dep);
  7021. $dependency = $xmldoc->createElement('dependency');
  7022. $dependency->setAttribute('identifierref',$res_id);
  7023. $my_resource->appendChild($dependency);
  7024. $i++;
  7025. }
  7026. //$my_dependency = $xmldoc->createElement('dependency');
  7027. //$my_dependency->setAttribute('identifierref','');
  7028. $resources->appendChild($my_resource);
  7029. $zip_files[] = $my_file_path;
  7030. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  7031. }
  7032. else
  7033. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  7034. if($item->type == TOOL_LINK)
  7035. {
  7036. $my_item = $xmldoc->createElement('item');
  7037. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7038. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7039. $my_item->setAttribute('isvisible','true');
  7040. //give a child element <title> to the <item> element
  7041. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7042. $my_item->appendChild($my_title);
  7043. //give a child element <adlcp:prerequisites> to the <item> element
  7044. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7045. $my_prereqs->setAttribute('type','aicc_script');
  7046. $my_item->appendChild($my_prereqs);
  7047. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  7048. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7049. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  7050. //$xmldoc->createElement('adlcp:timelimitaction','');
  7051. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  7052. //$xmldoc->createElement('adlcp:datafromlms','');
  7053. //give a child element <adlcp:masteryscore> to the <item> element
  7054. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  7055. $my_item->appendChild($my_masteryscore);
  7056. //attach this item to the organization element or its parent if there is one
  7057. if(!empty($item->parent) && $item->parent!=0)
  7058. {
  7059. $children = $organization->childNodes;
  7060. for($i=0;$i<$children->length;$i++){
  7061. $item_temp = $children->item($i);
  7062. if ($item_temp -> nodeName == 'item')
  7063. {
  7064. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7065. {
  7066. $item_temp -> appendChild($my_item);
  7067. }
  7068. }
  7069. }
  7070. }
  7071. else
  7072. {
  7073. $organization->appendChild($my_item);
  7074. }
  7075. $my_file_path = 'link_'.$item->get_id().'.html';
  7076. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7077. $rs = api_sql_query($sql, __FILE__, __LINE__);
  7078. if($link = Database :: fetch_array($rs))
  7079. {
  7080. $url = $link['url'];
  7081. $title = stripslashes($link['title']);
  7082. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  7083. $my_xml_file_path = htmlentities($my_file_path);
  7084. $my_sub_dir = dirname($my_file_path);
  7085. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7086. //give a <resource> child to the <resources> element
  7087. $my_resource = $xmldoc->createElement('resource');
  7088. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7089. $my_resource->setAttribute('type','webcontent');
  7090. $my_resource->setAttribute('href',$my_xml_file_path);
  7091. //adlcp:scormtype can be either 'sco' or 'asset'
  7092. $my_resource->setAttribute('adlcp:scormtype','asset');
  7093. //xml:base is the base directory to find the files declared in this resource
  7094. $my_resource->setAttribute('xml:base','');
  7095. //give a <file> child to the <resource> element
  7096. $my_file = $xmldoc->createElement('file');
  7097. $my_file->setAttribute('href',$my_xml_file_path);
  7098. $my_resource->appendChild($my_file);
  7099. $resources->appendChild($my_resource);
  7100. }
  7101. }
  7102. elseif($item->type == TOOL_QUIZ)
  7103. {
  7104. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  7105. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  7106. $exe = new Exercise();
  7107. $exe->read($exe_id);
  7108. $my_item = $xmldoc->createElement('item');
  7109. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7110. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7111. $my_item->setAttribute('isvisible','true');
  7112. //give a child element <title> to the <item> element
  7113. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7114. $my_item->appendChild($my_title);
  7115. //give a child element <adlcp:prerequisites> to the <item> element
  7116. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7117. $my_prereqs->setAttribute('type','aicc_script');
  7118. $my_item->appendChild($my_prereqs);
  7119. //give a child element <adlcp:masteryscore> to the <item> element
  7120. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  7121. $my_item->appendChild($my_masteryscore);
  7122. //attach this item to the organization element or hits parent if there is one
  7123. if(!empty($item->parent) && $item->parent!=0)
  7124. {
  7125. $children = $organization->childNodes;
  7126. for($i=0;$i<$children->length;$i++){
  7127. $item_temp = $children->item($i);
  7128. if ($item_temp -> nodeName == 'item')
  7129. {
  7130. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7131. {
  7132. $item_temp -> appendChild($my_item);
  7133. }
  7134. }
  7135. }
  7136. }
  7137. else
  7138. {
  7139. $organization->appendChild($my_item);
  7140. }
  7141. //include export scripts
  7142. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  7143. //get the path of the file(s) from the course directory root
  7144. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7145. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7146. //write the contents of the exported exercise into a (big) html file
  7147. //to later pack it into the exported SCORM. The file will be removed afterwards
  7148. $contents = export_exercise($exe_id,true);
  7149. $tmp_file_path = $garbage_path.$temp_dir_short.'/'.$my_file_path;
  7150. $res = file_put_contents($tmp_file_path,$contents);
  7151. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7152. $files_cleanup[] = $tmp_file_path;
  7153. //error_log($tmp_path);die();
  7154. $my_xml_file_path = htmlentities($my_file_path);
  7155. $my_sub_dir = dirname($my_file_path);
  7156. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7157. //give a <resource> child to the <resources> element
  7158. $my_resource = $xmldoc->createElement('resource');
  7159. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7160. $my_resource->setAttribute('type','webcontent');
  7161. $my_resource->setAttribute('href',$my_xml_file_path);
  7162. //adlcp:scormtype can be either 'sco' or 'asset'
  7163. $my_resource->setAttribute('adlcp:scormtype','sco');
  7164. //xml:base is the base directory to find the files declared in this resource
  7165. $my_resource->setAttribute('xml:base','');
  7166. //give a <file> child to the <resource> element
  7167. $my_file = $xmldoc->createElement('file');
  7168. $my_file->setAttribute('href',$my_xml_file_path);
  7169. $my_resource->appendChild($my_file);
  7170. //get included docs
  7171. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7172. //dependency to other files - not yet supported
  7173. $i = 1;
  7174. foreach($inc_docs as $doc_info)
  7175. {
  7176. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7177. $my_dep = $xmldoc->createElement('resource');
  7178. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7179. $my_dep->setAttribute('identifier',$res_id);
  7180. $my_dep->setAttribute('type','webcontent');
  7181. $my_dep->setAttribute('adlcp:scormtype','asset');
  7182. $my_dep_file = $xmldoc->createElement('file');
  7183. //check type of URL
  7184. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7185. if($doc_info[1] == 'remote')
  7186. { //remote file. Save url as is
  7187. $my_dep_file->setAttribute('href',$doc_info[0]);
  7188. $my_dep->setAttribute('xml:base','');
  7189. }elseif($doc_info[1] == 'local'){
  7190. switch($doc_info[2])
  7191. {
  7192. case 'url': //local URL - save path as url for now, don't zip file
  7193. //save file but as local file (retrieve from URL)
  7194. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7195. $current_dir = dirname($abs_path);
  7196. $file_path = realpath($abs_path);
  7197. $my_dep_file->setAttribute('href','document/'.$file_path);
  7198. $my_dep->setAttribute('xml:base','');
  7199. if(strstr($file_path,$main_path) !== false)
  7200. {//the calculated real path is really inside the dokeos root path
  7201. //reduce file path to what's under the DocumentRoot
  7202. $file_path = substr($file_path,strlen($root_path));
  7203. //echo $file_path;echo '<br><br>';
  7204. //error_log('Reduced path: '.$file_path,0);
  7205. $zip_files_abs[] = $file_path;
  7206. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7207. $my_dep_file->setAttribute('href','document/'.$file_path);
  7208. $my_dep->setAttribute('xml:base','');
  7209. }
  7210. else if (empty($file_path))
  7211. {
  7212. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7213. if(strpos($document_root,-1)=='/')
  7214. {
  7215. $document_root = substr(0, -1, $document_root);
  7216. }*/
  7217. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7218. $file_path = str_replace('//','/',$file_path);
  7219. if(file_exists($file_path))
  7220. {
  7221. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7222. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7223. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7224. $my_dep_file->setAttribute('href','document/'.$file_path);
  7225. $my_dep->setAttribute('xml:base','');
  7226. }
  7227. }
  7228. break;
  7229. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7230. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7231. $file_path = realpath($doc_info[0]);
  7232. $my_dep_file->setAttribute('href',$file_path);
  7233. $my_dep->setAttribute('xml:base','');
  7234. if(strstr($file_path,$main_path) !== false)
  7235. {//the calculated real path is really inside the dokeos root path
  7236. //reduce file path to what's under the DocumentRoot
  7237. $file_path = substr($file_path,strlen($root_path));
  7238. //echo $file_path;echo '<br><br>';
  7239. //error_log('Reduced path: '.$file_path,0);
  7240. $zip_files_abs[] = $file_path;
  7241. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7242. $my_dep_file->setAttribute('href','document/'.$file_path);
  7243. $my_dep->setAttribute('xml:base','');
  7244. }
  7245. else if (empty($file_path))
  7246. {
  7247. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7248. if(strpos($document_root,-1)=='/')
  7249. {
  7250. $document_root = substr(0, -1, $document_root);
  7251. }*/
  7252. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7253. $file_path = str_replace('//','/',$file_path);
  7254. if(file_exists($file_path))
  7255. {
  7256. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7257. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7258. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7259. $my_dep_file->setAttribute('href','document/'.$file_path);
  7260. $my_dep->setAttribute('xml:base','');
  7261. }
  7262. }
  7263. break;
  7264. 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
  7265. if(substr($doc_info[0],0,2)=='..')
  7266. { //relative path going up
  7267. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7268. $file_path = realpath($current_dir.$doc_info[0]);
  7269. //error_log($file_path.' <-> '.$main_path,0);
  7270. if(strstr($file_path,$main_path) !== false)
  7271. {//the calculated real path is really inside the dokeos root path
  7272. //reduce file path to what's under the DocumentRoot
  7273. $file_path = substr($file_path,strlen($root_path));
  7274. //error_log('Reduced path: '.$file_path,0);
  7275. $zip_files_abs[] = $file_path;
  7276. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7277. $my_dep_file->setAttribute('href','document/'.$file_path);
  7278. $my_dep->setAttribute('xml:base','');
  7279. }
  7280. }else{
  7281. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7282. $my_dep_file->setAttribute('href',$doc_info[0]);
  7283. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7284. }
  7285. break;
  7286. default:
  7287. $my_dep_file->setAttribute('href',$doc_info[0]);
  7288. $my_dep->setAttribute('xml:base','');
  7289. break;
  7290. }
  7291. }
  7292. $my_dep->appendChild($my_dep_file);
  7293. $resources->appendChild($my_dep);
  7294. $dependency = $xmldoc->createElement('dependency');
  7295. $dependency->setAttribute('identifierref',$res_id);
  7296. $my_resource->appendChild($dependency);
  7297. $i++;
  7298. }
  7299. $resources->appendChild($my_resource);
  7300. $zip_files[] = $my_file_path;
  7301. }
  7302. else
  7303. {
  7304. //get the path of the file(s) from the course directory root
  7305. $my_file_path = 'non_exportable.html';
  7306. $my_xml_file_path = htmlentities($my_file_path);
  7307. $my_sub_dir = dirname($my_file_path);
  7308. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7309. //give a <resource> child to the <resources> element
  7310. $my_resource = $xmldoc->createElement('resource');
  7311. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7312. $my_resource->setAttribute('type','webcontent');
  7313. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7314. //adlcp:scormtype can be either 'sco' or 'asset'
  7315. $my_resource->setAttribute('adlcp:scormtype','asset');
  7316. //xml:base is the base directory to find the files declared in this resource
  7317. $my_resource->setAttribute('xml:base','');
  7318. //give a <file> child to the <resource> element
  7319. $my_file = $xmldoc->createElement('file');
  7320. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7321. $my_resource->appendChild($my_file);
  7322. $resources->appendChild($my_resource);
  7323. }
  7324. }
  7325. }
  7326. $organizations->appendChild($organization);
  7327. $root->appendChild($organizations);
  7328. $root->appendChild($resources);
  7329. $xmldoc->appendChild($root);
  7330. //todo: add a readme file here, with a short description and a link to the Reload player
  7331. //then add the file to the zip, then destroy the file (this is done automatically)
  7332. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7333. //error_log(print_r($zip_files,true),0);
  7334. foreach($zip_files as $file_path)
  7335. {
  7336. if(empty($file_path)){continue;}
  7337. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7338. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  7339. $this->create_path($dest_file);
  7340. //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);
  7341. //echo $main_path.$file_path.'<br>';
  7342. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7343. //check if the file needs a link update
  7344. if(in_array($file_path,array_keys($link_updates))){
  7345. $string = file_get_contents($dest_file);
  7346. unlink($dest_file);
  7347. foreach($link_updates[$file_path] as $old_new)
  7348. {
  7349. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7350. //this is an ugly hack that allows .flv files to be found by the flv player that
  7351. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7352. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7353. // ../../.. to return from inc/lib/flv_player to the document/main path
  7354. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7355. {
  7356. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7357. }
  7358. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7359. {
  7360. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7361. }
  7362. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7363. }
  7364. file_put_contents($dest_file,$string);
  7365. }
  7366. }
  7367. foreach($zip_files_abs as $file_path)
  7368. {
  7369. if(empty($file_path)){continue;}
  7370. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7371. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7372. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7373. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  7374. $this->create_path($dest_file);
  7375. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  7376. //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);
  7377. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7378. copy($main_path.$file_path,$dest_file);
  7379. //check if the file needs a link update
  7380. if(in_array($file_path,array_keys($link_updates)))
  7381. {
  7382. $string = file_get_contents($dest_file);
  7383. unlink($dest_file);
  7384. foreach($link_updates[$file_path] as $old_new)
  7385. {
  7386. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7387. //this is an ugly hack that allows .flv files to be found by the flv player that
  7388. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7389. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7390. // ../../.. to return from inc/lib/flv_player to the document/main path
  7391. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7392. {
  7393. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7394. }
  7395. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7396. }
  7397. file_put_contents($dest_file,$string);
  7398. }
  7399. }
  7400. if(is_array($links_to_create))
  7401. {
  7402. foreach($links_to_create as $file=>$link)
  7403. {
  7404. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7405. file_put_contents($garbage_path.$temp_dir_short.'/'.$file, $file_content);
  7406. }
  7407. }
  7408. // add non exportable message explanation
  7409. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7410. $file_content =
  7411. <<<EOD
  7412. <html>
  7413. <head>
  7414. <style>
  7415. .error-message {
  7416. font-family: arial, verdana, helvetica, sans-serif;
  7417. border-width: 1px;
  7418. border-style: solid;
  7419. left: 50%;
  7420. margin: 10px auto;
  7421. min-height: 30px;
  7422. padding: 5px;
  7423. right: 50%;
  7424. width: 500px;
  7425. background-color: #FFD1D1;
  7426. border-color: #FF0000;
  7427. color: #000;
  7428. }
  7429. </style>
  7430. <body>
  7431. <div class="error-message">
  7432. $lang_not_exportable
  7433. </div>
  7434. </body>
  7435. </html>
  7436. EOD;
  7437. if(!is_dir($garbage_path.$temp_dir_short.'/document'))
  7438. {
  7439. @mkdir($garbage_path.$temp_dir_short.'/document');
  7440. }
  7441. file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7442. //Add the extra files that go along with a SCORM package
  7443. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7444. $extra_files = scandir($main_code_path);
  7445. foreach($extra_files as $extra_file)
  7446. {
  7447. if(strpos($extra_file,'.')===0) continue;
  7448. else
  7449. {
  7450. $dest_file = $garbage_path.$temp_dir_short.'/'.$extra_file;
  7451. $this->create_path($dest_file);
  7452. copy($main_code_path.$extra_file,$dest_file);
  7453. }
  7454. }
  7455. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7456. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7457. $zip_folder->add($garbage_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/'.$temp_dir_short.'/');
  7458. //clean possible temporary files
  7459. foreach($files_cleanup as $file)
  7460. {
  7461. $res = unlink($file);
  7462. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7463. }
  7464. //Send file to client
  7465. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7466. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7467. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7468. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7469. }
  7470. /**
  7471. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7472. * if it doesn't exist
  7473. */
  7474. function create_path($path){
  7475. $path_bits = split('/',dirname($path));
  7476. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7477. $path_built = IS_WINDOWS_OS ? '' : '/';
  7478. foreach($path_bits as $bit){
  7479. if(!empty($bit)){
  7480. $new_path = $path_built.$bit;
  7481. if(is_dir($new_path)){
  7482. $path_built = $new_path.'/';
  7483. }
  7484. else
  7485. {
  7486. mkdir($new_path);
  7487. $path_built = $new_path.'/';
  7488. }
  7489. }
  7490. }
  7491. }
  7492. /**
  7493. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7494. * @return boolean The results of the unlink function, or false if there was no image to start with
  7495. */
  7496. function delete_lp_image()
  7497. {
  7498. $img = $this->get_preview_image();
  7499. if ($img!='')
  7500. {
  7501. $del_file = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$img;
  7502. $this->set_preview_image('');
  7503. return @unlink($del_file);
  7504. }
  7505. else
  7506. {
  7507. return false;
  7508. }
  7509. }
  7510. /**
  7511. * Uploads an author image to the upload/learning_path/images directory
  7512. * @param array The image array, coming from the $_FILES superglobal
  7513. * @return boolean True on success, false on error
  7514. */
  7515. function upload_image($image_array)
  7516. {
  7517. $image_moved=false;
  7518. if(!empty($image_array['name']))
  7519. {
  7520. $upload_ok = process_uploaded_file($image_array);
  7521. $has_attachment=true;
  7522. }
  7523. else
  7524. {
  7525. $image_moved=true;
  7526. }
  7527. if($upload_ok)
  7528. {
  7529. if ($has_attachment)
  7530. {
  7531. $courseDir = api_get_course_path().'/upload/learning_path/images';
  7532. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7533. $updir = $sys_course_path.$courseDir;
  7534. // Try to add an extension to the file if it hasn't one
  7535. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7536. if (!filter_extension($new_file_name))
  7537. {
  7538. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7539. $image_moved=false;
  7540. }
  7541. else
  7542. {
  7543. $file_extension = explode('.', $image_array['name']);
  7544. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7545. $new_file_name = uniqid('').'.'.$file_extension;
  7546. $new_path=$updir.'/'.$new_file_name;
  7547. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7548. // resize the image
  7549. include_once (api_get_path(LIBRARY_PATH).'image.lib.php');
  7550. $temp = new image($image_array['tmp_name']);
  7551. $picture_infos=getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7552. if ($picture_infos[0]>240)
  7553. $thumbwidth=240;
  7554. else
  7555. $thumbwidth=$picture_infos[0];
  7556. if ($picture_infos[1]>100)
  7557. $new_height=100;
  7558. else
  7559. $new_height = $picture_infos[1];
  7560. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7561. $temp->resize($thumbwidth,$new_height,0);
  7562. $type=$picture_infos[2];
  7563. $result=false;
  7564. switch ($type)
  7565. {
  7566. case 2 :
  7567. $result=$temp->send_image('JPG',$new_path);
  7568. break;
  7569. case 3 :
  7570. $result=$temp->send_image('PNG',$new_path);
  7571. break;
  7572. case 1 :
  7573. $result=$temp->send_image('GIF',$new_path);
  7574. break;
  7575. }
  7576. // Storing the image filename
  7577. if ($result)
  7578. {
  7579. $image_moved=true;
  7580. $this->set_preview_image($new_file_name);
  7581. return true;
  7582. }
  7583. }
  7584. }
  7585. }
  7586. return false;
  7587. }
  7588. }
  7589. if (!function_exists('trim_value')) {
  7590. function trim_value(&$value) {
  7591. $value = trim($value);
  7592. }
  7593. }