learnpath.class.php 333 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  5. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  6. * @package dokeos.learnpath
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. * @license GNU/GPL - See Dokeos license directory for details
  9. */
  10. /**
  11. * Defines the learnpath parent class
  12. * @package dokeos.learnpath
  13. */
  14. // including the global file
  15. require_once '../inc/global.inc.php';
  16. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  17. if (api_get_setting('show_glossary_in_documents') == 'ismanual' || api_get_setting('show_glossary_in_documents') == 'isautomatic' ) {
  18. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js" type="text/javascript" language="javascript"></script>';
  19. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>';
  20. }
  21. $htmlHeadXtra[] = '<script type="text/javascript">
  22. function setFocus(){
  23. $("#idTitle").focus();
  24. }
  25. $(window).load(function () {
  26. setFocus();
  27. });
  28. </script>';
  29. class learnpath {
  30. var $attempt = 0; //the number for the current ID view
  31. var $cc; //course (code) this learnpath is located in
  32. var $current; //id of the current item the user is viewing
  33. var $current_score; //the score of the current item
  34. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  35. var $current_time_stop; //the time the user closed this resource
  36. var $default_status = 'not attempted';
  37. var $encoding = 'UTF-8';
  38. var $error = '';
  39. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  40. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  41. var $index; //the index of the active learnpath_item in $ordered_items array
  42. var $items = array();
  43. var $last; //item_id of last item viewed in the learning path
  44. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  45. var $license; //which license this course has been given - not used yet on 20060522
  46. var $lp_id; //DB ID for this learnpath
  47. var $lp_view_id; //DB ID for lp_view
  48. var $log_file; //file where to log learnpath API msg
  49. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  50. var $message = '';
  51. var $mode = 'embedded'; //holds the video display mode (fullscreen or embedded)
  52. var $name; //learnpath name (they generally have one)
  53. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  54. var $path = ''; //path inside the scorm directory (if scorm)
  55. var $theme; // the current theme of the learning path
  56. var $preview_image; // the current image of the learning path
  57. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  58. var $prevent_reinit = 1;
  59. // Describes the mode of progress bar display
  60. var $progress_bar_mode = '%';
  61. // Percentage progress as saved in the db
  62. var $progress_db = '0';
  63. var $proximity; //wether the content is distant or local or unknown
  64. var $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  65. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  66. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  67. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  68. //TODO check if this type variable is useful here (instead of just in the controller script)
  69. var $user_id; //ID of the user that is viewing/using the course
  70. var $update_queue = array();
  71. var $scorm_debug = 0;
  72. var $arrMenu = array(); //array for the menu items
  73. var $debug = 0; //logging level
  74. var $lp_session_id =0;
  75. /**
  76. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  77. * Also builds the list of items into $this->items.
  78. * @param string Course code
  79. * @param integer Learnpath ID
  80. * @param integer User ID
  81. * @return boolean True on success, false on error
  82. */
  83. function learnpath($course, $lp_id, $user_id) {
  84. //check params
  85. //check course code
  86. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  87. if(empty($course)){
  88. $this->error = 'Course code is empty';
  89. return false;
  90. }
  91. else
  92. {
  93. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  94. //$course = Database::escape_string($course);
  95. $course = $this->escape_string($course);
  96. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  97. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  98. //$res = Database::query($sql);
  99. $res = Database::query($sql, __FILE__, __LINE__);
  100. if(Database::num_rows($res)>0)
  101. {
  102. $this->cc = $course;
  103. }
  104. else
  105. {
  106. $this->error = 'Course code does not exist in database ('.$sql.')';
  107. return false;
  108. }
  109. }
  110. //check learnpath ID
  111. if(empty($lp_id))
  112. {
  113. $this->error = 'Learnpath ID is empty';
  114. return false;
  115. }
  116. else
  117. {
  118. //TODO make it flexible to use any course_code (still using env course code here)
  119. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  120. //$id = Database::escape_integer($id);
  121. $lp_id = $this->escape_string($lp_id);
  122. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  123. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  124. //$res = Database::query($sql);
  125. $res = Database::query($sql, __FILE__, __LINE__);
  126. if(Database::num_rows($res)>0)
  127. {
  128. $this->lp_id = $lp_id;
  129. $row = Database::fetch_array($res);
  130. $this->type = $row['lp_type'];
  131. $this->name = stripslashes($row['name']);
  132. $this->encoding = $row['default_encoding'];
  133. $this->proximity = $row['content_local'];
  134. $this->theme = $row['theme'];
  135. $this->maker = $row['content_maker'];
  136. $this->prevent_reinit = $row['prevent_reinit'];
  137. $this->license = $row['content_license'];
  138. $this->scorm_debug = $row['debug'];
  139. $this->js_lib = $row['js_lib'];
  140. $this->path = $row['path'];
  141. $this->preview_image= $row['preview_image'];
  142. $this->author= $row['author'];
  143. $this->lp_session_id = $row['session_id'];
  144. if($this->type == 2){
  145. if($row['force_commit'] == 1){
  146. $this->force_commit = true;
  147. }
  148. }
  149. $this->mode = $row['default_view_mod'];
  150. }
  151. else
  152. {
  153. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  154. return false;
  155. }
  156. }
  157. //check user ID
  158. if(empty($user_id)){
  159. $this->error = 'User ID is empty';
  160. return false;
  161. }
  162. else
  163. {
  164. //$main_table = Database::get_main_user_table();
  165. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  166. //$user_id = Database::escape_integer($user_id);
  167. $user_id = $this->escape_string($user_id);
  168. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  169. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  170. //$res = Database::query($sql);
  171. $res = Database::query($sql, __FILE__, __LINE__);
  172. if(Database::num_rows($res)>0)
  173. {
  174. $this->user_id = $user_id;
  175. }
  176. else
  177. {
  178. $this->error = 'User ID does not exist in database ('.$sql.')';
  179. return false;
  180. }
  181. }
  182. //end of variables checking
  183. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  184. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  185. //selecting by view_count descending allows to get the highest view_count first
  186. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  187. if ($this->debug > 2) {
  188. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);
  189. }
  190. //$res = Database::query($sql);
  191. $res = Database::query($sql, __FILE__, __LINE__);
  192. $view_id = 0; //used later to query lp_item_view
  193. if (Database :: num_rows($res) > 0) {
  194. if ($this->debug > 2) {
  195. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Found previous view', 0);
  196. }
  197. $row = Database :: fetch_array($res);
  198. $this->attempt = $row['view_count'];
  199. $this->lp_view_id = $row['id'];
  200. $this->last_item_seen = $row['last_item'];
  201. $this->progress_db = $row['progress'];
  202. } else {
  203. if ($this->debug > 2) {
  204. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - NOT Found previous view', 0);
  205. }
  206. $this->attempt = 1;
  207. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  208. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  209. $this->lp_view_id = Database :: insert_id();
  210. if ($this->debug > 2) {
  211. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  212. }
  213. }
  214. //initialise items
  215. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  216. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  217. $res = Database::query($sql, __FILE__, __LINE__);
  218. while($row = Database::fetch_array($res))
  219. {
  220. $oItem = '';
  221. //$this->ordered_items[] = $row['id'];
  222. switch ($this->type) {
  223. case 3 : //aicc
  224. $oItem = new aiccItem('db', $row['id']);
  225. if (is_object($oItem)) {
  226. $my_item_id = $oItem->get_id();
  227. $oItem->set_lp_view($this->lp_view_id);
  228. $oItem->set_prevent_reinit($this->prevent_reinit);
  229. // Don't use reference here as the next loop will make the pointed object change
  230. $this->items[$my_item_id] = $oItem;
  231. $this->refs_list[$oItem->ref] = $my_item_id;
  232. if ($this->debug > 2) {
  233. error_log('New LP - learnpath::learnpath() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  234. }
  235. }
  236. break;
  237. case 2 :
  238. require_once ('scorm.class.php');
  239. require_once ('scormItem.class.php');
  240. $oItem = new scormItem('db', $row['id']);
  241. if (is_object($oItem)) {
  242. $my_item_id = $oItem->get_id();
  243. $oItem->set_lp_view($this->lp_view_id);
  244. $oItem->set_prevent_reinit($this->prevent_reinit);
  245. // Don't use reference here as the next loop will make the pointed object change
  246. $this->items[$my_item_id] = $oItem;
  247. $this->refs_list[$oItem->ref] = $my_item_id;
  248. if ($this->debug > 2) {
  249. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  250. }
  251. }
  252. break;
  253. case 1 :
  254. default :
  255. require_once ('learnpathItem.class.php');
  256. $oItem = new learnpathItem($row['id'], $user_id);
  257. if (is_object($oItem)) {
  258. $my_item_id = $oItem->get_id();
  259. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  260. $oItem->set_prevent_reinit($this->prevent_reinit);
  261. // Don't use reference here as the next loop will make the pointed object change
  262. $this->items[$my_item_id] = $oItem;
  263. $this->refs_list[$my_item_id] = $my_item_id;
  264. if ($this->debug > 2) {
  265. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  266. }
  267. }
  268. break;
  269. }
  270. //items is a list of pointers to all items, classified by DB ID, not SCO id
  271. if ($row['parent_item_id'] == 0 OR empty ($this->items[$row['parent_item_id']])) {
  272. $this->items[$row['id']]->set_level(0);
  273. } else {
  274. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  275. $this->items[$row['id']]->set_level($level);
  276. if (is_object($this->items[$row['parent_item_id']])) {
  277. //items is a list of pointers from item DB ids to item objects
  278. $this->items[$row['parent_item_id']]->add_child($row['id']);
  279. } else {
  280. if ($this->debug > 2) {
  281. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  282. }
  283. }
  284. }
  285. //get last viewing vars
  286. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  287. //this query should only return one or zero result
  288. $sql = "SELECT * " .
  289. "FROM $lp_item_view_table " .
  290. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  291. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  292. if ($this->debug > 2) {
  293. error_log('New LP - learnpath::learnpath() - Selecting item_views: ' . $sql, 0);
  294. }
  295. //get the item status
  296. $res2 = Database::query($sql, __FILE__, __LINE__);
  297. if (Database :: num_rows($res2) > 0) {
  298. //if this learnpath has already been used by this user, get his last attempt count and
  299. //the last item seen back into this object
  300. //$max = 0;
  301. $row2 = Database :: fetch_array($res2);
  302. if ($this->debug > 2) {
  303. error_log('New LP - learnpath::learnpath() - Got item_view: ' . print_r($row2, true), 0);
  304. }
  305. $this->items[$row['id']]->set_status($row2['status']);
  306. if (empty ($row2['status'])) {
  307. $this->items[$row['id']]->set_status($this->default_status);
  308. }
  309. //$this->attempt = $row['view_count'];
  310. //$this->last_item = $row['id'];
  311. } else //no item found in lp_item_view for this view
  312. {
  313. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  314. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  315. //$this->attempt = 1;
  316. //$this->last_item = 0;
  317. $this->items[$row['id']]->set_status($this->default_status);
  318. //Add that row to the lp_item_view table so that we have something to show in the stats page
  319. $sql_ins = "INSERT INTO $lp_item_view_table " .
  320. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  321. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  322. if ($this->debug > 2) {
  323. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  324. }
  325. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  326. }
  327. //setting the view in the item object
  328. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  329. }
  330. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0);
  331. $this->max_ordered_items = 0;
  332. foreach ($this->ordered_items as $index => $dummy) {
  333. if ($index > $this->max_ordered_items AND !empty ($dummy)) {
  334. $this->max_ordered_items = $index;
  335. }
  336. }
  337. //TODO define the current item better
  338. $this->first();
  339. if ($this->debug > 2) {
  340. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  341. }
  342. }
  343. /**
  344. * 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
  345. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  346. *
  347. * @param int $parent
  348. * @param int $previous
  349. * @param string $type
  350. * @param int $id
  351. * @param string $title
  352. * @param string $description
  353. * @return int
  354. */
  355. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  356. if ($this->debug > 0) {
  357. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  358. }
  359. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  360. $parent = intval($parent);
  361. $previous = intval($previous);
  362. $type = $this->escape_string($type);
  363. $id = intval($id);
  364. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  365. if (empty ($max_time_allowed)) {
  366. $max_time_allowed = 0;
  367. }
  368. //$title = htmlspecialchars($title, ENT_QUOTES, $charset); // TODO: To be checked for encoding problems.
  369. //$title = $this->escape_string(api_convert_encoding($title, $this->encoding, $charset));
  370. $title = $this->escape_string(api_convert_encoding($title, $this->encoding, api_get_system_encoding()));
  371. $description = $this->escape_string(api_convert_encoding($description, $this->encoding, api_get_system_encoding()));
  372. $sql_count = " SELECT COUNT(id) AS num
  373. FROM " . $tbl_lp_item . "
  374. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  375. $res_count = Database::query($sql_count, __FILE__, __LINE__);
  376. $row = Database :: fetch_array($res_count);
  377. $num = $row['num'];
  378. if ($num > 0) {
  379. if ($previous == 0) {
  380. $sql = "SELECT id, next_item_id, display_order
  381. FROM " . $tbl_lp_item . "
  382. WHERE
  383. lp_id = " . $this->get_id() . " AND
  384. parent_item_id = " . $parent . " AND
  385. previous_item_id = 0 OR previous_item_id=" . $parent;
  386. $result = Database::query($sql, __FILE__, __LINE__);
  387. $row = Database :: fetch_array($result);
  388. $tmp_previous = 0;
  389. $next = $row['id'];
  390. $display_order = 0;
  391. } else {
  392. $previous = (int) $previous;
  393. $sql = "
  394. SELECT
  395. id,
  396. previous_item_id,
  397. next_item_id,
  398. display_order
  399. FROM " . $tbl_lp_item . "
  400. WHERE
  401. lp_id = " . $this->get_id() . " AND
  402. id = " . $previous;
  403. $result = Database::query($sql, __FILE__, __LINE__);
  404. $row = Database :: fetch_array($result);
  405. $tmp_previous = $row['id'];
  406. $next = $row['next_item_id'];
  407. $display_order = $row['display_order'];
  408. }
  409. } else {
  410. $tmp_previous = 0;
  411. $next = 0;
  412. $display_order = 0;
  413. }
  414. $new_item_id = -1;
  415. $id = $this->escape_string($id);
  416. if ($type == 'quiz') {
  417. $sql = 'SELECT SUM(ponderation)
  418. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  419. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  420. ON quiz_question.id = quiz_rel_question.question_id
  421. AND quiz_rel_question.exercice_id = ' . $id;
  422. $rsQuiz = Database::query($sql, __FILE__, __LINE__);
  423. $max_score = Database :: result($rsQuiz, 0, 0);
  424. } else {
  425. $max_score = 100;
  426. }
  427. if ($prerequisites != 0) {
  428. $sql_ins = "
  429. INSERT INTO " . $tbl_lp_item . " (
  430. lp_id,
  431. item_type,
  432. ref,
  433. title,
  434. description,
  435. path,
  436. max_score,
  437. parent_item_id,
  438. previous_item_id,
  439. next_item_id,
  440. display_order,
  441. prerequisite,
  442. max_time_allowed
  443. ) VALUES (
  444. " . $this->get_id() . ",
  445. '" . $type . "',
  446. '',
  447. '" . $title . "',
  448. '" . $description . "',
  449. '" . $id . "',
  450. '" . $max_score . "',
  451. " . $parent . ",
  452. " . $previous . ",
  453. " . $next . ",
  454. " . ($display_order +1) . ",
  455. " . $prerequisites . ",
  456. " . $max_time_allowed . "
  457. )";
  458. } else {
  459. //insert new item
  460. $sql_ins = "
  461. INSERT INTO " . $tbl_lp_item . " (
  462. lp_id,
  463. item_type,
  464. ref,
  465. title,
  466. description,
  467. path,
  468. max_score,
  469. parent_item_id,
  470. previous_item_id,
  471. next_item_id,
  472. display_order,
  473. max_time_allowed
  474. ) VALUES (
  475. " . $this->get_id() . ",
  476. '" . $type . "',
  477. '',
  478. '" . $title . "',
  479. '" . $description . "',
  480. '" . $id . "',
  481. '" . $max_score . "',
  482. " . $parent . ",
  483. " . $previous . ",
  484. " . $next . ",
  485. " . ($display_order +1) . ",
  486. " . $max_time_allowed . "
  487. )";
  488. }
  489. if ($this->debug > 2) {
  490. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  491. }
  492. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  493. if ($res_ins > 0) {
  494. $new_item_id = Database :: insert_id($res_ins);
  495. //update the item that should come after the new item
  496. $sql_update_next = "
  497. UPDATE " . $tbl_lp_item . "
  498. SET previous_item_id = " . $new_item_id . "
  499. WHERE id = " . $next;
  500. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  501. //update the item that should be before the new item
  502. $sql_update_previous = "
  503. UPDATE " . $tbl_lp_item . "
  504. SET next_item_id = " . $new_item_id . "
  505. WHERE id = " . $tmp_previous;
  506. $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
  507. //update all the items after the new item
  508. $sql_update_order = "
  509. UPDATE " . $tbl_lp_item . "
  510. SET display_order = display_order + 1
  511. WHERE
  512. lp_id = " . $this->get_id() . " AND
  513. id <> " . $new_item_id . " AND
  514. parent_item_id = " . $parent . " AND
  515. display_order > " . $display_order;
  516. $res_update_previous = Database::query($sql_update_order, __FILE__, __LINE__);
  517. //update the item that should come after the new item
  518. $sql_update_ref = "
  519. UPDATE " . $tbl_lp_item . "
  520. SET ref = " . $new_item_id . "
  521. WHERE id = " . $new_item_id;
  522. Database::query($sql_update_ref, __FILE__, __LINE__);
  523. }
  524. // upload audio
  525. if (!empty ($_FILES['mp3']['name'])) {
  526. // create the audio folder if it does not exist yet
  527. global $_course;
  528. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  529. if (!is_dir($filepath . 'audio')) {
  530. $perm = api_get_setting('permissions_for_new_directories');
  531. $perm = octdec(!empty ($perm) ? $perm : '0770');
  532. mkdir($filepath . 'audio', $perm);
  533. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  534. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  535. }
  536. // upload the file in the documents tool
  537. include_once (api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  538. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  539. // getting the filename only
  540. $file_components = explode('/', $file_path);
  541. $file = $file_components[count($file_components) - 1];
  542. // store the mp3 file in the lp_item table
  543. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  544. Database::query($sql_insert_audio, __FILE__, __LINE__);
  545. }
  546. return $new_item_id;
  547. }
  548. /**
  549. * Static admin function allowing addition of a learnpath to a course.
  550. * @param string Course code
  551. * @param string Learnpath name
  552. * @param string Learnpath description string, if provided
  553. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  554. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  555. * @param string Zip file containing the learnpath or directory containing the learnpath
  556. * @return integer The new learnpath ID on success, 0 on failure
  557. */
  558. function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '') {
  559. global $charset;
  560. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  561. //TODO
  562. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  563. //check course code exists
  564. //check lp_name doesn't exist, otherwise append something
  565. $i = 0;
  566. $name = learnpath :: escape_string($name);
  567. //session_id
  568. $session_id = api_get_session_id();
  569. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  570. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  571. $res_name = Database::query($check_name, __FILE__, __LINE__);
  572. while (Database :: num_rows($res_name)) {
  573. //there is already one such name, update the current one a bit
  574. $i++;
  575. $name = $name . ' - ' . $i;
  576. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  577. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  578. $res_name = Database::query($check_name, __FILE__, __LINE__);
  579. }
  580. //new name does not exist yet; keep it
  581. //escape description
  582. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); //Kevin: added htmlentities()
  583. $type = 1;
  584. switch ($learnpath) {
  585. case 'guess' :
  586. break;
  587. case 'dokeos' :
  588. $type = 1;
  589. break;
  590. case 'aicc' :
  591. break;
  592. }
  593. switch ($origin) {
  594. case 'zip' :
  595. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  596. break;
  597. case 'manual' :
  598. default :
  599. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  600. $res_max = Database::query($get_max, __FILE__, __LINE__);
  601. if (Database :: num_rows($res_max) < 1) {
  602. $dsp = 1;
  603. } else {
  604. $row = Database :: fetch_array($res_max);
  605. $dsp = $row[0] + 1;
  606. }
  607. $sql_insert = "INSERT INTO $tbl_lp " .
  608. "(lp_type,name,description,path,default_view_mod," .
  609. "default_encoding,display_order,content_maker," .
  610. "content_local,js_lib,session_id) " .
  611. "VALUES ($type,'$name','$description','','embedded'," .
  612. "'UTF-8','$dsp','Dokeos'," .
  613. "'local','','".Database::escape_string($session_id)."')";
  614. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  615. $res_insert = Database::query($sql_insert, __FILE__, __LINE__);
  616. $id = Database :: insert_id();
  617. if ($id > 0) {
  618. //insert into item_property
  619. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  620. return $id;
  621. }
  622. break;
  623. }
  624. }
  625. /**
  626. * Appends a message to the message attribute
  627. * @param string Message to append.
  628. */
  629. function append_message($string) {
  630. if ($this->debug > 0) {
  631. error_log('New LP - In learnpath::append_message()', 0);
  632. }
  633. $this->message .= $string;
  634. }
  635. /**
  636. * Autocompletes the parents of an item in case it's been completed or passed
  637. * @param integer Optional ID of the item from which to look for parents
  638. */
  639. function autocomplete_parents($item) {
  640. if ($this->debug > 0) {
  641. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  642. }
  643. if (empty ($item)) {
  644. $item = $this->current;
  645. }
  646. $parent_id = $this->items[$item]->get_parent();
  647. if ($this->debug > 2) {
  648. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  649. }
  650. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  651. //if $item points to an object and there is a parent
  652. if ($this->debug > 2) {
  653. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  654. }
  655. $current_item = & $this->items[$item];
  656. $parent = & $this->items[$parent_id]; //get the parent
  657. //new experiment including failed and browsed in completed status
  658. $current_status = $current_item->get_status();
  659. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  660. //if the current item is completed or passes or succeeded
  661. $completed = true;
  662. if ($this->debug > 2) {
  663. error_log('New LP - Status of current item is alright', 0);
  664. }
  665. foreach ($parent->get_children() as $child) {
  666. //check all his brothers (his parent's children) for completion status
  667. if ($child != $item) {
  668. if ($this->debug > 2) {
  669. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  670. }
  671. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  672. //Trying completing parents of failed and browsed items as well
  673. if ($this->items[$child]->status_is(array (
  674. 'completed',
  675. 'passed',
  676. 'succeeded',
  677. 'browsed',
  678. 'failed'
  679. ))) {
  680. //keep completion status to true
  681. } else {
  682. if ($this->debug > 2) {
  683. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  684. }
  685. $completed = false;
  686. }
  687. }
  688. }
  689. if ($completed == true) { //if all the children were completed
  690. $parent->set_status('completed');
  691. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  692. $this->update_queue[$parent->get_id()] = $parent->get_status();
  693. if ($this->debug > 2) {
  694. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  695. }
  696. $this->autocomplete_parents($parent->get_id()); //recursive call
  697. }
  698. } else {
  699. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  700. }
  701. }
  702. }
  703. /**
  704. * Autosaves the current results into the database for the whole learnpath
  705. */
  706. function autosave() {
  707. if ($this->debug > 0) {
  708. error_log('New LP - In learnpath::autosave()', 0);
  709. }
  710. //TODO add aditionnal save operations for the learnpath itself
  711. }
  712. /**
  713. * Clears the message attribute
  714. */
  715. function clear_message() {
  716. if ($this->debug > 0) {
  717. error_log('New LP - In learnpath::clear_message()', 0);
  718. }
  719. $this->message = '';
  720. }
  721. /**
  722. * Closes the current resource
  723. *
  724. * Stops the timer
  725. * Saves into the database if required
  726. * Clears the current resource data from this object
  727. * @return boolean True on success, false on failure
  728. */
  729. function close() {
  730. if ($this->debug > 0) {
  731. error_log('New LP - In learnpath::close()', 0);
  732. }
  733. if (empty ($this->lp_id)) {
  734. $this->error = 'Trying to close this learnpath but no ID is set';
  735. return false;
  736. }
  737. $this->current_time_stop = time();
  738. if ($this->save) {
  739. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  740. /*
  741. $sql = "UPDATE $learnpath_view_table " .
  742. "SET " .
  743. "stop_time = ".$this->current_time_stop.", " .
  744. "score = ".$this->current_score.", ".
  745. "WHERE learnpath_id = '".$this->lp_id."'";
  746. //$res = Database::query($sql);
  747. $res = Database::query($res);
  748. if(Database::affected_rows($res)<1)
  749. {
  750. $this->error = 'Could not update learnpath_view table while closing learnpath';
  751. return false;
  752. }
  753. */
  754. }
  755. $this->ordered_items = array ();
  756. $this->index = 0;
  757. unset ($this->lp_id);
  758. //unset other stuff
  759. return true;
  760. }
  761. /**
  762. * Static admin function allowing removal of a learnpath
  763. * @param string Course code
  764. * @param integer Learnpath ID
  765. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  766. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  767. */
  768. function delete($course = null, $id = null, $delete = 'keep') {
  769. //TODO implement a way of getting this to work when the current object is not set
  770. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  771. //if(empty($course)){$course = api_get_course_id();}
  772. //if(empty($id)){$id = $this->get_id();}
  773. //If an ID is specifically given and the current LP is not the same,
  774. //prevent delete
  775. if (!empty ($id) && ($id != $this->lp_id)) {
  776. return false;
  777. }
  778. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  779. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  780. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  781. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  782. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  783. //delete lp item id
  784. foreach ($this->items as $id => $dummy) {
  785. //$this->items[$id]->delete();
  786. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  787. $res_del_item_view = Database::query($sql_del_view, __FILE__, __LINE__);
  788. }
  789. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  790. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  791. $res_del_item = Database::query($sql_del_item, __FILE__, __LINE__);
  792. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  793. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  794. $res_del_view = Database::query($sql_del_view, __FILE__, __LINE__);
  795. $this->toggle_publish($this->lp_id, 'i');
  796. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  797. if ($this->type == 2 OR $this->type == 3) {
  798. //this is a scorm learning path, delete the files as well
  799. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  800. $res = Database::query($sql, __FILE__, __LINE__);
  801. if (Database :: num_rows($res) > 0) {
  802. $row = Database :: fetch_array($res);
  803. $path = $row['path'];
  804. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  805. $res = Database::query($sql, __FILE__, __LINE__);
  806. if (Database :: num_rows($res) > 0) { //another learning path uses this directory, so don't delete it
  807. if ($this->debug > 2) {
  808. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  809. }
  810. } else {
  811. //no other LP uses that directory, delete it
  812. $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses
  813. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course
  814. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  815. if ($this->debug > 2) {
  816. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  817. }
  818. // Proposed by Christophe (clefevre).
  819. if (strcmp(substr($path, -2), "/.") == 0) {
  820. $path = substr($path, 0, -1); // Remove "." at the end
  821. }
  822. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  823. rmdirr($course_scorm_dir . $path);
  824. }
  825. }
  826. }
  827. }
  828. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  829. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  830. $res_del_lp = Database::query($sql_del_lp, __FILE__, __LINE__);
  831. $this->update_display_order(); //updates the display order of all lps
  832. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  833. require_once '../gradebook/lib/be.inc.php';
  834. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  835. //delete link of gradebook tool
  836. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  837. $result = Database::query($sql, __FILE__, __LINE__);
  838. $row = Database :: fetch_array($result, 'ASSOC');
  839. //fixing gradebook link deleted see #5229
  840. if (!empty($row['id'])) {
  841. $link = LinkFactory :: load($row['id']);
  842. if ($link[0] != null) {
  843. $link[0]->delete();
  844. }
  845. }
  846. //TODO: also delete items and item-views
  847. if (api_get_setting('search_enabled') == 'true') {
  848. require_once (api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  849. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  850. }
  851. }
  852. /**
  853. * Removes all the children of one item - dangerous!
  854. * @param integer Element ID of which children have to be removed
  855. * @return integer Total number of children removed
  856. */
  857. function delete_children_items($id) {
  858. if ($this->debug > 0) {
  859. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  860. }
  861. $num = 0;
  862. if (empty ($id) || $id != strval(intval($id))) {
  863. return false;
  864. }
  865. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  866. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  867. $res = Database::query($sql, __FILE__, __LINE__);
  868. while ($row = Database :: fetch_array($res)) {
  869. $num += $this->delete_children_items($row['id']);
  870. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  871. $res_del = Database::query($sql_del, __FILE__, __LINE__);
  872. $num++;
  873. }
  874. return $num;
  875. }
  876. /**
  877. * Removes an item from the current learnpath
  878. * @param integer Elem ID (0 if first)
  879. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  880. * @return integer Number of elements moved
  881. * @todo implement resource removal
  882. */
  883. function delete_item($id, $remove = 'keep') {
  884. if ($this->debug > 0) {
  885. error_log('New LP - In learnpath::delete_item()', 0);
  886. }
  887. //TODO - implement the resource removal
  888. if (empty ($id) || $id != strval(intval($id))) {
  889. return false;
  890. }
  891. //first select item to get previous, next, and display order
  892. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  893. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  894. $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
  895. if (Database :: num_rows($res_sel) < 1) {
  896. return false;
  897. }
  898. $row = Database :: fetch_array($res_sel);
  899. $previous = $row['previous_item_id'];
  900. $next = $row['next_item_id'];
  901. $display = $row['display_order'];
  902. $parent = $row['parent_item_id'];
  903. $lp = $row['lp_id'];
  904. //delete children items
  905. $num = $this->delete_children_items($id);
  906. if ($this->debug > 2) {
  907. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  908. }
  909. //now delete the item
  910. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  911. if ($this->debug > 2) {
  912. error_log('New LP - Deleting item: ' . $sql_del, 0);
  913. }
  914. $res_del = Database::query($sql_del, __FILE__, __LINE__);
  915. //now update surrounding items
  916. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  917. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  918. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  919. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  920. //now update all following items with new display order
  921. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  922. $res_all = Database::query($sql_all, __FILE__, __LINE__);
  923. // remove from search engine if enabled
  924. if (api_get_setting('search_enabled') == 'true') {
  925. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  926. $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';
  927. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  928. $res = Database::query($sql, __FILE__, __LINE__);
  929. if (Database :: num_rows($res) > 0) {
  930. $row2 = Database :: fetch_array($res);
  931. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  932. $di = new DokeosIndexer();
  933. $di->remove_document((int) $row2['search_did']);
  934. }
  935. $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';
  936. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  937. Database::query($sql, __FILE__, __LINE__);
  938. }
  939. }
  940. /**
  941. * Updates an item's content in place
  942. * @param integer Element ID
  943. * @param integer Parent item ID
  944. * @param integer Previous item ID
  945. * @param string Item title
  946. * @param string Item description
  947. * @param string Prerequisites (optional)
  948. * @param string Indexing terms (optional)
  949. * @param array The array resulting of the $_FILES[mp3] element
  950. * @return boolean True on success, false on error
  951. */
  952. function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = NULL, $max_time_allowed = 0) {
  953. global $charset;
  954. if ($this->debug > 0) {
  955. error_log('New LP - In learnpath::edit_item()', 0);
  956. }
  957. if (empty ($max_time_allowed)) {
  958. $max_time_allowed = 0;
  959. }
  960. if (empty ($id) or ($id != strval(intval($id))) or empty ($title)) {
  961. return false;
  962. }
  963. $title = api_convert_encoding($title, $this->encoding, $charset);
  964. $description = api_convert_encoding($description, $this->encoding, $charset);
  965. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  966. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  967. $res_select = Database::query($sql_select, __FILE__, __LINE__);
  968. $row_select = Database :: fetch_array($res_select);
  969. $audio_update_sql = '';
  970. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  971. // create the audio folder if it does not exist yet
  972. global $_course;
  973. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  974. if (!is_dir($filepath . 'audio')) {
  975. $perm = api_get_setting('permissions_for_new_directories');
  976. $perm = octdec(!empty ($perm) ? $perm : '0770');
  977. mkdir($filepath . 'audio', $perm);
  978. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  979. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  980. }
  981. //upload file in documents
  982. $pi = pathinfo($audio['name']);
  983. if ($pi['extension'] == 'mp3') {
  984. $c_det = api_get_course_info($this->cc);
  985. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  986. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  987. $path = substr($path, 7);
  988. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  989. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  990. }
  991. }
  992. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  993. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  994. //TODO: htmlspecialchars to be checked for encoding related problems.
  995. if ($same_parent && $same_previous) {
  996. //only update title and description
  997. $sql_update = " UPDATE " . $tbl_lp_item . "
  998. SET title = '" . $this->escape_string($title) . "',
  999. prerequisite = '" . $prerequisites . "',
  1000. description = '" . $this->escape_string($description) . "'
  1001. " . $audio_update_sql . ",
  1002. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  1003. WHERE id = " . $id;
  1004. $res_update = Database::query($sql_update, __FILE__, __LINE__);
  1005. } else {
  1006. $old_parent = $row_select['parent_item_id'];
  1007. $old_previous = $row_select['previous_item_id'];
  1008. $old_next = $row_select['next_item_id'];
  1009. $old_order = $row_select['display_order'];
  1010. $old_prerequisite = $row_select['prerequisite'];
  1011. $old_max_time_allowed = $row_select['max_time_allowed'];
  1012. /* BEGIN -- virtually remove the current item id */
  1013. /* for the next and previous item it is like the current item doesn't exist anymore */
  1014. if ($old_previous != 0) {
  1015. $sql_update_next = "
  1016. UPDATE " . $tbl_lp_item . "
  1017. SET next_item_id = " . $old_next . "
  1018. WHERE id = " . $old_previous;
  1019. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1020. //echo '<p>' . $sql_update_next . '</p>';
  1021. }
  1022. if ($old_next != 0) {
  1023. $sql_update_previous = "
  1024. UPDATE " . $tbl_lp_item . "
  1025. SET previous_item_id = " . $old_previous . "
  1026. WHERE id = " . $old_next;
  1027. $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
  1028. //echo '<p>' . $sql_update_previous . '</p>';
  1029. }
  1030. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  1031. $sql_update_order = "
  1032. UPDATE " . $tbl_lp_item . "
  1033. SET display_order = display_order - 1
  1034. WHERE
  1035. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1036. parent_item_id = " . $old_parent;
  1037. $res_update_order = Database::query($sql_update_order, __FILE__, __LINE__);
  1038. //echo '<p>' . $sql_update_order . '</p>';
  1039. /* END -- virtually remove the current item id */
  1040. /* BEGIN -- update the current item id to his new location */
  1041. if ($previous == 0) {
  1042. //select the data of the item that should come after the current item
  1043. $sql_select_old = "
  1044. SELECT
  1045. id,
  1046. display_order
  1047. FROM " . $tbl_lp_item . "
  1048. WHERE
  1049. lp_id = " . $this->lp_id . " AND
  1050. parent_item_id = " . $parent . " AND
  1051. previous_item_id = " . $previous;
  1052. $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
  1053. $row_select_old = Database :: fetch_array($res_select_old);
  1054. //echo '<p>' . $sql_select_old . '</p>';
  1055. //if the new parent didn't have children before
  1056. if (Database :: num_rows($res_select_old) == 0) {
  1057. $new_next = 0;
  1058. $new_order = 1;
  1059. } else {
  1060. $new_next = $row_select_old['id'];
  1061. $new_order = $row_select_old['display_order'];
  1062. }
  1063. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1064. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1065. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1066. } else {
  1067. //select the data of the item that should come before the current item
  1068. $sql_select_old = "
  1069. SELECT
  1070. next_item_id,
  1071. display_order
  1072. FROM " . $tbl_lp_item . "
  1073. WHERE id = " . $previous;
  1074. $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
  1075. $row_select_old = Database :: fetch_array($res_select_old);
  1076. //echo '<p>' . $sql_select_old . '</p>';
  1077. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1078. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1079. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1080. $new_next = $row_select_old['next_item_id'];
  1081. $new_order = $row_select_old['display_order'] + 1;
  1082. }
  1083. //TODO: htmlspecialchars to be checked for encoding related problems.
  1084. //update the current item with the new data
  1085. $sql_update = "
  1086. UPDATE " . $tbl_lp_item . "
  1087. SET
  1088. title = '" . $this->escape_string($title) . "',
  1089. description = '" . $this->escape_string($description) . "',
  1090. parent_item_id = " . $parent . ",
  1091. previous_item_id = " . $previous . ",
  1092. next_item_id = " . $new_next . ",
  1093. display_order = " . $new_order . "
  1094. " . $audio_update_sql . "
  1095. WHERE id = " . $id;
  1096. $res_update_next = Database::query($sql_update, __FILE__, __LINE__);
  1097. //echo '<p>' . $sql_update . '</p>';
  1098. if ($previous != 0) {
  1099. //update the previous item's next_item_id
  1100. $sql_update_previous = "
  1101. UPDATE " . $tbl_lp_item . "
  1102. SET next_item_id = " . $id . "
  1103. WHERE id = " . $previous;
  1104. $res_update_next = Database::query($sql_update_previous, __FILE__, __LINE__);
  1105. //echo '<p>' . $sql_update_previous . '</p>';
  1106. }
  1107. if ($new_next != 0) {
  1108. //update the next item's previous_item_id
  1109. $sql_update_next = "
  1110. UPDATE " . $tbl_lp_item . "
  1111. SET previous_item_id = " . $id . "
  1112. WHERE id = " . $new_next;
  1113. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1114. //echo '<p>' . $sql_update_next . '</p>';
  1115. }
  1116. if ($old_prerequisite != $prerequisites) {
  1117. $sql_update_next = "
  1118. UPDATE " . $tbl_lp_item . "
  1119. SET prerequisite = " . $prerequisites . "
  1120. WHERE id = " . $id;
  1121. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1122. }
  1123. if ($old_max_time_allowed != $max_time_allowed) {
  1124. $sql_update_max_time_allowed = "
  1125. UPDATE " . $tbl_lp_item . "
  1126. SET max_time_allowed = " . $max_time_allowed . "
  1127. WHERE id = " . $id;
  1128. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed, __FILE__, __LINE__);
  1129. }
  1130. //update all the items with the same or a bigger display_order than
  1131. //the current item
  1132. $sql_update_order = "
  1133. UPDATE " . $tbl_lp_item . "
  1134. SET display_order = display_order + 1
  1135. WHERE
  1136. lp_id = " . $this->get_id() . " AND
  1137. id <> " . $id . " AND
  1138. parent_item_id = " . $parent . " AND
  1139. display_order >= " . $new_order;
  1140. $res_update_next = Database::query($sql_update_order, __FILE__, __LINE__);
  1141. //echo '<p>' . $sql_update_order . '</p>';
  1142. /* END -- update the current item id to his new location */
  1143. }
  1144. }
  1145. /**
  1146. * Updates an item's prereq in place
  1147. * @param integer Element ID
  1148. * @param string Prerequisite Element ID
  1149. * @param string Prerequisite item type
  1150. * @param string Prerequisite min score
  1151. * @param string Prerequisite max score
  1152. * @return boolean True on success, false on error
  1153. */
  1154. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1155. if ($this->debug > 0) {
  1156. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1157. }
  1158. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1159. return false;
  1160. }
  1161. $prerequisite_id = $this->escape_string($prerequisite_id);
  1162. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1163. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1164. $mastery_score = 0;
  1165. if (!is_numeric($max_score) || $max_score < 0)
  1166. $max_score = 100;
  1167. if ($mastery_score > $max_score)
  1168. $max_score = $mastery_score;
  1169. if (!is_numeric($prerequisite_id))
  1170. $prerequisite_id = 'NULL';
  1171. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1172. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1173. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  1174. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1175. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1176. mastery_score = " . $mastery_score .
  1177. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1178. " WHERE ref = '" . $prerequisite_id . "'"; //will this be enough to ensure unicity?
  1179. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  1180. }
  1181. //TODO update the item object (can be ignored for now because refreshed)
  1182. return true;
  1183. }
  1184. /**
  1185. * Escapes a string with the available database escape function
  1186. * @param string String to escape
  1187. * @return string String escaped
  1188. */
  1189. function escape_string($string) {
  1190. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1191. return Database :: escape_string($string);
  1192. }
  1193. /**
  1194. * Static admin function exporting a learnpath into a zip file
  1195. * @param string Export type (scorm, zip, cd)
  1196. * @param string Course code
  1197. * @param integer Learnpath ID
  1198. * @param string Zip file name
  1199. * @return string Zip file path (or false on error)
  1200. */
  1201. function export_lp($type, $course, $id, $zipname) {
  1202. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1203. //TODO
  1204. if (empty ($type) OR empty ($course) OR empty ($id) OR empty ($zipname)) {
  1205. return false;
  1206. }
  1207. $url = '';
  1208. switch ($type) {
  1209. case 'scorm' :
  1210. break;
  1211. case 'zip' :
  1212. break;
  1213. case 'cdrom' :
  1214. break;
  1215. }
  1216. return $url;
  1217. }
  1218. /**
  1219. * Gets all the chapters belonging to the same parent as the item/chapter given
  1220. * Can also be called as abstract method
  1221. * @param integer Item ID
  1222. * @return array A list of all the "brother items" (or an empty array on failure)
  1223. */
  1224. function get_brother_chapters($id) {
  1225. if ($this->debug > 0) {
  1226. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1227. }
  1228. if (empty ($id) OR $id != strval(intval($id))) {
  1229. return array ();
  1230. }
  1231. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1232. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1233. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  1234. if (Database :: num_rows($res_parent) > 0) {
  1235. $row_parent = Database :: fetch_array($res_parent);
  1236. $parent = $row_parent['parent_item_id'];
  1237. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1238. $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
  1239. $list = array ();
  1240. while ($row_bro = Database :: fetch_array($res_bros)) {
  1241. $list[] = $row_bro;
  1242. }
  1243. return $list;
  1244. }
  1245. return array ();
  1246. }
  1247. /**
  1248. * Gets all the items belonging to the same parent as the item given
  1249. * Can also be called as abstract method
  1250. * @param integer Item ID
  1251. * @return array A list of all the "brother items" (or an empty array on failure)
  1252. */
  1253. function get_brother_items($id) {
  1254. if ($this->debug > 0) {
  1255. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1256. }
  1257. if (empty ($id) OR $id != strval(intval($id))) {
  1258. return array ();
  1259. }
  1260. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1261. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1262. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  1263. if (Database :: num_rows($res_parent) > 0) {
  1264. $row_parent = Database :: fetch_array($res_parent);
  1265. $parent = $row_parent['parent_item_id'];
  1266. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1267. $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
  1268. $list = array ();
  1269. while ($row_bro = Database :: fetch_array($res_bros)) {
  1270. $list[] = $row_bro;
  1271. }
  1272. return $list;
  1273. }
  1274. return array ();
  1275. }
  1276. /**
  1277. * Get the specific prefix index terms of this learning path
  1278. * @return array Array of terms
  1279. */
  1280. function get_common_index_terms_by_prefix($prefix) {
  1281. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  1282. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1283. $prefix_terms = array ();
  1284. foreach ($terms as $term) {
  1285. $prefix_terms[] = $term['value'];
  1286. }
  1287. return $prefix_terms;
  1288. }
  1289. /**
  1290. * Gets the number of items currently completed
  1291. * @return integer The number of items currently completed
  1292. */
  1293. function get_complete_items_count() {
  1294. if ($this->debug > 0) {
  1295. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1296. }
  1297. $i = 0;
  1298. foreach ($this->items as $id => $dummy) {
  1299. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1300. //Trying failed and browsed considered "progressed" as well
  1301. if ($this->items[$id]->status_is(array (
  1302. 'completed',
  1303. 'passed',
  1304. 'succeeded',
  1305. 'browsed',
  1306. 'failed'
  1307. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1308. $i++;
  1309. }
  1310. }
  1311. return $i;
  1312. }
  1313. /**
  1314. * Gets the current item ID
  1315. * @return integer The current learnpath item id
  1316. */
  1317. function get_current_item_id() {
  1318. $current = 0;
  1319. if ($this->debug > 0) {
  1320. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1321. }
  1322. if (!empty ($this->current)) {
  1323. $current = $this->current;
  1324. }
  1325. if ($this->debug > 2) {
  1326. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1327. }
  1328. return $current;
  1329. }
  1330. /** Force to get the first learnpath item id
  1331. * @return integer The current learnpath item id
  1332. */
  1333. function get_first_item_id() {
  1334. $current = 0;
  1335. if (is_array($this->ordered_items)) {
  1336. $current = $this->ordered_items[0];
  1337. }
  1338. return $current;
  1339. }
  1340. /**
  1341. * Gets the total number of items available for viewing in this SCORM
  1342. * @return integer The total number of items
  1343. */
  1344. function get_total_items_count() {
  1345. if ($this->debug > 0) {
  1346. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1347. }
  1348. return count($this->items);
  1349. }
  1350. /**
  1351. * Gets the total number of items available for viewing in this SCORM but without chapters
  1352. * @return integer The total no-chapters number of items
  1353. */
  1354. function get_total_items_count_without_chapters() {
  1355. if ($this->debug > 0) {
  1356. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1357. }
  1358. $total = 0;
  1359. foreach ($this->items as $temp => $temp2) {
  1360. if (!in_array($temp2->get_type(), array (
  1361. 'dokeos_chapter',
  1362. 'chapter',
  1363. 'dir'
  1364. )))
  1365. $total++;
  1366. }
  1367. return $total;
  1368. }
  1369. /**
  1370. * Gets the first element URL.
  1371. * @return string URL to load into the viewer
  1372. */
  1373. function first() {
  1374. if ($this->debug > 0) {
  1375. error_log('New LP - In learnpath::first()', 0);
  1376. }
  1377. //test if the last_item_seen exists and is not a dir
  1378. if (count($this->ordered_items) == 0) {
  1379. $this->index = 0;
  1380. }
  1381. if (!empty ($this->last_item_seen) && !empty ($this->items[$this->last_item_seen]) && $this->items[$this->last_item_seen]->get_type() != 'dir' && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' && $this->items[$this->last_item_seen]->is_done() != true) {
  1382. if ($this->debug > 2) {
  1383. 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);
  1384. }
  1385. $index = -1;
  1386. foreach ($this->ordered_items as $myindex => $item_id) {
  1387. if ($item_id == $this->last_item_seen) {
  1388. $index = $myindex;
  1389. break;
  1390. }
  1391. }
  1392. if ($index == -1) {
  1393. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1394. if ($this->debug > 2) {
  1395. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1396. }
  1397. return false;
  1398. } else {
  1399. $this->last = $this->last_item_seen;
  1400. $this->current = $this->last_item_seen;
  1401. $this->index = $index;
  1402. }
  1403. } else {
  1404. if ($this->debug > 2) {
  1405. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1406. }
  1407. $index = 0;
  1408. //loop through all ordered items and stop at the first item that is
  1409. //not a directory *and* that has not been completed yet
  1410. while (!empty ($this->ordered_items[$index]) AND is_a($this->items[$this->ordered_items[$index]], 'learnpathItem') AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter' OR $this->items[$this->ordered_items[$index]]->is_done() === true) AND $index < $this->max_ordered_items) {
  1411. $index++;
  1412. }
  1413. $this->last = $this->current;
  1414. //current is
  1415. $this->current = $this->ordered_items[$index];
  1416. $this->index = $index;
  1417. if ($this->debug > 2) {
  1418. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1419. }
  1420. }
  1421. if ($this->debug > 2) {
  1422. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1423. }
  1424. }
  1425. /**
  1426. * Gets the information about an item in a format usable as JavaScript to update
  1427. * the JS API by just printing this content into the <head> section of the message frame
  1428. * @param integer Item ID
  1429. * @return string
  1430. */
  1431. function get_js_info($item_id = '') {
  1432. if ($this->debug > 0) {
  1433. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1434. }
  1435. $info = '';
  1436. $item_id = $this->escape_string($item_id);
  1437. if (!empty ($item_id) && is_object($this->items[$item_id])) {
  1438. //if item is defined, return values from DB
  1439. $oItem = $this->items[$item_id];
  1440. $info .= '<script language="javascript">';
  1441. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1442. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1443. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1444. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1445. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1446. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1447. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1448. $info .= "top.set_flag_synchronized();";
  1449. $info .= '</script>';
  1450. if ($this->debug > 2) {
  1451. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1452. }
  1453. return $info;
  1454. } else {
  1455. //if item_id is empty, just update to default SCORM data
  1456. $info .= '<script language="javascript">';
  1457. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1458. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1459. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1460. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1461. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1462. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1463. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1464. $info .= "top.set_flag_synchronized();";
  1465. $info .= '</script>';
  1466. if ($this->debug > 2) {
  1467. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1468. }
  1469. return $info;
  1470. }
  1471. }
  1472. /**
  1473. * Gets the js library from the database
  1474. * @return string The name of the javascript library to be used
  1475. */
  1476. function get_js_lib() {
  1477. $lib = '';
  1478. if (!empty ($this->js_lib)) {
  1479. $lib = $this->js_lib;
  1480. }
  1481. return $lib;
  1482. }
  1483. /**
  1484. * Gets the learnpath database ID
  1485. * @return integer Learnpath ID in the lp table
  1486. */
  1487. function get_id() {
  1488. //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1489. if (!empty ($this->lp_id)) {
  1490. return $this->lp_id;
  1491. } else {
  1492. return 0;
  1493. }
  1494. }
  1495. /**
  1496. * Gets the last element URL.
  1497. * @return string URL to load into the viewer
  1498. */
  1499. function get_last() {
  1500. if ($this->debug > 0) {
  1501. error_log('New LP - In learnpath::get_last()', 0);
  1502. }
  1503. $this->index = count($this->ordered_items) - 1;
  1504. return $this->ordered_items[$this->index];
  1505. }
  1506. /**
  1507. * Gets the navigation bar for the learnpath display screen
  1508. * @return string The HTML string to use as a navigation bar
  1509. */
  1510. function get_navigation_bar() {
  1511. if ($this->debug > 0) {
  1512. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1513. }
  1514. //TODO find a good value for the following variables
  1515. $file = '';
  1516. $openDir = '';
  1517. $edoceo = '';
  1518. $time = 0;
  1519. $navbar = '';
  1520. $RequestUri = '';
  1521. $mycurrentitemid = $this->get_current_item_id();
  1522. if ($this->mode == 'fullscreen') {
  1523. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1524. ' <tr> ' . "\n" .
  1525. ' <td>' . "\n" .
  1526. ' <div class="buttons">' . "\n" .
  1527. ' <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" .
  1528. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1529. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1530. //' <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" .
  1531. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1532. ' </div>' . "\n" .
  1533. ' </td>' . "\n" .
  1534. ' </tr>' . "\n" .
  1535. '</table>' . "\n";
  1536. } else {
  1537. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1538. ' <tr> ' . "\n" .
  1539. ' <td>' . "\n" .
  1540. ' <div class="buttons">' . "\n" .
  1541. ' <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" .
  1542. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1543. ' <a href="" onclick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1544. // ' <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" .
  1545. ' </div>' . "\n" .
  1546. ' </td>' . "\n" .
  1547. ' </tr>' . "\n" .
  1548. '</table>' . "\n";
  1549. }
  1550. return $navbar;
  1551. }
  1552. /**
  1553. * Gets the next resource in queue (url).
  1554. * @return string URL to load into the viewer
  1555. */
  1556. function get_next_index() {
  1557. if ($this->debug > 0) {
  1558. error_log('New LP - In learnpath::get_next_index()', 0);
  1559. }
  1560. //TODO
  1561. $index = $this->index;
  1562. $index++;
  1563. if ($this->debug > 2) {
  1564. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1565. }
  1566. 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) {
  1567. $index++;
  1568. if ($index == $this->max_ordered_items) {
  1569. return $this->index;
  1570. }
  1571. }
  1572. if (empty ($this->ordered_items[$index])) {
  1573. return $this->index;
  1574. }
  1575. if ($this->debug > 2) {
  1576. error_log('New LP - index is now ' . $index, 0);
  1577. }
  1578. return $index;
  1579. }
  1580. /**
  1581. * Gets item_id for the next element
  1582. * @return integer Next item (DB) ID
  1583. */
  1584. function get_next_item_id() {
  1585. if ($this->debug > 0) {
  1586. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1587. }
  1588. $new_index = $this->get_next_index();
  1589. if (!empty ($new_index)) {
  1590. if (isset ($this->ordered_items[$new_index])) {
  1591. if ($this->debug > 2) {
  1592. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1593. }
  1594. return $this->ordered_items[$new_index];
  1595. }
  1596. }
  1597. if ($this->debug > 2) {
  1598. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1599. }
  1600. return 0;
  1601. }
  1602. /**
  1603. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1604. *
  1605. * Generally, the package provided is in the form of a zip file, so the function
  1606. * has been written to test a zip file. If not a zip, the function will return the
  1607. * default return value: ''
  1608. * @param string the path to the file
  1609. * @param string the original name of the file
  1610. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1611. */
  1612. function get_package_type($file_path, $file_name) {
  1613. //get name of the zip file without the extension
  1614. $file_info = pathinfo($file_name);
  1615. $filename = $file_info['basename']; //name including extension
  1616. $extension = $file_info['extension']; //extension only
  1617. if (!empty ($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1618. 'dll',
  1619. 'exe'
  1620. ))) {
  1621. return 'oogie';
  1622. }
  1623. if (!empty ($_POST['woogie']) && !in_array(strtolower($extension), array (
  1624. 'dll',
  1625. 'exe'
  1626. ))) {
  1627. return 'woogie';
  1628. }
  1629. $file_base_name = str_replace('.' . $extension, '', $filename); //filename without its extension
  1630. $zipFile = new pclZip($file_path);
  1631. // Check the zip content (real size and file extension)
  1632. $zipContentArray = $zipFile->listContent();
  1633. $package_type = '';
  1634. $at_root = false;
  1635. $manifest = '';
  1636. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1637. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1638. foreach ($zipContentArray as $thisContent) {
  1639. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1640. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1641. }
  1642. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== FALSE) {
  1643. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1644. $package_type = 'scorm';
  1645. break; //exit the foreach loop
  1646. }
  1647. elseif (preg_match('/aicc\//i', $thisContent['filename']) != false) {
  1648. //if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1649. $package_type = 'aicc';
  1650. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1651. } else {
  1652. $package_type = '';
  1653. }
  1654. }
  1655. }
  1656. return $package_type;
  1657. }
  1658. /**
  1659. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1660. * @return string URL to load into the viewer
  1661. */
  1662. function get_previous_index() {
  1663. if ($this->debug > 0) {
  1664. error_log('New LP - In learnpath::get_previous_index()', 0);
  1665. }
  1666. $index = $this->index;
  1667. if (isset ($this->ordered_items[$index -1])) {
  1668. $index--;
  1669. 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')) {
  1670. $index--;
  1671. if ($index < 0) {
  1672. return $this->index;
  1673. }
  1674. }
  1675. } else {
  1676. if ($this->debug > 2) {
  1677. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1678. }
  1679. //no previous item
  1680. }
  1681. return $index;
  1682. }
  1683. /**
  1684. * Gets item_id for the next element
  1685. * @return integer Previous item (DB) ID
  1686. */
  1687. function get_previous_item_id() {
  1688. if ($this->debug > 0) {
  1689. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1690. }
  1691. $new_index = $this->get_previous_index();
  1692. return $this->ordered_items[$new_index];
  1693. }
  1694. /**
  1695. * Gets the progress value from the progress_db attribute
  1696. * @return integer Current progress value
  1697. */
  1698. function get_progress() {
  1699. if ($this->debug > 0) {
  1700. error_log('New LP - In learnpath::get_progress()', 0);
  1701. }
  1702. if (!empty ($this->progress_db)) {
  1703. return $this->progress_db;
  1704. }
  1705. return 0;
  1706. }
  1707. /**
  1708. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1709. * @param integer Learnpath ID
  1710. * @param integer User ID
  1711. * @param string Mode of display ('%','abs' or 'both')
  1712. * @param string Course database name (optional, defaults to '')
  1713. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1714. * @return integer Current progress value as found in the database
  1715. */
  1716. function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false) {
  1717. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1718. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1719. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1720. $res = Database::query($sql, __FILE__, __LINE__);
  1721. $view_id = 0;
  1722. if (Database :: num_rows($res) > 0) {
  1723. $row = Database :: fetch_array($res);
  1724. $progress = $row['progress'];
  1725. $view_id = $row['id'];
  1726. } else {
  1727. if ($sincere) {
  1728. return null;
  1729. }
  1730. }
  1731. if (empty ($progress)) {
  1732. $progress = '0';
  1733. }
  1734. if ($mode == '%') {
  1735. return $progress . '%';
  1736. } else {
  1737. //get the number of items completed and the number of items total
  1738. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1739. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1740. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1741. $res = Database::query($sql, __FILE__, __LINE__);
  1742. $row = Database :: fetch_array($res);
  1743. $total = $row[0];
  1744. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1745. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1746. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1747. //trying as also counting browsed and failed items
  1748. $sql = "SELECT count(distinct(lp_item_id))
  1749. FROM $tbl_item_view as item_view
  1750. INNER JOIN $tbl_item as item
  1751. ON item.id = item_view.lp_item_id
  1752. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1753. WHERE lp_view_id = " . $view_id . "
  1754. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1755. $res = Database::query($sql, __FILE__, __LINE__);
  1756. $row = Database :: fetch_array($res);
  1757. $completed = $row[0];
  1758. if ($mode == 'abs') {
  1759. return $completed . '/' . $total;
  1760. }
  1761. elseif ($mode == 'both') {
  1762. if ($progress < ($completed / ($total ? $total : 1))) {
  1763. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1764. }
  1765. return $progress . '% (' . $completed . '/' . $total . ')';
  1766. }
  1767. }
  1768. return $progress;
  1769. }
  1770. /**
  1771. * Returns the HTML necessary to print a mediaplayer block inside a page
  1772. * @return string The mediaplayer HTML
  1773. */
  1774. function get_mediaplayer($autostart='true') {
  1775. global $_course;
  1776. // Database table definition
  1777. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1778. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1779. // getting all the information about the item
  1780. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp inner join " . $tbl_lp_item_view . " as lp_view on lp.id = lp_view.lp_item_id " .
  1781. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1782. $result = Database::query($sql, __FILE__, __LINE__);
  1783. $row = mysql_fetch_assoc($result);
  1784. $output = '';
  1785. if (!empty ($row['audio'])) {
  1786. $list = $_SESSION['oLP']->get_toc();
  1787. $type_quiz = false;
  1788. foreach($list as $toc) {
  1789. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1790. $type_quiz = true;
  1791. }
  1792. }
  1793. if ($type_quiz) {
  1794. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1795. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1796. } else {
  1797. $autostart_audio = $autostart;
  1798. }
  1799. } else {
  1800. $autostart_audio = 'true';
  1801. }
  1802. // the mp3 player
  1803. $output = '<div id="container">';
  1804. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1805. $output .= '<script type="text/javascript">
  1806. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1807. s1.addParam("allowscriptaccess","always");
  1808. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1809. s1.write("container");
  1810. </script></div>';
  1811. }
  1812. return $output;
  1813. }
  1814. /**
  1815. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1816. * completed so far.
  1817. * @param string Mode in which we want the values
  1818. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1819. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1820. * @param boolean true if it comes from a Diplay LP view
  1821. * @return string HTML string containing the progress bar
  1822. */
  1823. function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1824. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1825. global $lp_theme_css;
  1826. // Setting up the CSS path of the current style if exists
  1827. if (!empty ($lp_theme_css)) {
  1828. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1829. } else {
  1830. $css_path = '../img/';
  1831. }
  1832. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1833. if (isset ($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1834. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1835. }
  1836. $text = $percentage . $text_add;
  1837. //Default progress bar config
  1838. // times that will be greater or shorter
  1839. $factor = 1.2;
  1840. if ($from_lp)
  1841. $progress_height = '26';
  1842. else
  1843. $progress_height = '16';
  1844. $size = str_replace('%', '', $percentage);
  1845. $output = ''
  1846. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1847. . '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
  1848. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1849. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1850. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1851. if ($percentage <= 98) {
  1852. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1853. } else {
  1854. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1855. }
  1856. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
  1857. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1858. return $output;
  1859. }
  1860. /**
  1861. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1862. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1863. * //@param integer Additional steps to fake as completed
  1864. * @return list Percentage or number and symbol (% or /xx)
  1865. */
  1866. function get_progress_bar_text($mode = '', $add = 0) {
  1867. if ($this->debug > 0) {
  1868. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1869. }
  1870. if (empty ($mode)) {
  1871. $mode = $this->progress_bar_mode;
  1872. }
  1873. $total_items = $this->get_total_items_count_without_chapters();
  1874. if ($this->debug > 2) {
  1875. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1876. }
  1877. $i = $this->get_complete_items_count();
  1878. if ($this->debug > 2) {
  1879. error_log('New LP - Items completed so far: ' . $i, 0);
  1880. }
  1881. if ($add != 0) {
  1882. $i += $add;
  1883. if ($this->debug > 2) {
  1884. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1885. }
  1886. }
  1887. $text = '';
  1888. if ($i > $total_items) {
  1889. $i = $total_items;
  1890. }
  1891. if ($mode == '%') {
  1892. if ($total_items > 0) {
  1893. $percentage = ((float) $i / (float) $total_items) * 100;
  1894. } else {
  1895. $percentage = 0;
  1896. }
  1897. $percentage = number_format($percentage, 0);
  1898. $text = '%';
  1899. }
  1900. elseif ($mode == 'abs') {
  1901. $percentage = $i;
  1902. $text = '/' . $total_items;
  1903. }
  1904. return array (
  1905. $percentage,
  1906. $text
  1907. );
  1908. }
  1909. /**
  1910. * Gets the progress bar mode
  1911. * @return string The progress bar mode attribute
  1912. */
  1913. function get_progress_bar_mode() {
  1914. if ($this->debug > 0) {
  1915. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1916. }
  1917. if (!empty ($this->progress_bar_mode)) {
  1918. return $this->progress_bar_mode;
  1919. } else {
  1920. return '%';
  1921. }
  1922. }
  1923. /**
  1924. * Gets the learnpath proximity (remote or local)
  1925. * @return string Learnpath proximity
  1926. */
  1927. function get_proximity() {
  1928. if ($this->debug > 0) {
  1929. error_log('New LP - In learnpath::get_proximity()', 0);
  1930. }
  1931. if (!empty ($this->proximity)) {
  1932. return $this->proximity;
  1933. } else {
  1934. return '';
  1935. }
  1936. }
  1937. /**
  1938. * Gets the learnpath theme (remote or local)
  1939. * @return string Learnpath theme
  1940. */
  1941. function get_theme() {
  1942. if ($this->debug > 0) {
  1943. error_log('New LP - In learnpath::get_theme()', 0);
  1944. }
  1945. if (!empty ($this->theme)) {
  1946. return $this->theme;
  1947. } else {
  1948. return '';
  1949. }
  1950. }
  1951. /**
  1952. * Gets the learnpath session id
  1953. * @return string Learnpath theme
  1954. */
  1955. function get_lp_session_id() {
  1956. if ($this->debug > 0) {
  1957. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1958. }
  1959. if (!empty ($this->lp_session_id)) {
  1960. return $this->lp_session_id;
  1961. } else {
  1962. return 0;
  1963. }
  1964. }
  1965. /**
  1966. * Gets the learnpath image
  1967. * @return string Web URL of the LP image
  1968. */
  1969. function get_preview_image() {
  1970. if ($this->debug > 0) {
  1971. error_log('New LP - In learnpath::get_preview_image()', 0);
  1972. }
  1973. if (!empty ($this->preview_image)) {
  1974. return $this->preview_image;
  1975. } else {
  1976. return '';
  1977. }
  1978. }
  1979. /**
  1980. * Gets the learnpath author
  1981. * @return string LP's author
  1982. */
  1983. function get_author() {
  1984. if ($this->debug > 0) {
  1985. error_log('New LP - In learnpath::get_author()', 0);
  1986. }
  1987. if (!empty ($this->author)) {
  1988. return $this->author;
  1989. } else {
  1990. return '';
  1991. }
  1992. }
  1993. /**
  1994. * Generate a new prerequisites string for a given item. If this item was a sco and
  1995. * its prerequisites were strings (instead of IDs), then transform those strings into
  1996. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1997. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1998. * same rule as the scorm_export() method
  1999. * @param integer Item ID
  2000. * @return string Prerequisites string ready for the export as SCORM
  2001. */
  2002. function get_scorm_prereq_string($item_id) {
  2003. if ($this->debug > 0) {
  2004. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2005. }
  2006. if (!is_object($this->items[$item_id])) {
  2007. return false;
  2008. }
  2009. $oItem = $this->items[$item_id];
  2010. $prereq = $oItem->get_prereq_string();
  2011. if (empty ($prereq)) {
  2012. return '';
  2013. }
  2014. if (preg_match('/^\d+$/', $prereq) && is_object($this->items[$prereq])) { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  2015. //then simply return it (with the ITEM_ prefix)
  2016. return 'ITEM_' . $prereq;
  2017. } else {
  2018. if (isset ($this->refs_list[$prereq])) {
  2019. //it's a simple string item from which the ID can be found in the refs list
  2020. //so we can transform it directly to an ID for export
  2021. return 'ITEM_' . $this->refs_list[$prereq];
  2022. } else {
  2023. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  2024. //and replace them, one by one, by the internal IDs (dokeos db)
  2025. //TODO modify the '*' replacement to replace the multiplier in front of it
  2026. //by a space as well
  2027. $find = array (
  2028. '&',
  2029. '|',
  2030. '~',
  2031. '=',
  2032. '<>',
  2033. '{',
  2034. '}',
  2035. '*',
  2036. '(',
  2037. ')'
  2038. );
  2039. $replace = array (
  2040. ' ',
  2041. ' ',
  2042. ' ',
  2043. ' ',
  2044. ' ',
  2045. ' ',
  2046. ' ',
  2047. ' ',
  2048. ' ',
  2049. ' '
  2050. );
  2051. $prereq_mod = str_replace($find, $replace, $prereq);
  2052. $ids = split(' ', $prereq_mod);
  2053. foreach ($ids as $id) {
  2054. $id = trim($id);
  2055. if (isset ($this->refs_list[$id])) {
  2056. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2057. }
  2058. }
  2059. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2060. return $prereq;
  2061. }
  2062. }
  2063. }
  2064. /**
  2065. * Returns the XML DOM document's node
  2066. * @param resource Reference to a list of objects to search for the given ITEM_*
  2067. * @param string The identifier to look for
  2068. * @return mixed The reference to the element found with that identifier. False if not found
  2069. */
  2070. function get_scorm_xml_node(& $children, $id) {
  2071. for ($i = 0; $i < $children->length; $i++) {
  2072. $item_temp = $children->item($i);
  2073. if ($item_temp->nodeName == 'item') {
  2074. if ($item_temp->getAttribute('identifier') == $id) {
  2075. return $item_temp;
  2076. }
  2077. }
  2078. $subchildren = $item_temp->childNodes;
  2079. if ($subchildren->length > 0) {
  2080. $val = $this->get_scorm_xml_node($subchildren, $id);
  2081. if (is_object($val)) {
  2082. return $val;
  2083. }
  2084. }
  2085. }
  2086. return false;
  2087. }
  2088. /**
  2089. * Returns a usable array of stats related to the current learnpath and user
  2090. * @return array Well-formatted array containing status for the current learnpath
  2091. */
  2092. function get_stats() {
  2093. if ($this->debug > 0) {
  2094. error_log('New LP - In learnpath::get_stats()', 0);
  2095. }
  2096. //TODO
  2097. }
  2098. /**
  2099. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2100. * the given course (for all learnpaths and all users)
  2101. * @param string Course code
  2102. * @return array Well-formatted array containing status for the course's learnpaths
  2103. */
  2104. function get_stats_course($course) {
  2105. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  2106. //TODO
  2107. }
  2108. /**
  2109. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2110. * the given course and learnpath (for all users)
  2111. * @param string Course code
  2112. * @param integer Learnpath ID
  2113. * @return array Well-formatted array containing status for the specified learnpath
  2114. */
  2115. function get_stats_lp($course, $lp) {
  2116. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  2117. //TODO
  2118. }
  2119. /**
  2120. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2121. * the given course, learnpath and user.
  2122. * @param string Course code
  2123. * @param integer Learnpath ID
  2124. * @param integer User ID
  2125. * @return array Well-formatted array containing status for the specified learnpath and user
  2126. */
  2127. function get_stats_lp_user($course, $lp, $user) {
  2128. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  2129. //TODO
  2130. }
  2131. /**
  2132. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2133. * the given course and learnpath (for all users)
  2134. * @param string Course code
  2135. * @param integer User ID
  2136. * @return array Well-formatted array containing status for the user's learnpaths
  2137. */
  2138. function get_stats_user($course, $user) {
  2139. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  2140. //TODO
  2141. }
  2142. /**
  2143. * Gets the status list for all LP's items
  2144. * @return array Array of [index] => [item ID => current status]
  2145. */
  2146. function get_items_status_list() {
  2147. if ($this->debug > 0) {
  2148. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2149. }
  2150. $list = array ();
  2151. foreach ($this->ordered_items as $item_id) {
  2152. $list[] = array (
  2153. $item_id => $this->items[$item_id]->get_status()
  2154. );
  2155. }
  2156. return $list;
  2157. }
  2158. /**
  2159. * Return the number of interactions for the given learnpath Item View ID.
  2160. * This method can be used as static.
  2161. * @param integer Item View ID
  2162. * @return integer Number of interactions
  2163. */
  2164. function get_interactions_count_from_db($lp_iv_id = 0) {
  2165. if (empty ($lp_iv_id)) {
  2166. return -1;
  2167. }
  2168. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2169. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2170. $res = Database::query($sql, __FILE__, __LINE__);
  2171. $row = Database :: fetch_array($res);
  2172. $num = $row[0];
  2173. return $num;
  2174. }
  2175. /**
  2176. * Return the interactions as an array for the given lp_iv_id.
  2177. * This method can be used as static.
  2178. * @param integer Learnpath Item View ID
  2179. * @return array
  2180. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2181. */
  2182. function get_iv_interactions_array($lp_iv_id = 0) {
  2183. $charset = api_get_setting('platform_charset');
  2184. $list = array ();
  2185. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2186. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2187. $res = Database::query($sql, __FILE__, __LINE__);
  2188. $num = Database :: num_rows($res);
  2189. if ($num > 0) {
  2190. $list[] = array (
  2191. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2192. "id" => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES, $charset),
  2193. "type" => api_htmlentities(get_lang('Type'), ENT_QUOTES, $charset),
  2194. "time" => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES, $charset),
  2195. "correct_responses" => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES, $charset),
  2196. "student_response" => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES, $charset),
  2197. "result" => api_htmlentities(get_lang('Result'), ENT_QUOTES, $charset),
  2198. "latency" => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES, $charset)
  2199. );
  2200. while ($row = Database :: fetch_array($res)) {
  2201. $list[] = array (
  2202. "order_id" => ($row['order_id'] + 1),
  2203. "id" => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2204. "type" => $row['interaction_type'],
  2205. "time" => $row['completion_time'],
  2206. //"correct_responses"=>$row['correct_responses'],
  2207. //hide correct responses from students
  2208. "correct_responses" => '',
  2209. "student_response" => $row['student_response'],
  2210. "result" => $row['result'],
  2211. "latency" => $row['latency']
  2212. );
  2213. }
  2214. }
  2215. return $list;
  2216. }
  2217. /**
  2218. * Return the number of objectives for the given learnpath Item View ID.
  2219. * This method can be used as static.
  2220. * @param integer Item View ID
  2221. * @return integer Number of objectives
  2222. */
  2223. function get_objectives_count_from_db($lp_iv_id = 0) {
  2224. if (empty ($lp_iv_id)) {
  2225. return -1;
  2226. }
  2227. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2228. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2229. $res = Database::query($sql, __FILE__, __LINE__);
  2230. $row = Database :: fetch_array($res);
  2231. $num = $row[0];
  2232. return $num;
  2233. }
  2234. /**
  2235. * Return the objectives as an array for the given lp_iv_id.
  2236. * This method can be used as static.
  2237. * @param integer Learnpath Item View ID
  2238. * @return array
  2239. * @todo Translate labels
  2240. */
  2241. function get_iv_objectives_array($lp_iv_id = 0) {
  2242. global $chatset;
  2243. $list = array ();
  2244. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2245. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2246. $res = Database::query($sql, __FILE__, __LINE__);
  2247. $num = Database :: num_rows($res);
  2248. if ($num > 0) {
  2249. $list[] = array (
  2250. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2251. "objective_id" => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES, $charset),
  2252. "score_raw" => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES, $charset),
  2253. "score_max" => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES, $charset),
  2254. "score_min" => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES, $charset),
  2255. "status" => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES, $charset)
  2256. );
  2257. while ($row = Database :: fetch_array($res)) {
  2258. $list[] = array (
  2259. "order_id" => ($row['order_id'] + 1),
  2260. "objective_id" => urldecode($row['objective_id']), //urldecode because they often have %2F or stuff like that
  2261. "score_raw" => $row['score_raw'],
  2262. "score_max" => $row['score_max'],
  2263. "score_min" => $row['score_min'],
  2264. "status" => $row['status']
  2265. );
  2266. }
  2267. }
  2268. return $list;
  2269. }
  2270. /**
  2271. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2272. * used by get_html_toc() to be ready to display
  2273. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2274. */
  2275. function get_toc() {
  2276. if ($this->debug > 0) {
  2277. error_log('New LP - In learnpath::get_toc()', 0);
  2278. }
  2279. $toc = array ();
  2280. //echo "<pre>".print_r($this->items,true)."</pre>";
  2281. foreach ($this->ordered_items as $item_id) {
  2282. if ($this->debug > 2) {
  2283. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2284. }
  2285. //TODO change this link generation and use new function instead
  2286. $toc[] = array (
  2287. 'id' => $item_id,
  2288. 'title' => $this->items[$item_id]->get_title(),
  2289. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2290. 'status' => $this->items[$item_id]->get_status(),
  2291. 'level' => $this->items[$item_id]->get_level(),
  2292. 'type' => $this->items[$item_id]->get_type(),
  2293. 'description' => $this->items[$item_id]->get_description(),
  2294. 'path' => $this->items[$item_id]->get_path(),
  2295. );
  2296. }
  2297. if ($this->debug > 2) {
  2298. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2299. }
  2300. return $toc;
  2301. }
  2302. /**
  2303. * Generate and return the table of contents for this learnpath. The JS
  2304. * table returned is used inside of scorm_api.php
  2305. * @return string A JS array vairiable construction
  2306. */
  2307. function get_items_details_as_js($varname='olms.lms_item_types') {
  2308. if ($this->debug > 0) {
  2309. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2310. }
  2311. $toc = $varname.' = new Array();';
  2312. //echo "<pre>".print_r($this->items,true)."</pre>";
  2313. foreach ($this->ordered_items as $item_id) {
  2314. if ($this->debug > 2) {
  2315. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2316. }
  2317. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2318. }
  2319. if ($this->debug > 2) {
  2320. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2321. }
  2322. return $toc;
  2323. }
  2324. /**
  2325. * Gets the learning path type
  2326. * @param boolean Return the name? If false, return the ID. Default is false.
  2327. * @return mixed Type ID or name, depending on the parameter
  2328. */
  2329. function get_type($get_name = false) {
  2330. $res = false;
  2331. if ($this->debug > 0) {
  2332. error_log('New LP - In learnpath::get_type()', 0);
  2333. }
  2334. if (!empty ($this->type)) {
  2335. if ($get_name) {
  2336. //get it from the lp_type table in main db
  2337. } else {
  2338. $res = $this->type;
  2339. }
  2340. }
  2341. if ($this->debug > 2) {
  2342. error_log('New LP - In learnpath::get_type() - Returning ' . ($res == false ? 'false' : $res), 0);
  2343. }
  2344. return $res;
  2345. }
  2346. /**
  2347. * Gets the learning path type as static method
  2348. * @param boolean Return the name? If false, return the ID. Default is false.
  2349. * @return mixed Type ID or name, depending on the parameter
  2350. */
  2351. function get_type_static($lp_id = 0) {
  2352. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2353. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2354. $res = Database::query($sql, __FILE__, __LINE__);
  2355. if ($res === false) {
  2356. return null;
  2357. }
  2358. if (Database :: num_rows($res) <= 0) {
  2359. return null;
  2360. }
  2361. $row = Database :: fetch_array($res);
  2362. return $row['lp_type'];
  2363. }
  2364. /**
  2365. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2366. * This method can be used as abstract and is recursive
  2367. * @param integer Learnpath ID
  2368. * @param integer Parent ID of the items to look for
  2369. * @return mixed Ordered list of item IDs or false on error
  2370. */
  2371. function get_flat_ordered_items_list($lp, $parent = 0) {
  2372. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2373. $list = array ();
  2374. if (empty ($lp)) {
  2375. return false;
  2376. }
  2377. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2378. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2379. $res = Database::query($sql, __FILE__, __LINE__);
  2380. while ($row = Database :: fetch_array($res)) {
  2381. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id']);
  2382. $list[] = $row['id'];
  2383. foreach ($sublist as $item) {
  2384. $list[] = $item;
  2385. }
  2386. }
  2387. return $list;
  2388. }
  2389. /**
  2390. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2391. * @return string HTML TOC ready to display
  2392. */
  2393. function get_html_toc() {
  2394. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  2395. $charset = api_get_setting('platform_charset');
  2396. $display_action_links_with_icons = false;
  2397. if ($this->debug > 0) {
  2398. error_log('New LP - In learnpath::get_html_toc()', 0);
  2399. }
  2400. $list = $this->get_toc();
  2401. //echo $this->current;
  2402. //$parent = $this->items[$this->current]->get_parent();
  2403. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2404. $html = '<div class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS(api_convert_encoding($this->get_name(), $this->encoding, $charset)) . '</div></div>';
  2405. // build, display
  2406. if ($is_allowed_to_edit) {
  2407. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2408. //var_dump($this->get_lp_session_id());
  2409. if ($this->get_lp_session_id()==api_get_session_id()) {
  2410. $html .= '<div class="actions_lp">';
  2411. if ($display_action_links_with_icons) {
  2412. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . "</a>";
  2413. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . "</a>";
  2414. $html .= '<span>' . Display :: return_icon('learnpath_view_na.gif', get_lang("Display")) . ' <b>' . get_lang("Display") . '</b></span>';
  2415. } else {
  2416. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;gradebook=$gradebook&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('Build') . "</a>";
  2417. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('BasicOverview') . "</a>";
  2418. $html .= '<span><b>' . get_lang('Display') . '</b></span>';
  2419. }
  2420. $html .= '</div>';
  2421. }
  2422. }
  2423. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
  2424. require_once ('resourcelinker.inc.php');
  2425. //temp variables
  2426. $mycurrentitemid = $this->get_current_item_id();
  2427. $color_counter = 0;
  2428. $i = 0;
  2429. foreach ($list as $item) {
  2430. if ($this->debug > 2) {
  2431. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2432. }
  2433. //TODO complete this
  2434. $icon_name = array (
  2435. 'not attempted' => '../img/notattempted.gif',
  2436. 'incomplete' => '../img/incomplete.gif',
  2437. 'failed' => '../img/failed.gif',
  2438. 'completed' => '../img/completed.gif',
  2439. 'passed' => '../img/passed.gif',
  2440. 'succeeded' => '../img/succeeded.gif',
  2441. 'browsed' => '../img/completed.gif'
  2442. );
  2443. $style = 'scorm_item';
  2444. $scorm_color_background = 'scorm_item';
  2445. $style_item = 'scorm_item';
  2446. $current = false;
  2447. if ($item['id'] == $this->current) {
  2448. $style = 'scorm_item_highlight';
  2449. $scorm_color_background = 'scorm_item_highlight';
  2450. } else
  2451. if ($color_counter % 2 == 0) {
  2452. $scorm_color_background = 'scorm_item_1';
  2453. } else {
  2454. $scorm_color_background = 'scorm_item_2';
  2455. }
  2456. if ($scorm_color_background != '') {
  2457. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2458. }
  2459. //the anchor will let us center the TOC on the currently viewed item &^D
  2460. if ($item['type'] != 'dokeos_module' AND $item['type'] != 'dokeos_chapter') {
  2461. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2462. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2463. } else {
  2464. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2465. }
  2466. $title = $item['title'];
  2467. if (empty ($title)) {
  2468. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2469. }
  2470. //$title = api_htmlentities($title, ENT_QUOTES, $this->encoding);
  2471. $title = Security::remove_XSS($title);
  2472. if ($item['type'] != 'dokeos_chapter' and $item['type'] != 'dir' AND $item['type'] != 'dokeos_module') {
  2473. //$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>" ;
  2474. $url = $this->get_link('http', $item['id']);
  2475. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2476. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2477. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2478. $html .= '<a href="" onclick="switch_item(' .
  2479. $mycurrentitemid . ',' .
  2480. $item['id'] . ');' .
  2481. 'return false;" >' . stripslashes($title) . '</a>';
  2482. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2483. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2484. } elseif ($item['type'] == 'dir') {
  2485. $html .= stripslashes($title);
  2486. }
  2487. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2488. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2489. $user_id = api_get_user_id();
  2490. $course_id = api_get_course_id();
  2491. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2492. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2493. $result = Database::query($sql, __FILE__, __LINE__);
  2494. $count = Database :: num_rows($result);
  2495. if ($item['type'] == 'quiz') {
  2496. if ($item['status'] == 'completed') {
  2497. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2498. }
  2499. } else {
  2500. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2501. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2502. }
  2503. }
  2504. $html .= "</div>";
  2505. if ($scorm_color_background != '') {
  2506. $html .= '</div>';
  2507. }
  2508. $color_counter++;
  2509. }
  2510. $html .= "</div>\n";
  2511. return $html;
  2512. }
  2513. /**
  2514. * Gets the learnpath maker name - generally the editor's name
  2515. * @return string Learnpath maker name
  2516. */
  2517. function get_maker() {
  2518. if ($this->debug > 0) {
  2519. error_log('New LP - In learnpath::get_maker()', 0);
  2520. }
  2521. if (!empty ($this->maker)) {
  2522. return $this->maker;
  2523. } else {
  2524. return '';
  2525. }
  2526. }
  2527. /**
  2528. * Gets the user-friendly message stored in $this->message
  2529. * @return string Message
  2530. */
  2531. function get_message() {
  2532. if ($this->debug > 0) {
  2533. error_log('New LP - In learnpath::get_message()', 0);
  2534. }
  2535. return $this->message;
  2536. }
  2537. /**
  2538. * Gets the learnpath name/title
  2539. * @return string Learnpath name/title
  2540. */
  2541. function get_name() {
  2542. if ($this->debug > 0) {
  2543. error_log('New LP - In learnpath::get_name()', 0);
  2544. }
  2545. if (!empty ($this->name)) {
  2546. return $this->name;
  2547. } else {
  2548. return 'N/A';
  2549. }
  2550. }
  2551. /**
  2552. * Gets a link to the resource from the present location, depending on item ID.
  2553. * @param string Type of link expected
  2554. * @param integer Learnpath item ID
  2555. * @return string Link to the lp_item resource
  2556. */
  2557. function get_link($type = 'http', $item_id = null) {
  2558. if ($this->debug > 0) {
  2559. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2560. }
  2561. if (empty($item_id)) {
  2562. if ($this->debug > 2) {
  2563. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2564. }
  2565. $item_id = $this->get_current_item_id();
  2566. }
  2567. if (empty ($item_id)) {
  2568. if ($this->debug > 2) {
  2569. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2570. }
  2571. //still empty, this means there was no item_id given and we are not in an object context or
  2572. //the object property is empty, return empty link
  2573. $item_id = $this->first();
  2574. return '';
  2575. }
  2576. $file = '';
  2577. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2578. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2579. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2580. $item_id = Database::escape_string($item_id);
  2581. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2582. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2583. if ($this->debug > 2) {
  2584. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2585. }
  2586. $res = Database::query($sel, __FILE__, __LINE__);
  2587. if (Database :: num_rows($res) > 0) {
  2588. $row = Database :: fetch_array($res);
  2589. //var_dump($row);
  2590. $lp_type = $row['ltype'];
  2591. $lp_path = $row['lpath'];
  2592. $lp_item_type = $row['litype'];
  2593. $lp_item_path = $row['lipath'];
  2594. $lp_item_params = $row['liparams'];
  2595. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2596. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2597. }
  2598. //$lp_item_params = '?'.$lp_item_params;
  2599. //add ? if none - left commented to give freedom to scorm implementation
  2600. //if(substr($lp_item_params,0,1)!='?'){
  2601. // $lp_item_params = '?'.$lp_item_params;
  2602. //}
  2603. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2604. if ($type == 'http') {
  2605. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2606. } else {
  2607. $course_path = $sys_course_path; //system path
  2608. }
  2609. //now go through the specific cases to get the end of the path
  2610. switch ($lp_type) {
  2611. case 1 :
  2612. if ($lp_item_type == 'dokeos_chapter') {
  2613. $file = 'lp_content.php?type=dir';
  2614. } else {
  2615. require_once ('resourcelinker.inc.php');
  2616. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2617. // check how much attempts of a exercise exits in lp
  2618. $lp_item_id = $this->get_current_item_id();
  2619. $lp_view_id = $this->get_view_id();
  2620. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2621. $list = $this->get_toc();
  2622. $type_quiz = false;
  2623. foreach ($list as $toc) {
  2624. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2625. $type_quiz = true;
  2626. }
  2627. }
  2628. if ($type_quiz) {
  2629. $lp_item_id = Database :: escape_string($lp_item_id);
  2630. $lp_view_id = Database :: escape_string($lp_view_id);
  2631. $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'";
  2632. $result = Database::query($sql, __FILE__, __LINE__);
  2633. $row_count = Database :: fetch_row($result);
  2634. $count_item_view = (int) $row_count[0];
  2635. $not_multiple_attempt = 0;
  2636. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2637. $not_multiple_attempt = 1;
  2638. }
  2639. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2640. }
  2641. $tmp_array = explode("/", $file);
  2642. $document_name = $tmp_array[count($tmp_array) - 1];
  2643. if (strpos($document_name, '_DELETED_')) {
  2644. $file = 'blank.php?error=document_deleted';
  2645. }
  2646. }
  2647. break;
  2648. case 2 :
  2649. if ($this->debug > 2) {
  2650. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2651. }
  2652. if ($lp_item_type != 'dir') {
  2653. //Quite complex here:
  2654. //we want to make sure 'http://' (and similar) links can
  2655. //be loaded as is (withouth the Dokeos path in front) but
  2656. //some contents use this form: resource.htm?resource=http://blablabla
  2657. //which means we have to find a protocol at the path's start, otherwise
  2658. //it should not be considered as an external URL
  2659. //if($this->prerequisites_match($item_id)){
  2660. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2661. if ($this->debug > 2) {
  2662. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2663. }
  2664. //distant url, return as is
  2665. $file = $lp_item_path;
  2666. } else {
  2667. if ($this->debug > 2) {
  2668. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2669. }
  2670. //prevent getting untranslatable urls
  2671. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2672. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2673. //prepare the path
  2674. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2675. //TODO fix this for urls with protocol header
  2676. $file = str_replace('//', '/', $file);
  2677. $file = str_replace(':/', '://', $file);
  2678. if (substr($lp_path, -1) == '/') {
  2679. $lp_path = substr($lp_path, 0, -1);
  2680. }
  2681. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2682. //if file not found
  2683. $decoded = html_entity_decode($lp_item_path);
  2684. list ($decoded) = explode('?', $decoded);
  2685. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2686. require_once ('resourcelinker.inc.php');
  2687. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2688. if (empty($file)) {
  2689. $file = 'blank.php?error=document_not_found';
  2690. } else {
  2691. $tmp_array = explode("/", $file);
  2692. $document_name = $tmp_array[count($tmp_array) - 1];
  2693. if (strpos($document_name, '_DELETED_')) {
  2694. $file = 'blank.php?error=document_deleted';
  2695. } else {
  2696. $file = 'blank.php?error=document_not_found';
  2697. }
  2698. }
  2699. } else {
  2700. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2701. }
  2702. }
  2703. }
  2704. //}else{
  2705. //prerequisites did not match
  2706. //$file = 'blank.php';
  2707. //}
  2708. //We want to use parameters if they were defined in the imsmanifest
  2709. if ($file != 'blank.php') {
  2710. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2711. }
  2712. } else {
  2713. $file = 'lp_content.php?type=dir';
  2714. }
  2715. break;
  2716. case 3 :
  2717. if ($this->debug > 2) {
  2718. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2719. }
  2720. //formatting AICC HACP append URL
  2721. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2722. if ($lp_item_type != 'dir') {
  2723. //Quite complex here:
  2724. //we want to make sure 'http://' (and similar) links can
  2725. //be loaded as is (withouth the Dokeos path in front) but
  2726. //some contents use this form: resource.htm?resource=http://blablabla
  2727. //which means we have to find a protocol at the path's start, otherwise
  2728. //it should not be considered as an external URL
  2729. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2730. if ($this->debug > 2) {
  2731. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2732. }
  2733. //distant url, return as is
  2734. $file = $lp_item_path;
  2735. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2736. /*
  2737. if(stristr($file,'<servername>')!==false){
  2738. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2739. }
  2740. */
  2741. if (stripos($file, '<servername>') !== false) {
  2742. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2743. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2744. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2745. }
  2746. //
  2747. $file .= $aicc_append;
  2748. } else {
  2749. if ($this->debug > 2) {
  2750. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2751. }
  2752. //prevent getting untranslatable urls
  2753. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2754. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2755. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2756. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2757. //TODO fix this for urls with protocol header
  2758. $file = str_replace('//', '/', $file);
  2759. $file = str_replace(':/', '://', $file);
  2760. $file .= $aicc_append;
  2761. }
  2762. } else {
  2763. $file = 'lp_content.php?type=dir';
  2764. }
  2765. break;
  2766. case 4 :
  2767. break;
  2768. default :
  2769. break;
  2770. }
  2771. }
  2772. if ($this->debug > 2) {
  2773. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2774. }
  2775. return $file;
  2776. }
  2777. /**
  2778. * Gets the latest usable view or generate a new one
  2779. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2780. * @return integer DB lp_view id
  2781. */
  2782. function get_view($attempt_num = 0) {
  2783. if ($this->debug > 0) {
  2784. error_log('New LP - In learnpath::get_view()', 0);
  2785. }
  2786. $search = '';
  2787. //use $attempt_num to enable multi-views management (disabled so far)
  2788. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2789. $search = 'AND view_count = ' . $attempt_num;
  2790. }
  2791. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2792. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2793. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2794. "WHERE lp_id = " . $this->get_id() . " " .
  2795. "AND user_id = " . $this->get_user_id() . " " .
  2796. $search .
  2797. " ORDER BY view_count DESC";
  2798. $res = Database::query($sql, __FILE__, __LINE__);
  2799. if (Database :: num_rows($res) > 0) {
  2800. $row = Database :: fetch_array($res);
  2801. $this->lp_view_id = $row['id'];
  2802. } else {
  2803. //no database record, create one
  2804. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2805. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2806. $res = Database::query($sql, __FILE__, __LINE__);
  2807. $id = Database :: insert_id();
  2808. $this->lp_view_id = $id;
  2809. }
  2810. return $this->lp_view_id;
  2811. }
  2812. /**
  2813. * Gets the current view id
  2814. * @return integer View ID (from lp_view)
  2815. */
  2816. function get_view_id() {
  2817. if ($this->debug > 0) {
  2818. error_log('New LP - In learnpath::get_view_id()', 0);
  2819. }
  2820. if (!empty ($this->lp_view_id)) {
  2821. return $this->lp_view_id;
  2822. } else {
  2823. return 0;
  2824. }
  2825. }
  2826. /**
  2827. * Gets the update queue
  2828. * @return array Array containing IDs of items to be updated by JavaScript
  2829. */
  2830. function get_update_queue() {
  2831. if ($this->debug > 0) {
  2832. error_log('New LP - In learnpath::get_update_queue()', 0);
  2833. }
  2834. return $this->update_queue;
  2835. }
  2836. /**
  2837. * Gets the user ID
  2838. * @return integer User ID
  2839. */
  2840. function get_user_id() {
  2841. if ($this->debug > 0) {
  2842. error_log('New LP - In learnpath::get_user_id()', 0);
  2843. }
  2844. if (!empty ($this->user_id)) {
  2845. return $this->user_id;
  2846. } else {
  2847. return false;
  2848. }
  2849. }
  2850. /**
  2851. * Checks if any of the items has an audio element attached
  2852. * @return bool True or false
  2853. */
  2854. function has_audio() {
  2855. if ($this->debug > 1) {
  2856. error_log('New LP - In learnpath::has_audio()', 0);
  2857. }
  2858. $has = false;
  2859. foreach ($this->items as $i => $item) {
  2860. if (!empty ($this->items[$i]->audio)) {
  2861. $has = true;
  2862. break;
  2863. }
  2864. }
  2865. return $has;
  2866. }
  2867. /**
  2868. * Logs a message into a file
  2869. * @param string Message to log
  2870. * @return boolean True on success, false on error or if msg empty
  2871. */
  2872. function log($msg) {
  2873. if ($this->debug > 0) {
  2874. error_log('New LP - In learnpath::log()', 0);
  2875. }
  2876. //TODO
  2877. $this->error .= $msg . "\n";
  2878. return true;
  2879. }
  2880. /**
  2881. * Moves an item up and down at its level
  2882. * @param integer Item to move up and down
  2883. * @param string Direction 'up' or 'down'
  2884. * @return integer New display order, or false on error
  2885. */
  2886. function move_item($id, $direction) {
  2887. if ($this->debug > 0) {
  2888. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2889. }
  2890. if (empty ($id) or empty ($direction)) {
  2891. return false;
  2892. }
  2893. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2894. $sql_sel = "
  2895. SELECT *
  2896. FROM " . $tbl_lp_item . "
  2897. WHERE id = " . $id;
  2898. $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
  2899. //check if elem exists
  2900. if (Database :: num_rows($res_sel) < 1) {
  2901. return false;
  2902. }
  2903. //gather data
  2904. $row = Database :: fetch_array($res_sel);
  2905. $previous = $row['previous_item_id'];
  2906. $next = $row['next_item_id'];
  2907. $display = $row['display_order'];
  2908. $parent = $row['parent_item_id'];
  2909. $lp = $row['lp_id'];
  2910. //update the item (switch with previous/next one)
  2911. switch ($direction) {
  2912. case 'up' :
  2913. if ($this->debug > 2) {
  2914. error_log('Movement up detected', 0);
  2915. }
  2916. if ($display <= 1) { /*do nothing*/
  2917. } else {
  2918. $sql_sel2 = "SELECT *
  2919. FROM $tbl_lp_item
  2920. WHERE id = $previous";
  2921. if ($this->debug > 2) {
  2922. error_log('Selecting previous: ' . $sql_sel2, 0);
  2923. }
  2924. $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
  2925. if (Database :: num_rows($res_sel2) < 1) {
  2926. $previous_previous = 0;
  2927. }
  2928. //gather data
  2929. $row2 = Database :: fetch_array($res_sel2);
  2930. $previous_previous = $row2['previous_item_id'];
  2931. //update previous_previous item (switch "next" with current)
  2932. if ($previous_previous != 0) {
  2933. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2934. if ($this->debug > 2) {
  2935. error_log($sql_upd2, 0);
  2936. }
  2937. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2938. }
  2939. //update previous item (switch with current)
  2940. if ($previous != 0) {
  2941. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2942. if ($this->debug > 2) {
  2943. error_log($sql_upd2, 0);
  2944. }
  2945. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2946. }
  2947. //update current item (switch with previous)
  2948. if ($id != 0) {
  2949. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2950. if ($this->debug > 2) {
  2951. error_log($sql_upd2, 0);
  2952. }
  2953. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2954. }
  2955. //update next item (new previous item)
  2956. if ($next != 0) {
  2957. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2958. if ($this->debug > 2) {
  2959. error_log($sql_upd2, 0);
  2960. }
  2961. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2962. }
  2963. $display = $display -1;
  2964. }
  2965. break;
  2966. case 'down' :
  2967. if ($this->debug > 2) {
  2968. error_log('Movement down detected', 0);
  2969. }
  2970. if ($next == 0) { /*do nothing*/
  2971. } else {
  2972. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2973. if ($this->debug > 2) {
  2974. error_log('Selecting next: ' . $sql_sel2, 0);
  2975. }
  2976. $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
  2977. if (Database :: num_rows($res_sel2) < 1) {
  2978. $next_next = 0;
  2979. }
  2980. //gather data
  2981. $row2 = Database :: fetch_array($res_sel2);
  2982. $next_next = $row2['next_item_id'];
  2983. //update previous item (switch with current)
  2984. if ($previous != 0) {
  2985. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2986. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2987. }
  2988. //update current item (switch with previous)
  2989. if ($id != 0) {
  2990. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2991. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2992. }
  2993. //update next item (new previous item)
  2994. if ($next != 0) {
  2995. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2996. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2997. }
  2998. //update next_next item (switch "previous" with current)
  2999. if ($next_next != 0) {
  3000. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3001. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3002. }
  3003. $display = $display +1;
  3004. }
  3005. break;
  3006. default :
  3007. return false;
  3008. }
  3009. return $display;
  3010. }
  3011. /**
  3012. * Move a learnpath up (display_order)
  3013. * @param integer Learnpath ID
  3014. */
  3015. function move_up($lp_id) {
  3016. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3017. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3018. $res = Database::query($sql, __FILE__, __LINE__);
  3019. if ($res === false)
  3020. return false;
  3021. $lps = array ();
  3022. $lp_order = array ();
  3023. $num = Database :: num_rows($res);
  3024. //first check the order is correct, globally (might be wrong because
  3025. //of versions < 1.8.4)
  3026. if ($num > 0) {
  3027. $i = 1;
  3028. while ($row = Database :: fetch_array($res)) {
  3029. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3030. $need_fix = true;
  3031. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3032. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3033. }
  3034. $row['display_order'] = $i;
  3035. $lps[$row['id']] = $row;
  3036. $lp_order[$i] = $row['id'];
  3037. $i++;
  3038. }
  3039. }
  3040. if ($num > 1) //if there's only one element, no need to sort
  3041. {
  3042. $order = $lps[$lp_id]['display_order'];
  3043. if ($order > 1) //if it's the first element, no need to move up
  3044. {
  3045. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order -1];
  3046. $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
  3047. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order -1) . " WHERE id = " . $lp_id;
  3048. $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
  3049. }
  3050. }
  3051. }
  3052. /**
  3053. * Move a learnpath down (display_order)
  3054. * @param integer Learnpath ID
  3055. */
  3056. function move_down($lp_id) {
  3057. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3058. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3059. $res = Database::query($sql, __FILE__, __LINE__);
  3060. if ($res === false)
  3061. return false;
  3062. $lps = array ();
  3063. $lp_order = array ();
  3064. $num = Database :: num_rows($res);
  3065. $max = 0;
  3066. //first check the order is correct, globally (might be wrong because
  3067. //of versions < 1.8.4)
  3068. if ($num > 0) {
  3069. $i = 1;
  3070. while ($row = Database :: fetch_array($res)) {
  3071. $max = $i;
  3072. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3073. $need_fix = true;
  3074. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3075. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3076. }
  3077. $row['display_order'] = $i;
  3078. $lps[$row['id']] = $row;
  3079. $lp_order[$i] = $row['id'];
  3080. $i++;
  3081. }
  3082. }
  3083. if ($num > 1) //if there's only one element, no need to sort
  3084. {
  3085. $order = $lps[$lp_id]['display_order'];
  3086. if ($order < $max) //if it's the first element, no need to move up
  3087. {
  3088. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order +1];
  3089. $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
  3090. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order +1) . " WHERE id = " . $lp_id;
  3091. $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
  3092. }
  3093. }
  3094. }
  3095. /**
  3096. * Updates learnpath attributes to point to the next element
  3097. * The last part is similar to set_current_item but processing the other way around
  3098. */
  3099. function next() {
  3100. if ($this->debug > 0) {
  3101. error_log('New LP - In learnpath::next()', 0);
  3102. }
  3103. $this->last = $this->get_current_item_id();
  3104. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3105. $this->autocomplete_parents($this->last);
  3106. $new_index = $this->get_next_index();
  3107. if ($this->debug > 2) {
  3108. error_log('New LP - New index: ' . $new_index, 0);
  3109. }
  3110. $this->index = $new_index;
  3111. if ($this->debug > 2) {
  3112. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3113. }
  3114. $this->current = $this->ordered_items[$new_index];
  3115. if ($this->debug > 2) {
  3116. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3117. }
  3118. }
  3119. /**
  3120. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3121. * class, this might be redefined to allow several behaviours depending on the document type.
  3122. * @param integer Resource ID
  3123. * @return boolean True on success, false otherwise
  3124. */
  3125. function open($id) {
  3126. if ($this->debug > 0) {
  3127. error_log('New LP - In learnpath::open()', 0);
  3128. }
  3129. //TODO
  3130. //set the current resource attribute to this resource
  3131. //switch on element type (redefine in child class?)
  3132. //set status for this item to "opened"
  3133. //start timer
  3134. //initialise score
  3135. $this->index = 0; //or = the last item seen (see $this->last)
  3136. }
  3137. /**
  3138. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3139. * and the prerequisite string on error.
  3140. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3141. * @param integer Optional item ID. If none given, uses the current open item.
  3142. * @return boolean True if prerequisites are matched, false otherwise
  3143. * @return string Empty string if true returned, prerequisites string otherwise.
  3144. */
  3145. function prerequisites_match($item = null) {
  3146. if ($this->debug > 0) {
  3147. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3148. }
  3149. if (empty ($item)) {
  3150. $item = $this->current;
  3151. }
  3152. if (is_object($this->items[$item])) {
  3153. $prereq_string = $this->items[$item]->get_prereq_string();
  3154. if (empty ($prereq_string)) {
  3155. return true;
  3156. }
  3157. //clean spaces
  3158. $prereq_string = str_replace(' ', '', $prereq_string);
  3159. if ($this->debug > 0) {
  3160. error_log('Found prereq_string: ' . $prereq_string, 0);
  3161. }
  3162. //now send to the parse_prereq() function that will check this component's prerequisites
  3163. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3164. if ($result === false) {
  3165. $this->set_error_msg($this->items[$item]->prereq_alert);
  3166. }
  3167. } else {
  3168. $result = true;
  3169. if ($this->debug > 1) {
  3170. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3171. }
  3172. }
  3173. if ($this->debug > 1) {
  3174. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3175. }
  3176. return $result;
  3177. }
  3178. /**
  3179. * Updates learnpath attributes to point to the previous element
  3180. * The last part is similar to set_current_item but processing the other way around
  3181. */
  3182. function previous() {
  3183. if ($this->debug > 0) {
  3184. error_log('New LP - In learnpath::previous()', 0);
  3185. }
  3186. $this->last = $this->get_current_item_id();
  3187. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3188. $this->autocomplete_parents($this->last);
  3189. $new_index = $this->get_previous_index();
  3190. $this->index = $new_index;
  3191. $this->current = $this->ordered_items[$new_index];
  3192. }
  3193. /**
  3194. * Publishes a learnpath. This basically means show or hide the learnpath
  3195. * to normal users.
  3196. * Can be used as abstract
  3197. * @param integer Learnpath ID
  3198. * @param string New visibility
  3199. */
  3200. function toggle_visibility($lp_id, $set_visibility = 1) {
  3201. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  3202. $action = 'visible';
  3203. if ($set_visibility != 1) {
  3204. $action = 'invisible';
  3205. }
  3206. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3207. }
  3208. /**
  3209. * Publishes a learnpath. This basically means show or hide the learnpath
  3210. * on the course homepage
  3211. * Can be used as abstract
  3212. * @param integer Learnpath ID
  3213. * @param string New visibility
  3214. */
  3215. function toggle_publish($lp_id, $set_visibility = 'v') {
  3216. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  3217. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3218. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3219. $result = Database::query($sql, __FILE__, __LINE__);
  3220. $row = Database :: fetch_array($result);
  3221. $name = domesticate($row['name']);
  3222. if ($set_visibility == 'i') {
  3223. $s = $name . " " . get_lang('_no_published');
  3224. $dialogBox = $s;
  3225. $v = 0;
  3226. }
  3227. if ($set_visibility == 'v') {
  3228. $s = $name . " " . get_lang('_published');
  3229. $dialogBox = $s;
  3230. $v = 1;
  3231. }
  3232. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3233. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
  3234. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  3235. $result = Database::query($sql, __FILE__, __LINE__);
  3236. $num = Database :: num_rows($result);
  3237. $row2 = Database :: fetch_array($result);
  3238. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  3239. if (($set_visibility == 'i') && ($num > 0)) {
  3240. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  3241. }
  3242. elseif (($set_visibility == 'v') && ($num == 0)) {
  3243. $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)";
  3244. } else {
  3245. //parameter and database incompatible, do nothing
  3246. }
  3247. $result = Database::query($sql, __FILE__, __LINE__);
  3248. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3249. }
  3250. /**
  3251. * Restart the whole learnpath. Return the URL of the first element.
  3252. * Make sure the results are saved with anoter method. This method should probably be
  3253. * redefined in children classes.
  3254. * To use a similar method statically, use the create_new_attempt() method
  3255. * @return string URL to load in the viewer
  3256. */
  3257. function restart() {
  3258. if ($this->debug > 0) {
  3259. error_log('New LP - In learnpath::restart()', 0);
  3260. }
  3261. //TODO
  3262. //call autosave method to save the current progress
  3263. //$this->index = 0;
  3264. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3265. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  3266. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ")";
  3267. if ($this->debug > 2) {
  3268. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3269. }
  3270. $res = Database::query($sql, __FILE__, __LINE__);
  3271. if ($view_id = Database :: insert_id($res)) {
  3272. $this->lp_view_id = $view_id;
  3273. $this->attempt = $this->attempt + 1;
  3274. } else {
  3275. $this->error = 'Could not insert into item_view table...';
  3276. return false;
  3277. }
  3278. $this->autocomplete_parents($this->current);
  3279. foreach ($this->items as $index => $dummy) {
  3280. $this->items[$index]->restart();
  3281. $this->items[$index]->set_lp_view($this->lp_view_id);
  3282. }
  3283. $this->first();
  3284. return true;
  3285. }
  3286. /**
  3287. * Saves the current item
  3288. * @return boolean
  3289. */
  3290. function save_current() {
  3291. if ($this->debug > 0) {
  3292. error_log('New LP - In learnpath::save_current()', 0);
  3293. }
  3294. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3295. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3296. if ($this->debug > 2) {
  3297. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3298. }
  3299. if ($this->debug > 2) {
  3300. error_log('' . print_r($this->items, true), 0);
  3301. }
  3302. if (is_object($this->items[$this->current])) {
  3303. //$res = $this->items[$this->current]->save(false);
  3304. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3305. $this->autocomplete_parents($this->current);
  3306. $status = $this->items[$this->current]->get_status();
  3307. $this->append_message('new_item_status: ' . $status);
  3308. $this->update_queue[$this->current] = $status;
  3309. return $res;
  3310. }
  3311. return false;
  3312. }
  3313. /**
  3314. * Saves the given item
  3315. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3316. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3317. * @return boolean
  3318. */
  3319. function save_item($item_id = null, $from_outside = true) {
  3320. if ($this->debug > 0) {
  3321. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3322. }
  3323. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3324. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3325. if (empty ($item_id)) {
  3326. $item_id = $this->escape_string($_REQUEST['id']);
  3327. }
  3328. if (empty ($item_id)) {
  3329. $item_id = $this->get_current_item_id();
  3330. }
  3331. if ($this->debug > 2) {
  3332. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3333. }
  3334. if (is_object($this->items[$item_id])) {
  3335. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3336. //$res = $this->items[$item_id]->save($from_outside);
  3337. $this->autocomplete_parents($item_id);
  3338. $status = $this->items[$item_id]->get_status();
  3339. $this->append_message('new_item_status: ' . $status);
  3340. $this->update_queue[$item_id] = $status;
  3341. return $res;
  3342. }
  3343. return false;
  3344. }
  3345. /**
  3346. * Saves the last item seen's ID only in case
  3347. */
  3348. function save_last()
  3349. {
  3350. if ($this->debug > 0) {
  3351. error_log('New LP - In learnpath::save_last()', 0);
  3352. }
  3353. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3354. if (isset ($this->current)) {
  3355. if ($this->debug > 2) {
  3356. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3357. }
  3358. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3359. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id();
  3360. if ($this->debug > 2) {
  3361. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3362. }
  3363. $res = Database::query($sql, __FILE__, __LINE__);
  3364. }
  3365. //save progress
  3366. list ($progress, $text) = $this->get_progress_bar_text('%');
  3367. if ($progress >= 0 AND $progress <= 100) {
  3368. $progress = (int) $progress;
  3369. $sql = "UPDATE $table SET progress = $progress " .
  3370. "WHERE lp_id = " . $this->get_id() . " AND " .
  3371. "user_id = " . $this->get_user_id();
  3372. $res = Database::query($sql, __FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  3373. $this->progress_db = $progress;
  3374. }
  3375. }
  3376. /**
  3377. * Sets the current item ID (checks if valid and authorized first)
  3378. * @param integer New item ID. If not given or not authorized, defaults to current
  3379. */
  3380. function set_current_item($item_id = null) {
  3381. if ($this->debug > 0) {
  3382. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3383. }
  3384. if (empty ($item_id)) {
  3385. if ($this->debug > 2) {
  3386. error_log('New LP - No new current item given, ignore...', 0);
  3387. }
  3388. //do nothing
  3389. } else {
  3390. if ($this->debug > 2) {
  3391. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3392. }
  3393. if (is_numeric($item_id)) {
  3394. $item_id = $this->escape_string($item_id);
  3395. //TODO check in database here
  3396. $this->last = $this->current;
  3397. $this->current = $item_id;
  3398. //TODO update $this->index as well
  3399. foreach ($this->ordered_items as $index => $item) {
  3400. if ($item == $this->current) {
  3401. $this->index = $index;
  3402. break;
  3403. }
  3404. }
  3405. if ($this->debug > 2) {
  3406. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3407. }
  3408. } else {
  3409. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3410. }
  3411. }
  3412. }
  3413. /**
  3414. * Sets the encoding
  3415. * @param string New encoding
  3416. */
  3417. function set_encoding($enc = 'ISO-8859-15') {
  3418. if ($this->debug > 0) {
  3419. error_log('New LP - In learnpath::set_encoding()', 0);
  3420. }
  3421. $enc = strtoupper($enc);
  3422. $encodings = array (
  3423. 'UTF-8',
  3424. 'ISO-8859-1',
  3425. 'ISO-8859-15',
  3426. 'cp1251',
  3427. 'cp1252',
  3428. 'KOI8-R',
  3429. 'BIG5',
  3430. 'GB2312',
  3431. 'Shift_JIS',
  3432. 'EUC-JP',
  3433. ''
  3434. );
  3435. if (in_array($enc, $encodings)) {
  3436. $lp = $this->get_id();
  3437. if ($lp != 0) {
  3438. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3439. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3440. $res = Database::query($sql, __FILE__, __LINE__);
  3441. return $res;
  3442. }
  3443. }
  3444. return false;
  3445. }
  3446. /**
  3447. * Sets the JS lib setting in the database directly.
  3448. * This is the JavaScript library file this lp needs to load on startup
  3449. * @param string Proximity setting
  3450. */
  3451. function set_jslib($lib = '') {
  3452. if ($this->debug > 0) {
  3453. error_log('New LP - In learnpath::set_jslib()', 0);
  3454. }
  3455. $lp = $this->get_id();
  3456. if ($lp != 0) {
  3457. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3458. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3459. $res = Database::query($sql, __FILE__, __LINE__);
  3460. return $res;
  3461. } else {
  3462. return false;
  3463. }
  3464. }
  3465. /**
  3466. * Sets the name of the LP maker (publisher) (and save)
  3467. * @param string Optional string giving the new content_maker of this learnpath
  3468. */
  3469. function set_maker($name = '') {
  3470. if ($this->debug > 0) {
  3471. error_log('New LP - In learnpath::set_maker()', 0);
  3472. }
  3473. if (empty ($name))
  3474. return false;
  3475. $this->maker = $this->escape_string($name);
  3476. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3477. $lp_id = $this->get_id();
  3478. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3479. if ($this->debug > 2) {
  3480. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3481. }
  3482. //$res = Database::query($sql);
  3483. $res = Database::query($sql, __FILE__, __LINE__);
  3484. return true;
  3485. }
  3486. /**
  3487. * Sets the name of the current learnpath (and save)
  3488. * @param string Optional string giving the new name of this learnpath
  3489. */
  3490. function set_name($name = '') {
  3491. if ($this->debug > 0) {
  3492. error_log('New LP - In learnpath::set_name()', 0);
  3493. }
  3494. if (empty ($name))
  3495. return false;
  3496. $this->name = $this->escape_string($name);
  3497. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3498. $lp_id = $this->get_id();
  3499. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3500. if ($this->debug > 2) {
  3501. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3502. }
  3503. //$res = Database::query($sql);
  3504. $res = Database::query($sql, __FILE__, __LINE__);
  3505. // if the lp is visible on the homepage, change his name there
  3506. if (Database::affected_rows()) {
  3507. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3508. $sql = 'UPDATE ' . $table . ' SET
  3509. name = "' . $this->name . '"
  3510. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3511. Database::query($sql, __FILE__, __LINE__);
  3512. }
  3513. return true;
  3514. }
  3515. /**
  3516. * Set index specified prefix terms for all items in this path
  3517. * @param string Comma-separated list of terms
  3518. * @param char Xapian term prefix
  3519. * @return boolean False on error, true otherwise
  3520. */
  3521. function set_terms_by_prefix($terms_string, $prefix) {
  3522. if (api_get_setting('search_enabled') !== 'true')
  3523. return FALSE;
  3524. $terms_string = trim($terms_string);
  3525. $terms = explode(',', $terms_string);
  3526. array_walk($terms, 'trim_value');
  3527. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3528. //var_dump($stored_terms);
  3529. //var_dump($terms);
  3530. // don't do anything if no change, verify only at DB, not the search engine
  3531. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3532. return FALSE;
  3533. require_once ('xapian.php'); //TODO try catch every xapian use or make wrappers on api
  3534. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  3535. require_once (api_get_path(LIBRARY_PATH) . 'search/xapian/XapianQuery.php');
  3536. require_once (api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
  3537. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3538. //TODO: make query secure agains XSS : use member attr instead of post var
  3539. $lp_id = intval($_POST['lp_id']);
  3540. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3541. $result = Database::query($sql);
  3542. $di = new DokeosIndexer();
  3543. while ($lp_item = Database :: fetch_array($result)) {
  3544. // get search_did
  3545. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3546. $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';
  3547. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3548. $res = Database::query($sql, __FILE__, __LINE__);
  3549. if (Database::num_rows($res)>0) {
  3550. $se_ref = Database :: fetch_array($res);
  3551. // compare terms
  3552. $doc = $di->get_document($se_ref['search_did']);
  3553. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3554. //var_dump($xapian_terms);
  3555. $xterms = array ();
  3556. foreach ($xapian_terms as $xapian_term)
  3557. $xterms[] = substr($xapian_term['name'], 1);
  3558. $dterms = $terms;
  3559. //var_dump($xterms);
  3560. //var_dump($dterms);
  3561. $missing_terms = array_diff($dterms, $xterms);
  3562. $deprecated_terms = array_diff($xterms, $dterms);
  3563. // save it to search engine
  3564. foreach ($missing_terms as $term) {
  3565. $doc->add_term($prefix . $term, 1);
  3566. }
  3567. foreach ($deprecated_terms as $term) {
  3568. $doc->remove_term($prefix . $term);
  3569. }
  3570. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3571. $di->getDb()->flush();
  3572. }
  3573. }
  3574. return true;
  3575. }
  3576. /**
  3577. * Sets the theme of the LP (local/remote) (and save)
  3578. * @param string Optional string giving the new theme of this learnpath
  3579. * @return bool returns true if theme name is not empty
  3580. */
  3581. function set_theme($name = '') {
  3582. if ($this->debug > 0) {
  3583. error_log('New LP - In learnpath::set_theme()', 0);
  3584. }
  3585. $this->theme = $this->escape_string($name);
  3586. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3587. $lp_id = $this->get_id();
  3588. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3589. if ($this->debug > 2) {
  3590. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3591. }
  3592. //$res = Database::query($sql);
  3593. $res = Database::query($sql, __FILE__, __LINE__);
  3594. return true;
  3595. }
  3596. /**
  3597. * Sets the image of an LP (and save)
  3598. * @param string Optional string giving the new image of this learnpath
  3599. * @return bool returns true if theme name is not empty
  3600. */
  3601. function set_preview_image($name = '') {
  3602. if ($this->debug > 0) {
  3603. error_log('New LP - In learnpath::set_preview_image()', 0);
  3604. }
  3605. $this->preview_image = $this->escape_string($name);
  3606. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3607. $lp_id = $this->get_id();
  3608. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3609. if ($this->debug > 2) {
  3610. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3611. }
  3612. $res = Database::query($sql, __FILE__, __LINE__);
  3613. return true;
  3614. }
  3615. /**
  3616. * Sets the author of a LP (and save)
  3617. * @param string Optional string giving the new author of this learnpath
  3618. * @return bool returns true if author's name is not empty
  3619. */
  3620. function set_author($name = '') {
  3621. if ($this->debug > 0) {
  3622. error_log('New LP - In learnpath::set_author()', 0);
  3623. }
  3624. $this->author = $this->escape_string($name);
  3625. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3626. $lp_id = $this->get_id();
  3627. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3628. if ($this->debug > 2) {
  3629. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3630. }
  3631. $res = Database::query($sql, __FILE__, __LINE__);
  3632. return true;
  3633. }
  3634. /**
  3635. * Sets the location/proximity of the LP (local/remote) (and save)
  3636. * @param string Optional string giving the new location of this learnpath
  3637. */
  3638. function set_proximity($name = '') {
  3639. if ($this->debug > 0) {
  3640. error_log('New LP - In learnpath::set_proximity()', 0);
  3641. }
  3642. if (empty ($name))
  3643. return false;
  3644. $this->proximity = $this->escape_string($name);
  3645. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3646. $lp_id = $this->get_id();
  3647. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3648. if ($this->debug > 2) {
  3649. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3650. }
  3651. //$res = Database::query($sql);
  3652. $res = Database::query($sql, __FILE__, __LINE__);
  3653. return true;
  3654. }
  3655. /**
  3656. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3657. * @param integer DB ID of the item
  3658. */
  3659. function set_previous_item($id) {
  3660. if ($this->debug > 0) {
  3661. error_log('New LP - In learnpath::set_previous_item()', 0);
  3662. }
  3663. $this->last = $id;
  3664. }
  3665. /**
  3666. * Sets the object's error message
  3667. * @param string Error message. If empty, reinits the error string
  3668. * @return void
  3669. */
  3670. function set_error_msg($error = '') {
  3671. if ($this->debug > 0) {
  3672. error_log('New LP - In learnpath::set_error_msg()', 0);
  3673. }
  3674. if (empty ($error)) {
  3675. $this->error = '';
  3676. } else {
  3677. $this->error .= $error;
  3678. }
  3679. }
  3680. /**
  3681. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3682. *
  3683. */
  3684. function start_current_item($allow_new_attempt = false) {
  3685. if ($this->debug > 0) {
  3686. error_log('New LP - In learnpath::start_current_item()', 0);
  3687. }
  3688. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3689. $type = $this->get_type();
  3690. $item_type = $this->items[$this->current]->get_type();
  3691. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3692. $this->items[$this->current]->open($allow_new_attempt);
  3693. $this->autocomplete_parents($this->current);
  3694. $prereq_check = $this->prerequisites_match($this->current);
  3695. $this->items[$this->current]->save(false, $prereq_check);
  3696. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3697. } else {
  3698. //if sco, then it is supposed to have been updated by some other call
  3699. }
  3700. if ($item_type == 'sco') {
  3701. $this->items[$this->current]->restart();
  3702. }
  3703. }
  3704. if ($this->debug > 0) {
  3705. error_log('New LP - End of learnpath::start_current_item()', 0);
  3706. }
  3707. return true;
  3708. }
  3709. /**
  3710. * Stops the processing and counters for the old item (as held in $this->last)
  3711. * @param
  3712. */
  3713. function stop_previous_item() {
  3714. if ($this->debug > 0) {
  3715. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3716. }
  3717. if ($this->last != 0 AND $this->last != $this->current AND is_object($this->items[$this->last])) {
  3718. if ($this->debug > 2) {
  3719. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3720. }
  3721. switch ($this->get_type()) {
  3722. case '3' :
  3723. if ($this->items[$this->last]->get_type() != 'au') {
  3724. if ($this->debug > 2) {
  3725. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3726. }
  3727. $this->items[$this->last]->close();
  3728. //$this->autocomplete_parents($this->last);
  3729. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3730. } else {
  3731. if ($this->debug > 2) {
  3732. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3733. }
  3734. }
  3735. case '2' :
  3736. if ($this->items[$this->last]->get_type() != 'sco') {
  3737. if ($this->debug > 2) {
  3738. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3739. }
  3740. $this->items[$this->last]->close();
  3741. //$this->autocomplete_parents($this->last);
  3742. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3743. } else {
  3744. if ($this->debug > 2) {
  3745. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3746. }
  3747. }
  3748. break;
  3749. case '1' :
  3750. default :
  3751. if ($this->debug > 2) {
  3752. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3753. }
  3754. $this->items[$this->last]->close();
  3755. break;
  3756. }
  3757. } else {
  3758. if ($this->debug > 2) {
  3759. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3760. }
  3761. return false;
  3762. }
  3763. return true;
  3764. }
  3765. /**
  3766. * Updates the default view mode from fullscreen to embedded and inversely
  3767. * @return string The current default view mode ('fullscreen' or 'embedded')
  3768. */
  3769. function update_default_view_mode() {
  3770. if ($this->debug > 0) {
  3771. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3772. }
  3773. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3774. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3775. $res = Database::query($sql, __FILE__, __LINE__);
  3776. if (Database :: num_rows($res) > 0) {
  3777. $row = Database :: fetch_array($res);
  3778. $view_mode = $row['default_view_mod'];
  3779. if ($view_mode == 'fullscreen') {
  3780. $view_mode = 'embedded';
  3781. }
  3782. elseif ($view_mode == 'embedded') {
  3783. $view_mode = 'fullscreen';
  3784. }
  3785. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3786. $res = Database::query($sql, __FILE__, __LINE__);
  3787. $this->mode = $view_mode;
  3788. return $view_mode;
  3789. } else {
  3790. if ($this->debug > 2) {
  3791. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3792. }
  3793. }
  3794. return -1;
  3795. }
  3796. /**
  3797. * Updates the default behaviour about auto-commiting SCORM updates
  3798. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3799. */
  3800. function update_default_scorm_commit() {
  3801. if ($this->debug > 0) {
  3802. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3803. }
  3804. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3805. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3806. $res = Database::query($sql, __FILE__, __LINE__);
  3807. if (Database :: num_rows($res) > 0) {
  3808. $row = Database :: fetch_array($res);
  3809. $force = $row['force_commit'];
  3810. if ($force == 1) {
  3811. $force = 0;
  3812. $force_return = false;
  3813. }
  3814. elseif ($force == 0) {
  3815. $force = 1;
  3816. $force_return = true;
  3817. }
  3818. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3819. $res = Database::query($sql, __FILE__, __LINE__);
  3820. $this->force_commit = $force_return;
  3821. return $force_return;
  3822. } else {
  3823. if ($this->debug > 2) {
  3824. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3825. }
  3826. }
  3827. return -1;
  3828. }
  3829. /**
  3830. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3831. * @return bool True on success, false on failure
  3832. */
  3833. function update_display_order() {
  3834. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3835. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3836. $res = Database::query($sql, __FILE__, __LINE__);
  3837. if ($res === false)
  3838. return false;
  3839. $lps = array ();
  3840. $lp_order = array ();
  3841. $num = Database :: num_rows($res);
  3842. //first check the order is correct, globally (might be wrong because
  3843. //of versions < 1.8.4)
  3844. if ($num > 0) {
  3845. $i = 1;
  3846. while ($row = Database :: fetch_array($res)) {
  3847. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3848. $need_fix = true;
  3849. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3850. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3851. }
  3852. $i++;
  3853. }
  3854. }
  3855. return true;
  3856. }
  3857. /**
  3858. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3859. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3860. */
  3861. function update_reinit() {
  3862. if ($this->debug > 0) {
  3863. error_log('New LP - In learnpath::update_reinit()', 0);
  3864. }
  3865. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3866. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3867. $res = Database::query($sql, __FILE__, __LINE__);
  3868. if (Database :: num_rows($res) > 0) {
  3869. $row = Database :: fetch_array($res);
  3870. $force = $row['prevent_reinit'];
  3871. if ($force == 1) {
  3872. $force = 0;
  3873. }
  3874. elseif ($force == 0) {
  3875. $force = 1;
  3876. }
  3877. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  3878. $res = Database::query($sql, __FILE__, __LINE__);
  3879. $this->prevent_reinit = $force;
  3880. return $force;
  3881. } else {
  3882. if ($this->debug > 2) {
  3883. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3884. }
  3885. }
  3886. return -1;
  3887. }
  3888. /**
  3889. * Updates the "scorm_debug" value that shows or hide the debug window
  3890. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3891. */
  3892. function update_scorm_debug() {
  3893. if ($this->debug > 0) {
  3894. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  3895. }
  3896. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3897. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3898. $res = Database::query($sql, __FILE__, __LINE__);
  3899. if (Database :: num_rows($res) > 0) {
  3900. $row = Database :: fetch_array($res);
  3901. $force = $row['debug'];
  3902. if ($force == 1) {
  3903. $force = 0;
  3904. }
  3905. elseif ($force == 0) {
  3906. $force = 1;
  3907. }
  3908. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  3909. $res = Database::query($sql, __FILE__, __LINE__);
  3910. $this->scorm_debug = $force;
  3911. return $force;
  3912. } else {
  3913. if ($this->debug > 2) {
  3914. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3915. }
  3916. }
  3917. return -1;
  3918. }
  3919. /**
  3920. * Function that makes a call to the function sort_tree_array and create_tree_array
  3921. *
  3922. * @author Kevin Van Den Haute
  3923. *
  3924. * @param unknown_type $array
  3925. */
  3926. function tree_array($array) {
  3927. if ($this->debug > 1) {
  3928. error_log('New LP - In learnpath::tree_array()', 0);
  3929. }
  3930. $array = $this->sort_tree_array($array);
  3931. $this->create_tree_array($array);
  3932. }
  3933. /**
  3934. * Creates an array with the elements of the learning path tree in it
  3935. *
  3936. * @author Kevin Van Den Haute
  3937. *
  3938. * @param array $array
  3939. * @param int $parent
  3940. * @param int $depth
  3941. * @param array $tmp
  3942. */
  3943. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  3944. if ($this->debug > 1) {
  3945. error_log('New LP - In learnpath::create_tree_array())', 0);
  3946. }
  3947. if (is_array($array)) {
  3948. for ($i = 0; $i < count($array); $i++) {
  3949. if ($array[$i]['parent_item_id'] == $parent) {
  3950. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  3951. $tmp[] = $array[$i]['parent_item_id'];
  3952. $depth++;
  3953. }
  3954. $preq = (empty ($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  3955. $this->arrMenu[] = array (
  3956. 'id' => $array[$i]['id'],
  3957. 'item_type' => $array[$i]['item_type'],
  3958. 'title' => $array[$i]['title'],
  3959. 'path' => $array[$i]['path'],
  3960. 'description' => $array[$i]['description'],
  3961. 'parent_item_id' => $array[$i]['parent_item_id'],
  3962. 'previous_item_id' => $array[$i]['previous_item_id'],
  3963. 'next_item_id' => $array[$i]['next_item_id'],
  3964. 'min_score' => $array[$i]['min_score'],
  3965. 'max_score' => $array[$i]['max_score'],
  3966. 'mastery_score' => $array[$i]['mastery_score'],
  3967. 'display_order' => $array[$i]['display_order'],
  3968. 'prerequisite' => $preq,
  3969. 'depth' => $depth,
  3970. 'audio' => $array[$i]['audio']
  3971. );
  3972. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3973. }
  3974. }
  3975. }
  3976. }
  3977. /**
  3978. * Sorts a multi dimensional array by parent id and display order
  3979. * @author Kevin Van Den Haute
  3980. *
  3981. * @param array $array (array with al the learning path items in it)
  3982. *
  3983. * @return array
  3984. */
  3985. function sort_tree_array($array) {
  3986. foreach ($array as $key => $row) {
  3987. $parent[$key] = $row['parent_item_id'];
  3988. $position[$key] = $row['display_order'];
  3989. }
  3990. if (count($array) > 0)
  3991. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3992. return $array;
  3993. }
  3994. /**
  3995. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3996. * Also the actions for the modules, chapters and documents are in this table.
  3997. *
  3998. * @author Kevin Van Den Haute
  3999. *
  4000. * @param int $lp_id
  4001. *
  4002. * @return string
  4003. */
  4004. function overview() {
  4005. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4006. $platform_charset = api_get_system_encoding();
  4007. if ($this->debug > 0) {
  4008. error_log('New LP - In learnpath::overview()', 0);
  4009. }
  4010. global $charset, $_course;
  4011. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4012. $return = '';
  4013. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4014. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4015. WHERE lp_id = " . $this->lp_id;
  4016. $result = Database::query($sql, __FILE__, __LINE__);
  4017. $arrLP = array ();
  4018. while ($row = Database :: fetch_array($result)) {
  4019. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4020. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4021. $arrLP[] = array (
  4022. 'id' => $row['id'],
  4023. 'item_type' => $row['item_type'],
  4024. 'title' => $row['title'],
  4025. 'path' => $row['path'],
  4026. 'description' => $row['description'],
  4027. 'parent_item_id' => $row['parent_item_id'],
  4028. 'previous_item_id' => $row['previous_item_id'],
  4029. 'next_item_id' => $row['next_item_id'],
  4030. 'max_score' => $row['max_score'],
  4031. 'min_score' => $row['min_score'],
  4032. 'mastery_score' => $row['mastery_score'],
  4033. 'prerequisite' => $row['prerequisite'],
  4034. 'display_order' => $row['display_order'],
  4035. 'audio' => $row['audio']
  4036. );
  4037. }
  4038. $this->tree_array($arrLP);
  4039. $arrLP = $this->arrMenu;
  4040. unset ($this->arrMenu);
  4041. if ($is_allowed_to_edit) {
  4042. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4043. $return .= '<div class="actions">';
  4044. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="' . get_lang("Build") . '">' . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . '</a>';
  4045. $return .= '<span>' . Display :: return_icon('learnpath_organize_na.gif', get_lang("BasicOverview")) . ' <b>' . get_lang('BasicOverview') . '</b></span>';
  4046. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang("Display")) . ' ' . get_lang('Display') . '</a> ' . Display :: return_icon('i.gif');
  4047. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4048. $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>';
  4049. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewChapter") . '"><img alt="' . get_lang("NewChapter") . '" src="../img/lp_dokeos_chapter_add.gif" title="' . get_lang("NewChapter") . '" />' . get_lang("NewChapter") . '</a>';
  4050. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewStep") . '"><img alt="' . get_lang("NewStep") . '" src="../img/new_test.gif" title="' . get_lang("NewStep") . '" />' . get_lang("NewStep") . '</a>';
  4051. $return .= '</div>';
  4052. }
  4053. // we need to start a form when we want to update all the mp3 files
  4054. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4055. $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">';
  4056. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4057. }
  4058. $return .= '<table class="data_table">' . "\n";
  4059. $return .= "\t" . '<tr>' . "\n";
  4060. $return .= "\t" . '<th width="60%">' . get_lang("Title") . '</th>' . "\n";
  4061. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  4062. $return .= "\t" . '<th>' . get_lang("Audio") . '</th>' . "\n";
  4063. $return .= "\t" . '<th>' . get_lang("Move") . '</th>' . "\n";
  4064. $return .= "\t" . '<th>' . get_lang("Actions") . '</th>' . "\n";
  4065. $return .= "\t" . '</tr>' . "\n";
  4066. for ($i = 0; $i < count($arrLP); $i++) {
  4067. $title = $arrLP[$i]['title'];
  4068. if ($arrLP[$i]['description'] == '')
  4069. $arrLP[$i]['description'] = '&nbsp;';
  4070. if (($i % 2) == 0) {
  4071. $oddclass = "row_odd";
  4072. } else {
  4073. $oddclass = "row_even";
  4074. }
  4075. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4076. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4077. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4078. $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";
  4079. } else
  4080. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4081. $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";
  4082. } else {
  4083. //$return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>' . "\n";
  4084. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4085. }
  4086. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4087. // The audio column
  4088. $return .= "\t\t" . '<td align="center">';
  4089. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4090. if (!empty ($arrLP[$i]['audio'])) {
  4091. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4092. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4093. $return .= '<script type="text/javascript">
  4094. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4095. s1.addParam("allowscriptaccess","always");
  4096. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4097. s1.write("container' . $i . '");
  4098. </script>';
  4099. } else {
  4100. $return .= ' - ';
  4101. }
  4102. } else {
  4103. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4104. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4105. if (!empty ($arrLP[$i]['audio'])) {
  4106. $return .= '<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4107. }
  4108. }
  4109. }
  4110. $return .= '</td>' . "\n";
  4111. if ($is_allowed_to_edit) {
  4112. $return .= "\t\t" . '<td align="center">' . "\n";
  4113. if ($arrLP[$i]['previous_item_id'] != 0) {
  4114. $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 . '">';
  4115. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4116. $return .= '</a>' . "\n";
  4117. } else
  4118. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4119. if ($arrLP[$i]['next_item_id'] != 0) {
  4120. $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 . '">';
  4121. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4122. $return .= '</a>' . "\n";
  4123. } else
  4124. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4125. $return .= "\t\t" . '</td>' . "\n";
  4126. $return .= "\t\t" . '<td align="center">' . "\n";
  4127. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4128. $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'] . '">';
  4129. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4130. $return .= '</a>' . "\n";
  4131. } else {
  4132. $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'] . '">';
  4133. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4134. $return .= '</a>' . "\n";
  4135. }
  4136. $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) . '\');">';
  4137. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4138. $return .= '</a>' . "\n";
  4139. $return .= "\t\t" . '</td>' . "\n";
  4140. }
  4141. $return .= "\t" . '</tr>' . "\n";
  4142. }
  4143. if (count($arrLP) == 0) {
  4144. $return .= "\t" . '<tr>' . "\n";
  4145. $return .= "\t\t" . '<td colspan="4">' . get_lang("NoItemsInLp") . '</td>' . "\n";
  4146. $return .= "\t" . '</tr>' . "\n";
  4147. }
  4148. $return .= '</table>' . "\n";
  4149. // we need to close the form when we are updating the mp3 files
  4150. if ($_GET['updateaudio'] == 'true') {
  4151. $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">' . get_lang('SaveAudioAndOrganization') . '</button></div>'; // TODO: What kind of language variable is this?
  4152. }
  4153. // we need to close the form when we are updating the mp3 files
  4154. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4155. $return .= '</form>';
  4156. }
  4157. return $return;
  4158. }
  4159. /**
  4160. * This function builds the action menu
  4161. *
  4162. * */
  4163. function build_action_menu() {
  4164. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4165. echo '<div class="actions">';
  4166. //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  4167. echo '<span>' . Display :: return_icon('learnpath_build_na.gif', get_lang('Build')) . ' <b>' . get_lang('Build') . '</b></span>';
  4168. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("BasicOverview") . '">' . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . '</a>';
  4169. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang('Display')) . ' ' . get_lang('Display') . '</a>';
  4170. Display :: display_icon('i.gif');
  4171. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
  4172. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
  4173. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewChapter") . '">' . Display :: return_icon('lp_dokeos_chapter_add.gif', get_lang('NewChapter')) . ' ' . get_lang("NewChapter") . '</a>';
  4174. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewStep") . '">' . Display :: return_icon('new_test.gif', get_lang('NewStep')) . ' ' . get_lang("NewStep") . '</a>';
  4175. echo '</div>';
  4176. }
  4177. /**
  4178. * This functions builds the LP tree based on data from the database.
  4179. *
  4180. * @return string
  4181. * @uses dtree.js :: necessary javascript for building this tree
  4182. */
  4183. function build_tree() {
  4184. $platform_charset = api_get_system_encoding();
  4185. $return = "<script type=\"text/javascript\">\n";
  4186. $return .= "\tm = new dTree('m');\n\n";
  4187. $return .= "\tm.config.folderLinks = true;\n";
  4188. $return .= "\tm.config.useCookies = true;\n";
  4189. $return .= "\tm.config.useIcons = true;\n";
  4190. $return .= "\tm.config.useLines = true;\n";
  4191. $return .= "\tm.config.useSelection = true;\n";
  4192. $return .= "\tm.config.useStatustext = false;\n\n";
  4193. $menu = 0;
  4194. $parent = '';
  4195. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4196. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4197. $sql = " SELECT * FROM " . $tbl_lp_item . "
  4198. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4199. $result = Database::query($sql, __FILE__, __LINE__);
  4200. $arrLP = array ();
  4201. while ($row = Database :: fetch_array($result)) {
  4202. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4203. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4204. //$row['title'] = Security :: remove_XSS($row['title']);
  4205. $arrLP[] = array (
  4206. 'id' => $row['id'],
  4207. 'item_type' => $row['item_type'],
  4208. 'title' => $row['title'],
  4209. 'path' => $row['path'],
  4210. 'description' => $row['description'],
  4211. 'parent_item_id' => $row['parent_item_id'],
  4212. 'previous_item_id' => $row['previous_item_id'],
  4213. 'next_item_id' => $row['next_item_id'],
  4214. 'max_score' => $row['max_score'],
  4215. 'min_score' => $row['min_score'],
  4216. 'mastery_score' => $row['mastery_score'],
  4217. 'display_order' => $row['display_order']
  4218. );
  4219. }
  4220. $this->tree_array($arrLP);
  4221. $arrLP = $this->arrMenu;
  4222. unset ($this->arrMenu);
  4223. $title = '';
  4224. for ($i = 0; $i < count($arrLP); $i++) {
  4225. $title = addslashes($arrLP[$i]['title']);
  4226. $menu_page = api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  4227. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4228. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4229. $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";
  4230. } else
  4231. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4232. $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";
  4233. } else {
  4234. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4235. }
  4236. if ($menu < $arrLP[$i]['id'])
  4237. $menu = $arrLP[$i]['id'];
  4238. }
  4239. $return .= "\n\tdocument.write(m);\n";
  4240. $return .= "\t if(!m.selectedNode) m.s(1);";
  4241. $return .= "</script>\n";
  4242. return $return;
  4243. }
  4244. /**
  4245. * Create a new document //still needs some finetuning
  4246. *
  4247. * @param array $_course
  4248. * @return string
  4249. */
  4250. function create_document($_course) {
  4251. global $charset;
  4252. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4253. if (strstr($dir, '..'))
  4254. $dir = '/';
  4255. if ($dir[0] == '.')
  4256. $dir = substr($dir, 1);
  4257. if ($dir[0] != '/')
  4258. $dir = '/' . $dir;
  4259. if ($dir[strlen($dir) - 1] != '/')
  4260. $dir .= '/';
  4261. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4262. if (!is_dir($filepath)) {
  4263. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4264. $dir = '/';
  4265. }
  4266. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  4267. //is already escaped twice when it gets here
  4268. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4269. $title = disable_dangerous_file($title);
  4270. $filename = $title;
  4271. $content = $_POST['content_lp'];
  4272. $tmp_filename = $filename;
  4273. $i = 0;
  4274. while (file_exists($filepath . $tmp_filename . '.html'))
  4275. $tmp_filename = $filename . '_' . ++ $i;
  4276. $filename = $tmp_filename . '.html';
  4277. $content = stripslashes(text_filter($content));
  4278. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH) . 'courses/', $content);
  4279. // change the path of mp3 to absolute
  4280. // first regexp deals with ../../../ urls
  4281. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4282. //second regexp deals with audio/ urls
  4283. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4284. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  4285. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4286. if (!file_exists($filepath . $filename)) {
  4287. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4288. fputs($fp, $content);
  4289. fclose($fp);
  4290. $file_size = filesize($filepath . $filename);
  4291. $save_file_path = $dir . $filename;
  4292. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4293. if ($document_id) {
  4294. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(),null,null,null,null,api_get_session_id());
  4295. //update parent folders
  4296. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4297. $new_comment = (isset ($_POST['comment'])) ? trim($_POST['comment']) : '';
  4298. $new_title = (isset ($_POST['title'])) ? trim($_POST['title']) : '';
  4299. if ($new_comment || $new_title) {
  4300. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4301. $ct = '';
  4302. if ($new_comment)
  4303. $ct .= ", comment='" . $new_comment . "'";
  4304. if ($new_title)
  4305. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4306. $sql_update = "
  4307. UPDATE " . $tbl_doc . "
  4308. SET " . substr($ct, 1) . "
  4309. WHERE id = " . $document_id;
  4310. Database::query($sql_update, __FILE__, __LINE__);
  4311. }
  4312. }
  4313. return $document_id;
  4314. }
  4315. }
  4316. }
  4317. /**
  4318. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4319. *
  4320. * @param array $_course array
  4321. * @return void
  4322. */
  4323. function edit_document($_course) {
  4324. global $_configuration;
  4325. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4326. if (strstr($dir, '..'))
  4327. $dir = '/';
  4328. if ($dir[0] == '.')
  4329. $dir = substr($dir, 1);
  4330. if ($dir[0] != '/')
  4331. $dir = '/' . $dir;
  4332. if ($dir[strlen($dir) - 1] != '/')
  4333. $dir .= '/';
  4334. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4335. if (!is_dir($filepath)) {
  4336. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4337. $dir = '/';
  4338. }
  4339. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4340. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4341. $sql = "SELECT path
  4342. FROM " . $table_doc . "
  4343. WHERE id = " . Database::escape_string($_POST['path']);
  4344. $res = Database::query($sql, __FILE__, __LINE__);
  4345. $row = Database :: fetch_array($res);
  4346. $content = stripslashes($_POST['content_lp']);
  4347. $file = $filepath . $row['path'];
  4348. if ($fp = @ fopen($file, 'w')) {
  4349. $content = text_filter($content);
  4350. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'] . '/courses/', $content);
  4351. // change the path of mp3 to absolute
  4352. // first regexp deals with ../../../ urls
  4353. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4354. //second regexp deals with audio/ urls
  4355. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4356. fputs($fp, $content);
  4357. fclose($fp);
  4358. }
  4359. }
  4360. }
  4361. /**
  4362. * Displays the selected item, with a panel for manipulating the item
  4363. *
  4364. * @param int $item_id
  4365. * @param string $msg
  4366. * @return string
  4367. */
  4368. function display_item($item_id, $iframe = true, $msg = '') {
  4369. global $_course; //will disappear
  4370. $return = '';
  4371. if (is_numeric($item_id)) {
  4372. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4373. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4374. $sql = "SELECT lp.*
  4375. FROM " . $tbl_lp_item . " as lp
  4376. WHERE lp.id = " . Database :: escape_string($item_id);
  4377. $result = Database::query($sql, __FILE__, __LINE__);
  4378. while ($row = Database :: fetch_array($result)) {
  4379. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4380. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4381. $return .= '<div style="padding:10px;">';
  4382. if ($msg != '')
  4383. $return .= $msg;
  4384. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], api_get_system_encoding(), $this->encoding));
  4385. //$row['title'] = Security::remove_XSS(api_convert_encoding($row['title'], $this->encoding, api_get_system_encoding()));
  4386. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4387. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4388. //$return .= '<hr />';
  4389. if ($row['item_type'] == TOOL_DOCUMENT) {
  4390. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4391. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4392. $result = Database::query($sql_doc, __FILE__, __LINE__);
  4393. $path_file = Database :: result($result, 0, 0);
  4394. $path_parts = pathinfo($path_file);
  4395. if (in_array($path_parts['extension'], array (
  4396. 'html',
  4397. 'txt',
  4398. 'png',
  4399. 'jpg',
  4400. 'JPG',
  4401. 'jpeg',
  4402. 'JPEG',
  4403. 'gif',
  4404. 'swf'
  4405. ))) {
  4406. $return .= $this->display_document($row['path'], true, true);
  4407. }
  4408. }
  4409. $return .= '</div>';
  4410. }
  4411. }
  4412. return $return;
  4413. }
  4414. /**
  4415. * Shows the needed forms for editing a specific item
  4416. *
  4417. * @param int $item_id
  4418. * @return string
  4419. */
  4420. function display_edit_item($item_id) {
  4421. global $_course; //will disappear
  4422. $return = '';
  4423. if (is_numeric($item_id)) {
  4424. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4425. $sql = "SELECT *
  4426. FROM " . $tbl_lp_item . "
  4427. WHERE id = " . Database :: escape_string($item_id);
  4428. $res = Database::query($sql, __FILE__, __LINE__);
  4429. $row = Database :: fetch_array($res);
  4430. switch ($row['item_type']) {
  4431. case 'dokeos_chapter' :
  4432. case 'dir' :
  4433. case 'asset' :
  4434. case 'sco' :
  4435. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4436. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4437. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', 'edit', $item_id, $row);
  4438. } else {
  4439. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', $row);
  4440. }
  4441. break;
  4442. case TOOL_DOCUMENT :
  4443. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4444. $sql_step = " SELECT lp.*, doc.path as dir
  4445. FROM " . $tbl_lp_item . " as lp
  4446. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4447. WHERE lp.id = " . Database :: escape_string($item_id);
  4448. $res_step = Database::query($sql_step, __FILE__, __LINE__);
  4449. $row_step = Database :: fetch_array($res_step);
  4450. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4451. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4452. break;
  4453. case TOOL_LINK :
  4454. $link_id = (string) $row['path'];
  4455. if (ctype_digit($link_id)) {
  4456. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4457. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4458. $res_link = Database::query($sql_select, __FILE__, __LINE__);
  4459. $row_link = Database :: fetch_array($res_link);
  4460. if (is_array($row_link)) {
  4461. $row['url'] = $row_link['url'];
  4462. }
  4463. }
  4464. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4465. $return .= $this->display_link_form('edit', $item_id, $row);
  4466. break;
  4467. case 'dokeos_module' :
  4468. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4469. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4470. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule") . ' :', 'edit', $item_id, $row);
  4471. } else {
  4472. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule") . ' :', $row);
  4473. }
  4474. break;
  4475. case TOOL_QUIZ :
  4476. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4477. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4478. break;
  4479. case TOOL_HOTPOTATOES :
  4480. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4481. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4482. break;
  4483. case TOOL_STUDENTPUBLICATION :
  4484. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4485. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4486. break;
  4487. case TOOL_FORUM :
  4488. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4489. $return .= $this->display_forum_form('edit', $item_id, $row);
  4490. break;
  4491. case TOOL_THREAD :
  4492. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4493. $return .= $this->display_thread_form('edit', $item_id, $row);
  4494. break;
  4495. }
  4496. }
  4497. return $return;
  4498. }
  4499. /**
  4500. * Function that displays a list with al the resources that could be added to the learning path
  4501. *
  4502. * @return string
  4503. */
  4504. function display_resources() {
  4505. global $_course; //TODO: don't use globals
  4506. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4507. $return .= '<div class="sectioncomment"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . '<img title="Nuevo documento" src="../img/new_doc.gif" alt="Nuevo documento"/> ' . get_lang("NewDocument") . '</a></div>'; //TODO: A hardcoded Spanish text is here.
  4508. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4509. $return .= '<div class="sectioncomment">';
  4510. /* get all the docs */
  4511. $return .= $this->get_documents();
  4512. /* get all the exercises */
  4513. $return .= $this->get_exercises();
  4514. /* get all the links */
  4515. $return .= $this->get_links();
  4516. /* get al the student publications */
  4517. $return .= $this->get_student_publications();
  4518. /* get al the forums */
  4519. $return .= $this->get_forums();
  4520. $return .= '</div>';
  4521. return $return;
  4522. }
  4523. /**
  4524. * Returns the extension of a document
  4525. *
  4526. * @param unknown_type $filename
  4527. * @return unknown
  4528. */
  4529. function get_extension($filename) {
  4530. $explode = explode('.', $filename);
  4531. return $explode[count($explode) - 1];
  4532. }
  4533. /**
  4534. * Displays a document by id
  4535. *
  4536. * @param unknown_type $id
  4537. * @return unknown
  4538. */
  4539. function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4540. global $_course; //temporary
  4541. $return = '';
  4542. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4543. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4544. WHERE id = " . $id;
  4545. $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
  4546. $row_doc = Database :: fetch_array($res_doc);
  4547. //if($show_title)
  4548. //$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>';
  4549. //TODO: add a path filter
  4550. if ($iframe) {
  4551. $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>';
  4552. } else {
  4553. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4554. }
  4555. return $return;
  4556. }
  4557. /**
  4558. * Return HTML form to add/edit a quiz
  4559. *
  4560. * @param string Action (add/edit)
  4561. * @param integer Item ID if already exists
  4562. * @param mixed Extra information (quiz ID if integer)
  4563. * @return string HTML form
  4564. */
  4565. function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4566. global $charset;
  4567. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4568. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4569. if ($id != 0 && is_array($extra_info)) {
  4570. $item_title = stripslashes($extra_info['title']);
  4571. $item_description = stripslashes($extra_info['description']);
  4572. }
  4573. elseif (is_numeric($extra_info)) {
  4574. $sql_quiz = "
  4575. SELECT
  4576. title,
  4577. description
  4578. FROM " . $tbl_quiz . "
  4579. WHERE id = " . $extra_info;
  4580. $result = Database::query($sql_quiz, __FILE__, __LINE__);
  4581. $row = Database :: fetch_array($result);
  4582. $item_title = $row['title'];
  4583. $item_description = $row['description'];
  4584. } else {
  4585. $item_title = '';
  4586. $item_description = '';
  4587. }
  4588. $return = ' <div class="row">
  4589. <div class="form_header">';
  4590. if ($id != 0 && is_array($extra_info))
  4591. $parent = $extra_info['parent_item_id'];
  4592. else
  4593. $parent = 0;
  4594. $sql = "
  4595. SELECT *
  4596. FROM " . $tbl_lp_item . "
  4597. WHERE
  4598. lp_id = " . $this->lp_id;
  4599. $result = Database::query($sql, __FILE__, __LINE__);
  4600. $arrLP = array ();
  4601. while ($row = Database :: fetch_array($result)) {
  4602. $arrLP[] = array (
  4603. 'id' => $row['id'],
  4604. 'item_type' => $row['item_type'],
  4605. 'title' => $row['title'],
  4606. 'path' => $row['path'],
  4607. 'description' => $row['description'],
  4608. 'parent_item_id' => $row['parent_item_id'],
  4609. 'previous_item_id' => $row['previous_item_id'],
  4610. 'next_item_id' => $row['next_item_id'],
  4611. 'display_order' => $row['display_order'],
  4612. 'max_score' => $row['max_score'],
  4613. 'min_score' => $row['min_score'],
  4614. 'mastery_score' => $row['mastery_score'],
  4615. 'prerequisite' => $row['prerequisite'],
  4616. 'max_time_allowed' => $row['max_time_allowed']
  4617. );
  4618. }
  4619. $this->tree_array($arrLP);
  4620. $arrLP = $this->arrMenu;
  4621. unset ($this->arrMenu);
  4622. if ($action == 'add')
  4623. $return .= get_lang("CreateTheExercise") . '&nbsp;:' . "\n";
  4624. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentExercise") . '&nbsp;:' . "\n";
  4625. else
  4626. $return .= get_lang("EditCurrentExecice") . '&nbsp;:' . "\n";
  4627. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4628. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4629. }
  4630. $return .= ' </div>
  4631. </div>';
  4632. $return .= '<div class="sectioncomment">';
  4633. $return .= '<form method="POST">' . "\n";
  4634. $return .= "\t" . '<table class="lp_form">' . "\n";
  4635. if ($action != 'move') {
  4636. $return .= "\t\t" . '<tr>' . "\n";
  4637. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4638. $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";
  4639. $return .= "\t\t" . '</tr>' . "\n";
  4640. }
  4641. $return .= "\t\t" . '<tr>' . "\n";
  4642. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4643. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4644. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4645. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4646. $arrHide = array (
  4647. $id
  4648. );
  4649. $parent_item_id = $_SESSION['parent_item_id'];
  4650. for ($i = 0; $i < count($arrLP); $i++) {
  4651. if ($action != 'add') {
  4652. 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)) {
  4653. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4654. } else {
  4655. $arrHide[] = $arrLP[$i]['id'];
  4656. }
  4657. } else {
  4658. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4659. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4660. }
  4661. }
  4662. if (is_array($arrLP)) {
  4663. reset($arrLP);
  4664. }
  4665. $return .= "\t\t\t\t" . '</select>';
  4666. $return .= "\t\t\t" . '</td>' . "\n";
  4667. $return .= "\t\t" . '</tr>' . "\n";
  4668. $return .= "\t\t" . '<tr>' . "\n";
  4669. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4670. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4671. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4672. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4673. for ($i = 0; $i < count($arrLP); $i++) {
  4674. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4675. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4676. $selected = 'selected="selected" ';
  4677. elseif ($action == 'add') $selected = 'selected="selected" ';
  4678. else
  4679. $selected = '';
  4680. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  4681. }
  4682. }
  4683. $return .= "\t\t\t\t" . '</select>';
  4684. $return .= "\t\t\t" . '</td>' . "\n";
  4685. $return .= "\t\t" . '</tr>' . "\n";
  4686. if ($action != 'move') {
  4687. $id_prerequisite = 0;
  4688. if (is_array($arrLP)) {
  4689. foreach ($arrLP as $key => $value) {
  4690. if ($value['id'] == $id) {
  4691. $id_prerequisite = $value['prerequisite'];
  4692. break;
  4693. }
  4694. }
  4695. }
  4696. $arrHide = array ();
  4697. for ($i = 0; $i < count($arrLP); $i++) {
  4698. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4699. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4700. $s_selected_position = $arrLP[$i]['id'];
  4701. elseif ($action == 'add') $s_selected_position = 0;
  4702. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4703. }
  4704. }
  4705. /*//comented the prerequisites, only visible in edit (exercise)
  4706. $return .= "\t\t" . '<tr>' . "\n";
  4707. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4708. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4709. foreach($arrHide as $key => $value){
  4710. if($key==$s_selected_position && $action == 'add'){
  4711. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4712. }
  4713. elseif($key==$id_prerequisite && $action == 'edit'){
  4714. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4715. }
  4716. else{
  4717. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4718. }
  4719. }
  4720. $return .= "</select></td>";
  4721. */
  4722. $return .= "\t\t" . '</tr>' . "\n";
  4723. /*$return .= "\t\t" . '<tr>' . "\n";
  4724. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4725. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4726. //Remove temporaly the test description
  4727. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4728. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4729. $return .= "\t\t" . '</tr>' . "\n"; */
  4730. }
  4731. $return .= "\t\t" . '<tr>' . "\n";
  4732. if ($action == 'add') {
  4733. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4734. } else {
  4735. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4736. }
  4737. $return .= "\t\t" . '</tr>' . "\n";
  4738. $return .= "\t" . '</table>' . "\n";
  4739. if ($action == 'move') {
  4740. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4741. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4742. }
  4743. if (is_numeric($extra_info)) {
  4744. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4745. }
  4746. elseif (is_array($extra_info)) {
  4747. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4748. }
  4749. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4750. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4751. $return .= '</form>' . "\n";
  4752. $return .= '</div>' . "\n";
  4753. return $return;
  4754. }
  4755. /**
  4756. * Addition of Hotpotatoes tests
  4757. * @param string Action
  4758. * @param integer Internal ID of the item
  4759. * @param mixed Extra information - can be an array with title and description indexes
  4760. * @return string HTML structure to display the hotpotatoes addition formular
  4761. */
  4762. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4763. global $charset;
  4764. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4765. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4766. if ($id != 0 && is_array($extra_info)) {
  4767. $item_title = stripslashes($extra_info['title']);
  4768. $item_description = stripslashes($extra_info['description']);
  4769. }
  4770. elseif (is_numeric($extra_info)) {
  4771. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4772. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4773. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4774. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4775. $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
  4776. $row = Database :: fetch_array($res_hot);
  4777. $item_title = $row['title'];
  4778. $item_description = $row['description'];
  4779. if (!empty ($row['comment'])) {
  4780. $item_title = $row['comment'];
  4781. }
  4782. } else {
  4783. $item_title = '';
  4784. $item_description = '';
  4785. }
  4786. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4787. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4788. $return = '<div style="margin:3px 12px;">';
  4789. if ($id != 0 && is_array($extra_info))
  4790. $parent = $extra_info['parent_item_id'];
  4791. else
  4792. $parent = 0;
  4793. $sql = "
  4794. SELECT *
  4795. FROM " . $tbl_lp_item . "
  4796. WHERE
  4797. lp_id = " . $this->lp_id;
  4798. $result = Database::query($sql, __FILE__, __LINE__);
  4799. $arrLP = array ();
  4800. while ($row = Database :: fetch_array($result)) {
  4801. $arrLP[] = array (
  4802. 'id' => $row['id'],
  4803. 'item_type' => $row['item_type'],
  4804. 'title' => $row['title'],
  4805. 'path' => $row['path'],
  4806. 'description' => $row['description'],
  4807. 'parent_item_id' => $row['parent_item_id'],
  4808. 'previous_item_id' => $row['previous_item_id'],
  4809. 'next_item_id' => $row['next_item_id'],
  4810. 'display_order' => $row['display_order'],
  4811. 'max_score' => $row['max_score'],
  4812. 'min_score' => $row['min_score'],
  4813. 'mastery_score' => $row['mastery_score'],
  4814. 'prerequisite' => $row['prerequisite'],
  4815. 'max_time_allowed' => $row['max_time_allowed']
  4816. );
  4817. }
  4818. $this->tree_array($arrLP);
  4819. $arrLP = $this->arrMenu;
  4820. unset ($this->arrMenu);
  4821. if ($action == 'add')
  4822. $return .= '<p class="lp_title">' . get_lang("CreateTheExercise") . '&nbsp;:</p>' . "\n";
  4823. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentExercise") . '&nbsp;:</p>' . "\n";
  4824. else
  4825. $return .= '<p class="lp_title">' . get_lang("EditCurrentExecice") . '&nbsp;:</p>' . "\n";
  4826. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4827. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4828. }
  4829. $return .= '<form method="POST">' . "\n";
  4830. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4831. $return .= "\t\t" . '<tr>' . "\n";
  4832. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . ' :</label></td>' . "\n";
  4833. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4834. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4835. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4836. $arrHide = array (
  4837. $id
  4838. );
  4839. if (count($arrLP) > 0) {
  4840. for ($i = 0; $i < count($arrLP); $i++) {
  4841. if ($action != 'add') {
  4842. 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)) {
  4843. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4844. } else {
  4845. $arrHide[] = $arrLP[$i]['id'];
  4846. }
  4847. } else {
  4848. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4849. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4850. }
  4851. }
  4852. reset($arrLP);
  4853. }
  4854. $return .= "\t\t\t\t" . '</select>';
  4855. $return .= "\t\t\t" . '</td>' . "\n";
  4856. $return .= "\t\t" . '</tr>' . "\n";
  4857. $return .= "\t\t" . '<tr>' . "\n";
  4858. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . ' :</label></td>' . "\n";
  4859. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4860. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4861. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4862. for ($i = 0; $i < count($arrLP); $i++) {
  4863. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4864. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4865. $selected = 'selected="selected" ';
  4866. elseif ($action == 'add') $selected = 'selected="selected" ';
  4867. else
  4868. $selected = '';
  4869. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  4870. }
  4871. }
  4872. $return .= "\t\t\t\t" . '</select>';
  4873. $return .= "\t\t\t" . '</td>' . "\n";
  4874. $return .= "\t\t" . '</tr>' . "\n";
  4875. if ($action != 'move') {
  4876. $return .= "\t\t" . '<tr>' . "\n";
  4877. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . ' :</label></td>' . "\n";
  4878. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4879. $return .= "\t\t" . '</tr>' . "\n";
  4880. $id_prerequisite = 0;
  4881. if (is_array($arrLP) && count($arrLP) > 0) {
  4882. foreach ($arrLP as $key => $value) {
  4883. if ($value['id'] == $id) {
  4884. $id_prerequisite = $value['prerequisite'];
  4885. break;
  4886. }
  4887. }
  4888. $arrHide = array ();
  4889. for ($i = 0; $i < count($arrLP); $i++) {
  4890. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4891. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4892. $s_selected_position = $arrLP[$i]['id'];
  4893. elseif ($action == 'add') $s_selected_position = 0;
  4894. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4895. }
  4896. }
  4897. }
  4898. $return .= "\t\t" . '<tr>' . "\n";
  4899. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4900. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4901. foreach ($arrHide as $key => $value) {
  4902. if ($key == $s_selected_position && $action == 'add') {
  4903. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4904. }
  4905. elseif ($key == $id_prerequisite && $action == 'edit') {
  4906. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4907. } else {
  4908. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  4909. }
  4910. }
  4911. $return .= "</select></td>";
  4912. $return .= "\t\t" . '</tr>' . "\n";
  4913. $return .= "\t\t" . '<tr>' . "\n";
  4914. //Remove temporaly the test description
  4915. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4916. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4917. $return .= "\t\t" . '</tr>' . "\n";
  4918. }
  4919. $return .= "\t\t" . '<tr>' . "\n";
  4920. $return .= "\t\t\t" . '<td> &nbsp;</td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>' . "\n";
  4921. $return .= "\t\t" . '</tr>' . "\n";
  4922. $return .= "\t" . '</table>' . "\n";
  4923. if ($action == 'move') {
  4924. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4925. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4926. }
  4927. if (is_numeric($extra_info)) {
  4928. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4929. }
  4930. elseif (is_array($extra_info)) {
  4931. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4932. }
  4933. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  4934. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4935. $return .= '</form>' . "\n";
  4936. $return .= '</div>' . "\n";
  4937. return $return;
  4938. }
  4939. //fin du hotpot form
  4940. /**
  4941. * Return the form to display the forum edit/add option
  4942. *
  4943. * @param string Action (add/edit)
  4944. * @param integer ID of the lp_item if already exists
  4945. * @param mixed Forum ID or title
  4946. * @return string HTML form
  4947. */
  4948. function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  4949. global $charset;
  4950. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4951. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  4952. if ($id != 0 && is_array($extra_info)) {
  4953. $item_title = stripslashes($extra_info['title']);
  4954. }
  4955. elseif (is_numeric($extra_info)) {
  4956. $sql_forum = "
  4957. SELECT
  4958. forum_title as title, forum_comment as comment
  4959. FROM " . $tbl_forum . "
  4960. WHERE forum_id = " . $extra_info;
  4961. $result = Database::query($sql_forum, __FILE__, __LINE__);
  4962. $row = Database :: fetch_array($result);
  4963. $item_title = $row['title'];
  4964. $item_description = $row['comment'];
  4965. } else {
  4966. $item_title = '';
  4967. $item_description = '';
  4968. }
  4969. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4970. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4971. $return = ' <div class="row">
  4972. <div class="form_header">';
  4973. if ($id != 0 && is_array($extra_info))
  4974. $parent = $extra_info['parent_item_id'];
  4975. else
  4976. $parent = 0;
  4977. $sql = "
  4978. SELECT *
  4979. FROM " . $tbl_lp_item . "
  4980. WHERE
  4981. lp_id = " . $this->lp_id;
  4982. $result = Database::query($sql, __FILE__, __LINE__);
  4983. $arrLP = array ();
  4984. while ($row = Database :: fetch_array($result)) {
  4985. $arrLP[] = array (
  4986. 'id' => $row['id'],
  4987. 'item_type' => $row['item_type'],
  4988. 'title' => $row['title'],
  4989. 'path' => $row['path'],
  4990. 'description' => $row['description'],
  4991. 'parent_item_id' => $row['parent_item_id'],
  4992. 'previous_item_id' => $row['previous_item_id'],
  4993. 'next_item_id' => $row['next_item_id'],
  4994. 'display_order' => $row['display_order'],
  4995. 'max_score' => $row['max_score'],
  4996. 'min_score' => $row['min_score'],
  4997. 'mastery_score' => $row['mastery_score'],
  4998. 'prerequisite' => $row['prerequisite']
  4999. );
  5000. }
  5001. $this->tree_array($arrLP);
  5002. $arrLP = $this->arrMenu;
  5003. unset ($this->arrMenu);
  5004. if ($action == 'add')
  5005. $return .= get_lang("CreateTheForum") . '&nbsp;:' . "\n";
  5006. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentForum") . '&nbsp;:' . "\n";
  5007. else
  5008. $return .= get_lang("EditCurrentForum") . '&nbsp;:' . "\n";
  5009. $return .= ' </div>
  5010. </div>';
  5011. $return .= '<div class="sectioncomment">';
  5012. $return .= '<form method="POST">' . "\n";
  5013. $return .= "\t" . '<table class="lp_form">' . "\n";
  5014. if ($action != 'move') {
  5015. $return .= "\t\t" . '<tr>' . "\n";
  5016. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5017. $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";
  5018. $return .= "\t\t" . '</tr>' . "\n";
  5019. }
  5020. $return .= "\t\t" . '<tr>' . "\n";
  5021. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5022. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5023. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5024. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5025. $arrHide = array (
  5026. $id
  5027. );
  5028. $parent_item_id = $_SESSION['parent_item_id'];
  5029. for ($i = 0; $i < count($arrLP); $i++) {
  5030. if ($action != 'add') {
  5031. 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)) {
  5032. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5033. } else {
  5034. $arrHide[] = $arrLP[$i]['id'];
  5035. }
  5036. } else {
  5037. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5038. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5039. }
  5040. }
  5041. if (is_array($arrLP)) {
  5042. reset($arrLP);
  5043. }
  5044. $return .= "\t\t\t\t" . '</select>';
  5045. $return .= "\t\t\t" . '</td>' . "\n";
  5046. $return .= "\t\t" . '</tr>' . "\n";
  5047. $return .= "\t\t" . '<tr>' . "\n";
  5048. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5049. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5050. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5051. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5052. for ($i = 0; $i < count($arrLP); $i++) {
  5053. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5054. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5055. $selected = 'selected="selected" ';
  5056. elseif ($action == 'add') $selected = 'selected="selected" ';
  5057. else
  5058. $selected = '';
  5059. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5060. }
  5061. }
  5062. $return .= "\t\t\t\t" . '</select>';
  5063. $return .= "\t\t\t" . '</td>' . "\n";
  5064. $return .= "\t\t" . '</tr>' . "\n";
  5065. if ($action != 'move') {
  5066. $return .= "\t\t" . '<tr>' . "\n";
  5067. //Remove temporaly the test description
  5068. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5069. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5070. $return .= "\t\t" . '</tr>' . "\n";
  5071. $id_prerequisite = 0;
  5072. if (is_array($arrLP)) {
  5073. foreach ($arrLP as $key => $value) {
  5074. if ($value['id'] == $id) {
  5075. $id_prerequisite = $value['prerequisite'];
  5076. break;
  5077. }
  5078. }
  5079. }
  5080. $arrHide = array ();
  5081. for ($i = 0; $i < count($arrLP); $i++) {
  5082. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5083. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5084. $s_selected_position = $arrLP[$i]['id'];
  5085. elseif ($action == 'add') $s_selected_position = 0;
  5086. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5087. }
  5088. }
  5089. /* //comented the prerequisites, only visible in edit (forum)
  5090. $return .= "\t\t" . '<tr>' . "\n";
  5091. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5092. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5093. foreach($arrHide as $key => $value) {
  5094. if($key==$s_selected_position && $action == 'add') {
  5095. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5096. }elseif($key==$id_prerequisite && $action == 'edit') {
  5097. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5098. } else {
  5099. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5100. }
  5101. }
  5102. $return .= "</select></td>";
  5103. */
  5104. $return .= "\t\t" . '</tr>' . "\n";
  5105. }
  5106. $return .= "\t\t" . '<tr>' . "\n";
  5107. if ($action == 'add') {
  5108. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5109. } else {
  5110. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5111. }
  5112. $return .= "\t\t" . '</tr>' . "\n";
  5113. $return .= "\t" . '</table>' . "\n";
  5114. if ($action == 'move') {
  5115. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5116. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5117. }
  5118. if (is_numeric($extra_info)) {
  5119. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5120. }
  5121. elseif (is_array($extra_info)) {
  5122. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5123. }
  5124. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5125. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5126. $return .= '</form>' . "\n";
  5127. $return .= '</div>' . "\n";
  5128. return $return;
  5129. }
  5130. /**
  5131. * Return HTML form to add/edit forum threads
  5132. * @param string Action (add/edit)
  5133. * @param integer Item ID if already exists in learning path
  5134. * @param mixed Extra information (thread ID if integer)
  5135. * @return string HTML form
  5136. */
  5137. function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5138. global $charset;
  5139. echo '
  5140. <style>
  5141. div.row div.label {
  5142. width:110px;
  5143. }
  5144. div.row div.formw {
  5145. width: 82%;
  5146. }
  5147. </style>';
  5148. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5149. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5150. if ($id != 0 && is_array($extra_info)) {
  5151. $item_title = stripslashes($extra_info['title']);
  5152. }
  5153. elseif (is_numeric($extra_info)) {
  5154. $sql_forum = "
  5155. SELECT
  5156. thread_title as title
  5157. FROM " . $tbl_forum . "
  5158. WHERE thread_id = " . $extra_info;
  5159. $result = Database::query($sql_forum, __FILE__, __LINE__);
  5160. $row = Database :: fetch_array($result);
  5161. $item_title = $row['title'];
  5162. $item_description = '';
  5163. } else {
  5164. $item_title = '';
  5165. $item_description = '';
  5166. }
  5167. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5168. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5169. $return = '<div style="margin:3px 12px;">';
  5170. if ($id != 0 && is_array($extra_info))
  5171. $parent = $extra_info['parent_item_id'];
  5172. else
  5173. $parent = 0;
  5174. $sql = "
  5175. SELECT *
  5176. FROM " . $tbl_lp_item . "
  5177. WHERE
  5178. lp_id = " . $this->lp_id;
  5179. $result = Database::query($sql, __FILE__, __LINE__);
  5180. $arrLP = array ();
  5181. while ($row = Database :: fetch_array($result)) {
  5182. $arrLP[] = array (
  5183. 'id' => $row['id'],
  5184. 'item_type' => $row['item_type'],
  5185. 'title' => $row['title'],
  5186. 'path' => $row['path'],
  5187. 'description' => $row['description'],
  5188. 'parent_item_id' => $row['parent_item_id'],
  5189. 'previous_item_id' => $row['previous_item_id'],
  5190. 'next_item_id' => $row['next_item_id'],
  5191. 'display_order' => $row['display_order'],
  5192. 'max_score' => $row['max_score'],
  5193. 'min_score' => $row['min_score'],
  5194. 'mastery_score' => $row['mastery_score'],
  5195. 'prerequisite' => $row['prerequisite']
  5196. );
  5197. }
  5198. $this->tree_array($arrLP);
  5199. $arrLP = $this->arrMenu;
  5200. unset ($this->arrMenu);
  5201. if ($action == 'add')
  5202. $return .= '<p class="lp_title">' . get_lang("CreateTheForum") . '&nbsp;:</p>' . "\n";
  5203. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentForum") . '&nbsp;:</p>' . "\n";
  5204. else
  5205. $return .= '<p class="lp_title">' . get_lang("EditCurrentForum") . '&nbsp;:</p>' . "\n";
  5206. $return .= '<form method="POST">' . "\n";
  5207. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5208. $return .= "\t\t" . '<tr>' . "\n";
  5209. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . '&nbsp;:</label></td>' . "\n";
  5210. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5211. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5212. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5213. $arrHide = array (
  5214. $id
  5215. );
  5216. for ($i = 0; $i < count($arrLP); $i++) {
  5217. if ($action != 'add') {
  5218. 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)) {
  5219. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5220. } else {
  5221. $arrHide[] = $arrLP[$i]['id'];
  5222. }
  5223. } else {
  5224. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5225. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5226. }
  5227. }
  5228. if ($arrLP != null) {
  5229. reset($arrLP);
  5230. }
  5231. $return .= "\t\t\t\t" . '</select>';
  5232. $return .= "\t\t\t" . '</td>' . "\n";
  5233. $return .= "\t\t" . '</tr>' . "\n";
  5234. $return .= "\t\t" . '<tr>' . "\n";
  5235. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . '&nbsp;:</label></td>' . "\n";
  5236. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5237. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5238. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5239. for ($i = 0; $i < count($arrLP); $i++) {
  5240. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5241. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5242. $selected = 'selected="selected" ';
  5243. elseif ($action == 'add') $selected = 'selected="selected" ';
  5244. else
  5245. $selected = '';
  5246. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5247. }
  5248. }
  5249. $return .= "\t\t\t\t" . '</select>';
  5250. $return .= "\t\t\t" . '</td>' . "\n";
  5251. $return .= "\t\t" . '</tr>' . "\n";
  5252. if ($action != 'move') {
  5253. $return .= "\t\t" . '<tr>' . "\n";
  5254. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . '&nbsp;:</label></td>' . "\n";
  5255. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5256. $return .= "\t\t" . '</tr>' . "\n";
  5257. $return .= "\t\t" . '<tr>' . "\n";
  5258. //Remove temporaly the test description
  5259. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5260. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5261. $return .= "\t\t" . '</tr>' . "\n";
  5262. $id_prerequisite = 0;
  5263. if ($arrLP != null) {
  5264. foreach ($arrLP as $key => $value) {
  5265. if ($value['id'] == $id) {
  5266. $id_prerequisite = $value['prerequisite'];
  5267. break;
  5268. }
  5269. }
  5270. }
  5271. $arrHide = array ();
  5272. for ($i = 0; $i < count($arrLP); $i++) {
  5273. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5274. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5275. $s_selected_position = $arrLP[$i]['id'];
  5276. elseif ($action == 'add') $s_selected_position = 0;
  5277. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5278. }
  5279. }
  5280. $return .= "\t\t" . '<tr>' . "\n";
  5281. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang("Prerequisites") . '&nbsp;:</label></td>' . "\n";
  5282. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang("NoPrerequisites") . '</option>';
  5283. foreach ($arrHide as $key => $value) {
  5284. if ($key == $s_selected_position && $action == 'add') {
  5285. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5286. }
  5287. elseif ($key == $id_prerequisite && $action == 'edit') {
  5288. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5289. } else {
  5290. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5291. }
  5292. }
  5293. $return .= "</select></td>";
  5294. $return .= "\t\t" . '</tr>' . "\n";
  5295. }
  5296. $return .= "\t\t" . '<tr>' . "\n";
  5297. $return .= "\t\t\t" . '<td colspan="2">
  5298. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5299. $return .= "\t\t" . '</tr>' . "\n";
  5300. $return .= "\t" . '</table>' . "\n";
  5301. if ($action == 'move') {
  5302. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5303. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5304. }
  5305. if (is_numeric($extra_info)) {
  5306. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5307. }
  5308. elseif (is_array($extra_info)) {
  5309. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5310. }
  5311. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5312. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5313. $return .= '</form>' . "\n";
  5314. $return .= '</div>' . "\n";
  5315. return $return;
  5316. }
  5317. /**
  5318. * Return the HTML form to display an item (generally a section/module item)
  5319. *
  5320. * @param string Item type (module/dokeos_module)
  5321. * @param string Title (optional, only when creating)
  5322. * @param string Action ('add'/'edit')
  5323. * @param integer lp_item ID
  5324. * @param mixed Extra info
  5325. * @return string HTML form
  5326. */
  5327. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5328. global $_course;
  5329. global $charset;
  5330. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5331. if ($id != 0 && is_array($extra_info)) {
  5332. $item_title = $extra_info['title'];
  5333. $item_description = $extra_info['description'];
  5334. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5335. } else {
  5336. $item_title = '';
  5337. $item_description = '';
  5338. }
  5339. $return = ' <div class="row">
  5340. <div class="form_header">';
  5341. if ($id != 0 && is_array($extra_info))
  5342. $parent = $extra_info['parent_item_id'];
  5343. else
  5344. $parent = 0;
  5345. $sql = "
  5346. SELECT *
  5347. FROM " . $tbl_lp_item . "
  5348. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5349. if ($item_type == 'module')
  5350. $sql .= " AND parent_item_id = 0";
  5351. $result = Database::query($sql, __FILE__, __LINE__);
  5352. $arrLP = array ();
  5353. while ($row = Database :: fetch_array($result)) {
  5354. $arrLP[] = array (
  5355. 'id' => $row['id'],
  5356. 'item_type' => $row['item_type'],
  5357. 'title' => $row['title'],
  5358. 'path' => $row['path'],
  5359. 'description' => $row['description'],
  5360. 'parent_item_id' => $row['parent_item_id'],
  5361. 'previous_item_id' => $row['previous_item_id'],
  5362. 'next_item_id' => $row['next_item_id'],
  5363. 'max_score' => $row['max_score'],
  5364. 'min_score' => $row['min_score'],
  5365. 'mastery_score' => $row['mastery_score'],
  5366. 'prerequisite' => $row['prerequisite'],
  5367. 'display_order' => $row['display_order']
  5368. );
  5369. }
  5370. $this->tree_array($arrLP);
  5371. $arrLP = $this->arrMenu;
  5372. unset ($this->arrMenu);
  5373. $return .= $title . "\n";
  5374. $return .= ' </div>
  5375. </div>';
  5376. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5377. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"]);
  5378. //$defaults["title"] = api_convert_encoding($item_title, $charset, $this->encoding);
  5379. $defaults["title"] = api_html_entity_decode(api_convert_encoding($item_title, $charset, $this->encoding), ENT_QUOTES, $charset);
  5380. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5381. $form->addElement('html', $return);
  5382. //$arrHide = array($id);
  5383. $arrHide[0]['value'] = Security :: remove_XSS(api_convert_encoding($this->name, api_get_system_encoding(), $_SESSION['oLP']->encoding));
  5384. $arrHide[0]['padding'] = 3;
  5385. $charset = api_get_system_encoding();
  5386. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5387. for ($i = 0; $i < count($arrLP); $i++) {
  5388. if ($action != 'add') {
  5389. 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)) {
  5390. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5391. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5392. if ($parent == $arrLP[$i]['id']) {
  5393. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5394. }
  5395. }
  5396. } else {
  5397. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5398. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5399. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5400. if ($parent == $arrLP[$i]['id']) {
  5401. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5402. }
  5403. }
  5404. }
  5405. }
  5406. if ($action != 'move') {
  5407. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5408. $form->applyFilter('title', 'html_filter');
  5409. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5410. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5411. } else {
  5412. $form->addElement('hidden', 'title');
  5413. }
  5414. $parent_select = & $form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
  5415. foreach ($arrHide as $key => $value) {
  5416. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5417. }
  5418. $parent_select->setSelected($s_selected_parent);
  5419. }
  5420. if (is_array($arrLP)) {
  5421. reset($arrLP);
  5422. }
  5423. $arrHide = array ();
  5424. //POSITION
  5425. for ($i = 0; $i < count($arrLP); $i++) {
  5426. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5427. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5428. $s_selected_position = $arrLP[$i]['id'];
  5429. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5430. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5431. }
  5432. }
  5433. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5434. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5435. foreach ($arrHide as $key => $value) {
  5436. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5437. }
  5438. if (!empty ($s_selected_position)) {
  5439. $position->setSelected($s_selected_position);
  5440. }
  5441. if (is_array($arrLP)) {
  5442. reset($arrLP);
  5443. }
  5444. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5445. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5446. $form->addElement('hidden', 'parent', '0');
  5447. }
  5448. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5449. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5450. if ($item_type == 'sco') {
  5451. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5452. }
  5453. $renderer = $form->defaultRenderer();
  5454. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5455. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5456. $defaults["content_lp"] = file_get_contents($item_path);
  5457. }
  5458. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5459. $form->addElement('hidden', 'post_time', time());
  5460. $form->setDefaults($defaults);
  5461. return $form->return_form();
  5462. }
  5463. /**
  5464. * Returns the form to update or create a document
  5465. *
  5466. * @param string Action (add/edit)
  5467. * @param integer ID of the lp_item (if already exists)
  5468. * @param mixed Integer if document ID, string if info ('new')
  5469. * @return string HTML form
  5470. */
  5471. function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5472. global $charset;
  5473. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5474. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5475. $path_parts = pathinfo($extra_info['dir']);
  5476. $no_display_edit_textarea = false;
  5477. //If action==edit document
  5478. //We don't display the document form if it's not an editable document (html or txt file)
  5479. if ($action == "edit") {
  5480. if (is_array($extra_info)) {
  5481. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5482. $no_display_edit_textarea = true;
  5483. }
  5484. }
  5485. }
  5486. $no_display_add = false;
  5487. //If action==add an existing document
  5488. //We don't display the document form if it's not an editable document (html or txt file)
  5489. if ($action == "add") {
  5490. if (is_numeric($extra_info)) {
  5491. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5492. $result = Database::query($sql_doc, __FILE__, __LINE__);
  5493. $path_file = Database :: result($result, 0, 0);
  5494. $path_parts = pathinfo($path_file);
  5495. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5496. $no_display_add = true;
  5497. }
  5498. }
  5499. }
  5500. if ($id != 0 && is_array($extra_info)) {
  5501. $item_title = stripslashes($extra_info['title']);
  5502. $item_description = stripslashes($extra_info['description']);
  5503. $item_terms = stripslashes($extra_info['terms']);
  5504. if (empty ($item_title)) {
  5505. $path_parts = pathinfo($extra_info['path']);
  5506. $item_title = stripslashes($path_parts['filename']);
  5507. }
  5508. }
  5509. elseif (is_numeric($extra_info)) {
  5510. $sql_doc = "SELECT path, title
  5511. FROM " . $tbl_doc . "
  5512. WHERE id = " . Database :: escape_string($extra_info);
  5513. $result = Database::query($sql_doc, __FILE__, __LINE__);
  5514. $row = Database :: fetch_array($result);
  5515. $explode = explode('.', $row['title']);
  5516. if (count($explode) > 1) {
  5517. for ($i = 0; $i < count($explode) - 1; $i++)
  5518. $item_title .= $explode[$i];
  5519. } else {
  5520. $item_title = $row['title'];
  5521. }
  5522. $item_title = str_replace('_', ' ', $item_title);
  5523. if (empty ($item_title)) {
  5524. $path_parts = pathinfo($row['path']);
  5525. $item_title = stripslashes($path_parts['filename']);
  5526. }
  5527. } else {
  5528. $item_title = '';
  5529. $item_description = '';
  5530. }
  5531. $return = ' <div class="row">
  5532. <div class="form_header">';
  5533. if ($id != 0 && is_array($extra_info))
  5534. $parent = $extra_info['parent_item_id'];
  5535. else
  5536. $parent = 0;
  5537. $sql = "
  5538. SELECT *
  5539. FROM " . $tbl_lp_item . "
  5540. WHERE
  5541. lp_id = " . $this->lp_id;
  5542. $result = Database::query($sql, __FILE__, __LINE__);
  5543. $arrLP = array ();
  5544. while ($row = Database :: fetch_array($result)) {
  5545. $arrLP[] = array (
  5546. 'id' => $row['id'],
  5547. 'item_type' => $row['item_type'],
  5548. 'title' => $row['title'],
  5549. 'path' => $row['path'],
  5550. 'description' => $row['description'],
  5551. 'parent_item_id' => $row['parent_item_id'],
  5552. 'previous_item_id' => $row['previous_item_id'],
  5553. 'next_item_id' => $row['next_item_id'],
  5554. 'display_order' => $row['display_order'],
  5555. 'max_score' => $row['max_score'],
  5556. 'min_score' => $row['min_score'],
  5557. 'mastery_score' => $row['mastery_score'],
  5558. 'prerequisite' => $row['prerequisite']
  5559. );
  5560. }
  5561. $this->tree_array($arrLP);
  5562. $arrLP = $this->arrMenu;
  5563. unset ($this->arrMenu);
  5564. if ($action == 'add') {
  5565. $return .= get_lang("CreateTheDocument") . "\n";
  5566. }
  5567. elseif ($action == 'move') {
  5568. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5569. } else {
  5570. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5571. }
  5572. $return .= ' </div>
  5573. </div>';
  5574. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5575. $return .= Display :: return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
  5576. }
  5577. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5578. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
  5579. $defaults["title"] = Security :: remove_XSS(api_convert_encoding($item_title, api_get_system_encoding() ,$this->encoding));
  5580. if (empty ($item_title)) {
  5581. $defaults["title"] = Security :: remove_XSS($item_title);
  5582. }
  5583. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5584. $form->addElement('html', $return);
  5585. if ($action != 'move') {
  5586. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5587. $form->applyFilter('title', 'html_filter');
  5588. }
  5589. //$arrHide = array($id);
  5590. $arrHide[0]['value'] = $this->name;
  5591. $arrHide[0]['padding'] = 3;
  5592. for ($i = 0; $i < count($arrLP); $i++) {
  5593. if ($action != 'add') {
  5594. 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)) {
  5595. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5596. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5597. if ($parent == $arrLP[$i]['id']) {
  5598. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5599. }
  5600. }
  5601. } else {
  5602. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5603. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5604. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5605. if ($parent == $arrLP[$i]['id']) {
  5606. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5607. }
  5608. }
  5609. }
  5610. }
  5611. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
  5612. $my_count=0;
  5613. foreach ($arrHide as $key => $value) {
  5614. if ($my_count!=0) {
  5615. // the LP name is also the first section and is not in the same charset like the other sections
  5616. $value['value'] = Security :: remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
  5617. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5618. } else {
  5619. $value['value'] = Security :: remove_XSS($value['value']);
  5620. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5621. }
  5622. $my_count++;
  5623. }
  5624. if (!empty ($id)) {
  5625. $parent_select->setSelected($parent);
  5626. } else {
  5627. $parent_item_id = $_SESSION['parent_item_id'];
  5628. $parent_select->setSelected($parent_item_id);
  5629. }
  5630. if (is_array($arrLP)) {
  5631. reset($arrLP);
  5632. }
  5633. $arrHide = array ();
  5634. //POSITION
  5635. for ($i = 0; $i < count($arrLP); $i++) {
  5636. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5637. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5638. $s_selected_position = $arrLP[$i]['id'];
  5639. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5640. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
  5641. }
  5642. }
  5643. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5644. $position->addOption(get_lang("FirstPosition"), 0);
  5645. foreach ($arrHide as $key => $value) {
  5646. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5647. }
  5648. $position->setSelected($s_selected_position);
  5649. if (is_array($arrLP)) {
  5650. reset($arrLP);
  5651. }
  5652. if ($action != 'move') {
  5653. $id_prerequisite = 0;
  5654. if (is_array($arrLP)) {
  5655. foreach ($arrLP as $key => $value) {
  5656. if ($value['id'] == $id) {
  5657. $id_prerequisite = $value['prerequisite'];
  5658. break;
  5659. }
  5660. }
  5661. }
  5662. //comented the prerequisites, only visible in edit (new document)
  5663. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5664. //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5665. // form element for uploading an mp3 file
  5666. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5667. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5668. /* Code deprecated - moved to lp level (not lp-item)
  5669. if ( api_get_setting('search_enabled') === 'true' )
  5670. {
  5671. //add terms field
  5672. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5673. $terms->setValue($item_terms);
  5674. }
  5675. */
  5676. $arrHide = array ();
  5677. for ($i = 0; $i < count($arrLP); $i++) {
  5678. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5679. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5680. $s_selected_position = $arrLP[$i]['id'];
  5681. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5682. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5683. }
  5684. }
  5685. /* foreach($arrHide as $key => $value){
  5686. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5687. if($key==$s_selected_position && $action == 'add'){
  5688. $select_prerequisites -> setSelected(0);
  5689. }
  5690. elseif($key==$id_prerequisite && $action == 'edit'){
  5691. $select_prerequisites -> setSelected($id_prerequisite);
  5692. }
  5693. }
  5694. */
  5695. if (!$no_display_add) {
  5696. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5697. if (isset ($_POST['content']))
  5698. $content = stripslashes($_POST['content']);
  5699. elseif (is_array($extra_info)) {
  5700. //If it's an html document or a text file
  5701. if (!$no_display_edit_textarea) {
  5702. $content = $this->display_document($extra_info['path'], false, false);
  5703. }
  5704. }
  5705. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5706. else
  5707. $content = '';
  5708. if (!$no_display_edit_textarea) {
  5709. // We need to claculate here some specific settings for the online editor.
  5710. // The calculated settings work for documents in the Documents tool
  5711. // (on the root or in subfolders).
  5712. // For documents in native scorm packages it is unclear whether the
  5713. // online editor should be activated or not.
  5714. $relative_path = $extra_info['dir'];
  5715. if ($relative_path == 'n/') {
  5716. // A new document, it is in the root of the repository.
  5717. $relative_path = '';
  5718. $relative_prefix = '';
  5719. } else {
  5720. // The document already exists. Whe have to determine its relative path towards the repository root.
  5721. $relative_path = explode('/', $relative_path);
  5722. $cnt = count($relative_path) - 2;
  5723. if ($cnt < 0) {
  5724. $cnt = 0;
  5725. }
  5726. $relative_prefix = str_repeat('../', $cnt);
  5727. $relative_path = array_slice($relative_path, 1, $cnt);
  5728. $relative_path = implode('/', $relative_path);
  5729. if (strlen($relative_path) > 0) {
  5730. $relative_path = $relative_path . '/';
  5731. }
  5732. }
  5733. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5734. 'CreateDocumentDir' => $relative_prefix,
  5735. 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/',
  5736. 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path
  5737. );
  5738. if ($_GET['action'] == 'add_item') {
  5739. $class = 'add';
  5740. $text = get_lang('LPCreateDocument');
  5741. } else
  5742. if ($_GET['action'] == 'edit_item') {
  5743. $class = 'save';
  5744. $text = get_lang('SaveDocument');
  5745. }
  5746. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5747. $renderer = $form->defaultRenderer();
  5748. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5749. $form->addElement('html', '<div style="margin:3px 12px">');
  5750. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5751. $form->addElement('html', '</div>');
  5752. $defaults["content_lp"] = $content;
  5753. }
  5754. }
  5755. elseif (is_numeric($extra_info)) {
  5756. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5757. $return = $this->display_document($extra_info, true, true, true);
  5758. $form->addElement('html', $return);
  5759. }
  5760. }
  5761. }
  5762. if ($action == 'move') {
  5763. $form->addElement('hidden', 'title', $item_title);
  5764. $form->addElement('hidden', 'description', $item_description);
  5765. }
  5766. if (is_numeric($extra_info)) {
  5767. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5768. $form->addElement('hidden', 'path', $extra_info);
  5769. }
  5770. elseif (is_array($extra_info)) {
  5771. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5772. $form->addElement('hidden', 'path', $extra_info['path']);
  5773. }
  5774. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5775. $form->addElement('hidden', 'post_time', time());
  5776. $form->setDefaults($defaults);
  5777. return $form->return_form();
  5778. }
  5779. /**
  5780. * Return HTML form to add/edit a link item
  5781. *
  5782. * @param string Action (add/edit)
  5783. * @param integer Item ID if exists
  5784. * @param mixed Extra info
  5785. * @return string HTML form
  5786. */
  5787. function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5788. global $charset;
  5789. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5790. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5791. if ($id != 0 && is_array($extra_info)) {
  5792. $item_title = stripslashes($extra_info['title']);
  5793. $item_description = stripslashes($extra_info['description']);
  5794. $item_url = stripslashes($extra_info['url']);
  5795. }
  5796. elseif (is_numeric($extra_info)) {
  5797. $sql_link = "
  5798. SELECT
  5799. title,
  5800. description,
  5801. url
  5802. FROM " . $tbl_link . "
  5803. WHERE id = " . $extra_info;
  5804. $result = Database::query($sql_link, __FILE__, __LINE__);
  5805. $row = Database :: fetch_array($result);
  5806. $item_title = $row['title'];
  5807. $item_description = $row['description'];
  5808. $item_url = $row['url'];
  5809. } else {
  5810. $item_title = '';
  5811. $item_description = '';
  5812. $item_url = '';
  5813. }
  5814. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5815. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5816. $return = ' <div class="row">
  5817. <div class="form_header">';
  5818. if ($id != 0 && is_array($extra_info))
  5819. $parent = $extra_info['parent_item_id'];
  5820. else
  5821. $parent = 0;
  5822. $sql = "
  5823. SELECT *
  5824. FROM " . $tbl_lp_item . "
  5825. WHERE
  5826. lp_id = " . $this->lp_id;
  5827. $result = Database::query($sql, __FILE__, __LINE__);
  5828. $arrLP = array ();
  5829. while ($row = Database :: fetch_array($result)) {
  5830. $arrLP[] = array (
  5831. 'id' => $row['id'],
  5832. 'item_type' => $row['item_type'],
  5833. 'title' => $row['title'],
  5834. 'path' => $row['path'],
  5835. 'description' => $row['description'],
  5836. 'parent_item_id' => $row['parent_item_id'],
  5837. 'previous_item_id' => $row['previous_item_id'],
  5838. 'next_item_id' => $row['next_item_id'],
  5839. 'display_order' => $row['display_order'],
  5840. 'max_score' => $row['max_score'],
  5841. 'min_score' => $row['min_score'],
  5842. 'mastery_score' => $row['mastery_score'],
  5843. 'prerequisite' => $row['prerequisite']
  5844. );
  5845. }
  5846. $this->tree_array($arrLP);
  5847. $arrLP = $this->arrMenu;
  5848. unset ($this->arrMenu);
  5849. if ($action == 'add')
  5850. $return .= get_lang("CreateTheLink") . '&nbsp;:' . "\n";
  5851. elseif ($action == 'move') $return .= get_lang("MoveCurrentLink") . '&nbsp;:' . "\n";
  5852. else
  5853. $return .= get_lang("EditCurrentLink") . '&nbsp;:' . "\n";
  5854. $return .= ' </div>
  5855. </div>';
  5856. $return .= '<div class="sectioncomment">';
  5857. $return .= '<form method="POST">' . "\n";
  5858. $return .= "\t" . '<table>' . "\n";
  5859. if ($action != 'move') {
  5860. $return .= "\t\t" . '<tr>' . "\n";
  5861. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5862. $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";
  5863. $return .= "\t\t" . '</tr>' . "\n";
  5864. }
  5865. $return .= "\t\t" . '<tr>' . "\n";
  5866. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5867. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5868. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5869. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5870. $arrHide = array (
  5871. $id
  5872. );
  5873. $parent_item_id = $_SESSION['parent_item_id'];
  5874. for ($i = 0; $i < count($arrLP); $i++) {
  5875. if ($action != 'add') {
  5876. 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)) {
  5877. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5878. } else {
  5879. $arrHide[] = $arrLP[$i]['id'];
  5880. }
  5881. } else {
  5882. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5883. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  5884. }
  5885. }
  5886. if (is_array($arrLP)) {
  5887. reset($arrLP);
  5888. }
  5889. $return .= "\t\t\t\t" . '</select>';
  5890. $return .= "\t\t\t" . '</td>' . "\n";
  5891. $return .= "\t\t" . '</tr>' . "\n";
  5892. $return .= "\t\t" . '<tr>' . "\n";
  5893. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5894. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5895. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5896. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  5897. for ($i = 0; $i < count($arrLP); $i++) {
  5898. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5899. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5900. $selected = 'selected="selected" ';
  5901. elseif ($action == 'add') $selected = 'selected="selected" ';
  5902. else
  5903. $selected = '';
  5904. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  5905. }
  5906. }
  5907. $return .= "\t\t\t\t" . '</select>';
  5908. $return .= "\t\t\t" . '</td>' . "\n";
  5909. $return .= "\t\t" . '</tr>' . "\n";
  5910. if ($action != 'move') {
  5911. //Description filed is commentd for link
  5912. /*$return .= "\t\t" . '<tr>' . "\n";
  5913. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
  5914. $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";
  5915. $return .= "\t\t" . '</tr>' . "\n";*/
  5916. $return .= "\t\t" . '<tr>' . "\n";
  5917. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  5918. $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";
  5919. $return .= "\t\t" . '</tr>' . "\n";
  5920. $id_prerequisite = 0;
  5921. if (is_array($arrLP)) {
  5922. foreach ($arrLP as $key => $value) {
  5923. if ($value['id'] == $id) {
  5924. $id_prerequisite = $value['prerequisite'];
  5925. break;
  5926. }
  5927. }
  5928. }
  5929. $arrHide = array ();
  5930. for ($i = 0; $i < count($arrLP); $i++) {
  5931. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5932. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5933. $s_selected_position = $arrLP[$i]['id'];
  5934. elseif ($action == 'add') $s_selected_position = 0;
  5935. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5936. }
  5937. }
  5938. /*//comented the prerequisites, only visible in edit (link)
  5939. $return .= "\t\t" . '<tr>' . "\n";
  5940. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5941. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5942. foreach($arrHide as $key => $value)
  5943. {
  5944. if($key==$s_selected_position && $action == 'add')
  5945. {
  5946. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5947. }
  5948. elseif($key==$id_prerequisite && $action == 'edit'){
  5949. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5950. }
  5951. else{
  5952. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5953. }
  5954. }
  5955. $return .= "</select></td>";
  5956. */
  5957. $return .= "\t\t" . '</tr>' . "\n";
  5958. }
  5959. $return .= "\t\t" . '<tr>' . "\n";
  5960. if ($action == 'add') {
  5961. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  5962. } else {
  5963. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  5964. }
  5965. $return .= "\t\t" . '</tr>' . "\n";
  5966. $return .= "\t" . '</table>' . "\n";
  5967. if ($action == 'move') {
  5968. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5969. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5970. }
  5971. if (is_numeric($extra_info)) {
  5972. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5973. }
  5974. elseif (is_array($extra_info)) {
  5975. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5976. }
  5977. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  5978. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5979. $return .= '</form>' . "\n";
  5980. $return .= '</div>' . "\n";
  5981. return $return;
  5982. }
  5983. /**
  5984. * Return HTML form to add/edit a student publication (work)
  5985. *
  5986. * @param string Action (add/edit)
  5987. * @param integer Item ID if already exists
  5988. * @param mixed Extra info (work ID if integer)
  5989. * @return string HTML form
  5990. */
  5991. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  5992. global $charset;
  5993. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5994. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  5995. if ($id != 0 && is_array($extra_info)) {
  5996. $item_title = stripslashes($extra_info['title']);
  5997. $item_description = stripslashes($extra_info['description']);
  5998. }
  5999. elseif (is_numeric($extra_info)) {
  6000. $sql_publication = "
  6001. SELECT
  6002. title,
  6003. description
  6004. FROM " . $tbl_publication . "
  6005. WHERE id = " . $extra_info;
  6006. $result = Database::query($sql_publication, __FILE__, __LINE__);
  6007. $row = Database :: fetch_array($result);
  6008. $item_title = $row['title'];
  6009. } else {
  6010. $item_title = get_lang('Student_publication');
  6011. }
  6012. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  6013. $return = ' <div class="row">
  6014. <div class="form_header">';
  6015. if ($id != 0 && is_array($extra_info))
  6016. $parent = $extra_info['parent_item_id'];
  6017. else
  6018. $parent = 0;
  6019. $sql = "
  6020. SELECT *
  6021. FROM " . $tbl_lp_item . "
  6022. WHERE
  6023. lp_id = " . $this->lp_id;
  6024. $result = Database::query($sql, __FILE__, __LINE__);
  6025. $arrLP = array ();
  6026. while ($row = Database :: fetch_array($result)) {
  6027. $arrLP[] = array (
  6028. 'id' => $row['id'],
  6029. 'item_type' => $row['item_type'],
  6030. 'title' => $row['title'],
  6031. 'path' => $row['path'],
  6032. 'description' => $row['description'],
  6033. 'parent_item_id' => $row['parent_item_id'],
  6034. 'previous_item_id' => $row['previous_item_id'],
  6035. 'next_item_id' => $row['next_item_id'],
  6036. 'display_order' => $row['display_order'],
  6037. 'max_score' => $row['max_score'],
  6038. 'min_score' => $row['min_score'],
  6039. 'mastery_score' => $row['mastery_score'],
  6040. 'prerequisite' => $row['prerequisite']
  6041. );
  6042. }
  6043. $this->tree_array($arrLP);
  6044. $arrLP = $this->arrMenu;
  6045. unset ($this->arrMenu);
  6046. if ($action == 'add')
  6047. $return .= get_lang("Student_publication") . '&nbsp;:' . "\n";
  6048. elseif ($action == 'move') $return .= get_lang("MoveCurrentStudentPublication") . '&nbsp;:' . "\n";
  6049. else
  6050. $return .= get_lang("EditCurrentStudentPublication") . '&nbsp;:' . "\n";
  6051. $return .= ' </div>
  6052. </div>';
  6053. $return .= '<div class="sectioncomment">';
  6054. $return .= '<form method="POST">' . "\n";
  6055. $return .= "\t" . '<table class="lp_form">' . "\n";
  6056. if ($action != 'move') {
  6057. $return .= "\t\t" . '<tr>' . "\n";
  6058. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6059. $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";
  6060. $return .= "\t\t" . '</tr>' . "\n";
  6061. }
  6062. $return .= "\t\t" . '<tr>' . "\n";
  6063. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6064. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6065. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6066. $parent_item_id = $_SESSION['parent_item_id'];
  6067. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6068. $arrHide = array (
  6069. $id
  6070. );
  6071. for ($i = 0; $i < count($arrLP); $i++) {
  6072. if ($action != 'add') {
  6073. 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)) {
  6074. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  6075. } else {
  6076. $arrHide[] = $arrLP[$i]['id'];
  6077. }
  6078. } else {
  6079. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6080. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  6081. }
  6082. }
  6083. if (is_array($arrLP)) {
  6084. reset($arrLP);
  6085. }
  6086. $return .= "\t\t\t\t" . '</select>';
  6087. $return .= "\t\t\t" . '</td>' . "\n";
  6088. $return .= "\t\t" . '</tr>' . "\n";
  6089. $return .= "\t\t" . '<tr>' . "\n";
  6090. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6091. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6092. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6093. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  6094. for ($i = 0; $i < count($arrLP); $i++) {
  6095. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6096. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6097. $selected = 'selected="selected" ';
  6098. elseif ($action == 'add') $selected = 'selected="selected" ';
  6099. else
  6100. $selected = '';
  6101. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"</option>';
  6102. }
  6103. }
  6104. $return .= "\t\t\t\t" . '</select>';
  6105. $return .= "\t\t\t" . '</td>' . "\n";
  6106. $return .= "\t\t" . '</tr>' . "\n";
  6107. if ($action != 'move') {
  6108. $id_prerequisite = 0;
  6109. if (is_array($arrLP)) {
  6110. foreach ($arrLP as $key => $value) {
  6111. if ($value['id'] == $id) {
  6112. $id_prerequisite = $value['prerequisite'];
  6113. break;
  6114. }
  6115. }
  6116. }
  6117. $arrHide = array ();
  6118. for ($i = 0; $i < count($arrLP); $i++) {
  6119. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6120. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6121. $s_selected_position = $arrLP[$i]['id'];
  6122. elseif ($action == 'add') $s_selected_position = 0;
  6123. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  6124. }
  6125. }
  6126. //comented the prerequisites, only visible in edit (work)
  6127. /*
  6128. $return .= "\t\t" . '<tr>' . "\n";
  6129. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6130. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  6131. foreach($arrHide as $key => $value){
  6132. if($key==$s_selected_position && $action == 'add'){
  6133. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6134. }
  6135. elseif($key==$id_prerequisite && $action == 'edit'){
  6136. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6137. }
  6138. else{
  6139. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6140. }
  6141. }
  6142. $return .= "</select></td>";
  6143. */
  6144. $return .= "\t\t" . '</tr>' . "\n";
  6145. }
  6146. $return .= "\t\t" . '<tr>' . "\n";
  6147. if ($action == 'add') {
  6148. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6149. } else {
  6150. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6151. }
  6152. $return .= "\t\t" . '</tr>' . "\n";
  6153. $return .= "\t" . '</table>' . "\n";
  6154. if ($action == 'move') {
  6155. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6156. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6157. }
  6158. if (is_numeric($extra_info)) {
  6159. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6160. }
  6161. elseif (is_array($extra_info)) {
  6162. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6163. }
  6164. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
  6165. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6166. $return .= '</form>' . "\n";
  6167. $return .= '</div>' . "\n";
  6168. return $return;
  6169. }
  6170. /**
  6171. * Displays the menu for manipulating a step
  6172. *
  6173. * @return unknown
  6174. */
  6175. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6176. global $charset, $_course;
  6177. $return = '<div class="actions">';
  6178. switch ($item_type) {
  6179. case 'dokeos_chapter' :
  6180. case 'chapter' :
  6181. //comented the message cause should not show it
  6182. //$lang = get_lang('TitleManipulateChapter');
  6183. break;
  6184. case 'dokeos_module' :
  6185. case 'module' :
  6186. //comented the message cause should not show it
  6187. //$lang = get_lang('TitleManipulateModule');
  6188. break;
  6189. case TOOL_DOCUMENT :
  6190. //comented the message cause should not show it
  6191. //$lang = get_lang('TitleManipulateDocument');
  6192. break;
  6193. case TOOL_LINK :
  6194. case 'link' :
  6195. //comented the message cause should not show it
  6196. //$lang = get_lang('TitleManipulateLink');
  6197. break;
  6198. case TOOL_QUIZ :
  6199. //comented the message cause should not show it
  6200. //$lang = get_lang('TitleManipulateQuiz');
  6201. break;
  6202. case TOOL_STUDENTPUBLICATION :
  6203. //comented the message cause should not show it
  6204. //$lang = get_lang('TitleManipulateStudentPublication');
  6205. break;
  6206. }
  6207. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6208. $sql = "
  6209. SELECT
  6210. *
  6211. FROM " . $tbl_lp_item . " as lp
  6212. WHERE
  6213. lp.id = " . $item_id;
  6214. $result = Database::query($sql, __FILE__, __LINE__);
  6215. $row = mysql_fetch_assoc($result);
  6216. $s_title = $row['title'];
  6217. $s_title = api_convert_encoding($s_title, $charset, $this->encoding);
  6218. // we display an audio player if needed
  6219. if (!empty ($row['audio'])) {
  6220. $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>';
  6221. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6222. $return .= '<script type="text/javascript">
  6223. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6224. s1.addParam("allowscriptaccess","always");
  6225. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6226. s1.write("container");
  6227. </script>';
  6228. }
  6229. //commented ":" for message in step
  6230. //$return .= $lang.': ';
  6231. $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>';
  6232. $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>';
  6233. // commented for now as prerequisites cannot be added to chapters
  6234. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6235. $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>';
  6236. }
  6237. $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>';
  6238. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  6239. //$return.="</td><td valign='top'>";
  6240. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  6241. ob_start();
  6242. $audio_recorder_studentview = 'false';
  6243. $audio_recorder_item_id = $item_id;
  6244. if (api_get_setting('service_visio', 'active') == 'true') {
  6245. include ('audiorecorder.inc.php');
  6246. }
  6247. $return .= ob_get_contents();
  6248. ob_end_clean();
  6249. // end of audiorecorder include
  6250. $return .= '</div>';
  6251. return $return;
  6252. }
  6253. /**
  6254. * Creates the javascript needed for filling up the checkboxes without page reload
  6255. *
  6256. * @return string
  6257. */
  6258. function create_js() {
  6259. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6260. $return .= 'function load_cbo(id){' . "\n";
  6261. $return .= "var cbo = document.getElementById('idPosition');\n";
  6262. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6263. $return .= 'cbo.options[i] = null;' . "\n";
  6264. $return .= 'var k=0;' . "\n";
  6265. $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
  6266. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
  6267. $return .= 'k=i;';
  6268. $return .= '}' . "\n\n";
  6269. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6270. $return .= '}';
  6271. $return .= 'var child_name = new Array();' . "\n";
  6272. $return .= 'var child_value = new Array();' . "\n\n";
  6273. $return .= 'child_name[0] = new Array();' . "\n";
  6274. $return .= 'child_value[0] = new Array();' . "\n\n";
  6275. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6276. $sql_zero = "
  6277. SELECT *
  6278. FROM " . $tbl_lp_item . "
  6279. WHERE
  6280. lp_id = " . $this->lp_id . " AND
  6281. parent_item_id = 0
  6282. ORDER BY display_order ASC";
  6283. $res_zero = Database::query($sql_zero, __FILE__, __LINE__);
  6284. global $charset;
  6285. $i = 0;
  6286. while ($row_zero = Database :: fetch_array($res_zero)) {
  6287. $return .= 'child_name[0][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_zero['title'], $charset, $this->encoding) . '\"";' . "\n";
  6288. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6289. }
  6290. $return .= "\n";
  6291. $sql = "
  6292. SELECT *
  6293. FROM " . $tbl_lp_item . "
  6294. WHERE
  6295. lp_id = " . $this->lp_id;
  6296. $res = Database::query($sql, __FILE__, __LINE__);
  6297. while ($row = Database :: fetch_array($res)) {
  6298. $sql_parent = "
  6299. SELECT *
  6300. FROM " . $tbl_lp_item . "
  6301. WHERE parent_item_id = " . $row['id'] . "
  6302. ORDER BY display_order ASC";
  6303. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  6304. $i = 0;
  6305. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6306. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6307. while ($row_parent = Database :: fetch_array($res_parent)) {
  6308. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_parent['title'], $charset, $this->encoding) . '\"";' . "\n";
  6309. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6310. }
  6311. $return .= "\n";
  6312. }
  6313. $return .= '</script>' . "\n";
  6314. return $return;
  6315. }
  6316. /**
  6317. * Display the form to allow moving an item
  6318. *
  6319. * @param integer Item ID
  6320. * @return string HTML form
  6321. */
  6322. function display_move_item($item_id) {
  6323. global $_course; //will disappear
  6324. global $charset;
  6325. $return = '';
  6326. if (is_numeric($item_id)) {
  6327. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6328. $sql = "SELECT *
  6329. FROM " . $tbl_lp_item . "
  6330. WHERE id = " . $item_id;
  6331. $res = Database::query($sql, __FILE__, __LINE__);
  6332. $row = Database :: fetch_array($res);
  6333. switch ($row['item_type']) {
  6334. case 'dokeos_chapter' :
  6335. case 'dir' :
  6336. case 'asset' :
  6337. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6338. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6339. break;
  6340. case 'dokeos_module' :
  6341. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6342. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6343. break;
  6344. case TOOL_DOCUMENT :
  6345. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6346. $return .= $this->display_document_form('move', $item_id, $row);
  6347. break;
  6348. case TOOL_LINK :
  6349. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6350. $return .= $this->display_link_form('move', $item_id, $row);
  6351. break;
  6352. case TOOL_HOTPOTATOES :
  6353. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6354. $return .= $this->display_link_form('move', $item_id, $row);
  6355. break;
  6356. case TOOL_QUIZ :
  6357. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6358. $return .= $this->display_quiz_form('move', $item_id, $row);
  6359. break;
  6360. case TOOL_STUDENTPUBLICATION :
  6361. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6362. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6363. break;
  6364. case TOOL_FORUM :
  6365. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6366. $return .= $this->display_forum_form('move', $item_id, $row);
  6367. }
  6368. }
  6369. return $return;
  6370. }
  6371. /**
  6372. * Displays a basic form on the overview page for changing the item title and the item description.
  6373. *
  6374. * @param string $item_type
  6375. * @param string $title
  6376. * @param array $data
  6377. * @return string
  6378. */
  6379. function display_item_small_form($item_type, $title = '', $data) {
  6380. global $charset;
  6381. $return .= '<div class="lp_small_form">' . "\n";
  6382. $return .= '<p class="lp_title">' . $title . '</p>';
  6383. $return .= '<form method="post">' . "\n";
  6384. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6385. $return .= "\t\t" . '<tr>' . "\n";
  6386. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6387. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode(api_convert_encoding(htmlspecialchars($data['title']), $charset, $this->encoding), ENT_QUOTES, $charset) . '" /></td>' . "\n";
  6388. $return .= "\t\t" . '</tr>' . "\n";
  6389. //it said these lines of code - see SVN#11724 and SVN#10770
  6390. //$return .= "\t\t" . '<tr>' . "\n";
  6391. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6392. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6393. //$return .= "\t\t" . '</tr>' . "\n";
  6394. $return .= "\t\t" . '<tr>' . "\n";
  6395. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6396. $return .= "\t\t" . '</tr>' . "\n";
  6397. $return .= "\t\t" . '</table>' . "\n";
  6398. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6399. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6400. $return .= '</form>';
  6401. $return .= '</div>';
  6402. return $return;
  6403. }
  6404. /**
  6405. * Return HTML form to allow prerequisites selection
  6406. *
  6407. * @param integer Item ID
  6408. * @return string HTML form
  6409. */
  6410. function display_item_prerequisites_form($item_id) {
  6411. global $charset;
  6412. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6413. /* current prerequisite */
  6414. $sql = "
  6415. SELECT *
  6416. FROM " . $tbl_lp_item . "
  6417. WHERE id = " . $item_id;
  6418. $result = Database::query($sql, __FILE__, __LINE__);
  6419. $row = Database :: fetch_array($result);
  6420. $preq_id = $row['prerequisite'];
  6421. //$preq_mastery = $row['mastery_score'];
  6422. //$preq_max = $row['max_score'];
  6423. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6424. $return = ' <div class="row">
  6425. <div class="form_header">';
  6426. $return .= get_lang('AddEditPrerequisites');
  6427. $return .= '</div> </div>';
  6428. $return .= '<div class="sectioncomment">';
  6429. $return .= '<form method="POST">';
  6430. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6431. $return .= '<tr style="border-collapse:collapse;">';
  6432. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6433. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6434. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6435. $return .= '</tr>';
  6436. //$return .= '<tr >';
  6437. //$return .= '<td class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6438. //$return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6439. //$return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6440. //$return .= '</td><td colspan="2" />';
  6441. //$return .= '</tr>';
  6442. $sql = "
  6443. SELECT *
  6444. FROM " . $tbl_lp_item . "
  6445. WHERE
  6446. lp_id = " . $this->lp_id;
  6447. $result = Database::query($sql, __FILE__, __LINE__);
  6448. $arrLP = array ();
  6449. while ($row = Database :: fetch_array($result)) {
  6450. $arrLP[] = array (
  6451. 'id' => $row['id'],
  6452. 'item_type' => $row['item_type'],
  6453. 'title' => api_convert_encoding($row['title'], $charset, $this->encoding),
  6454. 'ref' => $row['ref'],
  6455. 'description' => $row['description'],
  6456. 'parent_item_id' => $row['parent_item_id'],
  6457. 'previous_item_id' => $row['previous_item_id'],
  6458. 'next_item_id' => $row['next_item_id'],
  6459. 'max_score' => $row['max_score'],
  6460. 'min_score' => $row['min_score'],
  6461. 'mastery_score' => $row['mastery_score'],
  6462. 'prerequisite' => $row['prerequisite'],
  6463. 'next_item_id' => $row['next_item_id'],
  6464. 'display_order' => $row['display_order']
  6465. );
  6466. if ($row['ref'] == $preq_id) {
  6467. $preq_mastery = $row['mastery_score'];
  6468. $preq_max = $row['max_score'];
  6469. }
  6470. }
  6471. $this->tree_array($arrLP);
  6472. $arrLP = $this->arrMenu;
  6473. unset ($this->arrMenu);
  6474. for ($i = 0; $i < count($arrLP); $i++) {
  6475. if ($arrLP[$i]['id'] == $item_id)
  6476. break;
  6477. $return .= '<tr >';
  6478. $return .= '<td style="border:1px solid #B0B0B0; border-collapse:collapse; height:25px; padding: 3px 5px 3px 3px;" class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6479. $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'] . '" />';
  6480. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6481. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  6482. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6483. } else
  6484. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  6485. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6486. } else {
  6487. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6488. }
  6489. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6490. $return .= '</td>';
  6491. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6492. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6493. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6494. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6495. $return .= '</td>';
  6496. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6497. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6498. $return .= '</td>';
  6499. }
  6500. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6501. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6502. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6503. $return .= '</td>';
  6504. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6505. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6506. $return .= '</td>';
  6507. }
  6508. $return .= '</tr>';
  6509. }
  6510. $return .= '<tr>';
  6511. $return .= '<td colspan="3">';
  6512. $return .= '</td>';
  6513. $return .= '</tr>';
  6514. $return .= '</table>';
  6515. $return .= '<div style="padding-top:3px;">';
  6516. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang("ModifyPrerequisites") . ' </button></td>' . "\n";
  6517. $return .= '</div>';
  6518. $return .= '</form>';
  6519. $return .= '</div>';
  6520. return $return;
  6521. }
  6522. /**
  6523. * Creates a list with all the documents in it
  6524. *
  6525. * @return string
  6526. */
  6527. function get_documents() {
  6528. global $_course;
  6529. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6530. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6531. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6532. $path = '/';
  6533. $path = Database::escape_string(str_replace('_', '\_', $path));
  6534. $added_slash = ($path == '/') ? '' : '/';
  6535. //condition for the session
  6536. $current_session_id = api_get_session_id();
  6537. $condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '{$_course[id]}')))";
  6538. $sql_doc = "SELECT docs.*
  6539. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6540. WHERE docs.id = last.ref
  6541. AND docs.path LIKE '".$path.$added_slash."%'
  6542. AND docs.path NOT LIKE '%_DELETED_%'
  6543. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6544. //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
  6545. $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
  6546. $return = '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resDoc').style.display == 'block') {document.getElementById('resDoc').style.display = 'none';} else {document.getElementById('resDoc').style.display = 'block';}\"" . '>'.Display::return_icon('folder_document.gif',get_lang('Documents'),array('style'=>'margin-right:5px;', 'height' => '16px')).' '. get_lang('Documents') . '</div>';
  6547. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6548. $resources = Database::store_result($res_doc);
  6549. $resources_sorted = array ();
  6550. // if you want to debug it, I advise you to do "echo" on the eval statements
  6551. foreach ($resources as $resource) {
  6552. $resource_paths = explode('/', $resource['path']);
  6553. array_shift($resource_paths);
  6554. $path_to_eval = $last_path = '';
  6555. $is_file = false;
  6556. foreach ($resource_paths as $key => $resource_path) {
  6557. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // it's a folder
  6558. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6559. } else
  6560. if (strpos($resource_path, '.') !== false)
  6561. $is_file = true;
  6562. $last_path = $resource_path;
  6563. }
  6564. if ($is_file) {
  6565. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6566. } else {
  6567. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6568. }
  6569. }
  6570. $return .= $this->write_resources_tree($resources_sorted);
  6571. if (Database :: num_rows($res_doc) == 0)
  6572. $return .= '<div class="lp_resource_element">' . get_lang("NoDocuments") . '</div>';
  6573. $return .= '</div>';
  6574. return $return;
  6575. }
  6576. /**
  6577. * Generate and return an HTML list of resources based on a given array.
  6578. *
  6579. * This list is used to show the course creator a list of available resources to choose from
  6580. * when creating a learning path.
  6581. * @param array Array of elements to add to the list
  6582. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6583. * @return string The HTML list
  6584. */
  6585. function write_resources_tree($resources_sorted, $num = 0) {
  6586. include_once (api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  6587. if (count($resources_sorted) > 0) {
  6588. foreach ($resources_sorted as $key => $resource) {
  6589. if (is_int($resource['id'])) { // it's a folder
  6590. $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'] . '">';
  6591. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6592. $return .= "</div></div>\r\n";
  6593. } else {
  6594. // it's a file
  6595. $icon = choose_image($resource);
  6596. $position = strrpos($icon, '.');
  6597. $icon = substr($icon, 0, $position) . '_small.gif';
  6598. $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";
  6599. }
  6600. }
  6601. }
  6602. return $return;
  6603. }
  6604. /**
  6605. * Creates a list with all the exercises (quiz) in it
  6606. *
  6607. * @return string
  6608. */
  6609. function get_exercises() {
  6610. // new for hotpotatoes
  6611. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6612. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6613. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6614. $session_id = api_get_session_id();
  6615. $condition_session = api_get_session_condition($session_id);
  6616. $sql_quiz = "
  6617. SELECT *
  6618. FROM " . $tbl_quiz . "
  6619. WHERE active<>'-1' $condition_session
  6620. ORDER BY title ASC";
  6621. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6622. " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
  6623. " ORDER BY id ASC";
  6624. $res_quiz = Database::query($sql_quiz, __FILE__, __LINE__);
  6625. $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
  6626. $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>';
  6627. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6628. while ($row_hot = Database :: fetch_array($res_hot)) {
  6629. $return .= '<div class="lp_resource_element">';
  6630. //display quizhotpotatoes
  6631. $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
  6632. $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>';
  6633. //$return .= $row_quiz['title'];
  6634. $return .= '</div>';
  6635. }
  6636. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6637. $return .= '<div class="lp_resource_element">';
  6638. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6639. $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>';
  6640. //$return .= $row_quiz['title'];
  6641. $return .= '</div>';
  6642. }
  6643. if (Database :: num_rows($res_quiz) == 0)
  6644. $return .= '<div class="lp_resource_element">' . get_lang("NoExercisesAvailable") . '</div>';
  6645. $return .= '<div class="lp_resource_element">';
  6646. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6647. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6648. $return .= '</div>';
  6649. $return .= '</div>';
  6650. return $return;
  6651. }
  6652. /**
  6653. * Creates a list with all the links in it
  6654. *
  6655. * @return string
  6656. */
  6657. function get_links() {
  6658. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6659. $session_id = api_get_session_id();
  6660. $condition_session = api_get_session_condition($session_id,false);
  6661. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6662. $res_link = Database::query($sql_link, __FILE__, __LINE__);
  6663. $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>';
  6664. $return .= '<div class="lp_resource_elements" id="resLink">';
  6665. while ($row_link = Database :: fetch_array($res_link)) {
  6666. $return .= '<div class="lp_resource_element">';
  6667. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6668. $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>';
  6669. $return .= '</div>';
  6670. }
  6671. $return .= '<div class="lp_resource_element">';
  6672. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6673. $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>';
  6674. $return .= '</div>';
  6675. if (Database :: num_rows($res_link) == 0)
  6676. $return .= '<div class="lp_resource_element">' . get_lang("NoLinksAvailable") . '</div>';
  6677. $return .= '</div>';
  6678. return $return;
  6679. }
  6680. /**
  6681. * Creates a list with all the student publications in it
  6682. *
  6683. * @return unknown
  6684. */
  6685. function get_student_publications() {
  6686. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6687. $session_id = api_get_session_id();
  6688. $condition_session = api_get_session_condition($session_id,false);
  6689. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6690. $res_student = Database::query($sql_student, __FILE__, __LINE__);
  6691. $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>';
  6692. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6693. $return .= '<div class="lp_resource_element">';
  6694. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6695. $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>';
  6696. $return .= '</div>';
  6697. $return .= '</div>';
  6698. return $return;
  6699. }
  6700. /**
  6701. * Creates a list with all the forums in it
  6702. *
  6703. * @return string
  6704. */
  6705. function get_forums() {
  6706. include ('../forum/forumfunction.inc.php');
  6707. include ('../forum/forumconfig.inc.php');
  6708. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6709. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6710. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6711. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6712. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6713. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6714. $a_forums = get_forums();
  6715. $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>';
  6716. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6717. foreach ($a_forums as $forum) {
  6718. $return .= '<div class="lp_resource_element">';
  6719. $return .= '<script type="text/javascript">
  6720. function toggle_forum(forum_id){
  6721. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6722. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6723. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6724. }
  6725. else {
  6726. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6727. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6728. }
  6729. }
  6730. </script>
  6731. ';
  6732. if (!empty($forum['forum_id'])) {
  6733. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6734. $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>
  6735. <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">';
  6736. }
  6737. $a_threads = get_threads($forum['forum_id']);
  6738. if (is_array($a_threads)) {
  6739. foreach ($a_threads as $thread) {
  6740. $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>';
  6741. }
  6742. }
  6743. $return .= '</ul></div>';
  6744. }
  6745. $return .= '<div class="lp_resource_element">';
  6746. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6747. $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>';
  6748. $return .= '</div>';
  6749. return $return;
  6750. }
  6751. /**
  6752. * Exports the learning path as a SCORM package. This is the main function that
  6753. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6754. * whole thing and returns the zip.
  6755. *
  6756. * This method needs to be called in PHP5, as it will fail with non-adequate
  6757. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6758. * you need to call it on a learnpath object.
  6759. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6760. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6761. * path has been modified, it should use the generic method here below.
  6762. * @TODO link this function with the export_lp() function in the same class
  6763. * @param string Optional name of zip file. If none, title of learnpath is
  6764. * domesticated and trailed with ".zip"
  6765. * @return string Returns the zip package string, or null if error
  6766. */
  6767. function scorm_export()
  6768. {
  6769. global $_course;
  6770. global $charset;
  6771. if (!class_exists('DomDocument'))
  6772. {
  6773. error_log('DOM functions not supported for PHP version below 5.0',0);
  6774. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6775. return null;
  6776. }
  6777. //remove memory and time limits as much as possible as this might be a long process...
  6778. if(function_exists('ini_set'))
  6779. {
  6780. $mem = ini_get('memory_limit');
  6781. if(substr($mem,-1,1)=='M')
  6782. {
  6783. $mem_num = substr($mem,0,-1);
  6784. if($mem_num<128)
  6785. {
  6786. ini_set('memory_limit','128M');
  6787. }
  6788. }
  6789. else
  6790. {
  6791. ini_set('memory_limit','128M');
  6792. }
  6793. ini_set('max_execution_time',600);
  6794. //}else{
  6795. //error_log('Scorm export: could not change memory and time limits',0);
  6796. }
  6797. //Create the zip handler (this will remain available throughout the method)
  6798. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6799. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6800. $temp_dir_short = uniqid();
  6801. $temp_zip_dir = $archive_path."/".$temp_dir_short;
  6802. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6803. $zip_folder=new PclZip($temp_zip_file);
  6804. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6805. $root_path = $main_path = api_get_path(SYS_PATH);
  6806. $files_cleanup = array();
  6807. //place to temporarily stash the zipfiles
  6808. //create the temp dir if it doesn't exist
  6809. //or do a cleanup befor creating the zipfile
  6810. if(!is_dir($temp_zip_dir))
  6811. {
  6812. mkdir($temp_zip_dir);
  6813. }
  6814. else
  6815. {//cleanup: check the temp dir for old files and delete them
  6816. $handle=opendir($temp_zip_dir);
  6817. while (false!==($file = readdir($handle)))
  6818. {
  6819. if ($file != "." && $file != "..")
  6820. {
  6821. unlink("$temp_zip_dir/$file");
  6822. }
  6823. }
  6824. closedir($handle);
  6825. }
  6826. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6827. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6828. {
  6829. // remove the possible . at the end of the path
  6830. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6831. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6832. $perm = api_get_setting('permissions_for_new_directories');
  6833. $perm = octdec(!empty($perm)?$perm:'0770');
  6834. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6835. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6836. }
  6837. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6838. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6839. //Aggregation Model official document, secion "2.3 Content Packaging"
  6840. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6841. $root = $xmldoc->createElement('manifest');
  6842. $root->setAttribute('identifier','SingleCourseManifest');
  6843. $root->setAttribute('version','1.1');
  6844. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6845. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6846. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6847. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6848. //Build mandatory sub-root container elements
  6849. $metadata = $xmldoc->createElement('metadata');
  6850. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6851. $metadata->appendChild($md_schema);
  6852. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6853. $metadata->appendChild($md_schemaversion);
  6854. $root->appendChild($metadata);
  6855. $organizations = $xmldoc->createElement('organizations');
  6856. $resources = $xmldoc->createElement('resources');
  6857. //Build the only organization we will use in building our learnpaths
  6858. $organizations->setAttribute('default','dokeos_scorm_export');
  6859. $organization = $xmldoc->createElement('organization');
  6860. $organization->setAttribute('identifier','dokeos_scorm_export');
  6861. //to set the title of the SCORM entity (=organization), we take the name given
  6862. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6863. //learning path charset) as it is the encoding that defines how it is stored
  6864. //in the database. Then we convert it to HTML entities again as the "&" character
  6865. //alone is not authorized in XML (must be &amp;)
  6866. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6867. $org_title = $xmldoc->createElement('title',htmlentities(api_htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6868. $organization->appendChild($org_title);
  6869. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6870. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6871. //format
  6872. $link_updates = array();
  6873. foreach($this->items as $index => $item){
  6874. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6875. {
  6876. //get included documents from this item
  6877. if($item->type=='sco')
  6878. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6879. else
  6880. $inc_docs = $item->get_resources_from_source();
  6881. //give a child element <item> to the <organization> element
  6882. $my_item_id = $item->get_id();
  6883. $my_item = $xmldoc->createElement('item');
  6884. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6885. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6886. $my_item->setAttribute('isvisible','true');
  6887. //give a child element <title> to the <item> element
  6888. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  6889. $my_item->appendChild($my_title);
  6890. //give a child element <adlcp:prerequisites> to the <item> element
  6891. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6892. $my_prereqs->setAttribute('type','aicc_script');
  6893. $my_item->appendChild($my_prereqs);
  6894. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6895. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6896. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6897. //$xmldoc->createElement('adlcp:timelimitaction','');
  6898. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6899. //$xmldoc->createElement('adlcp:datafromlms','');
  6900. //give a child element <adlcp:masteryscore> to the <item> element
  6901. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  6902. $my_item->appendChild($my_masteryscore);
  6903. //attach this item to the organization element or hits parent if there is one
  6904. if(!empty($item->parent) && $item->parent!=0)
  6905. {
  6906. $children = $organization->childNodes;
  6907. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6908. if(is_object($possible_parent))
  6909. {
  6910. $possible_parent->appendChild($my_item);
  6911. }
  6912. else
  6913. {
  6914. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6915. }
  6916. }
  6917. else
  6918. {
  6919. if($this->debug>0){error_log('No parent');}
  6920. $organization->appendChild($my_item);
  6921. }
  6922. //get the path of the file(s) from the course directory root
  6923. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6924. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  6925. $my_sub_dir = dirname($my_file_path);
  6926. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  6927. //give a <resource> child to the <resources> element
  6928. $my_resource = $xmldoc->createElement('resource');
  6929. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6930. $my_resource->setAttribute('type','webcontent');
  6931. $my_resource->setAttribute('href',$my_xml_file_path);
  6932. //adlcp:scormtype can be either 'sco' or 'asset'
  6933. if($item->type=='sco')
  6934. {
  6935. $my_resource->setAttribute('adlcp:scormtype','sco');
  6936. }
  6937. else
  6938. {
  6939. $my_resource->setAttribute('adlcp:scormtype','asset');
  6940. }
  6941. //xml:base is the base directory to find the files declared in this resource
  6942. $my_resource->setAttribute('xml:base','');
  6943. //give a <file> child to the <resource> element
  6944. $my_file = $xmldoc->createElement('file');
  6945. $my_file->setAttribute('href',$my_xml_file_path);
  6946. $my_resource->appendChild($my_file);
  6947. //dependency to other files - not yet supported
  6948. $i = 1;
  6949. foreach($inc_docs as $doc_info)
  6950. {
  6951. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6952. $my_dep = $xmldoc->createElement('resource');
  6953. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6954. $my_dep->setAttribute('identifier',$res_id);
  6955. $my_dep->setAttribute('type','webcontent');
  6956. $my_dep->setAttribute('adlcp:scormtype','asset');
  6957. $my_dep_file = $xmldoc->createElement('file');
  6958. //check type of URL
  6959. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6960. if($doc_info[1] == 'remote')
  6961. { //remote file. Save url as is
  6962. $my_dep_file->setAttribute('href',$doc_info[0]);
  6963. $my_dep->setAttribute('xml:base','');
  6964. }elseif($doc_info[1] == 'local'){
  6965. switch($doc_info[2])
  6966. {
  6967. case 'url': //local URL - save path as url for now, don't zip file
  6968. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6969. $current_dir = dirname($abs_path);
  6970. $file_path = realpath($abs_path);
  6971. $my_dep_file->setAttribute('href',$file_path);
  6972. $my_dep->setAttribute('xml:base','');
  6973. if(strstr($file_path,$main_path) !== false)
  6974. {//the calculated real path is really inside the dokeos root path
  6975. //reduce file path to what's under the DocumentRoot
  6976. $file_path = substr($file_path,strlen($root_path)-1);
  6977. //echo $file_path;echo '<br><br>';
  6978. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6979. $zip_files_abs[] = $file_path;
  6980. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6981. $my_dep_file->setAttribute('href',$file_path);
  6982. $my_dep->setAttribute('xml:base','');
  6983. }
  6984. else if (empty($file_path))
  6985. {
  6986. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6987. if(strpos($document_root,-1)=='/')
  6988. {
  6989. $document_root = substr(0, -1, $document_root);
  6990. }*/
  6991. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6992. $file_path = str_replace('//','/',$file_path);
  6993. if(file_exists($file_path))
  6994. {
  6995. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6996. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6997. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6998. $my_dep_file->setAttribute('href',$file_path);
  6999. $my_dep->setAttribute('xml:base','');
  7000. }
  7001. }
  7002. break;
  7003. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7004. $my_dep_file->setAttribute('href',$doc_info[0]);
  7005. $my_dep->setAttribute('xml:base','');
  7006. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7007. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  7008. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7009. $abs_img_path_without_subdir = $doc_info[0];
  7010. $relp = api_get_path(REL_PATH); //the url-append config param
  7011. $pos = strpos($abs_img_path_without_subdir,$relp);
  7012. if($pos===0)
  7013. {
  7014. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  7015. }
  7016. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7017. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7018. $file_path = str_replace('\\','/',$file_path);
  7019. $file_path = str_replace('//','/',$file_path);
  7020. //error_log(__LINE__.'Abs path: '.$file_path,0);
  7021. //prepare the current directory path (until just under 'document') with a trailing slash
  7022. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  7023. //check if the current document is in that path
  7024. if(strstr($file_path,$cur_path) !== false)
  7025. {
  7026. //the document is in that path, now get the relative path
  7027. //to the containing document
  7028. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7029. $relative_path ='';
  7030. if(strstr($file_path,$cur_path)!==false)
  7031. {
  7032. $relative_path = substr($file_path,strlen($orig_file_path));
  7033. $file_path = substr($file_path,strlen($cur_path));
  7034. }
  7035. else
  7036. {
  7037. //this case is still a problem as it's difficult to calculate a relative path easily
  7038. //might still generate wrong links
  7039. //$file_path = substr($file_path,strlen($cur_path));
  7040. //calculate the directory path to the current file (without trailing slash)
  7041. $my_relative_path = dirname($file_path);
  7042. $my_relative_file = basename($file_path);
  7043. //calculate the directory path to the containing file (without trailing slash)
  7044. $my_orig_file_path = substr($orig_file_path,0,-1);
  7045. $dotdot = '';
  7046. $subdir = '';
  7047. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  7048. {
  7049. $my_relative_path2 = dirname($my_relative_path);
  7050. $my_orig_file_path = dirname($my_orig_file_path);
  7051. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  7052. $dotdot += '../';
  7053. $my_relative_path = $my_relative_path2;
  7054. }
  7055. $relative_path = $dotdot.$subdir.$my_relative_file;
  7056. }
  7057. //put the current document in the zip (this array is the array
  7058. //that will manage documents already in the course folder - relative)
  7059. $zip_files[] = $file_path;
  7060. //update the links to the current document in the containing document (make them relative)
  7061. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  7062. $my_dep_file->setAttribute('href',$file_path);
  7063. $my_dep->setAttribute('xml:base','');
  7064. }
  7065. elseif(strstr($file_path,$main_path) !== false)
  7066. {//the calculated real path is really inside the dokeos root path
  7067. //reduce file path to what's under the DocumentRoot
  7068. $file_path = substr($file_path,strlen($root_path));
  7069. //echo $file_path;echo '<br><br>';
  7070. //error_log('Reduced path: '.$file_path,0);
  7071. $zip_files_abs[] = $file_path;
  7072. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7073. $my_dep_file->setAttribute('href','document/'.$file_path);
  7074. $my_dep->setAttribute('xml:base','');
  7075. }
  7076. else if (empty($file_path))
  7077. {
  7078. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7079. if(strpos($document_root,-1)=='/')
  7080. {
  7081. $document_root = substr(0, -1, $document_root);
  7082. }*/
  7083. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7084. $file_path = str_replace('//','/',$file_path);
  7085. if(file_exists($file_path))
  7086. {
  7087. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7088. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7089. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7090. $my_dep_file->setAttribute('href','document/'.$file_path);
  7091. $my_dep->setAttribute('xml:base','');
  7092. }
  7093. }
  7094. break;
  7095. 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
  7096. if(substr($doc_info[0],0,2)=='..')
  7097. { //relative path going up
  7098. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7099. $file_path = realpath($current_dir.$doc_info[0]);
  7100. //error_log($file_path.' <-> '.$main_path,0);
  7101. if(strstr($file_path,$main_path) !== false)
  7102. {//the calculated real path is really inside the dokeos root path
  7103. //reduce file path to what's under the DocumentRoot
  7104. $file_path = substr($file_path,strlen($root_path));
  7105. //error_log('Reduced path: '.$file_path,0);
  7106. $zip_files_abs[] = $file_path;
  7107. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7108. $my_dep_file->setAttribute('href','document/'.$file_path);
  7109. $my_dep->setAttribute('xml:base','');
  7110. }
  7111. }else{
  7112. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7113. $my_dep_file->setAttribute('href',$doc_info[0]);
  7114. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7115. }
  7116. break;
  7117. default:
  7118. $my_dep_file->setAttribute('href',$doc_info[0]);
  7119. $my_dep->setAttribute('xml:base','');
  7120. break;
  7121. }
  7122. }
  7123. $my_dep->appendChild($my_dep_file);
  7124. $resources->appendChild($my_dep);
  7125. $dependency = $xmldoc->createElement('dependency');
  7126. $dependency->setAttribute('identifierref',$res_id);
  7127. $my_resource->appendChild($dependency);
  7128. $i++;
  7129. }
  7130. //$my_dependency = $xmldoc->createElement('dependency');
  7131. //$my_dependency->setAttribute('identifierref','');
  7132. $resources->appendChild($my_resource);
  7133. $zip_files[] = $my_file_path;
  7134. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  7135. }
  7136. else
  7137. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  7138. if($item->type == TOOL_LINK)
  7139. {
  7140. $my_item = $xmldoc->createElement('item');
  7141. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7142. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7143. $my_item->setAttribute('isvisible','true');
  7144. //give a child element <title> to the <item> element
  7145. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7146. $my_item->appendChild($my_title);
  7147. //give a child element <adlcp:prerequisites> to the <item> element
  7148. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7149. $my_prereqs->setAttribute('type','aicc_script');
  7150. $my_item->appendChild($my_prereqs);
  7151. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  7152. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7153. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  7154. //$xmldoc->createElement('adlcp:timelimitaction','');
  7155. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  7156. //$xmldoc->createElement('adlcp:datafromlms','');
  7157. //give a child element <adlcp:masteryscore> to the <item> element
  7158. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7159. $my_item->appendChild($my_masteryscore);
  7160. //attach this item to the organization element or its parent if there is one
  7161. if(!empty($item->parent) && $item->parent!=0)
  7162. {
  7163. $children = $organization->childNodes;
  7164. for($i=0;$i<$children->length;$i++){
  7165. $item_temp = $children->item($i);
  7166. if ($item_temp -> nodeName == 'item')
  7167. {
  7168. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7169. {
  7170. $item_temp -> appendChild($my_item);
  7171. }
  7172. }
  7173. }
  7174. }
  7175. else
  7176. {
  7177. $organization->appendChild($my_item);
  7178. }
  7179. $my_file_path = 'link_'.$item->get_id().'.html';
  7180. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7181. $rs = Database::query($sql, __FILE__, __LINE__);
  7182. if($link = Database :: fetch_array($rs))
  7183. {
  7184. $url = $link['url'];
  7185. $title = stripslashes($link['title']);
  7186. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  7187. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7188. $my_sub_dir = dirname($my_file_path);
  7189. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7190. //give a <resource> child to the <resources> element
  7191. $my_resource = $xmldoc->createElement('resource');
  7192. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7193. $my_resource->setAttribute('type','webcontent');
  7194. $my_resource->setAttribute('href',$my_xml_file_path);
  7195. //adlcp:scormtype can be either 'sco' or 'asset'
  7196. $my_resource->setAttribute('adlcp:scormtype','asset');
  7197. //xml:base is the base directory to find the files declared in this resource
  7198. $my_resource->setAttribute('xml:base','');
  7199. //give a <file> child to the <resource> element
  7200. $my_file = $xmldoc->createElement('file');
  7201. $my_file->setAttribute('href',$my_xml_file_path);
  7202. $my_resource->appendChild($my_file);
  7203. $resources->appendChild($my_resource);
  7204. }
  7205. }
  7206. elseif($item->type == TOOL_QUIZ)
  7207. {
  7208. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  7209. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  7210. $exe = new Exercise();
  7211. $exe->read($exe_id);
  7212. $my_item = $xmldoc->createElement('item');
  7213. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7214. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7215. $my_item->setAttribute('isvisible','true');
  7216. //give a child element <title> to the <item> element
  7217. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  7218. $my_item->appendChild($my_title);
  7219. $my_max_score = $xmldoc->createElement('max_score',$item->get_max());
  7220. $my_item->appendChild($my_max_score);
  7221. //give a child element <adlcp:prerequisites> to the <item> element
  7222. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7223. $my_prereqs->setAttribute('type','aicc_script');
  7224. $my_item->appendChild($my_prereqs);
  7225. //give a child element <adlcp:masteryscore> to the <item> element
  7226. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7227. $my_item->appendChild($my_masteryscore);
  7228. //attach this item to the organization element or hits parent if there is one
  7229. if(!empty($item->parent) && $item->parent!=0)
  7230. {
  7231. $children = $organization->childNodes;
  7232. for($i=0;$i<$children->length;$i++){
  7233. $item_temp = $children->item($i);
  7234. if ($item_temp -> nodeName == 'item')
  7235. {
  7236. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7237. {
  7238. $item_temp -> appendChild($my_item);
  7239. }
  7240. }
  7241. }
  7242. }
  7243. else
  7244. {
  7245. $organization->appendChild($my_item);
  7246. }
  7247. //include export scripts
  7248. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  7249. //get the path of the file(s) from the course directory root
  7250. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7251. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7252. //write the contents of the exported exercise into a (big) html file
  7253. //to later pack it into the exported SCORM. The file will be removed afterwards
  7254. $contents = export_exercise($exe_id,true);
  7255. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7256. $res = file_put_contents($tmp_file_path,$contents);
  7257. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7258. $files_cleanup[] = $tmp_file_path;
  7259. //error_log($tmp_path);die();
  7260. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7261. $my_sub_dir = dirname($my_file_path);
  7262. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7263. //give a <resource> child to the <resources> element
  7264. $my_resource = $xmldoc->createElement('resource');
  7265. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7266. $my_resource->setAttribute('type','webcontent');
  7267. $my_resource->setAttribute('href',$my_xml_file_path);
  7268. //adlcp:scormtype can be either 'sco' or 'asset'
  7269. $my_resource->setAttribute('adlcp:scormtype','sco');
  7270. //xml:base is the base directory to find the files declared in this resource
  7271. $my_resource->setAttribute('xml:base','');
  7272. //give a <file> child to the <resource> element
  7273. $my_file = $xmldoc->createElement('file');
  7274. $my_file->setAttribute('href',$my_xml_file_path);
  7275. $my_resource->appendChild($my_file);
  7276. //get included docs
  7277. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7278. //dependency to other files - not yet supported
  7279. $i = 1;
  7280. foreach($inc_docs as $doc_info)
  7281. {
  7282. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7283. $my_dep = $xmldoc->createElement('resource');
  7284. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7285. $my_dep->setAttribute('identifier',$res_id);
  7286. $my_dep->setAttribute('type','webcontent');
  7287. $my_dep->setAttribute('adlcp:scormtype','asset');
  7288. $my_dep_file = $xmldoc->createElement('file');
  7289. //check type of URL
  7290. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7291. if($doc_info[1] == 'remote')
  7292. { //remote file. Save url as is
  7293. $my_dep_file->setAttribute('href',$doc_info[0]);
  7294. $my_dep->setAttribute('xml:base','');
  7295. }elseif($doc_info[1] == 'local'){
  7296. switch($doc_info[2])
  7297. {
  7298. case 'url': //local URL - save path as url for now, don't zip file
  7299. //save file but as local file (retrieve from URL)
  7300. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7301. $current_dir = dirname($abs_path);
  7302. $file_path = realpath($abs_path);
  7303. $my_dep_file->setAttribute('href','document/'.$file_path);
  7304. $my_dep->setAttribute('xml:base','');
  7305. if(strstr($file_path,$main_path) !== false)
  7306. {//the calculated real path is really inside the dokeos root path
  7307. //reduce file path to what's under the DocumentRoot
  7308. $file_path = substr($file_path,strlen($root_path));
  7309. //echo $file_path;echo '<br><br>';
  7310. //error_log('Reduced path: '.$file_path,0);
  7311. $zip_files_abs[] = $file_path;
  7312. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7313. $my_dep_file->setAttribute('href','document/'.$file_path);
  7314. $my_dep->setAttribute('xml:base','');
  7315. }
  7316. else if (empty($file_path))
  7317. {
  7318. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7319. if(strpos($document_root,-1)=='/')
  7320. {
  7321. $document_root = substr(0, -1, $document_root);
  7322. }*/
  7323. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7324. $file_path = str_replace('//','/',$file_path);
  7325. if(file_exists($file_path))
  7326. {
  7327. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7328. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7329. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7330. $my_dep_file->setAttribute('href','document/'.$file_path);
  7331. $my_dep->setAttribute('xml:base','');
  7332. }
  7333. }
  7334. break;
  7335. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7336. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7337. $file_path = realpath($doc_info[0]);
  7338. $my_dep_file->setAttribute('href',$file_path);
  7339. $my_dep->setAttribute('xml:base','');
  7340. if(strstr($file_path,$main_path) !== false)
  7341. {//the calculated real path is really inside the dokeos root path
  7342. //reduce file path to what's under the DocumentRoot
  7343. $file_path = substr($file_path,strlen($root_path));
  7344. //echo $file_path;echo '<br><br>';
  7345. //error_log('Reduced path: '.$file_path,0);
  7346. $zip_files_abs[] = $file_path;
  7347. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7348. $my_dep_file->setAttribute('href','document/'.$file_path);
  7349. $my_dep->setAttribute('xml:base','');
  7350. }
  7351. else if (empty($file_path))
  7352. {
  7353. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7354. if(strpos($document_root,-1)=='/')
  7355. {
  7356. $document_root = substr(0, -1, $document_root);
  7357. }*/
  7358. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7359. $file_path = str_replace('//','/',$file_path);
  7360. if(file_exists($file_path))
  7361. {
  7362. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7363. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7364. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7365. $my_dep_file->setAttribute('href','document/'.$file_path);
  7366. $my_dep->setAttribute('xml:base','');
  7367. }
  7368. }
  7369. break;
  7370. 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
  7371. if(substr($doc_info[0],0,2)=='..')
  7372. { //relative path going up
  7373. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7374. $file_path = realpath($current_dir.$doc_info[0]);
  7375. //error_log($file_path.' <-> '.$main_path,0);
  7376. if(strstr($file_path,$main_path) !== false)
  7377. {//the calculated real path is really inside the dokeos root path
  7378. //reduce file path to what's under the DocumentRoot
  7379. $file_path = substr($file_path,strlen($root_path));
  7380. $file_path_dest=$file_path;
  7381. //file path is courses/DOKEOS/document/....
  7382. $info_file_path=explode('/',$file_path);
  7383. if ($info_file_path[0]=='courses') {//add character "/" in file path
  7384. $file_path_dest='/'.$file_path;
  7385. }
  7386. //error_log('Reduced path: '.$file_path,0);
  7387. $zip_files_abs[] = $file_path;
  7388. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path_dest);
  7389. $my_dep_file->setAttribute('href','document/'.$file_path);
  7390. $my_dep->setAttribute('xml:base','');
  7391. }
  7392. }else{
  7393. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7394. $my_dep_file->setAttribute('href',$doc_info[0]);
  7395. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7396. }
  7397. break;
  7398. default:
  7399. $my_dep_file->setAttribute('href',$doc_info[0]);// ../../courses/
  7400. $my_dep->setAttribute('xml:base','');
  7401. break;
  7402. }
  7403. }
  7404. $my_dep->appendChild($my_dep_file);
  7405. $resources->appendChild($my_dep);
  7406. $dependency = $xmldoc->createElement('dependency');
  7407. $dependency->setAttribute('identifierref',$res_id);
  7408. $my_resource->appendChild($dependency);
  7409. $i++;
  7410. }
  7411. $resources->appendChild($my_resource);
  7412. $zip_files[] = $my_file_path;
  7413. }
  7414. else
  7415. {
  7416. //get the path of the file(s) from the course directory root
  7417. $my_file_path = 'non_exportable.html';
  7418. $my_xml_file_path = api_htmlentities($my_file_path, ENT_COMPAT, $this->encoding);
  7419. $my_sub_dir = dirname($my_file_path);
  7420. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_COMPAT, $this->encoding);
  7421. //give a <resource> child to the <resources> element
  7422. $my_resource = $xmldoc->createElement('resource');
  7423. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7424. $my_resource->setAttribute('type','webcontent');
  7425. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7426. //adlcp:scormtype can be either 'sco' or 'asset'
  7427. $my_resource->setAttribute('adlcp:scormtype','asset');
  7428. //xml:base is the base directory to find the files declared in this resource
  7429. $my_resource->setAttribute('xml:base','');
  7430. //give a <file> child to the <resource> element
  7431. $my_file = $xmldoc->createElement('file');
  7432. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7433. $my_resource->appendChild($my_file);
  7434. $resources->appendChild($my_resource);
  7435. }
  7436. }
  7437. }
  7438. $organizations->appendChild($organization);
  7439. $root->appendChild($organizations);
  7440. $root->appendChild($resources);
  7441. $xmldoc->appendChild($root);
  7442. //todo: add a readme file here, with a short description and a link to the Reload player
  7443. //then add the file to the zip, then destroy the file (this is done automatically)
  7444. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7445. //error_log(print_r($zip_files,true),0);
  7446. foreach($zip_files as $file_path)
  7447. {
  7448. if(empty($file_path)){continue;}
  7449. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7450. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7451. $this->create_path($dest_file);
  7452. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('SYS_ARCHIVE_PATH').$temp_dir_short.'/'.$file_path,0);
  7453. //echo $main_path.$file_path.'<br>';
  7454. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7455. //check if the file needs a link update
  7456. if(in_array($file_path,array_keys($link_updates))){
  7457. $string = file_get_contents($dest_file);
  7458. unlink($dest_file);
  7459. foreach($link_updates[$file_path] as $old_new)
  7460. {
  7461. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7462. //this is an ugly hack that allows .flv files to be found by the flv player that
  7463. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7464. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7465. // ../../.. to return from inc/lib/flv_player to the document/main path
  7466. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7467. {
  7468. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7469. }
  7470. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7471. {
  7472. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7473. }
  7474. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7475. }
  7476. file_put_contents($dest_file,$string);
  7477. }
  7478. }
  7479. foreach($zip_files_abs as $file_path)
  7480. {
  7481. if(empty($file_path)){continue;}
  7482. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7483. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7484. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7485. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7486. $this->create_path($dest_file);
  7487. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path,0);
  7488. //error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path,0);
  7489. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7490. copy($main_path.$file_path,$dest_file);
  7491. //check if the file needs a link update
  7492. if(in_array($file_path,array_keys($link_updates)))
  7493. {
  7494. $string = file_get_contents($dest_file);
  7495. unlink($dest_file);
  7496. foreach($link_updates[$file_path] as $old_new)
  7497. {
  7498. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7499. //this is an ugly hack that allows .flv files to be found by the flv player that
  7500. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7501. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7502. // ../../.. to return from inc/lib/flv_player to the document/main path
  7503. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7504. {
  7505. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7506. }
  7507. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7508. }
  7509. file_put_contents($dest_file,$string);
  7510. }
  7511. }
  7512. if(is_array($links_to_create))
  7513. {
  7514. foreach($links_to_create as $file=>$link)
  7515. {
  7516. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7517. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7518. }
  7519. }
  7520. // add non exportable message explanation
  7521. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7522. $file_content =
  7523. <<<EOD
  7524. <html>
  7525. <head>
  7526. <style>
  7527. .error-message {
  7528. font-family: arial, verdana, helvetica, sans-serif;
  7529. border-width: 1px;
  7530. border-style: solid;
  7531. left: 50%;
  7532. margin: 10px auto;
  7533. min-height: 30px;
  7534. padding: 5px;
  7535. right: 50%;
  7536. width: 500px;
  7537. background-color: #FFD1D1;
  7538. border-color: #FF0000;
  7539. color: #000;
  7540. }
  7541. </style>
  7542. <body>
  7543. <div class="error-message">
  7544. $lang_not_exportable
  7545. </div>
  7546. </body>
  7547. </html>
  7548. EOD;
  7549. if(!is_dir($archive_path.$temp_dir_short.'/document'))
  7550. {
  7551. @mkdir($archive_path.$temp_dir_short.'/document');
  7552. }
  7553. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7554. //Add the extra files that go along with a SCORM package
  7555. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7556. $extra_files = scandir($main_code_path);
  7557. foreach ($extra_files as $extra_file) {
  7558. if (strpos($extra_file, '.') === 0)
  7559. continue;
  7560. else {
  7561. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7562. $this->create_path($dest_file);
  7563. copy($main_code_path.$extra_file,$dest_file);
  7564. }
  7565. }
  7566. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7567. $xmldoc->save($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7568. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7569. //clean possible temporary files
  7570. foreach($files_cleanup as $file)
  7571. {
  7572. $res = unlink($file);
  7573. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7574. }
  7575. //Send file to client
  7576. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7577. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7578. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7579. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7580. }
  7581. /**
  7582. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7583. * if it doesn't exist
  7584. */
  7585. function create_path($path) {
  7586. $path_bits = split('/', dirname($path));
  7587. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7588. $path_built = IS_WINDOWS_OS ? '' : '/';
  7589. foreach ($path_bits as $bit) {
  7590. if (!empty ($bit)) {
  7591. $new_path = $path_built . $bit;
  7592. if (is_dir($new_path)) {
  7593. $path_built = $new_path . '/';
  7594. } else {
  7595. mkdir($new_path);
  7596. $path_built = $new_path . '/';
  7597. }
  7598. }
  7599. }
  7600. }
  7601. /**
  7602. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7603. * @return boolean The results of the unlink function, or false if there was no image to start with
  7604. */
  7605. function delete_lp_image() {
  7606. $img = $this->get_preview_image();
  7607. if ($img != '') {
  7608. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7609. $this->set_preview_image('');
  7610. return @ unlink($del_file);
  7611. } else {
  7612. return false;
  7613. }
  7614. }
  7615. /**
  7616. * Uploads an author image to the upload/learning_path/images directory
  7617. * @param array The image array, coming from the $_FILES superglobal
  7618. * @return boolean True on success, false on error
  7619. */
  7620. function upload_image($image_array) {
  7621. $image_moved = false;
  7622. if (!empty ($image_array['name'])) {
  7623. $upload_ok = process_uploaded_file($image_array);
  7624. $has_attachment = true;
  7625. } else {
  7626. $image_moved = true;
  7627. }
  7628. if ($upload_ok) {
  7629. if ($has_attachment) {
  7630. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7631. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7632. $updir = $sys_course_path . $courseDir;
  7633. // Try to add an extension to the file if it hasn't one
  7634. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7635. if (!filter_extension($new_file_name)) {
  7636. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7637. $image_moved = false;
  7638. } else {
  7639. $file_extension = explode('.', $image_array['name']);
  7640. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7641. $new_file_name = uniqid('') . '.' . $file_extension;
  7642. $new_path = $updir . '/' . $new_file_name;
  7643. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7644. // resize the image
  7645. include_once (api_get_path(LIBRARY_PATH) . 'image.lib.php');
  7646. $temp = new image($image_array['tmp_name']);
  7647. $picture_infos=@getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7648. if ($picture_infos[0] > 104) {
  7649. $thumbwidth = 104;
  7650. } else {
  7651. $thumbwidth = $picture_infos[0];
  7652. }
  7653. if ($picture_infos[1] > 96) {
  7654. $new_height = 96;
  7655. } else {
  7656. $new_height = $picture_infos[1];
  7657. }
  7658. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7659. $temp->resize($thumbwidth,$new_height,0);
  7660. $type=$picture_infos[2];
  7661. $result=false;
  7662. switch ($type)
  7663. {
  7664. case 2 :
  7665. $result=$temp->send_image('JPG',$new_path);
  7666. break;
  7667. case 3 :
  7668. $result=$temp->send_image('PNG',$new_path);
  7669. break;
  7670. case 1 :
  7671. $result=$temp->send_image('GIF',$new_path);
  7672. break;
  7673. }
  7674. $temp->resize($thumbwidth, $new_height, 0);
  7675. $type = $picture_infos[2];
  7676. $result = false;
  7677. switch ($type) {
  7678. case 2 :
  7679. $result = $temp->send_image('JPG', $new_path);
  7680. break;
  7681. case 3 :
  7682. $result = $temp->send_image('PNG', $new_path);
  7683. break;
  7684. case 1 :
  7685. $result = $temp->send_image('GIF', $new_path);
  7686. break;
  7687. }
  7688. // Storing the image filename
  7689. if ($result) {
  7690. $image_moved = true;
  7691. $this->set_preview_image($new_file_name);
  7692. return true;
  7693. }
  7694. }
  7695. }
  7696. }
  7697. return false;
  7698. }
  7699. }
  7700. if (!function_exists('trim_value')) {
  7701. function trim_value(& $value) {
  7702. $value = trim($value);
  7703. }
  7704. }