learnpath.class.php 333 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001
  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. class learnpath {
  15. var $attempt = 0; //the number for the current ID view
  16. var $cc; //course (code) this learnpath is located in
  17. var $current; //id of the current item the user is viewing
  18. var $current_score; //the score of the current item
  19. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  20. var $current_time_stop; //the time the user closed this resource
  21. var $default_status = 'not attempted';
  22. var $encoding = 'UTF-8';
  23. var $error = '';
  24. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  25. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  26. var $index; //the index of the active learnpath_item in $ordered_items array
  27. var $items = array();
  28. var $last; //item_id of last item viewed in the learning path
  29. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  30. var $license; //which license this course has been given - not used yet on 20060522
  31. var $lp_id; //DB ID for this learnpath
  32. var $lp_view_id; //DB ID for lp_view
  33. var $log_file; //file where to log learnpath API msg
  34. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  35. var $message = '';
  36. var $mode = 'embedded'; //holds the video display mode (fullscreen or embedded)
  37. var $name; //learnpath name (they generally have one)
  38. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  39. var $path = ''; //path inside the scorm directory (if scorm)
  40. var $theme; // the current theme of the learning path
  41. var $preview_image; // the current image of the learning path
  42. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  43. var $prevent_reinit = 1;
  44. // Describes the mode of progress bar display
  45. var $progress_bar_mode = '%';
  46. // Percentage progress as saved in the db
  47. var $progress_db = '0';
  48. var $proximity; //wether the content is distant or local or unknown
  49. var $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  50. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  51. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  52. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  53. //TODO check if this type variable is useful here (instead of just in the controller script)
  54. var $user_id; //ID of the user that is viewing/using the course
  55. var $update_queue = array();
  56. var $scorm_debug = 0;
  57. var $arrMenu = array(); //array for the menu items
  58. var $debug = 0; //logging level
  59. var $lp_session_id =0;
  60. /**
  61. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  62. * Also builds the list of items into $this->items.
  63. * @param string Course code
  64. * @param integer Learnpath ID
  65. * @param integer User ID
  66. * @return boolean True on success, false on error
  67. */
  68. function learnpath($course, $lp_id, $user_id) {
  69. //check params
  70. //check course code
  71. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  72. if(empty($course)){
  73. $this->error = 'Course code is empty';
  74. return false;
  75. }
  76. else
  77. {
  78. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  79. //$course = Database::escape_string($course);
  80. $course = $this->escape_string($course);
  81. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  82. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  83. //$res = Database::query($sql);
  84. $res = Database::query($sql, __FILE__, __LINE__);
  85. if(Database::num_rows($res)>0)
  86. {
  87. $this->cc = $course;
  88. }
  89. else
  90. {
  91. $this->error = 'Course code does not exist in database ('.$sql.')';
  92. return false;
  93. }
  94. }
  95. //check learnpath ID
  96. if(empty($lp_id))
  97. {
  98. $this->error = 'Learnpath ID is empty';
  99. return false;
  100. }
  101. else
  102. {
  103. //TODO make it flexible to use any course_code (still using env course code here)
  104. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  105. //$id = Database::escape_integer($id);
  106. $lp_id = $this->escape_string($lp_id);
  107. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  108. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  109. //$res = Database::query($sql);
  110. $res = Database::query($sql, __FILE__, __LINE__);
  111. if(Database::num_rows($res)>0)
  112. {
  113. $this->lp_id = $lp_id;
  114. $row = Database::fetch_array($res);
  115. $this->type = $row['lp_type'];
  116. $this->name = stripslashes($row['name']);
  117. $this->encoding = $row['default_encoding'];
  118. $this->proximity = $row['content_local'];
  119. $this->theme = $row['theme'];
  120. $this->maker = $row['content_maker'];
  121. $this->prevent_reinit = $row['prevent_reinit'];
  122. $this->license = $row['content_license'];
  123. $this->scorm_debug = $row['debug'];
  124. $this->js_lib = $row['js_lib'];
  125. $this->path = $row['path'];
  126. $this->preview_image= $row['preview_image'];
  127. $this->author= $row['author'];
  128. $this->lp_session_id = $row['session_id'];
  129. if($this->type == 2){
  130. if($row['force_commit'] == 1){
  131. $this->force_commit = true;
  132. }
  133. }
  134. $this->mode = $row['default_view_mod'];
  135. }
  136. else
  137. {
  138. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  139. return false;
  140. }
  141. }
  142. //check user ID
  143. if(empty($user_id)){
  144. $this->error = 'User ID is empty';
  145. return false;
  146. }
  147. else
  148. {
  149. //$main_table = Database::get_main_user_table();
  150. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  151. //$user_id = Database::escape_integer($user_id);
  152. $user_id = $this->escape_string($user_id);
  153. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  154. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  155. //$res = Database::query($sql);
  156. $res = Database::query($sql, __FILE__, __LINE__);
  157. if(Database::num_rows($res)>0)
  158. {
  159. $this->user_id = $user_id;
  160. }
  161. else
  162. {
  163. $this->error = 'User ID does not exist in database ('.$sql.')';
  164. return false;
  165. }
  166. }
  167. //end of variables checking
  168. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  169. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  170. //selecting by view_count descending allows to get the highest view_count first
  171. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  172. if ($this->debug > 2) {
  173. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);
  174. }
  175. //$res = Database::query($sql);
  176. $res = Database::query($sql, __FILE__, __LINE__);
  177. $view_id = 0; //used later to query lp_item_view
  178. if (Database :: num_rows($res) > 0) {
  179. if ($this->debug > 2) {
  180. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Found previous view', 0);
  181. }
  182. $row = Database :: fetch_array($res);
  183. $this->attempt = $row['view_count'];
  184. $this->lp_view_id = $row['id'];
  185. $this->last_item_seen = $row['last_item'];
  186. $this->progress_db = $row['progress'];
  187. } else {
  188. if ($this->debug > 2) {
  189. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - NOT Found previous view', 0);
  190. }
  191. $this->attempt = 1;
  192. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  193. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  194. $this->lp_view_id = Database :: insert_id();
  195. if ($this->debug > 2) {
  196. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  197. }
  198. }
  199. //initialise items
  200. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  201. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  202. $res = Database::query($sql, __FILE__, __LINE__);
  203. while($row = Database::fetch_array($res))
  204. {
  205. $oItem = '';
  206. //$this->ordered_items[] = $row['id'];
  207. switch ($this->type) {
  208. case 3 : //aicc
  209. $oItem = new aiccItem('db', $row['id']);
  210. if (is_object($oItem)) {
  211. $my_item_id = $oItem->get_id();
  212. $oItem->set_lp_view($this->lp_view_id);
  213. $oItem->set_prevent_reinit($this->prevent_reinit);
  214. // Don't use reference here as the next loop will make the pointed object change
  215. $this->items[$my_item_id] = $oItem;
  216. $this->refs_list[$oItem->ref] = $my_item_id;
  217. if ($this->debug > 2) {
  218. error_log('New LP - learnpath::learnpath() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  219. }
  220. }
  221. break;
  222. case 2 :
  223. require_once ('scorm.class.php');
  224. require_once ('scormItem.class.php');
  225. $oItem = new scormItem('db', $row['id']);
  226. if (is_object($oItem)) {
  227. $my_item_id = $oItem->get_id();
  228. $oItem->set_lp_view($this->lp_view_id);
  229. $oItem->set_prevent_reinit($this->prevent_reinit);
  230. // Don't use reference here as the next loop will make the pointed object change
  231. $this->items[$my_item_id] = $oItem;
  232. $this->refs_list[$oItem->ref] = $my_item_id;
  233. if ($this->debug > 2) {
  234. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  235. }
  236. }
  237. break;
  238. case 1 :
  239. default :
  240. require_once ('learnpathItem.class.php');
  241. $oItem = new learnpathItem($row['id'], $user_id);
  242. if (is_object($oItem)) {
  243. $my_item_id = $oItem->get_id();
  244. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  245. $oItem->set_prevent_reinit($this->prevent_reinit);
  246. // Don't use reference here as the next loop will make the pointed object change
  247. $this->items[$my_item_id] = $oItem;
  248. $this->refs_list[$my_item_id] = $my_item_id;
  249. if ($this->debug > 2) {
  250. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  251. }
  252. }
  253. break;
  254. }
  255. //items is a list of pointers to all items, classified by DB ID, not SCO id
  256. if ($row['parent_item_id'] == 0 OR empty ($this->items[$row['parent_item_id']])) {
  257. $this->items[$row['id']]->set_level(0);
  258. } else {
  259. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  260. $this->items[$row['id']]->set_level($level);
  261. if (is_object($this->items[$row['parent_item_id']])) {
  262. //items is a list of pointers from item DB ids to item objects
  263. $this->items[$row['parent_item_id']]->add_child($row['id']);
  264. } else {
  265. if ($this->debug > 2) {
  266. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  267. }
  268. }
  269. }
  270. //get last viewing vars
  271. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  272. //this query should only return one or zero result
  273. $sql = "SELECT * " .
  274. "FROM $lp_item_view_table " .
  275. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  276. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  277. if ($this->debug > 2) {
  278. error_log('New LP - learnpath::learnpath() - Selecting item_views: ' . $sql, 0);
  279. }
  280. //get the item status
  281. $res2 = Database::query($sql, __FILE__, __LINE__);
  282. if (Database :: num_rows($res2) > 0) {
  283. //if this learnpath has already been used by this user, get his last attempt count and
  284. //the last item seen back into this object
  285. //$max = 0;
  286. $row2 = Database :: fetch_array($res2);
  287. if ($this->debug > 2) {
  288. error_log('New LP - learnpath::learnpath() - Got item_view: ' . print_r($row2, true), 0);
  289. }
  290. $this->items[$row['id']]->set_status($row2['status']);
  291. if (empty ($row2['status'])) {
  292. $this->items[$row['id']]->set_status($this->default_status);
  293. }
  294. //$this->attempt = $row['view_count'];
  295. //$this->last_item = $row['id'];
  296. } else //no item found in lp_item_view for this view
  297. {
  298. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  299. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  300. //$this->attempt = 1;
  301. //$this->last_item = 0;
  302. $this->items[$row['id']]->set_status($this->default_status);
  303. //Add that row to the lp_item_view table so that we have something to show in the stats page
  304. $sql_ins = "INSERT INTO $lp_item_view_table " .
  305. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  306. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  307. if ($this->debug > 2) {
  308. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  309. }
  310. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  311. }
  312. //setting the view in the item object
  313. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  314. }
  315. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0);
  316. $this->max_ordered_items = 0;
  317. foreach ($this->ordered_items as $index => $dummy) {
  318. if ($index > $this->max_ordered_items AND !empty ($dummy)) {
  319. $this->max_ordered_items = $index;
  320. }
  321. }
  322. //TODO define the current item better
  323. $this->first();
  324. if ($this->debug > 2) {
  325. error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  326. }
  327. }
  328. /**
  329. * Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
  330. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  331. *
  332. * @param int $parent
  333. * @param int $previous
  334. * @param string $type
  335. * @param int $id
  336. * @param string $title
  337. * @param string $description
  338. * @return int
  339. */
  340. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  341. if ($this->debug > 0) {
  342. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  343. }
  344. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  345. $parent = intval($parent);
  346. $previous = intval($previous);
  347. $type = $this->escape_string($type);
  348. $id = intval($id);
  349. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  350. if (empty ($max_time_allowed)) {
  351. $max_time_allowed = 0;
  352. }
  353. //$title = htmlspecialchars($title, ENT_QUOTES, $charset); // TODO: To be checked for encoding problems.
  354. //$title = $this->escape_string(api_convert_encoding($title, $this->encoding, $charset));
  355. $title = $this->escape_string(api_convert_encoding($title, $this->encoding, api_get_system_encoding()));
  356. $description = $this->escape_string(api_convert_encoding($description, $this->encoding, api_get_system_encoding()));
  357. $sql_count = " SELECT COUNT(id) AS num
  358. FROM " . $tbl_lp_item . "
  359. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  360. $res_count = Database::query($sql_count, __FILE__, __LINE__);
  361. $row = Database :: fetch_array($res_count);
  362. $num = $row['num'];
  363. if ($num > 0) {
  364. if ($previous == 0) {
  365. $sql = "SELECT id, next_item_id, display_order
  366. FROM " . $tbl_lp_item . "
  367. WHERE
  368. lp_id = " . $this->get_id() . " AND
  369. parent_item_id = " . $parent . " AND
  370. previous_item_id = 0 OR previous_item_id=" . $parent;
  371. $result = Database::query($sql, __FILE__, __LINE__);
  372. $row = Database :: fetch_array($result);
  373. $tmp_previous = 0;
  374. $next = $row['id'];
  375. $display_order = 0;
  376. } else {
  377. $previous = (int) $previous;
  378. $sql = "
  379. SELECT
  380. id,
  381. previous_item_id,
  382. next_item_id,
  383. display_order
  384. FROM " . $tbl_lp_item . "
  385. WHERE
  386. lp_id = " . $this->get_id() . " AND
  387. id = " . $previous;
  388. $result = Database::query($sql, __FILE__, __LINE__);
  389. $row = Database :: fetch_array($result);
  390. $tmp_previous = $row['id'];
  391. $next = $row['next_item_id'];
  392. $display_order = $row['display_order'];
  393. }
  394. } else {
  395. $tmp_previous = 0;
  396. $next = 0;
  397. $display_order = 0;
  398. }
  399. $new_item_id = -1;
  400. $id = $this->escape_string($id);
  401. if ($type == 'quiz') {
  402. $sql = 'SELECT SUM(ponderation)
  403. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  404. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  405. ON quiz_question.id = quiz_rel_question.question_id
  406. AND quiz_rel_question.exercice_id = ' . $id;
  407. $rsQuiz = Database::query($sql, __FILE__, __LINE__);
  408. $max_score = Database :: result($rsQuiz, 0, 0);
  409. } else {
  410. $max_score = 100;
  411. }
  412. if ($prerequisites != 0) {
  413. $sql_ins = "
  414. INSERT INTO " . $tbl_lp_item . " (
  415. lp_id,
  416. item_type,
  417. ref,
  418. title,
  419. description,
  420. path,
  421. max_score,
  422. parent_item_id,
  423. previous_item_id,
  424. next_item_id,
  425. display_order,
  426. prerequisite,
  427. max_time_allowed
  428. ) VALUES (
  429. " . $this->get_id() . ",
  430. '" . $type . "',
  431. '',
  432. '" . $title . "',
  433. '" . $description . "',
  434. '" . $id . "',
  435. '" . $max_score . "',
  436. " . $parent . ",
  437. " . $previous . ",
  438. " . $next . ",
  439. " . ($display_order +1) . ",
  440. " . $prerequisites . ",
  441. " . $max_time_allowed . "
  442. )";
  443. } else {
  444. //insert new item
  445. $sql_ins = "
  446. INSERT INTO " . $tbl_lp_item . " (
  447. lp_id,
  448. item_type,
  449. ref,
  450. title,
  451. description,
  452. path,
  453. max_score,
  454. parent_item_id,
  455. previous_item_id,
  456. next_item_id,
  457. display_order,
  458. max_time_allowed
  459. ) VALUES (
  460. " . $this->get_id() . ",
  461. '" . $type . "',
  462. '',
  463. '" . $title . "',
  464. '" . $description . "',
  465. '" . $id . "',
  466. '" . $max_score . "',
  467. " . $parent . ",
  468. " . $previous . ",
  469. " . $next . ",
  470. " . ($display_order +1) . ",
  471. " . $max_time_allowed . "
  472. )";
  473. }
  474. if ($this->debug > 2) {
  475. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  476. }
  477. $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
  478. if ($res_ins > 0) {
  479. $new_item_id = Database :: insert_id($res_ins);
  480. //update the item that should come after the new item
  481. $sql_update_next = "
  482. UPDATE " . $tbl_lp_item . "
  483. SET previous_item_id = " . $new_item_id . "
  484. WHERE id = " . $next;
  485. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  486. //update the item that should be before the new item
  487. $sql_update_previous = "
  488. UPDATE " . $tbl_lp_item . "
  489. SET next_item_id = " . $new_item_id . "
  490. WHERE id = " . $tmp_previous;
  491. $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
  492. //update all the items after the new item
  493. $sql_update_order = "
  494. UPDATE " . $tbl_lp_item . "
  495. SET display_order = display_order + 1
  496. WHERE
  497. lp_id = " . $this->get_id() . " AND
  498. id <> " . $new_item_id . " AND
  499. parent_item_id = " . $parent . " AND
  500. display_order > " . $display_order;
  501. $res_update_previous = Database::query($sql_update_order, __FILE__, __LINE__);
  502. //update the item that should come after the new item
  503. $sql_update_ref = "
  504. UPDATE " . $tbl_lp_item . "
  505. SET ref = " . $new_item_id . "
  506. WHERE id = " . $new_item_id;
  507. Database::query($sql_update_ref, __FILE__, __LINE__);
  508. }
  509. // upload audio
  510. if (!empty ($_FILES['mp3']['name'])) {
  511. // create the audio folder if it does not exist yet
  512. global $_course;
  513. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  514. if (!is_dir($filepath . 'audio')) {
  515. $perm = api_get_setting('permissions_for_new_directories');
  516. $perm = octdec(!empty ($perm) ? $perm : '0770');
  517. mkdir($filepath . 'audio', $perm);
  518. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  519. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  520. }
  521. // upload the file in the documents tool
  522. include_once (api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  523. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  524. // getting the filename only
  525. $file_components = explode('/', $file_path);
  526. $file = $file_components[count($file_components) - 1];
  527. // store the mp3 file in the lp_item table
  528. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  529. Database::query($sql_insert_audio, __FILE__, __LINE__);
  530. }
  531. return $new_item_id;
  532. }
  533. /**
  534. * Static admin function allowing addition of a learnpath to a course.
  535. * @param string Course code
  536. * @param string Learnpath name
  537. * @param string Learnpath description string, if provided
  538. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  539. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  540. * @param string Zip file containing the learnpath or directory containing the learnpath
  541. * @return integer The new learnpath ID on success, 0 on failure
  542. */
  543. function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '') {
  544. global $charset;
  545. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  546. //TODO
  547. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  548. //check course code exists
  549. //check lp_name doesn't exist, otherwise append something
  550. $i = 0;
  551. $name = learnpath :: escape_string($name);
  552. //session_id
  553. $session_id = api_get_session_id();
  554. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  555. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  556. $res_name = Database::query($check_name, __FILE__, __LINE__);
  557. while (Database :: num_rows($res_name)) {
  558. //there is already one such name, update the current one a bit
  559. $i++;
  560. $name = $name . ' - ' . $i;
  561. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  562. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  563. $res_name = Database::query($check_name, __FILE__, __LINE__);
  564. }
  565. //new name does not exist yet; keep it
  566. //escape description
  567. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); //Kevin: added htmlentities()
  568. $type = 1;
  569. switch ($learnpath) {
  570. case 'guess' :
  571. break;
  572. case 'dokeos' :
  573. $type = 1;
  574. break;
  575. case 'aicc' :
  576. break;
  577. }
  578. switch ($origin) {
  579. case 'zip' :
  580. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  581. break;
  582. case 'manual' :
  583. default :
  584. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  585. $res_max = Database::query($get_max, __FILE__, __LINE__);
  586. if (Database :: num_rows($res_max) < 1) {
  587. $dsp = 1;
  588. } else {
  589. $row = Database :: fetch_array($res_max);
  590. $dsp = $row[0] + 1;
  591. }
  592. $sql_insert = "INSERT INTO $tbl_lp " .
  593. "(lp_type,name,description,path,default_view_mod," .
  594. "default_encoding,display_order,content_maker," .
  595. "content_local,js_lib,session_id) " .
  596. "VALUES ($type,'$name','$description','','embedded'," .
  597. "'UTF-8','$dsp','Dokeos'," .
  598. "'local','','".Database::escape_string($session_id)."')";
  599. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  600. $res_insert = Database::query($sql_insert, __FILE__, __LINE__);
  601. $id = Database :: insert_id();
  602. if ($id > 0) {
  603. //insert into item_property
  604. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  605. return $id;
  606. }
  607. break;
  608. }
  609. }
  610. /**
  611. * Appends a message to the message attribute
  612. * @param string Message to append.
  613. */
  614. function append_message($string) {
  615. if ($this->debug > 0) {
  616. error_log('New LP - In learnpath::append_message()', 0);
  617. }
  618. $this->message .= $string;
  619. }
  620. /**
  621. * Autocompletes the parents of an item in case it's been completed or passed
  622. * @param integer Optional ID of the item from which to look for parents
  623. */
  624. function autocomplete_parents($item) {
  625. if ($this->debug > 0) {
  626. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  627. }
  628. if (empty ($item)) {
  629. $item = $this->current;
  630. }
  631. $parent_id = $this->items[$item]->get_parent();
  632. if ($this->debug > 2) {
  633. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  634. }
  635. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  636. //if $item points to an object and there is a parent
  637. if ($this->debug > 2) {
  638. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  639. }
  640. $current_item = & $this->items[$item];
  641. $parent = & $this->items[$parent_id]; //get the parent
  642. //new experiment including failed and browsed in completed status
  643. $current_status = $current_item->get_status();
  644. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  645. //if the current item is completed or passes or succeeded
  646. $completed = true;
  647. if ($this->debug > 2) {
  648. error_log('New LP - Status of current item is alright', 0);
  649. }
  650. foreach ($parent->get_children() as $child) {
  651. //check all his brothers (his parent's children) for completion status
  652. if ($child != $item) {
  653. if ($this->debug > 2) {
  654. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  655. }
  656. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  657. //Trying completing parents of failed and browsed items as well
  658. if ($this->items[$child]->status_is(array (
  659. 'completed',
  660. 'passed',
  661. 'succeeded',
  662. 'browsed',
  663. 'failed'
  664. ))) {
  665. //keep completion status to true
  666. } else {
  667. if ($this->debug > 2) {
  668. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  669. }
  670. $completed = false;
  671. }
  672. }
  673. }
  674. if ($completed == true) { //if all the children were completed
  675. $parent->set_status('completed');
  676. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  677. $this->update_queue[$parent->get_id()] = $parent->get_status();
  678. if ($this->debug > 2) {
  679. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  680. }
  681. $this->autocomplete_parents($parent->get_id()); //recursive call
  682. }
  683. } else {
  684. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  685. }
  686. }
  687. }
  688. /**
  689. * Autosaves the current results into the database for the whole learnpath
  690. */
  691. function autosave() {
  692. if ($this->debug > 0) {
  693. error_log('New LP - In learnpath::autosave()', 0);
  694. }
  695. //TODO add aditionnal save operations for the learnpath itself
  696. }
  697. /**
  698. * Clears the message attribute
  699. */
  700. function clear_message() {
  701. if ($this->debug > 0) {
  702. error_log('New LP - In learnpath::clear_message()', 0);
  703. }
  704. $this->message = '';
  705. }
  706. /**
  707. * Closes the current resource
  708. *
  709. * Stops the timer
  710. * Saves into the database if required
  711. * Clears the current resource data from this object
  712. * @return boolean True on success, false on failure
  713. */
  714. function close() {
  715. if ($this->debug > 0) {
  716. error_log('New LP - In learnpath::close()', 0);
  717. }
  718. if (empty ($this->lp_id)) {
  719. $this->error = 'Trying to close this learnpath but no ID is set';
  720. return false;
  721. }
  722. $this->current_time_stop = time();
  723. if ($this->save) {
  724. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  725. /*
  726. $sql = "UPDATE $learnpath_view_table " .
  727. "SET " .
  728. "stop_time = ".$this->current_time_stop.", " .
  729. "score = ".$this->current_score.", ".
  730. "WHERE learnpath_id = '".$this->lp_id."'";
  731. //$res = Database::query($sql);
  732. $res = Database::query($res);
  733. if(Database::affected_rows($res)<1)
  734. {
  735. $this->error = 'Could not update learnpath_view table while closing learnpath';
  736. return false;
  737. }
  738. */
  739. }
  740. $this->ordered_items = array ();
  741. $this->index = 0;
  742. unset ($this->lp_id);
  743. //unset other stuff
  744. return true;
  745. }
  746. /**
  747. * Static admin function allowing removal of a learnpath
  748. * @param string Course code
  749. * @param integer Learnpath ID
  750. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  751. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  752. */
  753. function delete($course = null, $id = null, $delete = 'keep') {
  754. //TODO implement a way of getting this to work when the current object is not set
  755. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  756. //if(empty($course)){$course = api_get_course_id();}
  757. //if(empty($id)){$id = $this->get_id();}
  758. //If an ID is specifically given and the current LP is not the same,
  759. //prevent delete
  760. if (!empty ($id) && ($id != $this->lp_id)) {
  761. return false;
  762. }
  763. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  764. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  765. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  766. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  767. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  768. //delete lp item id
  769. foreach ($this->items as $id => $dummy) {
  770. //$this->items[$id]->delete();
  771. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  772. $res_del_item_view = Database::query($sql_del_view, __FILE__, __LINE__);
  773. }
  774. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  775. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  776. $res_del_item = Database::query($sql_del_item, __FILE__, __LINE__);
  777. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  778. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  779. $res_del_view = Database::query($sql_del_view, __FILE__, __LINE__);
  780. $this->toggle_publish($this->lp_id, 'i');
  781. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  782. if ($this->type == 2 OR $this->type == 3) {
  783. //this is a scorm learning path, delete the files as well
  784. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  785. $res = Database::query($sql, __FILE__, __LINE__);
  786. if (Database :: num_rows($res) > 0) {
  787. $row = Database :: fetch_array($res);
  788. $path = $row['path'];
  789. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  790. $res = Database::query($sql, __FILE__, __LINE__);
  791. if (Database :: num_rows($res) > 0) { //another learning path uses this directory, so don't delete it
  792. if ($this->debug > 2) {
  793. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  794. }
  795. } else {
  796. //no other LP uses that directory, delete it
  797. $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses
  798. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course
  799. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  800. if ($this->debug > 2) {
  801. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  802. }
  803. // Proposed by Christophe (clefevre).
  804. if (strcmp(substr($path, -2), "/.") == 0) {
  805. $path = substr($path, 0, -1); // Remove "." at the end
  806. }
  807. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  808. rmdirr($course_scorm_dir . $path);
  809. }
  810. }
  811. }
  812. }
  813. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  814. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  815. $res_del_lp = Database::query($sql_del_lp, __FILE__, __LINE__);
  816. $this->update_display_order(); //updates the display order of all lps
  817. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  818. require_once '../gradebook/lib/be.inc.php';
  819. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  820. //delete link of gradebook tool
  821. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  822. $result = Database::query($sql, __FILE__, __LINE__);
  823. $row = Database :: fetch_array($result, 'ASSOC');
  824. //fixing gradebook link deleted see #5229
  825. if (!empty($row['id'])) {
  826. $link = LinkFactory :: load($row['id']);
  827. if ($link[0] != null) {
  828. $link[0]->delete();
  829. }
  830. }
  831. //TODO: also delete items and item-views
  832. if (api_get_setting('search_enabled') == 'true') {
  833. require_once (api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  834. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  835. }
  836. }
  837. /**
  838. * Removes all the children of one item - dangerous!
  839. * @param integer Element ID of which children have to be removed
  840. * @return integer Total number of children removed
  841. */
  842. function delete_children_items($id) {
  843. if ($this->debug > 0) {
  844. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  845. }
  846. $num = 0;
  847. if (empty ($id) || $id != strval(intval($id))) {
  848. return false;
  849. }
  850. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  851. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  852. $res = Database::query($sql, __FILE__, __LINE__);
  853. while ($row = Database :: fetch_array($res)) {
  854. $num += $this->delete_children_items($row['id']);
  855. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  856. $res_del = Database::query($sql_del, __FILE__, __LINE__);
  857. $num++;
  858. }
  859. return $num;
  860. }
  861. /**
  862. * Removes an item from the current learnpath
  863. * @param integer Elem ID (0 if first)
  864. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  865. * @return integer Number of elements moved
  866. * @todo implement resource removal
  867. */
  868. function delete_item($id, $remove = 'keep') {
  869. if ($this->debug > 0) {
  870. error_log('New LP - In learnpath::delete_item()', 0);
  871. }
  872. //TODO - implement the resource removal
  873. if (empty ($id) || $id != strval(intval($id))) {
  874. return false;
  875. }
  876. //first select item to get previous, next, and display order
  877. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  878. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  879. $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
  880. if (Database :: num_rows($res_sel) < 1) {
  881. return false;
  882. }
  883. $row = Database :: fetch_array($res_sel);
  884. $previous = $row['previous_item_id'];
  885. $next = $row['next_item_id'];
  886. $display = $row['display_order'];
  887. $parent = $row['parent_item_id'];
  888. $lp = $row['lp_id'];
  889. //delete children items
  890. $num = $this->delete_children_items($id);
  891. if ($this->debug > 2) {
  892. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  893. }
  894. //now delete the item
  895. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  896. if ($this->debug > 2) {
  897. error_log('New LP - Deleting item: ' . $sql_del, 0);
  898. }
  899. $res_del = Database::query($sql_del, __FILE__, __LINE__);
  900. //now update surrounding items
  901. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  902. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  903. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  904. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  905. //now update all following items with new display order
  906. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  907. $res_all = Database::query($sql_all, __FILE__, __LINE__);
  908. // remove from search engine if enabled
  909. if (api_get_setting('search_enabled') == 'true') {
  910. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  911. $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';
  912. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  913. $res = Database::query($sql, __FILE__, __LINE__);
  914. if (Database :: num_rows($res) > 0) {
  915. $row2 = Database :: fetch_array($res);
  916. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  917. $di = new DokeosIndexer();
  918. $di->remove_document((int) $row2['search_did']);
  919. }
  920. $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';
  921. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  922. Database::query($sql, __FILE__, __LINE__);
  923. }
  924. }
  925. /**
  926. * Updates an item's content in place
  927. * @param integer Element ID
  928. * @param integer Parent item ID
  929. * @param integer Previous item ID
  930. * @param string Item title
  931. * @param string Item description
  932. * @param string Prerequisites (optional)
  933. * @param string Indexing terms (optional)
  934. * @param array The array resulting of the $_FILES[mp3] element
  935. * @return boolean True on success, false on error
  936. */
  937. function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = NULL, $max_time_allowed = 0) {
  938. global $charset;
  939. if ($this->debug > 0) {
  940. error_log('New LP - In learnpath::edit_item()', 0);
  941. }
  942. if (empty ($max_time_allowed)) {
  943. $max_time_allowed = 0;
  944. }
  945. if (empty ($id) or ($id != strval(intval($id))) or empty ($title)) {
  946. return false;
  947. }
  948. $title = api_convert_encoding($title, $this->encoding, $charset);
  949. $description = api_convert_encoding($description, $this->encoding, $charset);
  950. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  951. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  952. $res_select = Database::query($sql_select, __FILE__, __LINE__);
  953. $row_select = Database :: fetch_array($res_select);
  954. $audio_update_sql = '';
  955. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  956. // create the audio folder if it does not exist yet
  957. global $_course;
  958. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  959. if (!is_dir($filepath . 'audio')) {
  960. $perm = api_get_setting('permissions_for_new_directories');
  961. $perm = octdec(!empty ($perm) ? $perm : '0770');
  962. mkdir($filepath . 'audio', $perm);
  963. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  964. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
  965. }
  966. //upload file in documents
  967. $pi = pathinfo($audio['name']);
  968. if ($pi['extension'] == 'mp3') {
  969. $c_det = api_get_course_info($this->cc);
  970. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  971. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  972. $path = substr($path, 7);
  973. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  974. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  975. }
  976. }
  977. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  978. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  979. //TODO: htmlspecialchars to be checked for encoding related problems.
  980. if ($same_parent && $same_previous) {
  981. //only update title and description
  982. $sql_update = " UPDATE " . $tbl_lp_item . "
  983. SET title = '" . $this->escape_string($title) . "',
  984. prerequisite = '" . $prerequisites . "',
  985. description = '" . $this->escape_string($description) . "'
  986. " . $audio_update_sql . ",
  987. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  988. WHERE id = " . $id;
  989. $res_update = Database::query($sql_update, __FILE__, __LINE__);
  990. } else {
  991. $old_parent = $row_select['parent_item_id'];
  992. $old_previous = $row_select['previous_item_id'];
  993. $old_next = $row_select['next_item_id'];
  994. $old_order = $row_select['display_order'];
  995. $old_prerequisite = $row_select['prerequisite'];
  996. $old_max_time_allowed = $row_select['max_time_allowed'];
  997. /* BEGIN -- virtually remove the current item id */
  998. /* for the next and previous item it is like the current item doesn't exist anymore */
  999. if ($old_previous != 0) {
  1000. $sql_update_next = "
  1001. UPDATE " . $tbl_lp_item . "
  1002. SET next_item_id = " . $old_next . "
  1003. WHERE id = " . $old_previous;
  1004. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1005. //echo '<p>' . $sql_update_next . '</p>';
  1006. }
  1007. if ($old_next != 0) {
  1008. $sql_update_previous = "
  1009. UPDATE " . $tbl_lp_item . "
  1010. SET previous_item_id = " . $old_previous . "
  1011. WHERE id = " . $old_next;
  1012. $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
  1013. //echo '<p>' . $sql_update_previous . '</p>';
  1014. }
  1015. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  1016. $sql_update_order = "
  1017. UPDATE " . $tbl_lp_item . "
  1018. SET display_order = display_order - 1
  1019. WHERE
  1020. display_order > " . $old_order . " AND
  1021. parent_item_id = " . $old_parent;
  1022. $res_update_order = Database::query($sql_update_order, __FILE__, __LINE__);
  1023. //echo '<p>' . $sql_update_order . '</p>';
  1024. /* END -- virtually remove the current item id */
  1025. /* BEGIN -- update the current item id to his new location */
  1026. if ($previous == 0) {
  1027. //select the data of the item that should come after the current item
  1028. $sql_select_old = "
  1029. SELECT
  1030. id,
  1031. display_order
  1032. FROM " . $tbl_lp_item . "
  1033. WHERE
  1034. lp_id = " . $this->lp_id . " AND
  1035. parent_item_id = " . $parent . " AND
  1036. previous_item_id = " . $previous;
  1037. $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
  1038. $row_select_old = Database :: fetch_array($res_select_old);
  1039. //echo '<p>' . $sql_select_old . '</p>';
  1040. //if the new parent didn't have children before
  1041. if (Database :: num_rows($res_select_old) == 0) {
  1042. $new_next = 0;
  1043. $new_order = 1;
  1044. } else {
  1045. $new_next = $row_select_old['id'];
  1046. $new_order = $row_select_old['display_order'];
  1047. }
  1048. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1049. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1050. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1051. } else {
  1052. //select the data of the item that should come before the current item
  1053. $sql_select_old = "
  1054. SELECT
  1055. next_item_id,
  1056. display_order
  1057. FROM " . $tbl_lp_item . "
  1058. WHERE id = " . $previous;
  1059. $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
  1060. $row_select_old = Database :: fetch_array($res_select_old);
  1061. //echo '<p>' . $sql_select_old . '</p>';
  1062. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1063. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1064. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1065. $new_next = $row_select_old['next_item_id'];
  1066. $new_order = $row_select_old['display_order'] + 1;
  1067. }
  1068. //TODO: htmlspecialchars to be checked for encoding related problems.
  1069. //update the current item with the new data
  1070. $sql_update = "
  1071. UPDATE " . $tbl_lp_item . "
  1072. SET
  1073. title = '" . $this->escape_string($title) . "',
  1074. description = '" . $this->escape_string($description) . "',
  1075. parent_item_id = " . $parent . ",
  1076. previous_item_id = " . $previous . ",
  1077. next_item_id = " . $new_next . ",
  1078. display_order = " . $new_order . "
  1079. " . $audio_update_sql . "
  1080. WHERE id = " . $id;
  1081. $res_update_next = Database::query($sql_update, __FILE__, __LINE__);
  1082. //echo '<p>' . $sql_update . '</p>';
  1083. if ($previous != 0) {
  1084. //update the previous item's next_item_id
  1085. $sql_update_previous = "
  1086. UPDATE " . $tbl_lp_item . "
  1087. SET next_item_id = " . $id . "
  1088. WHERE id = " . $previous;
  1089. $res_update_next = Database::query($sql_update_previous, __FILE__, __LINE__);
  1090. //echo '<p>' . $sql_update_previous . '</p>';
  1091. }
  1092. if ($new_next != 0) {
  1093. //update the next item's previous_item_id
  1094. $sql_update_next = "
  1095. UPDATE " . $tbl_lp_item . "
  1096. SET previous_item_id = " . $id . "
  1097. WHERE id = " . $new_next;
  1098. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1099. //echo '<p>' . $sql_update_next . '</p>';
  1100. }
  1101. if ($old_prerequisite != $prerequisites) {
  1102. $sql_update_next = "
  1103. UPDATE " . $tbl_lp_item . "
  1104. SET prerequisite = " . $prerequisites . "
  1105. WHERE id = " . $id;
  1106. $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
  1107. }
  1108. if ($old_max_time_allowed != $max_time_allowed) {
  1109. $sql_update_max_time_allowed = "
  1110. UPDATE " . $tbl_lp_item . "
  1111. SET max_time_allowed = " . $max_time_allowed . "
  1112. WHERE id = " . $id;
  1113. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed, __FILE__, __LINE__);
  1114. }
  1115. //update all the items with the same or a bigger display_order than
  1116. //the current item
  1117. $sql_update_order = "
  1118. UPDATE " . $tbl_lp_item . "
  1119. SET display_order = display_order + 1
  1120. WHERE
  1121. lp_id = " . $this->get_id() . " AND
  1122. id <> " . $id . " AND
  1123. parent_item_id = " . $parent . " AND
  1124. display_order >= " . $new_order;
  1125. $res_update_next = Database::query($sql_update_order, __FILE__, __LINE__);
  1126. //echo '<p>' . $sql_update_order . '</p>';
  1127. /* END -- update the current item id to his new location */
  1128. }
  1129. }
  1130. /**
  1131. * Updates an item's prereq in place
  1132. * @param integer Element ID
  1133. * @param string Prerequisite Element ID
  1134. * @param string Prerequisite item type
  1135. * @param string Prerequisite min score
  1136. * @param string Prerequisite max score
  1137. * @return boolean True on success, false on error
  1138. */
  1139. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1140. if ($this->debug > 0) {
  1141. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1142. }
  1143. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1144. return false;
  1145. }
  1146. $prerequisite_id = $this->escape_string($prerequisite_id);
  1147. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1148. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1149. $mastery_score = 0;
  1150. if (!is_numeric($max_score) || $max_score < 0)
  1151. $max_score = 100;
  1152. if ($mastery_score > $max_score)
  1153. $max_score = $mastery_score;
  1154. if (!is_numeric($prerequisite_id))
  1155. $prerequisite_id = 'NULL';
  1156. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1157. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1158. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  1159. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1160. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1161. mastery_score = " . $mastery_score .
  1162. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1163. " WHERE ref = '" . $prerequisite_id . "'"; //will this be enough to ensure unicity?
  1164. $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
  1165. }
  1166. //TODO update the item object (can be ignored for now because refreshed)
  1167. return true;
  1168. }
  1169. /**
  1170. * Escapes a string with the available database escape function
  1171. * @param string String to escape
  1172. * @return string String escaped
  1173. */
  1174. function escape_string($string) {
  1175. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1176. return Database :: escape_string($string);
  1177. }
  1178. /**
  1179. * Static admin function exporting a learnpath into a zip file
  1180. * @param string Export type (scorm, zip, cd)
  1181. * @param string Course code
  1182. * @param integer Learnpath ID
  1183. * @param string Zip file name
  1184. * @return string Zip file path (or false on error)
  1185. */
  1186. function export_lp($type, $course, $id, $zipname) {
  1187. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1188. //TODO
  1189. if (empty ($type) OR empty ($course) OR empty ($id) OR empty ($zipname)) {
  1190. return false;
  1191. }
  1192. $url = '';
  1193. switch ($type) {
  1194. case 'scorm' :
  1195. break;
  1196. case 'zip' :
  1197. break;
  1198. case 'cdrom' :
  1199. break;
  1200. }
  1201. return $url;
  1202. }
  1203. /**
  1204. * Gets all the chapters belonging to the same parent as the item/chapter given
  1205. * Can also be called as abstract method
  1206. * @param integer Item ID
  1207. * @return array A list of all the "brother items" (or an empty array on failure)
  1208. */
  1209. function get_brother_chapters($id) {
  1210. if ($this->debug > 0) {
  1211. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1212. }
  1213. if (empty ($id) OR $id != strval(intval($id))) {
  1214. return array ();
  1215. }
  1216. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1217. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1218. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  1219. if (Database :: num_rows($res_parent) > 0) {
  1220. $row_parent = Database :: fetch_array($res_parent);
  1221. $parent = $row_parent['parent_item_id'];
  1222. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1223. $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
  1224. $list = array ();
  1225. while ($row_bro = Database :: fetch_array($res_bros)) {
  1226. $list[] = $row_bro;
  1227. }
  1228. return $list;
  1229. }
  1230. return array ();
  1231. }
  1232. /**
  1233. * Gets all the items belonging to the same parent as the item given
  1234. * Can also be called as abstract method
  1235. * @param integer Item ID
  1236. * @return array A list of all the "brother items" (or an empty array on failure)
  1237. */
  1238. function get_brother_items($id) {
  1239. if ($this->debug > 0) {
  1240. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1241. }
  1242. if (empty ($id) OR $id != strval(intval($id))) {
  1243. return array ();
  1244. }
  1245. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1246. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1247. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  1248. if (Database :: num_rows($res_parent) > 0) {
  1249. $row_parent = Database :: fetch_array($res_parent);
  1250. $parent = $row_parent['parent_item_id'];
  1251. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1252. $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
  1253. $list = array ();
  1254. while ($row_bro = Database :: fetch_array($res_bros)) {
  1255. $list[] = $row_bro;
  1256. }
  1257. return $list;
  1258. }
  1259. return array ();
  1260. }
  1261. /**
  1262. * Get the specific prefix index terms of this learning path
  1263. * @return array Array of terms
  1264. */
  1265. function get_common_index_terms_by_prefix($prefix) {
  1266. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  1267. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1268. $prefix_terms = array ();
  1269. foreach ($terms as $term) {
  1270. $prefix_terms[] = $term['value'];
  1271. }
  1272. return $prefix_terms;
  1273. }
  1274. /**
  1275. * Gets the number of items currently completed
  1276. * @return integer The number of items currently completed
  1277. */
  1278. function get_complete_items_count() {
  1279. if ($this->debug > 0) {
  1280. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1281. }
  1282. $i = 0;
  1283. foreach ($this->items as $id => $dummy) {
  1284. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1285. //Trying failed and browsed considered "progressed" as well
  1286. if ($this->items[$id]->status_is(array (
  1287. 'completed',
  1288. 'passed',
  1289. 'succeeded',
  1290. 'browsed',
  1291. 'failed'
  1292. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1293. $i++;
  1294. }
  1295. }
  1296. return $i;
  1297. }
  1298. /**
  1299. * Gets the current item ID
  1300. * @return integer The current learnpath item id
  1301. */
  1302. function get_current_item_id() {
  1303. $current = 0;
  1304. if ($this->debug > 0) {
  1305. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1306. }
  1307. if (!empty ($this->current)) {
  1308. $current = $this->current;
  1309. }
  1310. if ($this->debug > 2) {
  1311. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1312. }
  1313. return $current;
  1314. }
  1315. /** Force to get the first learnpath item id
  1316. * @return integer The current learnpath item id
  1317. */
  1318. function get_first_item_id() {
  1319. $current = 0;
  1320. if (is_array($this->ordered_items)) {
  1321. $current = $this->ordered_items[0];
  1322. }
  1323. return $current;
  1324. }
  1325. /**
  1326. * Gets the total number of items available for viewing in this SCORM
  1327. * @return integer The total number of items
  1328. */
  1329. function get_total_items_count() {
  1330. if ($this->debug > 0) {
  1331. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1332. }
  1333. return count($this->items);
  1334. }
  1335. /**
  1336. * Gets the total number of items available for viewing in this SCORM but without chapters
  1337. * @return integer The total no-chapters number of items
  1338. */
  1339. function get_total_items_count_without_chapters() {
  1340. if ($this->debug > 0) {
  1341. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1342. }
  1343. $total = 0;
  1344. foreach ($this->items as $temp => $temp2) {
  1345. if (!in_array($temp2->get_type(), array (
  1346. 'dokeos_chapter',
  1347. 'chapter',
  1348. 'dir'
  1349. )))
  1350. $total++;
  1351. }
  1352. return $total;
  1353. }
  1354. /**
  1355. * Gets the first element URL.
  1356. * @return string URL to load into the viewer
  1357. */
  1358. function first() {
  1359. if ($this->debug > 0) {
  1360. error_log('New LP - In learnpath::first()', 0);
  1361. }
  1362. //test if the last_item_seen exists and is not a dir
  1363. if (count($this->ordered_items) == 0) {
  1364. $this->index = 0;
  1365. }
  1366. 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) {
  1367. if ($this->debug > 2) {
  1368. 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);
  1369. }
  1370. $index = -1;
  1371. foreach ($this->ordered_items as $myindex => $item_id) {
  1372. if ($item_id == $this->last_item_seen) {
  1373. $index = $myindex;
  1374. break;
  1375. }
  1376. }
  1377. if ($index == -1) {
  1378. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1379. if ($this->debug > 2) {
  1380. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1381. }
  1382. return false;
  1383. } else {
  1384. $this->last = $this->last_item_seen;
  1385. $this->current = $this->last_item_seen;
  1386. $this->index = $index;
  1387. }
  1388. } else {
  1389. if ($this->debug > 2) {
  1390. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1391. }
  1392. $index = 0;
  1393. //loop through all ordered items and stop at the first item that is
  1394. //not a directory *and* that has not been completed yet
  1395. 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) {
  1396. $index++;
  1397. }
  1398. $this->last = $this->current;
  1399. //current is
  1400. $this->current = $this->ordered_items[$index];
  1401. $this->index = $index;
  1402. if ($this->debug > 2) {
  1403. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1404. }
  1405. }
  1406. if ($this->debug > 2) {
  1407. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1408. }
  1409. }
  1410. /**
  1411. * Gets the information about an item in a format usable as JavaScript to update
  1412. * the JS API by just printing this content into the <head> section of the message frame
  1413. * @param integer Item ID
  1414. * @return string
  1415. */
  1416. function get_js_info($item_id = '') {
  1417. if ($this->debug > 0) {
  1418. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1419. }
  1420. $info = '';
  1421. $item_id = $this->escape_string($item_id);
  1422. if (!empty ($item_id) && is_object($this->items[$item_id])) {
  1423. //if item is defined, return values from DB
  1424. $oItem = $this->items[$item_id];
  1425. $info .= '<script language="javascript">';
  1426. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1427. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1428. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1429. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1430. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1431. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1432. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1433. $info .= "top.set_flag_synchronized();";
  1434. $info .= '</script>';
  1435. if ($this->debug > 2) {
  1436. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1437. }
  1438. return $info;
  1439. } else {
  1440. //if item_id is empty, just update to default SCORM data
  1441. $info .= '<script language="javascript">';
  1442. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1443. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1444. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1445. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1446. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1447. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1448. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1449. $info .= "top.set_flag_synchronized();";
  1450. $info .= '</script>';
  1451. if ($this->debug > 2) {
  1452. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1453. }
  1454. return $info;
  1455. }
  1456. }
  1457. /**
  1458. * Gets the js library from the database
  1459. * @return string The name of the javascript library to be used
  1460. */
  1461. function get_js_lib() {
  1462. $lib = '';
  1463. if (!empty ($this->js_lib)) {
  1464. $lib = $this->js_lib;
  1465. }
  1466. return $lib;
  1467. }
  1468. /**
  1469. * Gets the learnpath database ID
  1470. * @return integer Learnpath ID in the lp table
  1471. */
  1472. function get_id() {
  1473. //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1474. if (!empty ($this->lp_id)) {
  1475. return $this->lp_id;
  1476. } else {
  1477. return 0;
  1478. }
  1479. }
  1480. /**
  1481. * Gets the last element URL.
  1482. * @return string URL to load into the viewer
  1483. */
  1484. function get_last() {
  1485. if ($this->debug > 0) {
  1486. error_log('New LP - In learnpath::get_last()', 0);
  1487. }
  1488. $this->index = count($this->ordered_items) - 1;
  1489. return $this->ordered_items[$this->index];
  1490. }
  1491. /**
  1492. * Gets the navigation bar for the learnpath display screen
  1493. * @return string The HTML string to use as a navigation bar
  1494. */
  1495. function get_navigation_bar() {
  1496. if ($this->debug > 0) {
  1497. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1498. }
  1499. //TODO find a good value for the following variables
  1500. $file = '';
  1501. $openDir = '';
  1502. $edoceo = '';
  1503. $time = 0;
  1504. $navbar = '';
  1505. $RequestUri = '';
  1506. $mycurrentitemid = $this->get_current_item_id();
  1507. if ($this->mode == 'fullscreen') {
  1508. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1509. ' <tr> ' . "\n" .
  1510. ' <td>' . "\n" .
  1511. ' <div class="buttons">' . "\n" .
  1512. ' <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" .
  1513. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1514. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1515. //' <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" .
  1516. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1517. ' </div>' . "\n" .
  1518. ' </td>' . "\n" .
  1519. ' </tr>' . "\n" .
  1520. '</table>' . "\n";
  1521. } else {
  1522. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1523. ' <tr> ' . "\n" .
  1524. ' <td>' . "\n" .
  1525. ' <div class="buttons">' . "\n" .
  1526. ' <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" .
  1527. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1528. ' <a href="" onclick="dokeos_xajax_handler.switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1529. // ' <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" .
  1530. ' </div>' . "\n" .
  1531. ' </td>' . "\n" .
  1532. ' </tr>' . "\n" .
  1533. '</table>' . "\n";
  1534. }
  1535. return $navbar;
  1536. }
  1537. /**
  1538. * Gets the next resource in queue (url).
  1539. * @return string URL to load into the viewer
  1540. */
  1541. function get_next_index() {
  1542. if ($this->debug > 0) {
  1543. error_log('New LP - In learnpath::get_next_index()', 0);
  1544. }
  1545. //TODO
  1546. $index = $this->index;
  1547. $index++;
  1548. if ($this->debug > 2) {
  1549. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1550. }
  1551. 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) {
  1552. $index++;
  1553. if ($index == $this->max_ordered_items) {
  1554. return $this->index;
  1555. }
  1556. }
  1557. if (empty ($this->ordered_items[$index])) {
  1558. return $this->index;
  1559. }
  1560. if ($this->debug > 2) {
  1561. error_log('New LP - index is now ' . $index, 0);
  1562. }
  1563. return $index;
  1564. }
  1565. /**
  1566. * Gets item_id for the next element
  1567. * @return integer Next item (DB) ID
  1568. */
  1569. function get_next_item_id() {
  1570. if ($this->debug > 0) {
  1571. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1572. }
  1573. $new_index = $this->get_next_index();
  1574. if (!empty ($new_index)) {
  1575. if (isset ($this->ordered_items[$new_index])) {
  1576. if ($this->debug > 2) {
  1577. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1578. }
  1579. return $this->ordered_items[$new_index];
  1580. }
  1581. }
  1582. if ($this->debug > 2) {
  1583. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1584. }
  1585. return 0;
  1586. }
  1587. /**
  1588. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1589. *
  1590. * Generally, the package provided is in the form of a zip file, so the function
  1591. * has been written to test a zip file. If not a zip, the function will return the
  1592. * default return value: ''
  1593. * @param string the path to the file
  1594. * @param string the original name of the file
  1595. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1596. */
  1597. function get_package_type($file_path, $file_name) {
  1598. //get name of the zip file without the extension
  1599. $file_info = pathinfo($file_name);
  1600. $filename = $file_info['basename']; //name including extension
  1601. $extension = $file_info['extension']; //extension only
  1602. if (!empty ($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1603. 'dll',
  1604. 'exe'
  1605. ))) {
  1606. return 'oogie';
  1607. }
  1608. if (!empty ($_POST['woogie']) && !in_array(strtolower($extension), array (
  1609. 'dll',
  1610. 'exe'
  1611. ))) {
  1612. return 'woogie';
  1613. }
  1614. $file_base_name = str_replace('.' . $extension, '', $filename); //filename without its extension
  1615. $zipFile = new pclZip($file_path);
  1616. // Check the zip content (real size and file extension)
  1617. $zipContentArray = $zipFile->listContent();
  1618. $package_type = '';
  1619. $at_root = false;
  1620. $manifest = '';
  1621. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1622. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1623. foreach ($zipContentArray as $thisContent) {
  1624. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1625. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1626. }
  1627. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== FALSE) {
  1628. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1629. $package_type = 'scorm';
  1630. break; //exit the foreach loop
  1631. }
  1632. elseif (preg_match('/aicc\//i', $thisContent['filename']) != false) {
  1633. //if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1634. $package_type = 'aicc';
  1635. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1636. } else {
  1637. $package_type = '';
  1638. }
  1639. }
  1640. }
  1641. return $package_type;
  1642. }
  1643. /**
  1644. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1645. * @return string URL to load into the viewer
  1646. */
  1647. function get_previous_index() {
  1648. if ($this->debug > 0) {
  1649. error_log('New LP - In learnpath::get_previous_index()', 0);
  1650. }
  1651. $index = $this->index;
  1652. if (isset ($this->ordered_items[$index -1])) {
  1653. $index--;
  1654. 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')) {
  1655. $index--;
  1656. if ($index < 0) {
  1657. return $this->index;
  1658. }
  1659. }
  1660. } else {
  1661. if ($this->debug > 2) {
  1662. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1663. }
  1664. //no previous item
  1665. }
  1666. return $index;
  1667. }
  1668. /**
  1669. * Gets item_id for the next element
  1670. * @return integer Previous item (DB) ID
  1671. */
  1672. function get_previous_item_id() {
  1673. if ($this->debug > 0) {
  1674. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1675. }
  1676. $new_index = $this->get_previous_index();
  1677. return $this->ordered_items[$new_index];
  1678. }
  1679. /**
  1680. * Gets the progress value from the progress_db attribute
  1681. * @return integer Current progress value
  1682. */
  1683. function get_progress() {
  1684. if ($this->debug > 0) {
  1685. error_log('New LP - In learnpath::get_progress()', 0);
  1686. }
  1687. if (!empty ($this->progress_db)) {
  1688. return $this->progress_db;
  1689. }
  1690. return 0;
  1691. }
  1692. /**
  1693. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1694. * @param integer Learnpath ID
  1695. * @param integer User ID
  1696. * @param string Mode of display ('%','abs' or 'both')
  1697. * @param string Course database name (optional, defaults to '')
  1698. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1699. * @return integer Current progress value as found in the database
  1700. */
  1701. function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false) {
  1702. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1703. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1704. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1705. $res = Database::query($sql, __FILE__, __LINE__);
  1706. $view_id = 0;
  1707. if (Database :: num_rows($res) > 0) {
  1708. $row = Database :: fetch_array($res);
  1709. $progress = $row['progress'];
  1710. $view_id = $row['id'];
  1711. } else {
  1712. if ($sincere) {
  1713. return null;
  1714. }
  1715. }
  1716. if (empty ($progress)) {
  1717. $progress = '0';
  1718. }
  1719. if ($mode == '%') {
  1720. return $progress . '%';
  1721. } else {
  1722. //get the number of items completed and the number of items total
  1723. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1724. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1725. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1726. $res = Database::query($sql, __FILE__, __LINE__);
  1727. $row = Database :: fetch_array($res);
  1728. $total = $row[0];
  1729. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1730. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1731. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1732. //trying as also counting browsed and failed items
  1733. $sql = "SELECT count(distinct(lp_item_id))
  1734. FROM $tbl_item_view as item_view
  1735. INNER JOIN $tbl_item as item
  1736. ON item.id = item_view.lp_item_id
  1737. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1738. WHERE lp_view_id = " . $view_id . "
  1739. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1740. $res = Database::query($sql, __FILE__, __LINE__);
  1741. $row = Database :: fetch_array($res);
  1742. $completed = $row[0];
  1743. if ($mode == 'abs') {
  1744. return $completed . '/' . $total;
  1745. }
  1746. elseif ($mode == 'both') {
  1747. if ($progress < ($completed / ($total ? $total : 1))) {
  1748. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1749. }
  1750. return $progress . '% (' . $completed . '/' . $total . ')';
  1751. }
  1752. }
  1753. return $progress;
  1754. }
  1755. /**
  1756. * Returns the HTML necessary to print a mediaplayer block inside a page
  1757. * @return string The mediaplayer HTML
  1758. */
  1759. function get_mediaplayer($autostart='true') {
  1760. global $_course;
  1761. // Database table definition
  1762. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1763. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1764. // getting all the information about the item
  1765. $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 " .
  1766. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1767. $result = Database::query($sql, __FILE__, __LINE__);
  1768. $row = mysql_fetch_assoc($result);
  1769. $output = '';
  1770. if (!empty ($row['audio'])) {
  1771. $list = $_SESSION['oLP']->get_toc();
  1772. $type_quiz = false;
  1773. foreach($list as $toc) {
  1774. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1775. $type_quiz = true;
  1776. }
  1777. }
  1778. if ($type_quiz) {
  1779. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1780. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1781. } else {
  1782. $autostart_audio = $autostart;
  1783. }
  1784. } else {
  1785. $autostart_audio = 'true';
  1786. }
  1787. // the mp3 player
  1788. $output = '<div id="container">';
  1789. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1790. $output .= '<script type="text/javascript">
  1791. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1792. s1.addParam("allowscriptaccess","always");
  1793. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1794. s1.write("container");
  1795. </script></div>';
  1796. }
  1797. return $output;
  1798. }
  1799. /**
  1800. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1801. * completed so far.
  1802. * @param string Mode in which we want the values
  1803. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1804. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1805. * @param boolean true if it comes from a Diplay LP view
  1806. * @return string HTML string containing the progress bar
  1807. */
  1808. function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1809. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1810. global $lp_theme_css;
  1811. // Setting up the CSS path of the current style if exists
  1812. if (!empty ($lp_theme_css)) {
  1813. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1814. } else {
  1815. $css_path = '../img/';
  1816. }
  1817. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1818. if (isset ($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1819. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1820. }
  1821. $text = $percentage . $text_add;
  1822. //Default progress bar config
  1823. // times that will be greater or shorter
  1824. $factor = 1.2;
  1825. if ($from_lp)
  1826. $progress_height = '26';
  1827. else
  1828. $progress_height = '16';
  1829. $size = str_replace('%', '', $percentage);
  1830. $output = ''
  1831. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1832. . '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
  1833. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1834. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1835. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1836. if ($percentage <= 98) {
  1837. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1838. } else {
  1839. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1840. }
  1841. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
  1842. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1843. return $output;
  1844. }
  1845. /**
  1846. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1847. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1848. * //@param integer Additional steps to fake as completed
  1849. * @return list Percentage or number and symbol (% or /xx)
  1850. */
  1851. function get_progress_bar_text($mode = '', $add = 0) {
  1852. if ($this->debug > 0) {
  1853. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1854. }
  1855. if (empty ($mode)) {
  1856. $mode = $this->progress_bar_mode;
  1857. }
  1858. $total_items = $this->get_total_items_count_without_chapters();
  1859. if ($this->debug > 2) {
  1860. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1861. }
  1862. $i = $this->get_complete_items_count();
  1863. if ($this->debug > 2) {
  1864. error_log('New LP - Items completed so far: ' . $i, 0);
  1865. }
  1866. if ($add != 0) {
  1867. $i += $add;
  1868. if ($this->debug > 2) {
  1869. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1870. }
  1871. }
  1872. $text = '';
  1873. if ($i > $total_items) {
  1874. $i = $total_items;
  1875. }
  1876. if ($mode == '%') {
  1877. if ($total_items > 0) {
  1878. $percentage = ((float) $i / (float) $total_items) * 100;
  1879. } else {
  1880. $percentage = 0;
  1881. }
  1882. $percentage = number_format($percentage, 0);
  1883. $text = '%';
  1884. }
  1885. elseif ($mode == 'abs') {
  1886. $percentage = $i;
  1887. $text = '/' . $total_items;
  1888. }
  1889. return array (
  1890. $percentage,
  1891. $text
  1892. );
  1893. }
  1894. /**
  1895. * Gets the progress bar mode
  1896. * @return string The progress bar mode attribute
  1897. */
  1898. function get_progress_bar_mode() {
  1899. if ($this->debug > 0) {
  1900. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1901. }
  1902. if (!empty ($this->progress_bar_mode)) {
  1903. return $this->progress_bar_mode;
  1904. } else {
  1905. return '%';
  1906. }
  1907. }
  1908. /**
  1909. * Gets the learnpath proximity (remote or local)
  1910. * @return string Learnpath proximity
  1911. */
  1912. function get_proximity() {
  1913. if ($this->debug > 0) {
  1914. error_log('New LP - In learnpath::get_proximity()', 0);
  1915. }
  1916. if (!empty ($this->proximity)) {
  1917. return $this->proximity;
  1918. } else {
  1919. return '';
  1920. }
  1921. }
  1922. /**
  1923. * Gets the learnpath theme (remote or local)
  1924. * @return string Learnpath theme
  1925. */
  1926. function get_theme() {
  1927. if ($this->debug > 0) {
  1928. error_log('New LP - In learnpath::get_theme()', 0);
  1929. }
  1930. if (!empty ($this->theme)) {
  1931. return $this->theme;
  1932. } else {
  1933. return '';
  1934. }
  1935. }
  1936. /**
  1937. * Gets the learnpath session id
  1938. * @return string Learnpath theme
  1939. */
  1940. function get_lp_session_id() {
  1941. if ($this->debug > 0) {
  1942. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1943. }
  1944. if (!empty ($this->lp_session_id)) {
  1945. return $this->lp_session_id;
  1946. } else {
  1947. return 0;
  1948. }
  1949. }
  1950. /**
  1951. * Gets the learnpath image
  1952. * @return string Web URL of the LP image
  1953. */
  1954. function get_preview_image() {
  1955. if ($this->debug > 0) {
  1956. error_log('New LP - In learnpath::get_preview_image()', 0);
  1957. }
  1958. if (!empty ($this->preview_image)) {
  1959. return $this->preview_image;
  1960. } else {
  1961. return '';
  1962. }
  1963. }
  1964. /**
  1965. * Gets the learnpath author
  1966. * @return string LP's author
  1967. */
  1968. function get_author() {
  1969. if ($this->debug > 0) {
  1970. error_log('New LP - In learnpath::get_author()', 0);
  1971. }
  1972. if (!empty ($this->author)) {
  1973. return $this->author;
  1974. } else {
  1975. return '';
  1976. }
  1977. }
  1978. /**
  1979. * Generate a new prerequisites string for a given item. If this item was a sco and
  1980. * its prerequisites were strings (instead of IDs), then transform those strings into
  1981. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1982. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1983. * same rule as the scorm_export() method
  1984. * @param integer Item ID
  1985. * @return string Prerequisites string ready for the export as SCORM
  1986. */
  1987. function get_scorm_prereq_string($item_id) {
  1988. if ($this->debug > 0) {
  1989. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  1990. }
  1991. if (!is_object($this->items[$item_id])) {
  1992. return false;
  1993. }
  1994. $oItem = $this->items[$item_id];
  1995. $prereq = $oItem->get_prereq_string();
  1996. if (empty ($prereq)) {
  1997. return '';
  1998. }
  1999. 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,
  2000. //then simply return it (with the ITEM_ prefix)
  2001. return 'ITEM_' . $prereq;
  2002. } else {
  2003. if (isset ($this->refs_list[$prereq])) {
  2004. //it's a simple string item from which the ID can be found in the refs list
  2005. //so we can transform it directly to an ID for export
  2006. return 'ITEM_' . $this->refs_list[$prereq];
  2007. } else {
  2008. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  2009. //and replace them, one by one, by the internal IDs (dokeos db)
  2010. //TODO modify the '*' replacement to replace the multiplier in front of it
  2011. //by a space as well
  2012. $find = array (
  2013. '&',
  2014. '|',
  2015. '~',
  2016. '=',
  2017. '<>',
  2018. '{',
  2019. '}',
  2020. '*',
  2021. '(',
  2022. ')'
  2023. );
  2024. $replace = array (
  2025. ' ',
  2026. ' ',
  2027. ' ',
  2028. ' ',
  2029. ' ',
  2030. ' ',
  2031. ' ',
  2032. ' ',
  2033. ' ',
  2034. ' '
  2035. );
  2036. $prereq_mod = str_replace($find, $replace, $prereq);
  2037. $ids = split(' ', $prereq_mod);
  2038. foreach ($ids as $id) {
  2039. $id = trim($id);
  2040. if (isset ($this->refs_list[$id])) {
  2041. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2042. }
  2043. }
  2044. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2045. return $prereq;
  2046. }
  2047. }
  2048. }
  2049. /**
  2050. * Returns the XML DOM document's node
  2051. * @param resource Reference to a list of objects to search for the given ITEM_*
  2052. * @param string The identifier to look for
  2053. * @return mixed The reference to the element found with that identifier. False if not found
  2054. */
  2055. function get_scorm_xml_node(& $children, $id) {
  2056. for ($i = 0; $i < $children->length; $i++) {
  2057. $item_temp = $children->item($i);
  2058. if ($item_temp->nodeName == 'item') {
  2059. if ($item_temp->getAttribute('identifier') == $id) {
  2060. return $item_temp;
  2061. }
  2062. }
  2063. $subchildren = $item_temp->childNodes;
  2064. if ($subchildren->length > 0) {
  2065. $val = $this->get_scorm_xml_node($subchildren, $id);
  2066. if (is_object($val)) {
  2067. return $val;
  2068. }
  2069. }
  2070. }
  2071. return false;
  2072. }
  2073. /**
  2074. * Returns a usable array of stats related to the current learnpath and user
  2075. * @return array Well-formatted array containing status for the current learnpath
  2076. */
  2077. function get_stats() {
  2078. if ($this->debug > 0) {
  2079. error_log('New LP - In learnpath::get_stats()', 0);
  2080. }
  2081. //TODO
  2082. }
  2083. /**
  2084. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2085. * the given course (for all learnpaths and all users)
  2086. * @param string Course code
  2087. * @return array Well-formatted array containing status for the course's learnpaths
  2088. */
  2089. function get_stats_course($course) {
  2090. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  2091. //TODO
  2092. }
  2093. /**
  2094. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2095. * the given course and learnpath (for all users)
  2096. * @param string Course code
  2097. * @param integer Learnpath ID
  2098. * @return array Well-formatted array containing status for the specified learnpath
  2099. */
  2100. function get_stats_lp($course, $lp) {
  2101. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  2102. //TODO
  2103. }
  2104. /**
  2105. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2106. * the given course, learnpath and user.
  2107. * @param string Course code
  2108. * @param integer Learnpath ID
  2109. * @param integer User ID
  2110. * @return array Well-formatted array containing status for the specified learnpath and user
  2111. */
  2112. function get_stats_lp_user($course, $lp, $user) {
  2113. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  2114. //TODO
  2115. }
  2116. /**
  2117. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2118. * the given course and learnpath (for all users)
  2119. * @param string Course code
  2120. * @param integer User ID
  2121. * @return array Well-formatted array containing status for the user's learnpaths
  2122. */
  2123. function get_stats_user($course, $user) {
  2124. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  2125. //TODO
  2126. }
  2127. /**
  2128. * Gets the status list for all LP's items
  2129. * @return array Array of [index] => [item ID => current status]
  2130. */
  2131. function get_items_status_list() {
  2132. if ($this->debug > 0) {
  2133. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2134. }
  2135. $list = array ();
  2136. foreach ($this->ordered_items as $item_id) {
  2137. $list[] = array (
  2138. $item_id => $this->items[$item_id]->get_status()
  2139. );
  2140. }
  2141. return $list;
  2142. }
  2143. /**
  2144. * Return the number of interactions for the given learnpath Item View ID.
  2145. * This method can be used as static.
  2146. * @param integer Item View ID
  2147. * @return integer Number of interactions
  2148. */
  2149. function get_interactions_count_from_db($lp_iv_id = 0) {
  2150. if (empty ($lp_iv_id)) {
  2151. return -1;
  2152. }
  2153. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2154. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2155. $res = Database::query($sql, __FILE__, __LINE__);
  2156. $row = Database :: fetch_array($res);
  2157. $num = $row[0];
  2158. return $num;
  2159. }
  2160. /**
  2161. * Return the interactions as an array for the given lp_iv_id.
  2162. * This method can be used as static.
  2163. * @param integer Learnpath Item View ID
  2164. * @return array
  2165. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2166. */
  2167. function get_iv_interactions_array($lp_iv_id = 0) {
  2168. $charset = api_get_setting('platform_charset');
  2169. $list = array ();
  2170. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2171. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2172. $res = Database::query($sql, __FILE__, __LINE__);
  2173. $num = Database :: num_rows($res);
  2174. if ($num > 0) {
  2175. $list[] = array (
  2176. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2177. "id" => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES, $charset),
  2178. "type" => api_htmlentities(get_lang('Type'), ENT_QUOTES, $charset),
  2179. "time" => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES, $charset),
  2180. "correct_responses" => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES, $charset),
  2181. "student_response" => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES, $charset),
  2182. "result" => api_htmlentities(get_lang('Result'), ENT_QUOTES, $charset),
  2183. "latency" => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES, $charset)
  2184. );
  2185. while ($row = Database :: fetch_array($res)) {
  2186. $list[] = array (
  2187. "order_id" => ($row['order_id'] + 1),
  2188. "id" => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2189. "type" => $row['interaction_type'],
  2190. "time" => $row['completion_time'],
  2191. //"correct_responses"=>$row['correct_responses'],
  2192. //hide correct responses from students
  2193. "correct_responses" => '',
  2194. "student_response" => $row['student_response'],
  2195. "result" => $row['result'],
  2196. "latency" => $row['latency']
  2197. );
  2198. }
  2199. }
  2200. return $list;
  2201. }
  2202. /**
  2203. * Return the number of objectives for the given learnpath Item View ID.
  2204. * This method can be used as static.
  2205. * @param integer Item View ID
  2206. * @return integer Number of objectives
  2207. */
  2208. function get_objectives_count_from_db($lp_iv_id = 0) {
  2209. if (empty ($lp_iv_id)) {
  2210. return -1;
  2211. }
  2212. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2213. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2214. $res = Database::query($sql, __FILE__, __LINE__);
  2215. $row = Database :: fetch_array($res);
  2216. $num = $row[0];
  2217. return $num;
  2218. }
  2219. /**
  2220. * Return the objectives as an array for the given lp_iv_id.
  2221. * This method can be used as static.
  2222. * @param integer Learnpath Item View ID
  2223. * @return array
  2224. * @todo Translate labels
  2225. */
  2226. function get_iv_objectives_array($lp_iv_id = 0) {
  2227. global $chatset;
  2228. $list = array ();
  2229. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2230. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2231. $res = Database::query($sql, __FILE__, __LINE__);
  2232. $num = Database :: num_rows($res);
  2233. if ($num > 0) {
  2234. $list[] = array (
  2235. "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
  2236. "objective_id" => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES, $charset),
  2237. "score_raw" => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES, $charset),
  2238. "score_max" => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES, $charset),
  2239. "score_min" => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES, $charset),
  2240. "status" => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES, $charset)
  2241. );
  2242. while ($row = Database :: fetch_array($res)) {
  2243. $list[] = array (
  2244. "order_id" => ($row['order_id'] + 1),
  2245. "objective_id" => urldecode($row['objective_id']), //urldecode because they often have %2F or stuff like that
  2246. "score_raw" => $row['score_raw'],
  2247. "score_max" => $row['score_max'],
  2248. "score_min" => $row['score_min'],
  2249. "status" => $row['status']
  2250. );
  2251. }
  2252. }
  2253. return $list;
  2254. }
  2255. /**
  2256. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2257. * used by get_html_toc() to be ready to display
  2258. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2259. */
  2260. function get_toc() {
  2261. if ($this->debug > 0) {
  2262. error_log('New LP - In learnpath::get_toc()', 0);
  2263. }
  2264. $toc = array ();
  2265. //echo "<pre>".print_r($this->items,true)."</pre>";
  2266. foreach ($this->ordered_items as $item_id) {
  2267. if ($this->debug > 2) {
  2268. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2269. }
  2270. //TODO change this link generation and use new function instead
  2271. $toc[] = array (
  2272. 'id' => $item_id,
  2273. 'title' => $this->items[$item_id]->get_title(),
  2274. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2275. 'status' => $this->items[$item_id]->get_status(),
  2276. 'level' => $this->items[$item_id]->get_level(),
  2277. 'type' => $this->items[$item_id]->get_type(),
  2278. 'description' => $this->items[$item_id]->get_description(),
  2279. 'path' => $this->items[$item_id]->get_path(),
  2280. );
  2281. }
  2282. if ($this->debug > 2) {
  2283. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2284. }
  2285. return $toc;
  2286. }
  2287. /**
  2288. * Gets the learning path type
  2289. * @param boolean Return the name? If false, return the ID. Default is false.
  2290. * @return mixed Type ID or name, depending on the parameter
  2291. */
  2292. function get_type($get_name = false) {
  2293. $res = false;
  2294. if ($this->debug > 0) {
  2295. error_log('New LP - In learnpath::get_type()', 0);
  2296. }
  2297. if (!empty ($this->type)) {
  2298. if ($get_name) {
  2299. //get it from the lp_type table in main db
  2300. } else {
  2301. $res = $this->type;
  2302. }
  2303. }
  2304. if ($this->debug > 2) {
  2305. error_log('New LP - In learnpath::get_type() - Returning ' . ($res == false ? 'false' : $res), 0);
  2306. }
  2307. return $res;
  2308. }
  2309. /**
  2310. * Gets the learning path type as static method
  2311. * @param boolean Return the name? If false, return the ID. Default is false.
  2312. * @return mixed Type ID or name, depending on the parameter
  2313. */
  2314. function get_type_static($lp_id = 0) {
  2315. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2316. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2317. $res = Database::query($sql, __FILE__, __LINE__);
  2318. if ($res === false) {
  2319. return null;
  2320. }
  2321. if (Database :: num_rows($res) <= 0) {
  2322. return null;
  2323. }
  2324. $row = Database :: fetch_array($res);
  2325. return $row['lp_type'];
  2326. }
  2327. /**
  2328. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2329. * This method can be used as abstract and is recursive
  2330. * @param integer Learnpath ID
  2331. * @param integer Parent ID of the items to look for
  2332. * @return mixed Ordered list of item IDs or false on error
  2333. */
  2334. function get_flat_ordered_items_list($lp, $parent = 0) {
  2335. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2336. $list = array ();
  2337. if (empty ($lp)) {
  2338. return false;
  2339. }
  2340. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2341. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2342. $res = Database::query($sql, __FILE__, __LINE__);
  2343. while ($row = Database :: fetch_array($res)) {
  2344. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id']);
  2345. $list[] = $row['id'];
  2346. foreach ($sublist as $item) {
  2347. $list[] = $item;
  2348. }
  2349. }
  2350. return $list;
  2351. }
  2352. /**
  2353. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2354. * @return string HTML TOC ready to display
  2355. */
  2356. /*function get_html_toc()
  2357. {
  2358. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2359. $list = $this->get_toc();
  2360. //echo $this->current;
  2361. //$parent = $this->items[$this->current]->get_parent();
  2362. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2363. $html = '<div class="inner_lp_toc">'."\n" ;
  2364. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2365. require_once('resourcelinker.inc.php');
  2366. //temp variables
  2367. $mycurrentitemid = $this->get_current_item_id();
  2368. foreach($list as $item)
  2369. {
  2370. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2371. //TODO complete this
  2372. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2373. 'incomplete' => '../img/incomplete.gif',
  2374. 'failed' => '../img/failed.gif',
  2375. 'completed' => '../img/completed.gif',
  2376. 'passed' => '../img/passed.gif',
  2377. 'succeeded' => '../img/succeeded.gif',
  2378. 'browsed' => '../img/completed.gif');
  2379. $style = 'scorm_item';
  2380. if($item['id'] == $this->current){
  2381. $style = 'scorm_item_highlight';
  2382. }
  2383. //the anchor will let us center the TOC on the currently viewed item &^D
  2384. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']/2).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
  2385. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2386. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2387. $title = $item['title'];
  2388. if(empty($title)){
  2389. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2390. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2391. }
  2392. if(empty($title))$title = '-';
  2393. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2394. //$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>" ;
  2395. $url = $this->get_link('http',$item['id']);
  2396. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2397. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2398. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2399. $mycurrentitemid.',' .
  2400. $item['id'].');' .
  2401. 'return false;" >'.$title.'</a>' ;
  2402. }else{
  2403. $html .= $title;
  2404. }
  2405. $html .= "</div>\n";
  2406. }
  2407. $html .= "</div>\n";
  2408. return $html;
  2409. }*/
  2410. /**
  2411. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2412. * @return string HTML TOC ready to display
  2413. */
  2414. function get_html_toc() {
  2415. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  2416. $charset = api_get_setting('platform_charset');
  2417. $display_action_links_with_icons = false;
  2418. if ($this->debug > 0) {
  2419. error_log('New LP - In learnpath::get_html_toc()', 0);
  2420. }
  2421. $list = $this->get_toc();
  2422. //echo $this->current;
  2423. //$parent = $this->items[$this->current]->get_parent();
  2424. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2425. $html = '<div class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS(api_convert_encoding($this->get_name(), $this->encoding, $charset)) . '</div></div>';
  2426. // build, display
  2427. if ($is_allowed_to_edit) {
  2428. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2429. //var_dump($this->get_lp_session_id());
  2430. if ($this->get_lp_session_id()==api_get_session_id()) {
  2431. $html .= '<div class="actions_lp">';
  2432. if ($display_action_links_with_icons) {
  2433. $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>";
  2434. $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>";
  2435. $html .= '<span>' . Display :: return_icon('learnpath_view_na.gif', get_lang("Display")) . ' <b>' . get_lang("Display") . '</b></span>';
  2436. } else {
  2437. $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>";
  2438. $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>";
  2439. $html .= '<span><b>' . get_lang('Display') . '</b></span>';
  2440. }
  2441. $html .= '</div>';
  2442. }
  2443. }
  2444. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
  2445. require_once ('resourcelinker.inc.php');
  2446. //temp variables
  2447. $mycurrentitemid = $this->get_current_item_id();
  2448. $color_counter = 0;
  2449. $i = 0;
  2450. foreach ($list as $item) {
  2451. if ($this->debug > 2) {
  2452. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2453. }
  2454. //TODO complete this
  2455. $icon_name = array (
  2456. 'not attempted' => '../img/notattempted.gif',
  2457. 'incomplete' => '../img/incomplete.gif',
  2458. 'failed' => '../img/failed.gif',
  2459. 'completed' => '../img/completed.gif',
  2460. 'passed' => '../img/passed.gif',
  2461. 'succeeded' => '../img/succeeded.gif',
  2462. 'browsed' => '../img/completed.gif'
  2463. );
  2464. $style = 'scorm_item';
  2465. $scorm_color_background = 'scorm_item';
  2466. $style_item = 'scorm_item';
  2467. $current = false;
  2468. if ($item['id'] == $this->current) {
  2469. $style = 'scorm_item_highlight';
  2470. $scorm_color_background = 'scorm_item_highlight';
  2471. } else
  2472. if ($color_counter % 2 == 0) {
  2473. $scorm_color_background = 'scorm_item_1';
  2474. } else {
  2475. $scorm_color_background = 'scorm_item_2';
  2476. }
  2477. if ($scorm_color_background != '') {
  2478. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2479. }
  2480. //the anchor will let us center the TOC on the currently viewed item &^D
  2481. if ($item['type'] != 'dokeos_module' AND $item['type'] != 'dokeos_chapter') {
  2482. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2483. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2484. } else {
  2485. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2486. }
  2487. $title = $item['title'];
  2488. if (empty ($title)) {
  2489. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2490. }
  2491. //$title = api_htmlentities($title, ENT_QUOTES, $this->encoding);
  2492. $title = Security::remove_XSS($title);
  2493. if ($item['type'] != 'dokeos_chapter' and $item['type'] != 'dir' AND $item['type'] != 'dokeos_module') {
  2494. //$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>" ;
  2495. $url = $this->get_link('http', $item['id']);
  2496. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2497. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2498. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2499. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2500. $mycurrentitemid . ',' .
  2501. $item['id'] . ');' .
  2502. 'return false;" >' . stripslashes($title) . '</a>';
  2503. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2504. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2505. } elseif ($item['type'] == 'dir') {
  2506. $html .= stripslashes($title);
  2507. }
  2508. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2509. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2510. $user_id = api_get_user_id();
  2511. $course_id = api_get_course_id();
  2512. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2513. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2514. $result = Database::query($sql, __FILE__, __LINE__);
  2515. $count = Database :: num_rows($result);
  2516. if ($item['type'] == 'quiz') {
  2517. if ($item['status'] == 'completed') {
  2518. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2519. }
  2520. } else {
  2521. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2522. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
  2523. }
  2524. }
  2525. $html .= "</div>";
  2526. if ($scorm_color_background != '') {
  2527. $html .= '</div>';
  2528. }
  2529. $color_counter++;
  2530. }
  2531. $html .= "</div>\n";
  2532. return $html;
  2533. }
  2534. /**
  2535. * Gets the learnpath maker name - generally the editor's name
  2536. * @return string Learnpath maker name
  2537. */
  2538. function get_maker() {
  2539. if ($this->debug > 0) {
  2540. error_log('New LP - In learnpath::get_maker()', 0);
  2541. }
  2542. if (!empty ($this->maker)) {
  2543. return $this->maker;
  2544. } else {
  2545. return '';
  2546. }
  2547. }
  2548. /**
  2549. * Gets the user-friendly message stored in $this->message
  2550. * @return string Message
  2551. */
  2552. function get_message() {
  2553. if ($this->debug > 0) {
  2554. error_log('New LP - In learnpath::get_message()', 0);
  2555. }
  2556. return $this->message;
  2557. }
  2558. /**
  2559. * Gets the learnpath name/title
  2560. * @return string Learnpath name/title
  2561. */
  2562. function get_name() {
  2563. if ($this->debug > 0) {
  2564. error_log('New LP - In learnpath::get_name()', 0);
  2565. }
  2566. if (!empty ($this->name)) {
  2567. return $this->name;
  2568. } else {
  2569. return 'N/A';
  2570. }
  2571. }
  2572. /**
  2573. * Gets a link to the resource from the present location, depending on item ID.
  2574. * @param string Type of link expected
  2575. * @param integer Learnpath item ID
  2576. * @return string Link to the lp_item resource
  2577. */
  2578. function get_link($type = 'http', $item_id = null) {
  2579. if ($this->debug > 0) {
  2580. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2581. }
  2582. if (empty($item_id)) {
  2583. if ($this->debug > 2) {
  2584. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2585. }
  2586. $item_id = $this->get_current_item_id();
  2587. }
  2588. if (empty ($item_id)) {
  2589. if ($this->debug > 2) {
  2590. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2591. }
  2592. //still empty, this means there was no item_id given and we are not in an object context or
  2593. //the object property is empty, return empty link
  2594. $item_id = $this->first();
  2595. return '';
  2596. }
  2597. $file = '';
  2598. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2599. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2600. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2601. $item_id = Database::escape_string($item_id);
  2602. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2603. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2604. if ($this->debug > 2) {
  2605. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2606. }
  2607. $res = Database::query($sel, __FILE__, __LINE__);
  2608. if (Database :: num_rows($res) > 0) {
  2609. $row = Database :: fetch_array($res);
  2610. //var_dump($row);
  2611. $lp_type = $row['ltype'];
  2612. $lp_path = $row['lpath'];
  2613. $lp_item_type = $row['litype'];
  2614. $lp_item_path = $row['lipath'];
  2615. $lp_item_params = $row['liparams'];
  2616. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2617. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2618. }
  2619. //$lp_item_params = '?'.$lp_item_params;
  2620. //add ? if none - left commented to give freedom to scorm implementation
  2621. //if(substr($lp_item_params,0,1)!='?'){
  2622. // $lp_item_params = '?'.$lp_item_params;
  2623. //}
  2624. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2625. if ($type == 'http') {
  2626. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2627. } else {
  2628. $course_path = $sys_course_path; //system path
  2629. }
  2630. //now go through the specific cases to get the end of the path
  2631. switch ($lp_type) {
  2632. case 1 :
  2633. if ($lp_item_type == 'dokeos_chapter') {
  2634. $file = 'lp_content.php?type=dir';
  2635. } else {
  2636. require_once ('resourcelinker.inc.php');
  2637. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2638. // check how much attempts of a exercise exits in lp
  2639. $lp_item_id = $this->get_current_item_id();
  2640. $lp_view_id = $this->get_view_id();
  2641. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2642. $list = $this->get_toc();
  2643. $type_quiz = false;
  2644. foreach ($list as $toc) {
  2645. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2646. $type_quiz = true;
  2647. }
  2648. }
  2649. if ($type_quiz) {
  2650. $lp_item_id = Database :: escape_string($lp_item_id);
  2651. $lp_view_id = Database :: escape_string($lp_view_id);
  2652. $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'";
  2653. $result = Database::query($sql, __FILE__, __LINE__);
  2654. $row_count = Database :: fetch_row($result);
  2655. $count_item_view = (int) $row_count[0];
  2656. $not_multiple_attempt = 0;
  2657. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2658. $not_multiple_attempt = 1;
  2659. }
  2660. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2661. }
  2662. $tmp_array = explode("/", $file);
  2663. $document_name = $tmp_array[count($tmp_array) - 1];
  2664. if (strpos($document_name, '_DELETED_')) {
  2665. $file = 'blank.php?error=document_deleted';
  2666. }
  2667. }
  2668. break;
  2669. case 2 :
  2670. if ($this->debug > 2) {
  2671. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2672. }
  2673. if ($lp_item_type != 'dir') {
  2674. //Quite complex here:
  2675. //we want to make sure 'http://' (and similar) links can
  2676. //be loaded as is (withouth the Dokeos path in front) but
  2677. //some contents use this form: resource.htm?resource=http://blablabla
  2678. //which means we have to find a protocol at the path's start, otherwise
  2679. //it should not be considered as an external URL
  2680. //if($this->prerequisites_match($item_id)){
  2681. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2682. if ($this->debug > 2) {
  2683. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2684. }
  2685. //distant url, return as is
  2686. $file = $lp_item_path;
  2687. } else {
  2688. if ($this->debug > 2) {
  2689. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2690. }
  2691. //prevent getting untranslatable urls
  2692. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2693. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2694. //prepare the path
  2695. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2696. //TODO fix this for urls with protocol header
  2697. $file = str_replace('//', '/', $file);
  2698. $file = str_replace(':/', '://', $file);
  2699. if (substr($lp_path, -1) == '/') {
  2700. $lp_path = substr($lp_path, 0, -1);
  2701. }
  2702. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2703. //if file not found
  2704. $decoded = html_entity_decode($lp_item_path);
  2705. list ($decoded) = explode('?', $decoded);
  2706. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2707. require_once ('resourcelinker.inc.php');
  2708. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2709. if (empty($file)) {
  2710. $file = 'blank.php?error=document_not_found';
  2711. } else {
  2712. $tmp_array = explode("/", $file);
  2713. $document_name = $tmp_array[count($tmp_array) - 1];
  2714. if (strpos($document_name, '_DELETED_')) {
  2715. $file = 'blank.php?error=document_deleted';
  2716. }
  2717. }
  2718. } else {
  2719. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2720. }
  2721. }
  2722. }
  2723. //}else{
  2724. //prerequisites did not match
  2725. //$file = 'blank.php';
  2726. //}
  2727. //We want to use parameters if they were defined in the imsmanifest
  2728. if ($file != 'blank.php') {
  2729. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2730. }
  2731. } else {
  2732. $file = 'lp_content.php?type=dir';
  2733. }
  2734. break;
  2735. case 3 :
  2736. if ($this->debug > 2) {
  2737. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2738. }
  2739. //formatting AICC HACP append URL
  2740. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2741. if ($lp_item_type != 'dir') {
  2742. //Quite complex here:
  2743. //we want to make sure 'http://' (and similar) links can
  2744. //be loaded as is (withouth the Dokeos path in front) but
  2745. //some contents use this form: resource.htm?resource=http://blablabla
  2746. //which means we have to find a protocol at the path's start, otherwise
  2747. //it should not be considered as an external URL
  2748. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2749. if ($this->debug > 2) {
  2750. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2751. }
  2752. //distant url, return as is
  2753. $file = $lp_item_path;
  2754. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2755. /*
  2756. if(stristr($file,'<servername>')!==false){
  2757. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2758. }
  2759. */
  2760. if (stripos($file, '<servername>') !== false) {
  2761. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2762. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2763. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2764. }
  2765. //
  2766. $file .= $aicc_append;
  2767. } else {
  2768. if ($this->debug > 2) {
  2769. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2770. }
  2771. //prevent getting untranslatable urls
  2772. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2773. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2774. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2775. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2776. //TODO fix this for urls with protocol header
  2777. $file = str_replace('//', '/', $file);
  2778. $file = str_replace(':/', '://', $file);
  2779. $file .= $aicc_append;
  2780. }
  2781. } else {
  2782. $file = 'lp_content.php?type=dir';
  2783. }
  2784. break;
  2785. case 4 :
  2786. break;
  2787. default :
  2788. break;
  2789. }
  2790. }
  2791. if ($this->debug > 2) {
  2792. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2793. }
  2794. return $file;
  2795. }
  2796. /**
  2797. * Gets the latest usable view or generate a new one
  2798. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2799. * @return integer DB lp_view id
  2800. */
  2801. function get_view($attempt_num = 0) {
  2802. if ($this->debug > 0) {
  2803. error_log('New LP - In learnpath::get_view()', 0);
  2804. }
  2805. $search = '';
  2806. //use $attempt_num to enable multi-views management (disabled so far)
  2807. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2808. $search = 'AND view_count = ' . $attempt_num;
  2809. }
  2810. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2811. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2812. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2813. "WHERE lp_id = " . $this->get_id() . " " .
  2814. "AND user_id = " . $this->get_user_id() . " " .
  2815. $search .
  2816. " ORDER BY view_count DESC";
  2817. $res = Database::query($sql, __FILE__, __LINE__);
  2818. if (Database :: num_rows($res) > 0) {
  2819. $row = Database :: fetch_array($res);
  2820. $this->lp_view_id = $row['id'];
  2821. } else {
  2822. //no database record, create one
  2823. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2824. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2825. $res = Database::query($sql, __FILE__, __LINE__);
  2826. $id = Database :: insert_id();
  2827. $this->lp_view_id = $id;
  2828. }
  2829. return $this->lp_view_id;
  2830. }
  2831. /**
  2832. * Gets the current view id
  2833. * @return integer View ID (from lp_view)
  2834. */
  2835. function get_view_id() {
  2836. if ($this->debug > 0) {
  2837. error_log('New LP - In learnpath::get_view_id()', 0);
  2838. }
  2839. if (!empty ($this->lp_view_id)) {
  2840. return $this->lp_view_id;
  2841. } else {
  2842. return 0;
  2843. }
  2844. }
  2845. /**
  2846. * Gets the update queue
  2847. * @return array Array containing IDs of items to be updated by JavaScript
  2848. */
  2849. function get_update_queue() {
  2850. if ($this->debug > 0) {
  2851. error_log('New LP - In learnpath::get_update_queue()', 0);
  2852. }
  2853. return $this->update_queue;
  2854. }
  2855. /**
  2856. * Gets the user ID
  2857. * @return integer User ID
  2858. */
  2859. function get_user_id() {
  2860. if ($this->debug > 0) {
  2861. error_log('New LP - In learnpath::get_user_id()', 0);
  2862. }
  2863. if (!empty ($this->user_id)) {
  2864. return $this->user_id;
  2865. } else {
  2866. return false;
  2867. }
  2868. }
  2869. /**
  2870. * Checks if any of the items has an audio element attached
  2871. * @return bool True or false
  2872. */
  2873. function has_audio() {
  2874. if ($this->debug > 1) {
  2875. error_log('New LP - In learnpath::has_audio()', 0);
  2876. }
  2877. $has = false;
  2878. foreach ($this->items as $i => $item) {
  2879. if (!empty ($this->items[$i]->audio)) {
  2880. $has = true;
  2881. break;
  2882. }
  2883. }
  2884. return $has;
  2885. }
  2886. /**
  2887. * Logs a message into a file
  2888. * @param string Message to log
  2889. * @return boolean True on success, false on error or if msg empty
  2890. */
  2891. function log($msg) {
  2892. if ($this->debug > 0) {
  2893. error_log('New LP - In learnpath::log()', 0);
  2894. }
  2895. //TODO
  2896. $this->error .= $msg . "\n";
  2897. return true;
  2898. }
  2899. /**
  2900. * Moves an item up and down at its level
  2901. * @param integer Item to move up and down
  2902. * @param string Direction 'up' or 'down'
  2903. * @return integer New display order, or false on error
  2904. */
  2905. function move_item($id, $direction) {
  2906. if ($this->debug > 0) {
  2907. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2908. }
  2909. if (empty ($id) or empty ($direction)) {
  2910. return false;
  2911. }
  2912. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2913. $sql_sel = "
  2914. SELECT *
  2915. FROM " . $tbl_lp_item . "
  2916. WHERE id = " . $id;
  2917. $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
  2918. //check if elem exists
  2919. if (Database :: num_rows($res_sel) < 1) {
  2920. return false;
  2921. }
  2922. //gather data
  2923. $row = Database :: fetch_array($res_sel);
  2924. $previous = $row['previous_item_id'];
  2925. $next = $row['next_item_id'];
  2926. $display = $row['display_order'];
  2927. $parent = $row['parent_item_id'];
  2928. $lp = $row['lp_id'];
  2929. //update the item (switch with previous/next one)
  2930. switch ($direction) {
  2931. case 'up' :
  2932. if ($this->debug > 2) {
  2933. error_log('Movement up detected', 0);
  2934. }
  2935. if ($display <= 1) { /*do nothing*/
  2936. } else {
  2937. $sql_sel2 = "SELECT *
  2938. FROM $tbl_lp_item
  2939. WHERE id = $previous";
  2940. if ($this->debug > 2) {
  2941. error_log('Selecting previous: ' . $sql_sel2, 0);
  2942. }
  2943. $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
  2944. if (Database :: num_rows($res_sel2) < 1) {
  2945. $previous_previous = 0;
  2946. }
  2947. //gather data
  2948. $row2 = Database :: fetch_array($res_sel2);
  2949. $previous_previous = $row2['previous_item_id'];
  2950. //update previous_previous item (switch "next" with current)
  2951. if ($previous_previous != 0) {
  2952. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2953. if ($this->debug > 2) {
  2954. error_log($sql_upd2, 0);
  2955. }
  2956. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2957. }
  2958. //update previous item (switch with current)
  2959. if ($previous != 0) {
  2960. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2961. if ($this->debug > 2) {
  2962. error_log($sql_upd2, 0);
  2963. }
  2964. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2965. }
  2966. //update current item (switch with previous)
  2967. if ($id != 0) {
  2968. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2969. if ($this->debug > 2) {
  2970. error_log($sql_upd2, 0);
  2971. }
  2972. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2973. }
  2974. //update next item (new previous item)
  2975. if ($next != 0) {
  2976. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2977. if ($this->debug > 2) {
  2978. error_log($sql_upd2, 0);
  2979. }
  2980. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  2981. }
  2982. $display = $display -1;
  2983. }
  2984. break;
  2985. case 'down' :
  2986. if ($this->debug > 2) {
  2987. error_log('Movement down detected', 0);
  2988. }
  2989. if ($next == 0) { /*do nothing*/
  2990. } else {
  2991. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2992. if ($this->debug > 2) {
  2993. error_log('Selecting next: ' . $sql_sel2, 0);
  2994. }
  2995. $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
  2996. if (Database :: num_rows($res_sel2) < 1) {
  2997. $next_next = 0;
  2998. }
  2999. //gather data
  3000. $row2 = Database :: fetch_array($res_sel2);
  3001. $next_next = $row2['next_item_id'];
  3002. //update previous item (switch with current)
  3003. if ($previous != 0) {
  3004. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3005. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3006. }
  3007. //update current item (switch with previous)
  3008. if ($id != 0) {
  3009. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3010. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3011. }
  3012. //update next item (new previous item)
  3013. if ($next != 0) {
  3014. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3015. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3016. }
  3017. //update next_next item (switch "previous" with current)
  3018. if ($next_next != 0) {
  3019. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3020. $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
  3021. }
  3022. $display = $display +1;
  3023. }
  3024. break;
  3025. default :
  3026. return false;
  3027. }
  3028. return $display;
  3029. }
  3030. /**
  3031. * Move a learnpath up (display_order)
  3032. * @param integer Learnpath ID
  3033. */
  3034. function move_up($lp_id) {
  3035. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3036. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3037. $res = Database::query($sql, __FILE__, __LINE__);
  3038. if ($res === false)
  3039. return false;
  3040. $lps = array ();
  3041. $lp_order = array ();
  3042. $num = Database :: num_rows($res);
  3043. //first check the order is correct, globally (might be wrong because
  3044. //of versions < 1.8.4)
  3045. if ($num > 0) {
  3046. $i = 1;
  3047. while ($row = Database :: fetch_array($res)) {
  3048. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3049. $need_fix = true;
  3050. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3051. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3052. }
  3053. $row['display_order'] = $i;
  3054. $lps[$row['id']] = $row;
  3055. $lp_order[$i] = $row['id'];
  3056. $i++;
  3057. }
  3058. }
  3059. if ($num > 1) //if there's only one element, no need to sort
  3060. {
  3061. $order = $lps[$lp_id]['display_order'];
  3062. if ($order > 1) //if it's the first element, no need to move up
  3063. {
  3064. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order -1];
  3065. $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
  3066. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order -1) . " WHERE id = " . $lp_id;
  3067. $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
  3068. }
  3069. }
  3070. }
  3071. /**
  3072. * Move a learnpath down (display_order)
  3073. * @param integer Learnpath ID
  3074. */
  3075. function move_down($lp_id) {
  3076. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3077. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3078. $res = Database::query($sql, __FILE__, __LINE__);
  3079. if ($res === false)
  3080. return false;
  3081. $lps = array ();
  3082. $lp_order = array ();
  3083. $num = Database :: num_rows($res);
  3084. $max = 0;
  3085. //first check the order is correct, globally (might be wrong because
  3086. //of versions < 1.8.4)
  3087. if ($num > 0) {
  3088. $i = 1;
  3089. while ($row = Database :: fetch_array($res)) {
  3090. $max = $i;
  3091. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3092. $need_fix = true;
  3093. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3094. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3095. }
  3096. $row['display_order'] = $i;
  3097. $lps[$row['id']] = $row;
  3098. $lp_order[$i] = $row['id'];
  3099. $i++;
  3100. }
  3101. }
  3102. if ($num > 1) //if there's only one element, no need to sort
  3103. {
  3104. $order = $lps[$lp_id]['display_order'];
  3105. if ($order < $max) //if it's the first element, no need to move up
  3106. {
  3107. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order +1];
  3108. $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
  3109. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order +1) . " WHERE id = " . $lp_id;
  3110. $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
  3111. }
  3112. }
  3113. }
  3114. /**
  3115. * Updates learnpath attributes to point to the next element
  3116. * The last part is similar to set_current_item but processing the other way around
  3117. */
  3118. function next() {
  3119. if ($this->debug > 0) {
  3120. error_log('New LP - In learnpath::next()', 0);
  3121. }
  3122. $this->last = $this->get_current_item_id();
  3123. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3124. $this->autocomplete_parents($this->last);
  3125. $new_index = $this->get_next_index();
  3126. if ($this->debug > 2) {
  3127. error_log('New LP - New index: ' . $new_index, 0);
  3128. }
  3129. $this->index = $new_index;
  3130. if ($this->debug > 2) {
  3131. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3132. }
  3133. $this->current = $this->ordered_items[$new_index];
  3134. if ($this->debug > 2) {
  3135. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3136. }
  3137. }
  3138. /**
  3139. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3140. * class, this might be redefined to allow several behaviours depending on the document type.
  3141. * @param integer Resource ID
  3142. * @return boolean True on success, false otherwise
  3143. */
  3144. function open($id) {
  3145. if ($this->debug > 0) {
  3146. error_log('New LP - In learnpath::open()', 0);
  3147. }
  3148. //TODO
  3149. //set the current resource attribute to this resource
  3150. //switch on element type (redefine in child class?)
  3151. //set status for this item to "opened"
  3152. //start timer
  3153. //initialise score
  3154. $this->index = 0; //or = the last item seen (see $this->last)
  3155. }
  3156. /**
  3157. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3158. * and the prerequisite string on error.
  3159. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3160. * @param integer Optional item ID. If none given, uses the current open item.
  3161. * @return boolean True if prerequisites are matched, false otherwise
  3162. * @return string Empty string if true returned, prerequisites string otherwise.
  3163. */
  3164. function prerequisites_match($item = null) {
  3165. if ($this->debug > 0) {
  3166. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3167. }
  3168. if (empty ($item)) {
  3169. $item = $this->current;
  3170. }
  3171. if (is_object($this->items[$item])) {
  3172. $prereq_string = $this->items[$item]->get_prereq_string();
  3173. if (empty ($prereq_string)) {
  3174. return true;
  3175. }
  3176. //clean spaces
  3177. $prereq_string = str_replace(' ', '', $prereq_string);
  3178. if ($this->debug > 0) {
  3179. error_log('Found prereq_string: ' . $prereq_string, 0);
  3180. }
  3181. //now send to the parse_prereq() function that will check this component's prerequisites
  3182. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3183. if ($result === false) {
  3184. $this->set_error_msg($this->items[$item]->prereq_alert);
  3185. }
  3186. } else {
  3187. $result = true;
  3188. if ($this->debug > 1) {
  3189. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3190. }
  3191. }
  3192. if ($this->debug > 1) {
  3193. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3194. }
  3195. return $result;
  3196. }
  3197. /**
  3198. * Updates learnpath attributes to point to the previous element
  3199. * The last part is similar to set_current_item but processing the other way around
  3200. */
  3201. function previous() {
  3202. if ($this->debug > 0) {
  3203. error_log('New LP - In learnpath::previous()', 0);
  3204. }
  3205. $this->last = $this->get_current_item_id();
  3206. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3207. $this->autocomplete_parents($this->last);
  3208. $new_index = $this->get_previous_index();
  3209. $this->index = $new_index;
  3210. $this->current = $this->ordered_items[$new_index];
  3211. }
  3212. /**
  3213. * Publishes a learnpath. This basically means show or hide the learnpath
  3214. * to normal users.
  3215. * Can be used as abstract
  3216. * @param integer Learnpath ID
  3217. * @param string New visibility
  3218. */
  3219. function toggle_visibility($lp_id, $set_visibility = 1) {
  3220. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  3221. $action = 'visible';
  3222. if ($set_visibility != 1) {
  3223. $action = 'invisible';
  3224. }
  3225. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3226. }
  3227. /**
  3228. * Publishes a learnpath. This basically means show or hide the learnpath
  3229. * on the course homepage
  3230. * Can be used as abstract
  3231. * @param integer Learnpath ID
  3232. * @param string New visibility
  3233. */
  3234. function toggle_publish($lp_id, $set_visibility = 'v') {
  3235. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  3236. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3237. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3238. $result = Database::query($sql, __FILE__, __LINE__);
  3239. $row = Database :: fetch_array($result);
  3240. $name = domesticate($row['name']);
  3241. if ($set_visibility == 'i') {
  3242. $s = $name . " " . get_lang('_no_published');
  3243. $dialogBox = $s;
  3244. $v = 0;
  3245. }
  3246. if ($set_visibility == 'v') {
  3247. $s = $name . " " . get_lang('_published');
  3248. $dialogBox = $s;
  3249. $v = 1;
  3250. }
  3251. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3252. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
  3253. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  3254. $result = Database::query($sql, __FILE__, __LINE__);
  3255. $num = Database :: num_rows($result);
  3256. $row2 = Database :: fetch_array($result);
  3257. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  3258. if (($set_visibility == 'i') && ($num > 0)) {
  3259. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  3260. }
  3261. elseif (($set_visibility == 'v') && ($num == 0)) {
  3262. $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)";
  3263. } else {
  3264. //parameter and database incompatible, do nothing
  3265. }
  3266. $result = Database::query($sql, __FILE__, __LINE__);
  3267. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3268. }
  3269. /**
  3270. * Restart the whole learnpath. Return the URL of the first element.
  3271. * Make sure the results are saved with anoter method. This method should probably be
  3272. * redefined in children classes.
  3273. * To use a similar method statically, use the create_new_attempt() method
  3274. * @return string URL to load in the viewer
  3275. */
  3276. function restart() {
  3277. if ($this->debug > 0) {
  3278. error_log('New LP - In learnpath::restart()', 0);
  3279. }
  3280. //TODO
  3281. //call autosave method to save the current progress
  3282. //$this->index = 0;
  3283. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3284. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  3285. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ")";
  3286. if ($this->debug > 2) {
  3287. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3288. }
  3289. $res = Database::query($sql, __FILE__, __LINE__);
  3290. if ($view_id = Database :: insert_id($res)) {
  3291. $this->lp_view_id = $view_id;
  3292. $this->attempt = $this->attempt + 1;
  3293. } else {
  3294. $this->error = 'Could not insert into item_view table...';
  3295. return false;
  3296. }
  3297. $this->autocomplete_parents($this->current);
  3298. foreach ($this->items as $index => $dummy) {
  3299. $this->items[$index]->restart();
  3300. $this->items[$index]->set_lp_view($this->lp_view_id);
  3301. }
  3302. $this->first();
  3303. return true;
  3304. }
  3305. /**
  3306. * Saves the current item
  3307. * @return boolean
  3308. */
  3309. function save_current() {
  3310. if ($this->debug > 0) {
  3311. error_log('New LP - In learnpath::save_current()', 0);
  3312. }
  3313. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3314. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3315. if ($this->debug > 2) {
  3316. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3317. }
  3318. if ($this->debug > 2) {
  3319. error_log('' . print_r($this->items, true), 0);
  3320. }
  3321. if (is_object($this->items[$this->current])) {
  3322. //$res = $this->items[$this->current]->save(false);
  3323. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3324. $this->autocomplete_parents($this->current);
  3325. $status = $this->items[$this->current]->get_status();
  3326. $this->append_message('new_item_status: ' . $status);
  3327. $this->update_queue[$this->current] = $status;
  3328. return $res;
  3329. }
  3330. return false;
  3331. }
  3332. /**
  3333. * Saves the given item
  3334. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3335. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3336. * @return boolean
  3337. */
  3338. function save_item($item_id = null, $from_outside = true) {
  3339. if ($this->debug > 0) {
  3340. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3341. }
  3342. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3343. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3344. if (empty ($item_id)) {
  3345. $item_id = $this->escape_string($_REQUEST['id']);
  3346. }
  3347. if (empty ($item_id)) {
  3348. $item_id = $this->get_current_item_id();
  3349. }
  3350. if ($this->debug > 2) {
  3351. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3352. }
  3353. if (is_object($this->items[$item_id])) {
  3354. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3355. //$res = $this->items[$item_id]->save($from_outside);
  3356. $this->autocomplete_parents($item_id);
  3357. $status = $this->items[$item_id]->get_status();
  3358. $this->append_message('new_item_status: ' . $status);
  3359. $this->update_queue[$item_id] = $status;
  3360. return $res;
  3361. }
  3362. return false;
  3363. }
  3364. /**
  3365. * Saves the last item seen's ID only in case
  3366. */
  3367. function save_last()
  3368. {
  3369. if ($this->debug > 0) {
  3370. error_log('New LP - In learnpath::save_last()', 0);
  3371. }
  3372. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3373. if (isset ($this->current)) {
  3374. if ($this->debug > 2) {
  3375. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3376. }
  3377. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3378. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id();
  3379. if ($this->debug > 2) {
  3380. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3381. }
  3382. $res = Database::query($sql, __FILE__, __LINE__);
  3383. }
  3384. //save progress
  3385. list ($progress, $text) = $this->get_progress_bar_text('%');
  3386. if ($progress >= 0 AND $progress <= 100) {
  3387. $progress = (int) $progress;
  3388. $sql = "UPDATE $table SET progress = $progress " .
  3389. "WHERE lp_id = " . $this->get_id() . " AND " .
  3390. "user_id = " . $this->get_user_id();
  3391. $res = Database::query($sql, __FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  3392. $this->progress_db = $progress;
  3393. }
  3394. }
  3395. /**
  3396. * Sets the current item ID (checks if valid and authorized first)
  3397. * @param integer New item ID. If not given or not authorized, defaults to current
  3398. */
  3399. function set_current_item($item_id = null) {
  3400. if ($this->debug > 0) {
  3401. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3402. }
  3403. if (empty ($item_id)) {
  3404. if ($this->debug > 2) {
  3405. error_log('New LP - No new current item given, ignore...', 0);
  3406. }
  3407. //do nothing
  3408. } else {
  3409. if ($this->debug > 2) {
  3410. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3411. }
  3412. if (is_numeric($item_id)) {
  3413. $item_id = $this->escape_string($item_id);
  3414. //TODO check in database here
  3415. $this->last = $this->current;
  3416. $this->current = $item_id;
  3417. //TODO update $this->index as well
  3418. foreach ($this->ordered_items as $index => $item) {
  3419. if ($item == $this->current) {
  3420. $this->index = $index;
  3421. break;
  3422. }
  3423. }
  3424. if ($this->debug > 2) {
  3425. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3426. }
  3427. } else {
  3428. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3429. }
  3430. }
  3431. }
  3432. /**
  3433. * Sets the encoding
  3434. * @param string New encoding
  3435. */
  3436. function set_encoding($enc = 'ISO-8859-15') {
  3437. if ($this->debug > 0) {
  3438. error_log('New LP - In learnpath::set_encoding()', 0);
  3439. }
  3440. $enc = strtoupper($enc);
  3441. $encodings = array (
  3442. 'UTF-8',
  3443. 'ISO-8859-1',
  3444. 'ISO-8859-15',
  3445. 'cp1251',
  3446. 'cp1252',
  3447. 'KOI8-R',
  3448. 'BIG5',
  3449. 'GB2312',
  3450. 'Shift_JIS',
  3451. 'EUC-JP',
  3452. ''
  3453. );
  3454. if (in_array($enc, $encodings)) {
  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 default_encoding = '$enc' WHERE id = " . $lp;
  3459. $res = Database::query($sql, __FILE__, __LINE__);
  3460. return $res;
  3461. }
  3462. }
  3463. return false;
  3464. }
  3465. /**
  3466. * Sets the JS lib setting in the database directly.
  3467. * This is the JavaScript library file this lp needs to load on startup
  3468. * @param string Proximity setting
  3469. */
  3470. function set_jslib($lib = '') {
  3471. if ($this->debug > 0) {
  3472. error_log('New LP - In learnpath::set_jslib()', 0);
  3473. }
  3474. $lp = $this->get_id();
  3475. if ($lp != 0) {
  3476. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3477. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3478. $res = Database::query($sql, __FILE__, __LINE__);
  3479. return $res;
  3480. } else {
  3481. return false;
  3482. }
  3483. }
  3484. /**
  3485. * Sets the name of the LP maker (publisher) (and save)
  3486. * @param string Optional string giving the new content_maker of this learnpath
  3487. */
  3488. function set_maker($name = '') {
  3489. if ($this->debug > 0) {
  3490. error_log('New LP - In learnpath::set_maker()', 0);
  3491. }
  3492. if (empty ($name))
  3493. return false;
  3494. $this->maker = $this->escape_string($name);
  3495. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3496. $lp_id = $this->get_id();
  3497. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3498. if ($this->debug > 2) {
  3499. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3500. }
  3501. //$res = Database::query($sql);
  3502. $res = Database::query($sql, __FILE__, __LINE__);
  3503. return true;
  3504. }
  3505. /**
  3506. * Sets the name of the current learnpath (and save)
  3507. * @param string Optional string giving the new name of this learnpath
  3508. */
  3509. function set_name($name = '') {
  3510. if ($this->debug > 0) {
  3511. error_log('New LP - In learnpath::set_name()', 0);
  3512. }
  3513. if (empty ($name))
  3514. return false;
  3515. $this->name = $this->escape_string($name);
  3516. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3517. $lp_id = $this->get_id();
  3518. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3519. if ($this->debug > 2) {
  3520. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3521. }
  3522. //$res = Database::query($sql);
  3523. $res = Database::query($sql, __FILE__, __LINE__);
  3524. // if the lp is visible on the homepage, change his name there
  3525. if (Database::affected_rows()) {
  3526. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3527. $sql = 'UPDATE ' . $table . ' SET
  3528. name = "' . $this->name . '"
  3529. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3530. Database::query($sql, __FILE__, __LINE__);
  3531. }
  3532. return true;
  3533. }
  3534. /**
  3535. * Set index specified prefix terms for all items in this path
  3536. * @param string Comma-separated list of terms
  3537. * @param char Xapian term prefix
  3538. * @return boolean False on error, true otherwise
  3539. */
  3540. function set_terms_by_prefix($terms_string, $prefix) {
  3541. if (api_get_setting('search_enabled') !== 'true')
  3542. return FALSE;
  3543. $terms_string = trim($terms_string);
  3544. $terms = explode(',', $terms_string);
  3545. array_walk($terms, 'trim_value');
  3546. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3547. //var_dump($stored_terms);
  3548. //var_dump($terms);
  3549. // don't do anything if no change, verify only at DB, not the search engine
  3550. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3551. return FALSE;
  3552. require_once ('xapian.php'); //TODO try catch every xapian use or make wrappers on api
  3553. require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  3554. require_once (api_get_path(LIBRARY_PATH) . 'search/xapian/XapianQuery.php');
  3555. require_once (api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
  3556. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3557. //TODO: make query secure agains XSS : use member attr instead of post var
  3558. $lp_id = intval($_POST['lp_id']);
  3559. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3560. $result = Database::query($sql);
  3561. $di = new DokeosIndexer();
  3562. while ($lp_item = Database :: fetch_array($result)) {
  3563. // get search_did
  3564. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3565. $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';
  3566. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3567. $res = Database::query($sql, __FILE__, __LINE__);
  3568. if (Database::num_rows($res)>0) {
  3569. $se_ref = Database :: fetch_array($res);
  3570. // compare terms
  3571. $doc = $di->get_document($se_ref['search_did']);
  3572. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3573. //var_dump($xapian_terms);
  3574. $xterms = array ();
  3575. foreach ($xapian_terms as $xapian_term)
  3576. $xterms[] = substr($xapian_term['name'], 1);
  3577. $dterms = $terms;
  3578. //var_dump($xterms);
  3579. //var_dump($dterms);
  3580. $missing_terms = array_diff($dterms, $xterms);
  3581. $deprecated_terms = array_diff($xterms, $dterms);
  3582. // save it to search engine
  3583. foreach ($missing_terms as $term) {
  3584. $doc->add_term($prefix . $term, 1);
  3585. }
  3586. foreach ($deprecated_terms as $term) {
  3587. $doc->remove_term($prefix . $term);
  3588. }
  3589. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3590. $di->getDb()->flush();
  3591. }
  3592. }
  3593. return true;
  3594. }
  3595. /**
  3596. * Sets the theme of the LP (local/remote) (and save)
  3597. * @param string Optional string giving the new theme of this learnpath
  3598. * @return bool returns true if theme name is not empty
  3599. */
  3600. function set_theme($name = '') {
  3601. if ($this->debug > 0) {
  3602. error_log('New LP - In learnpath::set_theme()', 0);
  3603. }
  3604. $this->theme = $this->escape_string($name);
  3605. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3606. $lp_id = $this->get_id();
  3607. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3608. if ($this->debug > 2) {
  3609. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3610. }
  3611. //$res = Database::query($sql);
  3612. $res = Database::query($sql, __FILE__, __LINE__);
  3613. return true;
  3614. }
  3615. /**
  3616. * Sets the image of an LP (and save)
  3617. * @param string Optional string giving the new image of this learnpath
  3618. * @return bool returns true if theme name is not empty
  3619. */
  3620. function set_preview_image($name = '') {
  3621. if ($this->debug > 0) {
  3622. error_log('New LP - In learnpath::set_preview_image()', 0);
  3623. }
  3624. $this->preview_image = $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 preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3628. if ($this->debug > 2) {
  3629. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3630. }
  3631. $res = Database::query($sql, __FILE__, __LINE__);
  3632. return true;
  3633. }
  3634. /**
  3635. * Sets the author of a LP (and save)
  3636. * @param string Optional string giving the new author of this learnpath
  3637. * @return bool returns true if author's name is not empty
  3638. */
  3639. function set_author($name = '') {
  3640. if ($this->debug > 0) {
  3641. error_log('New LP - In learnpath::set_author()', 0);
  3642. }
  3643. $this->author = $this->escape_string($name);
  3644. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3645. $lp_id = $this->get_id();
  3646. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3647. if ($this->debug > 2) {
  3648. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3649. }
  3650. $res = Database::query($sql, __FILE__, __LINE__);
  3651. return true;
  3652. }
  3653. /**
  3654. * Sets the location/proximity of the LP (local/remote) (and save)
  3655. * @param string Optional string giving the new location of this learnpath
  3656. */
  3657. function set_proximity($name = '') {
  3658. if ($this->debug > 0) {
  3659. error_log('New LP - In learnpath::set_proximity()', 0);
  3660. }
  3661. if (empty ($name))
  3662. return false;
  3663. $this->proximity = $this->escape_string($name);
  3664. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3665. $lp_id = $this->get_id();
  3666. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3667. if ($this->debug > 2) {
  3668. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3669. }
  3670. //$res = Database::query($sql);
  3671. $res = Database::query($sql, __FILE__, __LINE__);
  3672. return true;
  3673. }
  3674. /**
  3675. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3676. * @param integer DB ID of the item
  3677. */
  3678. function set_previous_item($id) {
  3679. if ($this->debug > 0) {
  3680. error_log('New LP - In learnpath::set_previous_item()', 0);
  3681. }
  3682. $this->last = $id;
  3683. }
  3684. /**
  3685. * Sets the object's error message
  3686. * @param string Error message. If empty, reinits the error string
  3687. * @return void
  3688. */
  3689. function set_error_msg($error = '') {
  3690. if ($this->debug > 0) {
  3691. error_log('New LP - In learnpath::set_error_msg()', 0);
  3692. }
  3693. if (empty ($error)) {
  3694. $this->error = '';
  3695. } else {
  3696. $this->error .= $error;
  3697. }
  3698. }
  3699. /**
  3700. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3701. *
  3702. */
  3703. function start_current_item($allow_new_attempt = false) {
  3704. if ($this->debug > 0) {
  3705. error_log('New LP - In learnpath::start_current_item()', 0);
  3706. }
  3707. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3708. $type = $this->get_type();
  3709. $item_type = $this->items[$this->current]->get_type();
  3710. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3711. $this->items[$this->current]->open($allow_new_attempt);
  3712. $this->autocomplete_parents($this->current);
  3713. $prereq_check = $this->prerequisites_match($this->current);
  3714. $this->items[$this->current]->save(false, $prereq_check);
  3715. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3716. } else {
  3717. //if sco, then it is supposed to have been updated by some other call
  3718. }
  3719. if ($item_type == 'sco') {
  3720. $this->items[$this->current]->restart();
  3721. }
  3722. }
  3723. if ($this->debug > 0) {
  3724. error_log('New LP - End of learnpath::start_current_item()', 0);
  3725. }
  3726. return true;
  3727. }
  3728. /**
  3729. * Stops the processing and counters for the old item (as held in $this->last)
  3730. * @param
  3731. */
  3732. function stop_previous_item() {
  3733. if ($this->debug > 0) {
  3734. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3735. }
  3736. if ($this->last != 0 AND $this->last != $this->current AND is_object($this->items[$this->last])) {
  3737. if ($this->debug > 2) {
  3738. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3739. }
  3740. switch ($this->get_type()) {
  3741. case '3' :
  3742. if ($this->items[$this->last]->get_type() != 'au') {
  3743. if ($this->debug > 2) {
  3744. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3745. }
  3746. $this->items[$this->last]->close();
  3747. //$this->autocomplete_parents($this->last);
  3748. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3749. } else {
  3750. if ($this->debug > 2) {
  3751. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3752. }
  3753. }
  3754. case '2' :
  3755. if ($this->items[$this->last]->get_type() != 'sco') {
  3756. if ($this->debug > 2) {
  3757. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3758. }
  3759. $this->items[$this->last]->close();
  3760. //$this->autocomplete_parents($this->last);
  3761. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3762. } else {
  3763. if ($this->debug > 2) {
  3764. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3765. }
  3766. }
  3767. break;
  3768. case '1' :
  3769. default :
  3770. if ($this->debug > 2) {
  3771. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3772. }
  3773. $this->items[$this->last]->close();
  3774. break;
  3775. }
  3776. } else {
  3777. if ($this->debug > 2) {
  3778. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3779. }
  3780. return false;
  3781. }
  3782. return true;
  3783. }
  3784. /**
  3785. * Updates the default view mode from fullscreen to embedded and inversely
  3786. * @return string The current default view mode ('fullscreen' or 'embedded')
  3787. */
  3788. function update_default_view_mode() {
  3789. if ($this->debug > 0) {
  3790. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3791. }
  3792. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3793. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3794. $res = Database::query($sql, __FILE__, __LINE__);
  3795. if (Database :: num_rows($res) > 0) {
  3796. $row = Database :: fetch_array($res);
  3797. $view_mode = $row['default_view_mod'];
  3798. if ($view_mode == 'fullscreen') {
  3799. $view_mode = 'embedded';
  3800. }
  3801. elseif ($view_mode == 'embedded') {
  3802. $view_mode = 'fullscreen';
  3803. }
  3804. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3805. $res = Database::query($sql, __FILE__, __LINE__);
  3806. $this->mode = $view_mode;
  3807. return $view_mode;
  3808. } else {
  3809. if ($this->debug > 2) {
  3810. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3811. }
  3812. }
  3813. return -1;
  3814. }
  3815. /**
  3816. * Updates the default behaviour about auto-commiting SCORM updates
  3817. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3818. */
  3819. function update_default_scorm_commit() {
  3820. if ($this->debug > 0) {
  3821. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3822. }
  3823. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3824. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3825. $res = Database::query($sql, __FILE__, __LINE__);
  3826. if (Database :: num_rows($res) > 0) {
  3827. $row = Database :: fetch_array($res);
  3828. $force = $row['force_commit'];
  3829. if ($force == 1) {
  3830. $force = 0;
  3831. $force_return = false;
  3832. }
  3833. elseif ($force == 0) {
  3834. $force = 1;
  3835. $force_return = true;
  3836. }
  3837. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3838. $res = Database::query($sql, __FILE__, __LINE__);
  3839. $this->force_commit = $force_return;
  3840. return $force_return;
  3841. } else {
  3842. if ($this->debug > 2) {
  3843. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3844. }
  3845. }
  3846. return -1;
  3847. }
  3848. /**
  3849. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3850. * @return bool True on success, false on failure
  3851. */
  3852. function update_display_order() {
  3853. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3854. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3855. $res = Database::query($sql, __FILE__, __LINE__);
  3856. if ($res === false)
  3857. return false;
  3858. $lps = array ();
  3859. $lp_order = array ();
  3860. $num = Database :: num_rows($res);
  3861. //first check the order is correct, globally (might be wrong because
  3862. //of versions < 1.8.4)
  3863. if ($num > 0) {
  3864. $i = 1;
  3865. while ($row = Database :: fetch_array($res)) {
  3866. if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
  3867. $need_fix = true;
  3868. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3869. $res_u = Database::query($sql_u, __FILE__, __LINE__);
  3870. }
  3871. $i++;
  3872. }
  3873. }
  3874. return true;
  3875. }
  3876. /**
  3877. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3878. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3879. */
  3880. function update_reinit() {
  3881. if ($this->debug > 0) {
  3882. error_log('New LP - In learnpath::update_reinit()', 0);
  3883. }
  3884. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3885. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3886. $res = Database::query($sql, __FILE__, __LINE__);
  3887. if (Database :: num_rows($res) > 0) {
  3888. $row = Database :: fetch_array($res);
  3889. $force = $row['prevent_reinit'];
  3890. if ($force == 1) {
  3891. $force = 0;
  3892. }
  3893. elseif ($force == 0) {
  3894. $force = 1;
  3895. }
  3896. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  3897. $res = Database::query($sql, __FILE__, __LINE__);
  3898. $this->prevent_reinit = $force;
  3899. return $force;
  3900. } else {
  3901. if ($this->debug > 2) {
  3902. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3903. }
  3904. }
  3905. return -1;
  3906. }
  3907. /**
  3908. * Updates the "scorm_debug" value that shows or hide the debug window
  3909. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3910. */
  3911. function update_scorm_debug() {
  3912. if ($this->debug > 0) {
  3913. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  3914. }
  3915. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3916. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3917. $res = Database::query($sql, __FILE__, __LINE__);
  3918. if (Database :: num_rows($res) > 0) {
  3919. $row = Database :: fetch_array($res);
  3920. $force = $row['debug'];
  3921. if ($force == 1) {
  3922. $force = 0;
  3923. }
  3924. elseif ($force == 0) {
  3925. $force = 1;
  3926. }
  3927. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  3928. $res = Database::query($sql, __FILE__, __LINE__);
  3929. $this->scorm_debug = $force;
  3930. return $force;
  3931. } else {
  3932. if ($this->debug > 2) {
  3933. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3934. }
  3935. }
  3936. return -1;
  3937. }
  3938. /**
  3939. * Function that makes a call to the function sort_tree_array and create_tree_array
  3940. *
  3941. * @author Kevin Van Den Haute
  3942. *
  3943. * @param unknown_type $array
  3944. */
  3945. function tree_array($array) {
  3946. if ($this->debug > 1) {
  3947. error_log('New LP - In learnpath::tree_array()', 0);
  3948. }
  3949. $array = $this->sort_tree_array($array);
  3950. $this->create_tree_array($array);
  3951. }
  3952. /**
  3953. * Creates an array with the elements of the learning path tree in it
  3954. *
  3955. * @author Kevin Van Den Haute
  3956. *
  3957. * @param array $array
  3958. * @param int $parent
  3959. * @param int $depth
  3960. * @param array $tmp
  3961. */
  3962. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  3963. if ($this->debug > 1) {
  3964. error_log('New LP - In learnpath::create_tree_array())', 0);
  3965. }
  3966. if (is_array($array)) {
  3967. for ($i = 0; $i < count($array); $i++) {
  3968. if ($array[$i]['parent_item_id'] == $parent) {
  3969. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  3970. $tmp[] = $array[$i]['parent_item_id'];
  3971. $depth++;
  3972. }
  3973. $preq = (empty ($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  3974. $this->arrMenu[] = array (
  3975. 'id' => $array[$i]['id'],
  3976. 'item_type' => $array[$i]['item_type'],
  3977. 'title' => $array[$i]['title'],
  3978. 'path' => $array[$i]['path'],
  3979. 'description' => $array[$i]['description'],
  3980. 'parent_item_id' => $array[$i]['parent_item_id'],
  3981. 'previous_item_id' => $array[$i]['previous_item_id'],
  3982. 'next_item_id' => $array[$i]['next_item_id'],
  3983. 'min_score' => $array[$i]['min_score'],
  3984. 'max_score' => $array[$i]['max_score'],
  3985. 'mastery_score' => $array[$i]['mastery_score'],
  3986. 'display_order' => $array[$i]['display_order'],
  3987. 'prerequisite' => $preq,
  3988. 'depth' => $depth,
  3989. 'audio' => $array[$i]['audio']
  3990. );
  3991. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3992. }
  3993. }
  3994. }
  3995. }
  3996. /**
  3997. * Sorts a multi dimensional array by parent id and display order
  3998. * @author Kevin Van Den Haute
  3999. *
  4000. * @param array $array (array with al the learning path items in it)
  4001. *
  4002. * @return array
  4003. */
  4004. function sort_tree_array($array) {
  4005. foreach ($array as $key => $row) {
  4006. $parent[$key] = $row['parent_item_id'];
  4007. $position[$key] = $row['display_order'];
  4008. }
  4009. if (count($array) > 0)
  4010. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4011. return $array;
  4012. }
  4013. /**
  4014. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4015. * Also the actions for the modules, chapters and documents are in this table.
  4016. *
  4017. * @author Kevin Van Den Haute
  4018. *
  4019. * @param int $lp_id
  4020. *
  4021. * @return string
  4022. */
  4023. function overview() {
  4024. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4025. $platform_charset = api_get_system_encoding();
  4026. if ($this->debug > 0) {
  4027. error_log('New LP - In learnpath::overview()', 0);
  4028. }
  4029. global $charset, $_course;
  4030. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4031. $return = '';
  4032. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4033. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4034. WHERE lp_id = " . $this->lp_id;
  4035. $result = Database::query($sql, __FILE__, __LINE__);
  4036. $arrLP = array ();
  4037. while ($row = Database :: fetch_array($result)) {
  4038. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4039. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4040. $arrLP[] = array (
  4041. 'id' => $row['id'],
  4042. 'item_type' => $row['item_type'],
  4043. 'title' => $row['title'],
  4044. 'path' => $row['path'],
  4045. 'description' => $row['description'],
  4046. 'parent_item_id' => $row['parent_item_id'],
  4047. 'previous_item_id' => $row['previous_item_id'],
  4048. 'next_item_id' => $row['next_item_id'],
  4049. 'max_score' => $row['max_score'],
  4050. 'min_score' => $row['min_score'],
  4051. 'mastery_score' => $row['mastery_score'],
  4052. 'prerequisite' => $row['prerequisite'],
  4053. 'display_order' => $row['display_order'],
  4054. 'audio' => $row['audio']
  4055. );
  4056. }
  4057. $this->tree_array($arrLP);
  4058. $arrLP = $this->arrMenu;
  4059. unset ($this->arrMenu);
  4060. if ($is_allowed_to_edit) {
  4061. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4062. $return .= '<div class="actions">';
  4063. $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>';
  4064. $return .= '<span>' . Display :: return_icon('learnpath_organize_na.gif', get_lang("BasicOverview")) . ' <b>' . get_lang('BasicOverview') . '</b></span>';
  4065. $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');
  4066. $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>';
  4067. $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>';
  4068. $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>';
  4069. $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>';
  4070. $return .= '</div>';
  4071. }
  4072. // we need to start a form when we want to update all the mp3 files
  4073. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4074. $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">';
  4075. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4076. }
  4077. $return .= '<table class="data_table">' . "\n";
  4078. $return .= "\t" . '<tr>' . "\n";
  4079. $return .= "\t" . '<th width="60%">' . get_lang("Title") . '</th>' . "\n";
  4080. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  4081. $return .= "\t" . '<th>' . get_lang("Audio") . '</th>' . "\n";
  4082. $return .= "\t" . '<th>' . get_lang("Move") . '</th>' . "\n";
  4083. $return .= "\t" . '<th>' . get_lang("Actions") . '</th>' . "\n";
  4084. $return .= "\t" . '</tr>' . "\n";
  4085. for ($i = 0; $i < count($arrLP); $i++) {
  4086. $title = $arrLP[$i]['title'];
  4087. if ($arrLP[$i]['description'] == '')
  4088. $arrLP[$i]['description'] = '&nbsp;';
  4089. if (($i % 2) == 0) {
  4090. $oddclass = "row_odd";
  4091. } else {
  4092. $oddclass = "row_even";
  4093. }
  4094. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4095. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4096. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4097. $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";
  4098. } else
  4099. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4100. $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";
  4101. } else {
  4102. //$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";
  4103. $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";
  4104. }
  4105. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4106. // The audio column
  4107. $return .= "\t\t" . '<td align="center">';
  4108. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4109. if (!empty ($arrLP[$i]['audio'])) {
  4110. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4111. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4112. $return .= '<script type="text/javascript">
  4113. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4114. s1.addParam("allowscriptaccess","always");
  4115. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4116. s1.write("container' . $i . '");
  4117. </script>';
  4118. } else {
  4119. $return .= ' - ';
  4120. }
  4121. } else {
  4122. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4123. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4124. if (!empty ($arrLP[$i]['audio'])) {
  4125. $return .= '<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4126. }
  4127. }
  4128. }
  4129. $return .= '</td>' . "\n";
  4130. if ($is_allowed_to_edit) {
  4131. $return .= "\t\t" . '<td align="center">' . "\n";
  4132. if ($arrLP[$i]['previous_item_id'] != 0) {
  4133. $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 . '">';
  4134. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4135. $return .= '</a>' . "\n";
  4136. } else
  4137. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4138. if ($arrLP[$i]['next_item_id'] != 0) {
  4139. $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 . '">';
  4140. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4141. $return .= '</a>' . "\n";
  4142. } else
  4143. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  4144. $return .= "\t\t" . '</td>' . "\n";
  4145. $return .= "\t\t" . '<td align="center">' . "\n";
  4146. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4147. $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'] . '">';
  4148. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4149. $return .= '</a>' . "\n";
  4150. } else {
  4151. $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'] . '">';
  4152. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4153. $return .= '</a>' . "\n";
  4154. }
  4155. $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) . '\');">';
  4156. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4157. $return .= '</a>' . "\n";
  4158. $return .= "\t\t" . '</td>' . "\n";
  4159. }
  4160. $return .= "\t" . '</tr>' . "\n";
  4161. }
  4162. if (count($arrLP) == 0) {
  4163. $return .= "\t" . '<tr>' . "\n";
  4164. $return .= "\t\t" . '<td colspan="4">' . get_lang("NoItemsInLp") . '</td>' . "\n";
  4165. $return .= "\t" . '</tr>' . "\n";
  4166. }
  4167. $return .= '</table>' . "\n";
  4168. // we need to close the form when we are updating the mp3 files
  4169. if ($_GET['updateaudio'] == 'true') {
  4170. $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?
  4171. }
  4172. // we need to close the form when we are updating the mp3 files
  4173. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4174. $return .= '</form>';
  4175. }
  4176. return $return;
  4177. }
  4178. /**
  4179. * This function builds the action menu
  4180. *
  4181. * */
  4182. function build_action_menu() {
  4183. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4184. echo '<div class="actions">';
  4185. //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  4186. echo '<span>' . Display :: return_icon('learnpath_build_na.gif', get_lang('Build')) . ' <b>' . get_lang('Build') . '</b></span>';
  4187. 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>';
  4188. 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>';
  4189. Display :: display_icon('i.gif');
  4190. 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>';
  4191. 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>';
  4192. 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>';
  4193. 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>';
  4194. echo '</div>';
  4195. }
  4196. /**
  4197. * This functions builds the LP tree based on data from the database.
  4198. *
  4199. * @return string
  4200. * @uses dtree.js :: necessary javascript for building this tree
  4201. */
  4202. function build_tree() {
  4203. $platform_charset = api_get_system_encoding();
  4204. $return = "<script type=\"text/javascript\">\n";
  4205. $return .= "\tm = new dTree('m');\n\n";
  4206. $return .= "\tm.config.folderLinks = true;\n";
  4207. $return .= "\tm.config.useCookies = true;\n";
  4208. $return .= "\tm.config.useIcons = true;\n";
  4209. $return .= "\tm.config.useLines = true;\n";
  4210. $return .= "\tm.config.useSelection = true;\n";
  4211. $return .= "\tm.config.useStatustext = false;\n\n";
  4212. $menu = 0;
  4213. $parent = '';
  4214. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4215. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4216. $sql = " SELECT * FROM " . $tbl_lp_item . "
  4217. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4218. $result = Database::query($sql, __FILE__, __LINE__);
  4219. $arrLP = array ();
  4220. while ($row = Database :: fetch_array($result)) {
  4221. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
  4222. $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
  4223. //$row['title'] = Security :: remove_XSS($row['title']);
  4224. $arrLP[] = array (
  4225. 'id' => $row['id'],
  4226. 'item_type' => $row['item_type'],
  4227. 'title' => $row['title'],
  4228. 'path' => $row['path'],
  4229. 'description' => $row['description'],
  4230. 'parent_item_id' => $row['parent_item_id'],
  4231. 'previous_item_id' => $row['previous_item_id'],
  4232. 'next_item_id' => $row['next_item_id'],
  4233. 'max_score' => $row['max_score'],
  4234. 'min_score' => $row['min_score'],
  4235. 'mastery_score' => $row['mastery_score'],
  4236. 'display_order' => $row['display_order']
  4237. );
  4238. }
  4239. $this->tree_array($arrLP);
  4240. $arrLP = $this->arrMenu;
  4241. unset ($this->arrMenu);
  4242. $title = '';
  4243. for ($i = 0; $i < count($arrLP); $i++) {
  4244. $title = addslashes($arrLP[$i]['title']);
  4245. $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;
  4246. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4247. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  4248. $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";
  4249. } else
  4250. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  4251. $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";
  4252. } else {
  4253. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4254. }
  4255. if ($menu < $arrLP[$i]['id'])
  4256. $menu = $arrLP[$i]['id'];
  4257. }
  4258. $return .= "\n\tdocument.write(m);\n";
  4259. $return .= "\t if(!m.selectedNode) m.s(1);";
  4260. $return .= "</script>\n";
  4261. return $return;
  4262. }
  4263. /**
  4264. * Create a new document //still needs some finetuning
  4265. *
  4266. * @param array $_course
  4267. * @return string
  4268. */
  4269. function create_document($_course) {
  4270. global $charset;
  4271. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4272. if (strstr($dir, '..'))
  4273. $dir = '/';
  4274. if ($dir[0] == '.')
  4275. $dir = substr($dir, 1);
  4276. if ($dir[0] != '/')
  4277. $dir = '/' . $dir;
  4278. if ($dir[strlen($dir) - 1] != '/')
  4279. $dir .= '/';
  4280. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4281. if (!is_dir($filepath)) {
  4282. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4283. $dir = '/';
  4284. }
  4285. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  4286. //is already escaped twice when it gets here
  4287. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4288. $title = disable_dangerous_file($title);
  4289. $filename = $title;
  4290. $content = $_POST['content_lp'];
  4291. $tmp_filename = $filename;
  4292. $i = 0;
  4293. while (file_exists($filepath . $tmp_filename . '.html'))
  4294. $tmp_filename = $filename . '_' . ++ $i;
  4295. $filename = $tmp_filename . '.html';
  4296. $content = stripslashes(text_filter($content));
  4297. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH) . 'courses/', $content);
  4298. // change the path of mp3 to absolute
  4299. // first regexp deals with ../../../ urls
  4300. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4301. //second regexp deals with audio/ urls
  4302. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4303. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  4304. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4305. if (!file_exists($filepath . $filename)) {
  4306. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4307. fputs($fp, $content);
  4308. fclose($fp);
  4309. $file_size = filesize($filepath . $filename);
  4310. $save_file_path = $dir . $filename;
  4311. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4312. if ($document_id) {
  4313. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(),null,null,null,null,api_get_session_id());
  4314. //update parent folders
  4315. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4316. $new_comment = (isset ($_POST['comment'])) ? trim($_POST['comment']) : '';
  4317. $new_title = (isset ($_POST['title'])) ? trim($_POST['title']) : '';
  4318. if ($new_comment || $new_title) {
  4319. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4320. $ct = '';
  4321. if ($new_comment)
  4322. $ct .= ", comment='" . $new_comment . "'";
  4323. if ($new_title)
  4324. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4325. $sql_update = "
  4326. UPDATE " . $tbl_doc . "
  4327. SET " . substr($ct, 1) . "
  4328. WHERE id = " . $document_id;
  4329. Database::query($sql_update, __FILE__, __LINE__);
  4330. }
  4331. }
  4332. return $document_id;
  4333. }
  4334. }
  4335. }
  4336. /**
  4337. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4338. *
  4339. * @param array $_course array
  4340. * @return void
  4341. */
  4342. function edit_document($_course) {
  4343. global $_configuration;
  4344. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4345. if (strstr($dir, '..'))
  4346. $dir = '/';
  4347. if ($dir[0] == '.')
  4348. $dir = substr($dir, 1);
  4349. if ($dir[0] != '/')
  4350. $dir = '/' . $dir;
  4351. if ($dir[strlen($dir) - 1] != '/')
  4352. $dir .= '/';
  4353. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4354. if (!is_dir($filepath)) {
  4355. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4356. $dir = '/';
  4357. }
  4358. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4359. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4360. $sql = "SELECT path
  4361. FROM " . $table_doc . "
  4362. WHERE id = " . Database::escape_string($_POST['path']);
  4363. $res = Database::query($sql, __FILE__, __LINE__);
  4364. $row = Database :: fetch_array($res);
  4365. $content = stripslashes($_POST['content_lp']);
  4366. $file = $filepath . $row['path'];
  4367. if ($fp = @ fopen($file, 'w')) {
  4368. $content = text_filter($content);
  4369. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'] . '/courses/', $content);
  4370. // change the path of mp3 to absolute
  4371. // first regexp deals with ../../../ urls
  4372. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4373. //second regexp deals with audio/ urls
  4374. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4375. fputs($fp, $content);
  4376. fclose($fp);
  4377. }
  4378. }
  4379. }
  4380. /**
  4381. * Displays the selected item, with a panel for manipulating the item
  4382. *
  4383. * @param int $item_id
  4384. * @param string $msg
  4385. * @return string
  4386. */
  4387. function display_item($item_id, $iframe = true, $msg = '') {
  4388. global $_course; //will disappear
  4389. $return = '';
  4390. if (is_numeric($item_id)) {
  4391. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4392. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4393. $sql = "SELECT lp.*
  4394. FROM " . $tbl_lp_item . " as lp
  4395. WHERE lp.id = " . Database :: escape_string($item_id);
  4396. $result = Database::query($sql, __FILE__, __LINE__);
  4397. while ($row = Database :: fetch_array($result)) {
  4398. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4399. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4400. $return .= '<div style="padding:10px;">';
  4401. if ($msg != '')
  4402. $return .= $msg;
  4403. $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], api_get_system_encoding(), $this->encoding));
  4404. //$row['title'] = Security::remove_XSS(api_convert_encoding($row['title'], $this->encoding, api_get_system_encoding()));
  4405. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4406. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4407. //$return .= '<hr />';
  4408. if ($row['item_type'] == TOOL_DOCUMENT) {
  4409. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4410. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4411. $result = Database::query($sql_doc, __FILE__, __LINE__);
  4412. $path_file = Database :: result($result, 0, 0);
  4413. $path_parts = pathinfo($path_file);
  4414. if (in_array($path_parts['extension'], array (
  4415. 'html',
  4416. 'txt',
  4417. 'png',
  4418. 'jpg',
  4419. 'JPG',
  4420. 'jpeg',
  4421. 'JPEG',
  4422. 'gif',
  4423. 'swf'
  4424. ))) {
  4425. $return .= $this->display_document($row['path'], true, true);
  4426. }
  4427. }
  4428. $return .= '</div>';
  4429. }
  4430. }
  4431. return $return;
  4432. }
  4433. /**
  4434. * Shows the needed forms for editing a specific item
  4435. *
  4436. * @param int $item_id
  4437. * @return string
  4438. */
  4439. function display_edit_item($item_id) {
  4440. global $_course; //will disappear
  4441. $return = '';
  4442. if (is_numeric($item_id)) {
  4443. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4444. $sql = "SELECT *
  4445. FROM " . $tbl_lp_item . "
  4446. WHERE id = " . Database :: escape_string($item_id);
  4447. $res = Database::query($sql, __FILE__, __LINE__);
  4448. $row = Database :: fetch_array($res);
  4449. switch ($row['item_type']) {
  4450. case 'dokeos_chapter' :
  4451. case 'dir' :
  4452. case 'asset' :
  4453. case 'sco' :
  4454. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4455. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4456. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', 'edit', $item_id, $row);
  4457. } else {
  4458. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', $row);
  4459. }
  4460. break;
  4461. case TOOL_DOCUMENT :
  4462. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4463. $sql_step = " SELECT lp.*, doc.path as dir
  4464. FROM " . $tbl_lp_item . " as lp
  4465. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4466. WHERE lp.id = " . Database :: escape_string($item_id);
  4467. $res_step = Database::query($sql_step, __FILE__, __LINE__);
  4468. $row_step = Database :: fetch_array($res_step);
  4469. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4470. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4471. break;
  4472. case TOOL_LINK :
  4473. $link_id = (string) $row['path'];
  4474. if (ctype_digit($link_id)) {
  4475. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4476. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4477. $res_link = Database::query($sql_select, __FILE__, __LINE__);
  4478. $row_link = Database :: fetch_array($res_link);
  4479. if (is_array($row_link)) {
  4480. $row['url'] = $row_link['url'];
  4481. }
  4482. }
  4483. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4484. $return .= $this->display_link_form('edit', $item_id, $row);
  4485. break;
  4486. case 'dokeos_module' :
  4487. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4488. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4489. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule") . ' :', 'edit', $item_id, $row);
  4490. } else {
  4491. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule") . ' :', $row);
  4492. }
  4493. break;
  4494. case TOOL_QUIZ :
  4495. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4496. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4497. break;
  4498. case TOOL_HOTPOTATOES :
  4499. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4500. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4501. break;
  4502. case TOOL_STUDENTPUBLICATION :
  4503. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4504. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4505. break;
  4506. case TOOL_FORUM :
  4507. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4508. $return .= $this->display_forum_form('edit', $item_id, $row);
  4509. break;
  4510. case TOOL_THREAD :
  4511. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4512. $return .= $this->display_thread_form('edit', $item_id, $row);
  4513. break;
  4514. }
  4515. }
  4516. return $return;
  4517. }
  4518. /**
  4519. * Function that displays a list with al the resources that could be added to the learning path
  4520. *
  4521. * @return string
  4522. */
  4523. function display_resources() {
  4524. global $_course; //TODO: don't use globals
  4525. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4526. $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.
  4527. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4528. $return .= '<div class="sectioncomment">';
  4529. /* get all the docs */
  4530. $return .= $this->get_documents();
  4531. /* get all the exercises */
  4532. $return .= $this->get_exercises();
  4533. /* get all the links */
  4534. $return .= $this->get_links();
  4535. /* get al the student publications */
  4536. $return .= $this->get_student_publications();
  4537. /* get al the forums */
  4538. $return .= $this->get_forums();
  4539. $return .= '</div>';
  4540. return $return;
  4541. }
  4542. /**
  4543. * Returns the extension of a document
  4544. *
  4545. * @param unknown_type $filename
  4546. * @return unknown
  4547. */
  4548. function get_extension($filename) {
  4549. $explode = explode('.', $filename);
  4550. return $explode[count($explode) - 1];
  4551. }
  4552. /**
  4553. * Displays a document by id
  4554. *
  4555. * @param unknown_type $id
  4556. * @return unknown
  4557. */
  4558. function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4559. global $_course; //temporary
  4560. $return = '';
  4561. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4562. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4563. WHERE id = " . $id;
  4564. $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
  4565. $row_doc = Database :: fetch_array($res_doc);
  4566. //if($show_title)
  4567. //$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>';
  4568. //TODO: add a path filter
  4569. if ($iframe) {
  4570. $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>';
  4571. } else {
  4572. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4573. }
  4574. return $return;
  4575. }
  4576. /**
  4577. * Return HTML form to add/edit a quiz
  4578. *
  4579. * @param string Action (add/edit)
  4580. * @param integer Item ID if already exists
  4581. * @param mixed Extra information (quiz ID if integer)
  4582. * @return string HTML form
  4583. */
  4584. function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4585. global $charset;
  4586. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4587. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4588. if ($id != 0 && is_array($extra_info)) {
  4589. $item_title = stripslashes($extra_info['title']);
  4590. $item_description = stripslashes($extra_info['description']);
  4591. }
  4592. elseif (is_numeric($extra_info)) {
  4593. $sql_quiz = "
  4594. SELECT
  4595. title,
  4596. description
  4597. FROM " . $tbl_quiz . "
  4598. WHERE id = " . $extra_info;
  4599. $result = Database::query($sql_quiz, __FILE__, __LINE__);
  4600. $row = Database :: fetch_array($result);
  4601. $item_title = $row['title'];
  4602. $item_description = $row['description'];
  4603. } else {
  4604. $item_title = '';
  4605. $item_description = '';
  4606. }
  4607. $return = ' <div class="row">
  4608. <div class="form_header">';
  4609. if ($id != 0 && is_array($extra_info))
  4610. $parent = $extra_info['parent_item_id'];
  4611. else
  4612. $parent = 0;
  4613. $sql = "
  4614. SELECT *
  4615. FROM " . $tbl_lp_item . "
  4616. WHERE
  4617. lp_id = " . $this->lp_id;
  4618. $result = Database::query($sql, __FILE__, __LINE__);
  4619. $arrLP = array ();
  4620. while ($row = Database :: fetch_array($result)) {
  4621. $arrLP[] = array (
  4622. 'id' => $row['id'],
  4623. 'item_type' => $row['item_type'],
  4624. 'title' => $row['title'],
  4625. 'path' => $row['path'],
  4626. 'description' => $row['description'],
  4627. 'parent_item_id' => $row['parent_item_id'],
  4628. 'previous_item_id' => $row['previous_item_id'],
  4629. 'next_item_id' => $row['next_item_id'],
  4630. 'display_order' => $row['display_order'],
  4631. 'max_score' => $row['max_score'],
  4632. 'min_score' => $row['min_score'],
  4633. 'mastery_score' => $row['mastery_score'],
  4634. 'prerequisite' => $row['prerequisite'],
  4635. 'max_time_allowed' => $row['max_time_allowed']
  4636. );
  4637. }
  4638. $this->tree_array($arrLP);
  4639. $arrLP = $this->arrMenu;
  4640. unset ($this->arrMenu);
  4641. if ($action == 'add')
  4642. $return .= get_lang("CreateTheExercise") . '&nbsp;:' . "\n";
  4643. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentExercise") . '&nbsp;:' . "\n";
  4644. else
  4645. $return .= get_lang("EditCurrentExecice") . '&nbsp;:' . "\n";
  4646. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4647. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4648. }
  4649. $return .= ' </div>
  4650. </div>';
  4651. $return .= '<div class="sectioncomment">';
  4652. $return .= '<form method="POST">' . "\n";
  4653. $return .= "\t" . '<table class="lp_form">' . "\n";
  4654. if ($action != 'move') {
  4655. $return .= "\t\t" . '<tr>' . "\n";
  4656. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4657. $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";
  4658. $return .= "\t\t" . '</tr>' . "\n";
  4659. }
  4660. $return .= "\t\t" . '<tr>' . "\n";
  4661. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4662. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4663. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4664. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4665. $arrHide = array (
  4666. $id
  4667. );
  4668. $parent_item_id = $_SESSION['parent_item_id'];
  4669. for ($i = 0; $i < count($arrLP); $i++) {
  4670. if ($action != 'add') {
  4671. 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)) {
  4672. $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>';
  4673. } else {
  4674. $arrHide[] = $arrLP[$i]['id'];
  4675. }
  4676. } else {
  4677. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4678. $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>';
  4679. }
  4680. }
  4681. if (is_array($arrLP)) {
  4682. reset($arrLP);
  4683. }
  4684. $return .= "\t\t\t\t" . '</select>';
  4685. $return .= "\t\t\t" . '</td>' . "\n";
  4686. $return .= "\t\t" . '</tr>' . "\n";
  4687. $return .= "\t\t" . '<tr>' . "\n";
  4688. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4689. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4690. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4691. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4692. for ($i = 0; $i < count($arrLP); $i++) {
  4693. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4694. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4695. $selected = 'selected="selected" ';
  4696. elseif ($action == 'add') $selected = 'selected="selected" ';
  4697. else
  4698. $selected = '';
  4699. $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>';
  4700. }
  4701. }
  4702. $return .= "\t\t\t\t" . '</select>';
  4703. $return .= "\t\t\t" . '</td>' . "\n";
  4704. $return .= "\t\t" . '</tr>' . "\n";
  4705. if ($action != 'move') {
  4706. $id_prerequisite = 0;
  4707. if (is_array($arrLP)) {
  4708. foreach ($arrLP as $key => $value) {
  4709. if ($value['id'] == $id) {
  4710. $id_prerequisite = $value['prerequisite'];
  4711. break;
  4712. }
  4713. }
  4714. }
  4715. $arrHide = array ();
  4716. for ($i = 0; $i < count($arrLP); $i++) {
  4717. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4718. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4719. $s_selected_position = $arrLP[$i]['id'];
  4720. elseif ($action == 'add') $s_selected_position = 0;
  4721. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4722. }
  4723. }
  4724. /*//comented the prerequisites, only visible in edit (exercise)
  4725. $return .= "\t\t" . '<tr>' . "\n";
  4726. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4727. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4728. foreach($arrHide as $key => $value){
  4729. if($key==$s_selected_position && $action == 'add'){
  4730. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4731. }
  4732. elseif($key==$id_prerequisite && $action == 'edit'){
  4733. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4734. }
  4735. else{
  4736. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4737. }
  4738. }
  4739. $return .= "</select></td>";
  4740. */
  4741. $return .= "\t\t" . '</tr>' . "\n";
  4742. /*$return .= "\t\t" . '<tr>' . "\n";
  4743. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4744. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4745. //Remove temporaly the test description
  4746. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4747. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4748. $return .= "\t\t" . '</tr>' . "\n"; */
  4749. }
  4750. $return .= "\t\t" . '<tr>' . "\n";
  4751. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>' . "\n";
  4752. $return .= "\t\t" . '</tr>' . "\n";
  4753. $return .= "\t" . '</table>' . "\n";
  4754. if ($action == 'move') {
  4755. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4756. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4757. }
  4758. if (is_numeric($extra_info)) {
  4759. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4760. }
  4761. elseif (is_array($extra_info)) {
  4762. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4763. }
  4764. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4765. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4766. $return .= '</form>' . "\n";
  4767. $return .= '</div>' . "\n";
  4768. return $return;
  4769. }
  4770. /**
  4771. * Addition of Hotpotatoes tests
  4772. * @param string Action
  4773. * @param integer Internal ID of the item
  4774. * @param mixed Extra information - can be an array with title and description indexes
  4775. * @return string HTML structure to display the hotpotatoes addition formular
  4776. */
  4777. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4778. global $charset;
  4779. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4780. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4781. if ($id != 0 && is_array($extra_info)) {
  4782. $item_title = stripslashes($extra_info['title']);
  4783. $item_description = stripslashes($extra_info['description']);
  4784. }
  4785. elseif (is_numeric($extra_info)) {
  4786. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4787. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4788. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4789. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4790. $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
  4791. $row = Database :: fetch_array($res_hot);
  4792. $item_title = $row['title'];
  4793. $item_description = $row['description'];
  4794. if (!empty ($row['comment'])) {
  4795. $item_title = $row['comment'];
  4796. }
  4797. } else {
  4798. $item_title = '';
  4799. $item_description = '';
  4800. }
  4801. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4802. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4803. $return = '<div style="margin:3px 12px;">';
  4804. if ($id != 0 && is_array($extra_info))
  4805. $parent = $extra_info['parent_item_id'];
  4806. else
  4807. $parent = 0;
  4808. $sql = "
  4809. SELECT *
  4810. FROM " . $tbl_lp_item . "
  4811. WHERE
  4812. lp_id = " . $this->lp_id;
  4813. $result = Database::query($sql, __FILE__, __LINE__);
  4814. $arrLP = array ();
  4815. while ($row = Database :: fetch_array($result)) {
  4816. $arrLP[] = array (
  4817. 'id' => $row['id'],
  4818. 'item_type' => $row['item_type'],
  4819. 'title' => $row['title'],
  4820. 'path' => $row['path'],
  4821. 'description' => $row['description'],
  4822. 'parent_item_id' => $row['parent_item_id'],
  4823. 'previous_item_id' => $row['previous_item_id'],
  4824. 'next_item_id' => $row['next_item_id'],
  4825. 'display_order' => $row['display_order'],
  4826. 'max_score' => $row['max_score'],
  4827. 'min_score' => $row['min_score'],
  4828. 'mastery_score' => $row['mastery_score'],
  4829. 'prerequisite' => $row['prerequisite'],
  4830. 'max_time_allowed' => $row['max_time_allowed']
  4831. );
  4832. }
  4833. $this->tree_array($arrLP);
  4834. $arrLP = $this->arrMenu;
  4835. unset ($this->arrMenu);
  4836. if ($action == 'add')
  4837. $return .= '<p class="lp_title">' . get_lang("CreateTheExercise") . '&nbsp;:</p>' . "\n";
  4838. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentExercise") . '&nbsp;:</p>' . "\n";
  4839. else
  4840. $return .= '<p class="lp_title">' . get_lang("EditCurrentExecice") . '&nbsp;:</p>' . "\n";
  4841. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4842. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
  4843. }
  4844. $return .= '<form method="POST">' . "\n";
  4845. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4846. $return .= "\t\t" . '<tr>' . "\n";
  4847. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . ' :</label></td>' . "\n";
  4848. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4849. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4850. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4851. $arrHide = array (
  4852. $id
  4853. );
  4854. if (count($arrLP) > 0) {
  4855. for ($i = 0; $i < count($arrLP); $i++) {
  4856. if ($action != 'add') {
  4857. 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)) {
  4858. $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>';
  4859. } else {
  4860. $arrHide[] = $arrLP[$i]['id'];
  4861. }
  4862. } else {
  4863. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4864. $return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '</option>';
  4865. }
  4866. }
  4867. reset($arrLP);
  4868. }
  4869. $return .= "\t\t\t\t" . '</select>';
  4870. $return .= "\t\t\t" . '</td>' . "\n";
  4871. $return .= "\t\t" . '</tr>' . "\n";
  4872. $return .= "\t\t" . '<tr>' . "\n";
  4873. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . ' :</label></td>' . "\n";
  4874. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4875. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4876. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4877. for ($i = 0; $i < count($arrLP); $i++) {
  4878. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4879. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4880. $selected = 'selected="selected" ';
  4881. elseif ($action == 'add') $selected = 'selected="selected" ';
  4882. else
  4883. $selected = '';
  4884. $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>';
  4885. }
  4886. }
  4887. $return .= "\t\t\t\t" . '</select>';
  4888. $return .= "\t\t\t" . '</td>' . "\n";
  4889. $return .= "\t\t" . '</tr>' . "\n";
  4890. if ($action != 'move') {
  4891. $return .= "\t\t" . '<tr>' . "\n";
  4892. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . ' :</label></td>' . "\n";
  4893. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4894. $return .= "\t\t" . '</tr>' . "\n";
  4895. $id_prerequisite = 0;
  4896. if (is_array($arrLP) && count($arrLP) > 0) {
  4897. foreach ($arrLP as $key => $value) {
  4898. if ($value['id'] == $id) {
  4899. $id_prerequisite = $value['prerequisite'];
  4900. break;
  4901. }
  4902. }
  4903. $arrHide = array ();
  4904. for ($i = 0; $i < count($arrLP); $i++) {
  4905. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4906. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4907. $s_selected_position = $arrLP[$i]['id'];
  4908. elseif ($action == 'add') $s_selected_position = 0;
  4909. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  4910. }
  4911. }
  4912. }
  4913. $return .= "\t\t" . '<tr>' . "\n";
  4914. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4915. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4916. foreach ($arrHide as $key => $value) {
  4917. if ($key == $s_selected_position && $action == 'add') {
  4918. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4919. }
  4920. elseif ($key == $id_prerequisite && $action == 'edit') {
  4921. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  4922. } else {
  4923. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  4924. }
  4925. }
  4926. $return .= "</select></td>";
  4927. $return .= "\t\t" . '</tr>' . "\n";
  4928. $return .= "\t\t" . '<tr>' . "\n";
  4929. //Remove temporaly the test description
  4930. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4931. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4932. $return .= "\t\t" . '</tr>' . "\n";
  4933. }
  4934. $return .= "\t\t" . '<tr>' . "\n";
  4935. $return .= "\t\t\t" . '<td> &nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddHotpotatoes') . '</button></td>' . "\n";
  4936. $return .= "\t\t" . '</tr>' . "\n";
  4937. $return .= "\t" . '</table>' . "\n";
  4938. if ($action == 'move') {
  4939. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4940. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4941. }
  4942. if (is_numeric($extra_info)) {
  4943. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4944. }
  4945. elseif (is_array($extra_info)) {
  4946. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4947. }
  4948. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  4949. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4950. $return .= '</form>' . "\n";
  4951. $return .= '</div>' . "\n";
  4952. return $return;
  4953. }
  4954. //fin du hotpot form
  4955. /**
  4956. * Return the form to display the forum edit/add option
  4957. *
  4958. * @param string Action (add/edit)
  4959. * @param integer ID of the lp_item if already exists
  4960. * @param mixed Forum ID or title
  4961. * @return string HTML form
  4962. */
  4963. function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  4964. global $charset;
  4965. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4966. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  4967. if ($id != 0 && is_array($extra_info)) {
  4968. $item_title = stripslashes($extra_info['title']);
  4969. }
  4970. elseif (is_numeric($extra_info)) {
  4971. $sql_forum = "
  4972. SELECT
  4973. forum_title as title, forum_comment as comment
  4974. FROM " . $tbl_forum . "
  4975. WHERE forum_id = " . $extra_info;
  4976. $result = Database::query($sql_forum, __FILE__, __LINE__);
  4977. $row = Database :: fetch_array($result);
  4978. $item_title = $row['title'];
  4979. $item_description = $row['comment'];
  4980. } else {
  4981. $item_title = '';
  4982. $item_description = '';
  4983. }
  4984. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  4985. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  4986. $return = ' <div class="row">
  4987. <div class="form_header">';
  4988. if ($id != 0 && is_array($extra_info))
  4989. $parent = $extra_info['parent_item_id'];
  4990. else
  4991. $parent = 0;
  4992. $sql = "
  4993. SELECT *
  4994. FROM " . $tbl_lp_item . "
  4995. WHERE
  4996. lp_id = " . $this->lp_id;
  4997. $result = Database::query($sql, __FILE__, __LINE__);
  4998. $arrLP = array ();
  4999. while ($row = Database :: fetch_array($result)) {
  5000. $arrLP[] = array (
  5001. 'id' => $row['id'],
  5002. 'item_type' => $row['item_type'],
  5003. 'title' => $row['title'],
  5004. 'path' => $row['path'],
  5005. 'description' => $row['description'],
  5006. 'parent_item_id' => $row['parent_item_id'],
  5007. 'previous_item_id' => $row['previous_item_id'],
  5008. 'next_item_id' => $row['next_item_id'],
  5009. 'display_order' => $row['display_order'],
  5010. 'max_score' => $row['max_score'],
  5011. 'min_score' => $row['min_score'],
  5012. 'mastery_score' => $row['mastery_score'],
  5013. 'prerequisite' => $row['prerequisite']
  5014. );
  5015. }
  5016. $this->tree_array($arrLP);
  5017. $arrLP = $this->arrMenu;
  5018. unset ($this->arrMenu);
  5019. if ($action == 'add')
  5020. $return .= get_lang("CreateTheForum") . '&nbsp;:' . "\n";
  5021. elseif ($action == 'move') $return .= get_lang("MoveTheCurrentForum") . '&nbsp;:' . "\n";
  5022. else
  5023. $return .= get_lang("EditCurrentForum") . '&nbsp;:' . "\n";
  5024. $return .= ' </div>
  5025. </div>';
  5026. $return .= '<div class="sectioncomment">';
  5027. $return .= '<form method="POST">' . "\n";
  5028. $return .= "\t" . '<table class="lp_form">' . "\n";
  5029. if ($action != 'move') {
  5030. $return .= "\t\t" . '<tr>' . "\n";
  5031. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5032. $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";
  5033. $return .= "\t\t" . '</tr>' . "\n";
  5034. }
  5035. $return .= "\t\t" . '<tr>' . "\n";
  5036. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5037. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5038. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5039. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5040. $arrHide = array (
  5041. $id
  5042. );
  5043. $parent_item_id = $_SESSION['parent_item_id'];
  5044. for ($i = 0; $i < count($arrLP); $i++) {
  5045. if ($action != 'add') {
  5046. 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)) {
  5047. $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>';
  5048. } else {
  5049. $arrHide[] = $arrLP[$i]['id'];
  5050. }
  5051. } else {
  5052. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5053. $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>';
  5054. }
  5055. }
  5056. if (is_array($arrLP)) {
  5057. reset($arrLP);
  5058. }
  5059. $return .= "\t\t\t\t" . '</select>';
  5060. $return .= "\t\t\t" . '</td>' . "\n";
  5061. $return .= "\t\t" . '</tr>' . "\n";
  5062. $return .= "\t\t" . '<tr>' . "\n";
  5063. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5064. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5065. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5066. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5067. for ($i = 0; $i < count($arrLP); $i++) {
  5068. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5069. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5070. $selected = 'selected="selected" ';
  5071. elseif ($action == 'add') $selected = 'selected="selected" ';
  5072. else
  5073. $selected = '';
  5074. $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>';
  5075. }
  5076. }
  5077. $return .= "\t\t\t\t" . '</select>';
  5078. $return .= "\t\t\t" . '</td>' . "\n";
  5079. $return .= "\t\t" . '</tr>' . "\n";
  5080. if ($action != 'move') {
  5081. $return .= "\t\t" . '<tr>' . "\n";
  5082. //Remove temporaly the test description
  5083. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5084. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5085. $return .= "\t\t" . '</tr>' . "\n";
  5086. $id_prerequisite = 0;
  5087. if (is_array($arrLP)) {
  5088. foreach ($arrLP as $key => $value) {
  5089. if ($value['id'] == $id) {
  5090. $id_prerequisite = $value['prerequisite'];
  5091. break;
  5092. }
  5093. }
  5094. }
  5095. $arrHide = array ();
  5096. for ($i = 0; $i < count($arrLP); $i++) {
  5097. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5098. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5099. $s_selected_position = $arrLP[$i]['id'];
  5100. elseif ($action == 'add') $s_selected_position = 0;
  5101. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5102. }
  5103. }
  5104. /* //comented the prerequisites, only visible in edit (forum)
  5105. $return .= "\t\t" . '<tr>' . "\n";
  5106. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5107. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5108. foreach($arrHide as $key => $value) {
  5109. if($key==$s_selected_position && $action == 'add') {
  5110. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5111. }elseif($key==$id_prerequisite && $action == 'edit') {
  5112. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5113. } else {
  5114. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5115. }
  5116. }
  5117. $return .= "</select></td>";
  5118. */
  5119. $return .= "\t\t" . '</tr>' . "\n";
  5120. }
  5121. $return .= "\t\t" . '<tr>' . "\n";
  5122. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>' . "\n";
  5123. $return .= "\t\t" . '</tr>' . "\n";
  5124. $return .= "\t" . '</table>' . "\n";
  5125. if ($action == 'move') {
  5126. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5127. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5128. }
  5129. if (is_numeric($extra_info)) {
  5130. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5131. }
  5132. elseif (is_array($extra_info)) {
  5133. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5134. }
  5135. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5136. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5137. $return .= '</form>' . "\n";
  5138. $return .= '</div>' . "\n";
  5139. return $return;
  5140. }
  5141. /**
  5142. * Return HTML form to add/edit forum threads
  5143. * @param string Action (add/edit)
  5144. * @param integer Item ID if already exists in learning path
  5145. * @param mixed Extra information (thread ID if integer)
  5146. * @return string HTML form
  5147. */
  5148. function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5149. global $charset;
  5150. echo '
  5151. <style>
  5152. div.row div.label {
  5153. width:110px;
  5154. }
  5155. div.row div.formw {
  5156. width: 82%;
  5157. }
  5158. </style>';
  5159. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5160. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5161. if ($id != 0 && is_array($extra_info)) {
  5162. $item_title = stripslashes($extra_info['title']);
  5163. }
  5164. elseif (is_numeric($extra_info)) {
  5165. $sql_forum = "
  5166. SELECT
  5167. thread_title as title
  5168. FROM " . $tbl_forum . "
  5169. WHERE thread_id = " . $extra_info;
  5170. $result = Database::query($sql_forum, __FILE__, __LINE__);
  5171. $row = Database :: fetch_array($result);
  5172. $item_title = $row['title'];
  5173. $item_description = '';
  5174. } else {
  5175. $item_title = '';
  5176. $item_description = '';
  5177. }
  5178. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5179. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5180. $return = '<div style="margin:3px 12px;">';
  5181. if ($id != 0 && is_array($extra_info))
  5182. $parent = $extra_info['parent_item_id'];
  5183. else
  5184. $parent = 0;
  5185. $sql = "
  5186. SELECT *
  5187. FROM " . $tbl_lp_item . "
  5188. WHERE
  5189. lp_id = " . $this->lp_id;
  5190. $result = Database::query($sql, __FILE__, __LINE__);
  5191. $arrLP = array ();
  5192. while ($row = Database :: fetch_array($result)) {
  5193. $arrLP[] = array (
  5194. 'id' => $row['id'],
  5195. 'item_type' => $row['item_type'],
  5196. 'title' => $row['title'],
  5197. 'path' => $row['path'],
  5198. 'description' => $row['description'],
  5199. 'parent_item_id' => $row['parent_item_id'],
  5200. 'previous_item_id' => $row['previous_item_id'],
  5201. 'next_item_id' => $row['next_item_id'],
  5202. 'display_order' => $row['display_order'],
  5203. 'max_score' => $row['max_score'],
  5204. 'min_score' => $row['min_score'],
  5205. 'mastery_score' => $row['mastery_score'],
  5206. 'prerequisite' => $row['prerequisite']
  5207. );
  5208. }
  5209. $this->tree_array($arrLP);
  5210. $arrLP = $this->arrMenu;
  5211. unset ($this->arrMenu);
  5212. if ($action == 'add')
  5213. $return .= '<p class="lp_title">' . get_lang("CreateTheForum") . '&nbsp;:</p>' . "\n";
  5214. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentForum") . '&nbsp;:</p>' . "\n";
  5215. else
  5216. $return .= '<p class="lp_title">' . get_lang("EditCurrentForum") . '&nbsp;:</p>' . "\n";
  5217. $return .= '<form method="POST">' . "\n";
  5218. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5219. $return .= "\t\t" . '<tr>' . "\n";
  5220. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . '&nbsp;:</label></td>' . "\n";
  5221. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5222. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  5223. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5224. $arrHide = array (
  5225. $id
  5226. );
  5227. for ($i = 0; $i < count($arrLP); $i++) {
  5228. if ($action != 'add') {
  5229. 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)) {
  5230. $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>';
  5231. } else {
  5232. $arrHide[] = $arrLP[$i]['id'];
  5233. }
  5234. } else {
  5235. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5236. $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>';
  5237. }
  5238. }
  5239. if ($arrLP != null) {
  5240. reset($arrLP);
  5241. }
  5242. $return .= "\t\t\t\t" . '</select>';
  5243. $return .= "\t\t\t" . '</td>' . "\n";
  5244. $return .= "\t\t" . '</tr>' . "\n";
  5245. $return .= "\t\t" . '<tr>' . "\n";
  5246. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . '&nbsp;:</label></td>' . "\n";
  5247. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5248. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5249. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5250. for ($i = 0; $i < count($arrLP); $i++) {
  5251. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5252. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5253. $selected = 'selected="selected" ';
  5254. elseif ($action == 'add') $selected = 'selected="selected" ';
  5255. else
  5256. $selected = '';
  5257. $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>';
  5258. }
  5259. }
  5260. $return .= "\t\t\t\t" . '</select>';
  5261. $return .= "\t\t\t" . '</td>' . "\n";
  5262. $return .= "\t\t" . '</tr>' . "\n";
  5263. if ($action != 'move') {
  5264. $return .= "\t\t" . '<tr>' . "\n";
  5265. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . '&nbsp;:</label></td>' . "\n";
  5266. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5267. $return .= "\t\t" . '</tr>' . "\n";
  5268. $return .= "\t\t" . '<tr>' . "\n";
  5269. //Remove temporaly the test description
  5270. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5271. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5272. $return .= "\t\t" . '</tr>' . "\n";
  5273. $id_prerequisite = 0;
  5274. if ($arrLP != null) {
  5275. foreach ($arrLP as $key => $value) {
  5276. if ($value['id'] == $id) {
  5277. $id_prerequisite = $value['prerequisite'];
  5278. break;
  5279. }
  5280. }
  5281. }
  5282. $arrHide = array ();
  5283. for ($i = 0; $i < count($arrLP); $i++) {
  5284. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5285. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5286. $s_selected_position = $arrLP[$i]['id'];
  5287. elseif ($action == 'add') $s_selected_position = 0;
  5288. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5289. }
  5290. }
  5291. $return .= "\t\t" . '<tr>' . "\n";
  5292. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang("Prerequisites") . '&nbsp;:</label></td>' . "\n";
  5293. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang("NoPrerequisites") . '</option>';
  5294. foreach ($arrHide as $key => $value) {
  5295. if ($key == $s_selected_position && $action == 'add') {
  5296. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5297. }
  5298. elseif ($key == $id_prerequisite && $action == 'edit') {
  5299. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5300. } else {
  5301. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5302. }
  5303. }
  5304. $return .= "</select></td>";
  5305. $return .= "\t\t" . '</tr>' . "\n";
  5306. }
  5307. $return .= "\t\t" . '<tr>' . "\n";
  5308. $return .= "\t\t\t" . '<td colspan="2">
  5309. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5310. $return .= "\t\t" . '</tr>' . "\n";
  5311. $return .= "\t" . '</table>' . "\n";
  5312. if ($action == 'move') {
  5313. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5314. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5315. }
  5316. if (is_numeric($extra_info)) {
  5317. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5318. }
  5319. elseif (is_array($extra_info)) {
  5320. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5321. }
  5322. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5323. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5324. $return .= '</form>' . "\n";
  5325. $return .= '</div>' . "\n";
  5326. return $return;
  5327. }
  5328. /**
  5329. * Return the HTML form to display an item (generally a section/module item)
  5330. *
  5331. * @param string Item type (module/dokeos_module)
  5332. * @param string Title (optional, only when creating)
  5333. * @param string Action ('add'/'edit')
  5334. * @param integer lp_item ID
  5335. * @param mixed Extra info
  5336. * @return string HTML form
  5337. */
  5338. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5339. global $_course;
  5340. global $charset;
  5341. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5342. if ($id != 0 && is_array($extra_info)) {
  5343. $item_title = $extra_info['title'];
  5344. $item_description = $extra_info['description'];
  5345. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5346. } else {
  5347. $item_title = '';
  5348. $item_description = '';
  5349. }
  5350. $return = ' <div class="row">
  5351. <div class="form_header">';
  5352. if ($id != 0 && is_array($extra_info))
  5353. $parent = $extra_info['parent_item_id'];
  5354. else
  5355. $parent = 0;
  5356. $sql = "
  5357. SELECT *
  5358. FROM " . $tbl_lp_item . "
  5359. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5360. if ($item_type == 'module')
  5361. $sql .= " AND parent_item_id = 0";
  5362. $result = Database::query($sql, __FILE__, __LINE__);
  5363. $arrLP = array ();
  5364. while ($row = Database :: fetch_array($result)) {
  5365. $arrLP[] = array (
  5366. 'id' => $row['id'],
  5367. 'item_type' => $row['item_type'],
  5368. 'title' => $row['title'],
  5369. 'path' => $row['path'],
  5370. 'description' => $row['description'],
  5371. 'parent_item_id' => $row['parent_item_id'],
  5372. 'previous_item_id' => $row['previous_item_id'],
  5373. 'next_item_id' => $row['next_item_id'],
  5374. 'max_score' => $row['max_score'],
  5375. 'min_score' => $row['min_score'],
  5376. 'mastery_score' => $row['mastery_score'],
  5377. 'prerequisite' => $row['prerequisite'],
  5378. 'display_order' => $row['display_order']
  5379. );
  5380. }
  5381. $this->tree_array($arrLP);
  5382. $arrLP = $this->arrMenu;
  5383. unset ($this->arrMenu);
  5384. $return .= $title . "\n";
  5385. $return .= ' </div>
  5386. </div>';
  5387. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5388. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"]);
  5389. //$defaults["title"] = api_convert_encoding($item_title, $charset, $this->encoding);
  5390. $defaults["title"] = api_html_entity_decode(api_convert_encoding($item_title, $charset, $this->encoding), ENT_QUOTES, $charset);
  5391. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5392. $form->addElement('html', $return);
  5393. //$arrHide = array($id);
  5394. $arrHide[0]['value'] = Security :: remove_XSS(api_convert_encoding($this->name, api_get_system_encoding(), $_SESSION['oLP']->encoding));
  5395. $arrHide[0]['padding'] = 3;
  5396. $charset = api_get_system_encoding();
  5397. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5398. for ($i = 0; $i < count($arrLP); $i++) {
  5399. if ($action != 'add') {
  5400. 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)) {
  5401. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5402. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5403. if ($parent == $arrLP[$i]['id']) {
  5404. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5405. }
  5406. }
  5407. } else {
  5408. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5409. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5410. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5411. if ($parent == $arrLP[$i]['id']) {
  5412. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5413. }
  5414. }
  5415. }
  5416. }
  5417. if ($action != 'move') {
  5418. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5419. $form->applyFilter('title', 'html_filter');
  5420. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5421. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5422. } else {
  5423. $form->addElement('hidden', 'title');
  5424. }
  5425. $parent_select = & $form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
  5426. foreach ($arrHide as $key => $value) {
  5427. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5428. }
  5429. $parent_select->setSelected($s_selected_parent);
  5430. }
  5431. if (is_array($arrLP)) {
  5432. reset($arrLP);
  5433. }
  5434. $arrHide = array ();
  5435. //POSITION
  5436. for ($i = 0; $i < count($arrLP); $i++) {
  5437. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5438. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5439. $s_selected_position = $arrLP[$i]['id'];
  5440. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5441. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5442. }
  5443. }
  5444. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5445. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5446. foreach ($arrHide as $key => $value) {
  5447. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5448. }
  5449. if (!empty ($s_selected_position)) {
  5450. $position->setSelected($s_selected_position);
  5451. }
  5452. if (is_array($arrLP)) {
  5453. reset($arrLP);
  5454. }
  5455. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5456. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5457. $form->addElement('hidden', 'parent', '0');
  5458. }
  5459. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5460. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5461. if ($item_type == 'sco') {
  5462. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5463. }
  5464. $renderer = $form->defaultRenderer();
  5465. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5466. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5467. $defaults["content_lp"] = file_get_contents($item_path);
  5468. }
  5469. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5470. $form->addElement('hidden', 'post_time', time());
  5471. $form->setDefaults($defaults);
  5472. return $form->return_form();
  5473. }
  5474. /**
  5475. * Returns the form to update or create a document
  5476. *
  5477. * @param string Action (add/edit)
  5478. * @param integer ID of the lp_item (if already exists)
  5479. * @param mixed Integer if document ID, string if info ('new')
  5480. * @return string HTML form
  5481. */
  5482. function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5483. global $charset;
  5484. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5485. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5486. $path_parts = pathinfo($extra_info['dir']);
  5487. $no_display_edit_textarea = false;
  5488. //If action==edit document
  5489. //We don't display the document form if it's not an editable document (html or txt file)
  5490. if ($action == "edit") {
  5491. if (is_array($extra_info)) {
  5492. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5493. $no_display_edit_textarea = true;
  5494. }
  5495. }
  5496. }
  5497. $no_display_add = false;
  5498. //If action==add an existing document
  5499. //We don't display the document form if it's not an editable document (html or txt file)
  5500. if ($action == "add") {
  5501. if (is_numeric($extra_info)) {
  5502. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5503. $result = Database::query($sql_doc, __FILE__, __LINE__);
  5504. $path_file = Database :: result($result, 0, 0);
  5505. $path_parts = pathinfo($path_file);
  5506. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5507. $no_display_add = true;
  5508. }
  5509. }
  5510. }
  5511. if ($id != 0 && is_array($extra_info)) {
  5512. $item_title = stripslashes($extra_info['title']);
  5513. $item_description = stripslashes($extra_info['description']);
  5514. $item_terms = stripslashes($extra_info['terms']);
  5515. if (empty ($item_title)) {
  5516. $path_parts = pathinfo($extra_info['path']);
  5517. $item_title = stripslashes($path_parts['filename']);
  5518. }
  5519. }
  5520. elseif (is_numeric($extra_info)) {
  5521. $sql_doc = "SELECT path, title
  5522. FROM " . $tbl_doc . "
  5523. WHERE id = " . Database :: escape_string($extra_info);
  5524. $result = Database::query($sql_doc, __FILE__, __LINE__);
  5525. $row = Database :: fetch_array($result);
  5526. $explode = explode('.', $row['title']);
  5527. if (count($explode) > 1) {
  5528. for ($i = 0; $i < count($explode) - 1; $i++)
  5529. $item_title .= $explode[$i];
  5530. } else {
  5531. $item_title = $row['title'];
  5532. }
  5533. $item_title = str_replace('_', ' ', $item_title);
  5534. if (empty ($item_title)) {
  5535. $path_parts = pathinfo($row['path']);
  5536. $item_title = stripslashes($path_parts['filename']);
  5537. }
  5538. } else {
  5539. $item_title = '';
  5540. $item_description = '';
  5541. }
  5542. $return = ' <div class="row">
  5543. <div class="form_header">';
  5544. if ($id != 0 && is_array($extra_info))
  5545. $parent = $extra_info['parent_item_id'];
  5546. else
  5547. $parent = 0;
  5548. $sql = "
  5549. SELECT *
  5550. FROM " . $tbl_lp_item . "
  5551. WHERE
  5552. lp_id = " . $this->lp_id;
  5553. $result = Database::query($sql, __FILE__, __LINE__);
  5554. $arrLP = array ();
  5555. while ($row = Database :: fetch_array($result)) {
  5556. $arrLP[] = array (
  5557. 'id' => $row['id'],
  5558. 'item_type' => $row['item_type'],
  5559. 'title' => $row['title'],
  5560. 'path' => $row['path'],
  5561. 'description' => $row['description'],
  5562. 'parent_item_id' => $row['parent_item_id'],
  5563. 'previous_item_id' => $row['previous_item_id'],
  5564. 'next_item_id' => $row['next_item_id'],
  5565. 'display_order' => $row['display_order'],
  5566. 'max_score' => $row['max_score'],
  5567. 'min_score' => $row['min_score'],
  5568. 'mastery_score' => $row['mastery_score'],
  5569. 'prerequisite' => $row['prerequisite']
  5570. );
  5571. }
  5572. $this->tree_array($arrLP);
  5573. $arrLP = $this->arrMenu;
  5574. unset ($this->arrMenu);
  5575. if ($action == 'add') {
  5576. $return .= get_lang("CreateTheDocument") . "\n";
  5577. }
  5578. elseif ($action == 'move') {
  5579. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5580. } else {
  5581. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5582. }
  5583. $return .= ' </div>
  5584. </div>';
  5585. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5586. $return .= Display :: return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
  5587. }
  5588. require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
  5589. $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
  5590. $defaults["title"] = Security :: remove_XSS(api_convert_encoding($item_title, api_get_system_encoding() ,$this->encoding));
  5591. if (empty ($item_title)) {
  5592. $defaults["title"] = Security :: remove_XSS($item_title);
  5593. }
  5594. $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
  5595. $form->addElement('html', $return);
  5596. if ($action != 'move') {
  5597. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5598. $form->applyFilter('title', 'html_filter');
  5599. }
  5600. //$arrHide = array($id);
  5601. $arrHide[0]['value'] = $this->name;
  5602. $arrHide[0]['padding'] = 3;
  5603. for ($i = 0; $i < count($arrLP); $i++) {
  5604. if ($action != 'add') {
  5605. 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)) {
  5606. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5607. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5608. if ($parent == $arrLP[$i]['id']) {
  5609. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5610. }
  5611. }
  5612. } else {
  5613. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5614. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5615. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5616. if ($parent == $arrLP[$i]['id']) {
  5617. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5618. }
  5619. }
  5620. }
  5621. }
  5622. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
  5623. $my_count=0;
  5624. foreach ($arrHide as $key => $value) {
  5625. if ($my_count!=0) {
  5626. // the LP name is also the first section and is not in the same charset like the other sections
  5627. $value['value'] = Security :: remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
  5628. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5629. } else {
  5630. $value['value'] = Security :: remove_XSS($value['value']);
  5631. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5632. }
  5633. $my_count++;
  5634. }
  5635. if (!empty ($id)) {
  5636. $parent_select->setSelected($parent);
  5637. } else {
  5638. $parent_item_id = $_SESSION['parent_item_id'];
  5639. $parent_select->setSelected($parent_item_id);
  5640. }
  5641. if (is_array($arrLP)) {
  5642. reset($arrLP);
  5643. }
  5644. $arrHide = array ();
  5645. //POSITION
  5646. for ($i = 0; $i < count($arrLP); $i++) {
  5647. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5648. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5649. $s_selected_position = $arrLP[$i]['id'];
  5650. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5651. $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
  5652. }
  5653. }
  5654. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5655. $position->addOption(get_lang("FirstPosition"), 0);
  5656. foreach ($arrHide as $key => $value) {
  5657. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5658. }
  5659. $position->setSelected($s_selected_position);
  5660. if (is_array($arrLP)) {
  5661. reset($arrLP);
  5662. }
  5663. if ($action != 'move') {
  5664. $id_prerequisite = 0;
  5665. if (is_array($arrLP)) {
  5666. foreach ($arrLP as $key => $value) {
  5667. if ($value['id'] == $id) {
  5668. $id_prerequisite = $value['prerequisite'];
  5669. break;
  5670. }
  5671. }
  5672. }
  5673. //comented the prerequisites, only visible in edit (new document)
  5674. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5675. //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5676. // form element for uploading an mp3 file
  5677. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5678. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5679. /* Code deprecated - moved to lp level (not lp-item)
  5680. if ( api_get_setting('search_enabled') === 'true' )
  5681. {
  5682. //add terms field
  5683. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5684. $terms->setValue($item_terms);
  5685. }
  5686. */
  5687. $arrHide = array ();
  5688. for ($i = 0; $i < count($arrLP); $i++) {
  5689. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5690. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5691. $s_selected_position = $arrLP[$i]['id'];
  5692. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5693. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5694. }
  5695. }
  5696. /* foreach($arrHide as $key => $value){
  5697. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5698. if($key==$s_selected_position && $action == 'add'){
  5699. $select_prerequisites -> setSelected(0);
  5700. }
  5701. elseif($key==$id_prerequisite && $action == 'edit'){
  5702. $select_prerequisites -> setSelected($id_prerequisite);
  5703. }
  5704. }
  5705. */
  5706. if (!$no_display_add) {
  5707. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5708. if (isset ($_POST['content']))
  5709. $content = stripslashes($_POST['content']);
  5710. elseif (is_array($extra_info)) {
  5711. //If it's an html document or a text file
  5712. if (!$no_display_edit_textarea) {
  5713. $content = $this->display_document($extra_info['path'], false, false);
  5714. }
  5715. }
  5716. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5717. else
  5718. $content = '';
  5719. if (!$no_display_edit_textarea) {
  5720. // We need to claculate here some specific settings for the online editor.
  5721. // The calculated settings work for documents in the Documents tool
  5722. // (on the root or in subfolders).
  5723. // For documents in native scorm packages it is unclear whether the
  5724. // online editor should be activated or not.
  5725. $relative_path = $extra_info['dir'];
  5726. if ($relative_path == 'n/') {
  5727. // A new document, it is in the root of the repository.
  5728. $relative_path = '';
  5729. $relative_prefix = '';
  5730. } else {
  5731. // The document already exists. Whe have to determine its relative path towards the repository root.
  5732. $relative_path = explode('/', $relative_path);
  5733. $cnt = count($relative_path) - 2;
  5734. if ($cnt < 0) {
  5735. $cnt = 0;
  5736. }
  5737. $relative_prefix = str_repeat('../', $cnt);
  5738. $relative_path = array_slice($relative_path, 1, $cnt);
  5739. $relative_path = implode('/', $relative_path);
  5740. if (strlen($relative_path) > 0) {
  5741. $relative_path = $relative_path . '/';
  5742. }
  5743. }
  5744. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5745. 'CreateDocumentDir' => $relative_prefix,
  5746. 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/',
  5747. 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path
  5748. );
  5749. if ($_GET['action'] == 'add_item') {
  5750. $class = 'add';
  5751. $text = get_lang('LPCreateDocument');
  5752. } else
  5753. if ($_GET['action'] == 'edit_item') {
  5754. $class = 'save';
  5755. $text = get_lang('SaveDocument');
  5756. }
  5757. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5758. $renderer = $form->defaultRenderer();
  5759. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5760. $form->addElement('html', '<div style="margin:3px 12px">');
  5761. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5762. $form->addElement('html', '</div>');
  5763. $defaults["content_lp"] = $content;
  5764. }
  5765. }
  5766. elseif (is_numeric($extra_info)) {
  5767. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5768. $return = $this->display_document($extra_info, true, true, true);
  5769. $form->addElement('html', $return);
  5770. }
  5771. }
  5772. }
  5773. if ($action == 'move') {
  5774. $form->addElement('hidden', 'title', $item_title);
  5775. $form->addElement('hidden', 'description', $item_description);
  5776. }
  5777. if (is_numeric($extra_info)) {
  5778. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5779. $form->addElement('hidden', 'path', $extra_info);
  5780. }
  5781. elseif (is_array($extra_info)) {
  5782. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5783. $form->addElement('hidden', 'path', $extra_info['path']);
  5784. }
  5785. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5786. $form->addElement('hidden', 'post_time', time());
  5787. $form->setDefaults($defaults);
  5788. return $form->return_form();
  5789. }
  5790. /**
  5791. * Return HTML form to add/edit a link item
  5792. *
  5793. * @param string Action (add/edit)
  5794. * @param integer Item ID if exists
  5795. * @param mixed Extra info
  5796. * @return string HTML form
  5797. */
  5798. function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5799. global $charset;
  5800. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5801. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5802. if ($id != 0 && is_array($extra_info)) {
  5803. $item_title = stripslashes($extra_info['title']);
  5804. $item_description = stripslashes($extra_info['description']);
  5805. $item_url = stripslashes($extra_info['url']);
  5806. }
  5807. elseif (is_numeric($extra_info)) {
  5808. $sql_link = "
  5809. SELECT
  5810. title,
  5811. description,
  5812. url
  5813. FROM " . $tbl_link . "
  5814. WHERE id = " . $extra_info;
  5815. $result = Database::query($sql_link, __FILE__, __LINE__);
  5816. $row = Database :: fetch_array($result);
  5817. $item_title = $row['title'];
  5818. $item_description = $row['description'];
  5819. $item_url = $row['url'];
  5820. } else {
  5821. $item_title = '';
  5822. $item_description = '';
  5823. $item_url = '';
  5824. }
  5825. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  5826. $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
  5827. $return = ' <div class="row">
  5828. <div class="form_header">';
  5829. if ($id != 0 && is_array($extra_info))
  5830. $parent = $extra_info['parent_item_id'];
  5831. else
  5832. $parent = 0;
  5833. $sql = "
  5834. SELECT *
  5835. FROM " . $tbl_lp_item . "
  5836. WHERE
  5837. lp_id = " . $this->lp_id;
  5838. $result = Database::query($sql, __FILE__, __LINE__);
  5839. $arrLP = array ();
  5840. while ($row = Database :: fetch_array($result)) {
  5841. $arrLP[] = array (
  5842. 'id' => $row['id'],
  5843. 'item_type' => $row['item_type'],
  5844. 'title' => $row['title'],
  5845. 'path' => $row['path'],
  5846. 'description' => $row['description'],
  5847. 'parent_item_id' => $row['parent_item_id'],
  5848. 'previous_item_id' => $row['previous_item_id'],
  5849. 'next_item_id' => $row['next_item_id'],
  5850. 'display_order' => $row['display_order'],
  5851. 'max_score' => $row['max_score'],
  5852. 'min_score' => $row['min_score'],
  5853. 'mastery_score' => $row['mastery_score'],
  5854. 'prerequisite' => $row['prerequisite']
  5855. );
  5856. }
  5857. $this->tree_array($arrLP);
  5858. $arrLP = $this->arrMenu;
  5859. unset ($this->arrMenu);
  5860. if ($action == 'add')
  5861. $return .= get_lang("CreateTheLink") . '&nbsp;:' . "\n";
  5862. elseif ($action == 'move') $return .= get_lang("MoveCurrentLink") . '&nbsp;:' . "\n";
  5863. else
  5864. $return .= get_lang("EditCurrentLink") . '&nbsp;:' . "\n";
  5865. $return .= ' </div>
  5866. </div>';
  5867. $return .= '<div class="sectioncomment">';
  5868. $return .= '<form method="POST">' . "\n";
  5869. $return .= "\t" . '<table>' . "\n";
  5870. if ($action != 'move') {
  5871. $return .= "\t\t" . '<tr>' . "\n";
  5872. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5873. $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";
  5874. $return .= "\t\t" . '</tr>' . "\n";
  5875. }
  5876. $return .= "\t\t" . '<tr>' . "\n";
  5877. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5878. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5879. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5880. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5881. $arrHide = array (
  5882. $id
  5883. );
  5884. $parent_item_id = $_SESSION['parent_item_id'];
  5885. for ($i = 0; $i < count($arrLP); $i++) {
  5886. if ($action != 'add') {
  5887. 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)) {
  5888. $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>';
  5889. } else {
  5890. $arrHide[] = $arrLP[$i]['id'];
  5891. }
  5892. } else {
  5893. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5894. $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>';
  5895. }
  5896. }
  5897. if (is_array($arrLP)) {
  5898. reset($arrLP);
  5899. }
  5900. $return .= "\t\t\t\t" . '</select>';
  5901. $return .= "\t\t\t" . '</td>' . "\n";
  5902. $return .= "\t\t" . '</tr>' . "\n";
  5903. $return .= "\t\t" . '<tr>' . "\n";
  5904. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5905. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5906. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5907. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  5908. for ($i = 0; $i < count($arrLP); $i++) {
  5909. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5910. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5911. $selected = 'selected="selected" ';
  5912. elseif ($action == 'add') $selected = 'selected="selected" ';
  5913. else
  5914. $selected = '';
  5915. $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>';
  5916. }
  5917. }
  5918. $return .= "\t\t\t\t" . '</select>';
  5919. $return .= "\t\t\t" . '</td>' . "\n";
  5920. $return .= "\t\t" . '</tr>' . "\n";
  5921. if ($action != 'move') {
  5922. //Description filed is commentd for link
  5923. /*$return .= "\t\t" . '<tr>' . "\n";
  5924. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
  5925. $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";
  5926. $return .= "\t\t" . '</tr>' . "\n";*/
  5927. $return .= "\t\t" . '<tr>' . "\n";
  5928. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  5929. $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";
  5930. $return .= "\t\t" . '</tr>' . "\n";
  5931. $id_prerequisite = 0;
  5932. if (is_array($arrLP)) {
  5933. foreach ($arrLP as $key => $value) {
  5934. if ($value['id'] == $id) {
  5935. $id_prerequisite = $value['prerequisite'];
  5936. break;
  5937. }
  5938. }
  5939. }
  5940. $arrHide = array ();
  5941. for ($i = 0; $i < count($arrLP); $i++) {
  5942. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5943. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5944. $s_selected_position = $arrLP[$i]['id'];
  5945. elseif ($action == 'add') $s_selected_position = 0;
  5946. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  5947. }
  5948. }
  5949. /*//comented the prerequisites, only visible in edit (link)
  5950. $return .= "\t\t" . '<tr>' . "\n";
  5951. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5952. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5953. foreach($arrHide as $key => $value)
  5954. {
  5955. if($key==$s_selected_position && $action == 'add')
  5956. {
  5957. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5958. }
  5959. elseif($key==$id_prerequisite && $action == 'edit'){
  5960. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5961. }
  5962. else{
  5963. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5964. }
  5965. }
  5966. $return .= "</select></td>";
  5967. */
  5968. $return .= "\t\t" . '</tr>' . "\n";
  5969. }
  5970. $return .= "\t\t" . '<tr>' . "\n";
  5971. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang("AddLinkToCourse") . '</button></td>' . "\n";
  5972. $return .= "\t\t" . '</tr>' . "\n";
  5973. $return .= "\t" . '</table>' . "\n";
  5974. if ($action == 'move') {
  5975. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5976. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5977. }
  5978. if (is_numeric($extra_info)) {
  5979. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5980. }
  5981. elseif (is_array($extra_info)) {
  5982. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5983. }
  5984. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  5985. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5986. $return .= '</form>' . "\n";
  5987. $return .= '</div>' . "\n";
  5988. return $return;
  5989. }
  5990. /**
  5991. * Return HTML form to add/edit a student publication (work)
  5992. *
  5993. * @param string Action (add/edit)
  5994. * @param integer Item ID if already exists
  5995. * @param mixed Extra info (work ID if integer)
  5996. * @return string HTML form
  5997. */
  5998. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  5999. global $charset;
  6000. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6001. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6002. if ($id != 0 && is_array($extra_info)) {
  6003. $item_title = stripslashes($extra_info['title']);
  6004. $item_description = stripslashes($extra_info['description']);
  6005. }
  6006. elseif (is_numeric($extra_info)) {
  6007. $sql_publication = "
  6008. SELECT
  6009. title,
  6010. description
  6011. FROM " . $tbl_publication . "
  6012. WHERE id = " . $extra_info;
  6013. $result = Database::query($sql_publication, __FILE__, __LINE__);
  6014. $row = Database :: fetch_array($result);
  6015. $item_title = $row['title'];
  6016. } else {
  6017. $item_title = get_lang('Student_publication');
  6018. }
  6019. $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
  6020. $return = ' <div class="row">
  6021. <div class="form_header">';
  6022. if ($id != 0 && is_array($extra_info))
  6023. $parent = $extra_info['parent_item_id'];
  6024. else
  6025. $parent = 0;
  6026. $sql = "
  6027. SELECT *
  6028. FROM " . $tbl_lp_item . "
  6029. WHERE
  6030. lp_id = " . $this->lp_id;
  6031. $result = Database::query($sql, __FILE__, __LINE__);
  6032. $arrLP = array ();
  6033. while ($row = Database :: fetch_array($result)) {
  6034. $arrLP[] = array (
  6035. 'id' => $row['id'],
  6036. 'item_type' => $row['item_type'],
  6037. 'title' => $row['title'],
  6038. 'path' => $row['path'],
  6039. 'description' => $row['description'],
  6040. 'parent_item_id' => $row['parent_item_id'],
  6041. 'previous_item_id' => $row['previous_item_id'],
  6042. 'next_item_id' => $row['next_item_id'],
  6043. 'display_order' => $row['display_order'],
  6044. 'max_score' => $row['max_score'],
  6045. 'min_score' => $row['min_score'],
  6046. 'mastery_score' => $row['mastery_score'],
  6047. 'prerequisite' => $row['prerequisite']
  6048. );
  6049. }
  6050. $this->tree_array($arrLP);
  6051. $arrLP = $this->arrMenu;
  6052. unset ($this->arrMenu);
  6053. if ($action == 'add')
  6054. $return .= get_lang("Student_publication") . '&nbsp;:' . "\n";
  6055. elseif ($action == 'move') $return .= get_lang("MoveCurrentStudentPublication") . '&nbsp;:' . "\n";
  6056. else
  6057. $return .= get_lang("EditCurrentStudentPublication") . '&nbsp;:' . "\n";
  6058. $return .= ' </div>
  6059. </div>';
  6060. $return .= '<div class="sectioncomment">';
  6061. $return .= '<form method="POST">' . "\n";
  6062. $return .= "\t" . '<table class="lp_form">' . "\n";
  6063. if ($action != 'move') {
  6064. $return .= "\t\t" . '<tr>' . "\n";
  6065. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6066. $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";
  6067. $return .= "\t\t" . '</tr>' . "\n";
  6068. }
  6069. $return .= "\t\t" . '<tr>' . "\n";
  6070. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6071. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6072. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6073. $parent_item_id = $_SESSION['parent_item_id'];
  6074. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6075. $arrHide = array (
  6076. $id
  6077. );
  6078. for ($i = 0; $i < count($arrLP); $i++) {
  6079. if ($action != 'add') {
  6080. 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)) {
  6081. $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>';
  6082. } else {
  6083. $arrHide[] = $arrLP[$i]['id'];
  6084. }
  6085. } else {
  6086. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6087. $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>';
  6088. }
  6089. }
  6090. if (is_array($arrLP)) {
  6091. reset($arrLP);
  6092. }
  6093. $return .= "\t\t\t\t" . '</select>';
  6094. $return .= "\t\t\t" . '</td>' . "\n";
  6095. $return .= "\t\t" . '</tr>' . "\n";
  6096. $return .= "\t\t" . '<tr>' . "\n";
  6097. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6098. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6099. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6100. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
  6101. for ($i = 0; $i < count($arrLP); $i++) {
  6102. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6103. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6104. $selected = 'selected="selected" ';
  6105. elseif ($action == 'add') $selected = 'selected="selected" ';
  6106. else
  6107. $selected = '';
  6108. $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>';
  6109. }
  6110. }
  6111. $return .= "\t\t\t\t" . '</select>';
  6112. $return .= "\t\t\t" . '</td>' . "\n";
  6113. $return .= "\t\t" . '</tr>' . "\n";
  6114. if ($action != 'move') {
  6115. $id_prerequisite = 0;
  6116. if (is_array($arrLP)) {
  6117. foreach ($arrLP as $key => $value) {
  6118. if ($value['id'] == $id) {
  6119. $id_prerequisite = $value['prerequisite'];
  6120. break;
  6121. }
  6122. }
  6123. }
  6124. $arrHide = array ();
  6125. for ($i = 0; $i < count($arrLP); $i++) {
  6126. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6127. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6128. $s_selected_position = $arrLP[$i]['id'];
  6129. elseif ($action == 'add') $s_selected_position = 0;
  6130. $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
  6131. }
  6132. }
  6133. //comented the prerequisites, only visible in edit (work)
  6134. /*
  6135. $return .= "\t\t" . '<tr>' . "\n";
  6136. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6137. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  6138. foreach($arrHide as $key => $value){
  6139. if($key==$s_selected_position && $action == 'add'){
  6140. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6141. }
  6142. elseif($key==$id_prerequisite && $action == 'edit'){
  6143. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6144. }
  6145. else{
  6146. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6147. }
  6148. }
  6149. $return .= "</select></td>";
  6150. */
  6151. $return .= "\t\t" . '</tr>' . "\n";
  6152. }
  6153. $return .= "\t\t" . '<tr>' . "\n";
  6154. $return .= "\t\t\t" . '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang("AddAssignmentToCourse") . '</button></td>' . "\n";
  6155. $return .= "\t\t" . '</tr>' . "\n";
  6156. $return .= "\t" . '</table>' . "\n";
  6157. if ($action == 'move') {
  6158. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6159. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6160. }
  6161. if (is_numeric($extra_info)) {
  6162. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6163. }
  6164. elseif (is_array($extra_info)) {
  6165. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6166. }
  6167. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
  6168. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6169. $return .= '</form>' . "\n";
  6170. $return .= '</div>' . "\n";
  6171. return $return;
  6172. }
  6173. /**
  6174. * Displays the menu for manipulating a step
  6175. *
  6176. * @return unknown
  6177. */
  6178. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6179. global $charset, $_course;
  6180. $return = '<div class="actions">';
  6181. switch ($item_type) {
  6182. case 'dokeos_chapter' :
  6183. case 'chapter' :
  6184. //comented the message cause should not show it
  6185. //$lang = get_lang('TitleManipulateChapter');
  6186. break;
  6187. case 'dokeos_module' :
  6188. case 'module' :
  6189. //comented the message cause should not show it
  6190. //$lang = get_lang('TitleManipulateModule');
  6191. break;
  6192. case TOOL_DOCUMENT :
  6193. //comented the message cause should not show it
  6194. //$lang = get_lang('TitleManipulateDocument');
  6195. break;
  6196. case TOOL_LINK :
  6197. case 'link' :
  6198. //comented the message cause should not show it
  6199. //$lang = get_lang('TitleManipulateLink');
  6200. break;
  6201. case TOOL_QUIZ :
  6202. //comented the message cause should not show it
  6203. //$lang = get_lang('TitleManipulateQuiz');
  6204. break;
  6205. case TOOL_STUDENTPUBLICATION :
  6206. //comented the message cause should not show it
  6207. //$lang = get_lang('TitleManipulateStudentPublication');
  6208. break;
  6209. }
  6210. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6211. $sql = "
  6212. SELECT
  6213. *
  6214. FROM " . $tbl_lp_item . " as lp
  6215. WHERE
  6216. lp.id = " . $item_id;
  6217. $result = Database::query($sql, __FILE__, __LINE__);
  6218. $row = mysql_fetch_assoc($result);
  6219. $s_title = $row['title'];
  6220. $s_title = api_convert_encoding($s_title, $charset, $this->encoding);
  6221. // we display an audio player if needed
  6222. if (!empty ($row['audio'])) {
  6223. $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>';
  6224. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6225. $return .= '<script type="text/javascript">
  6226. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6227. s1.addParam("allowscriptaccess","always");
  6228. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6229. s1.write("container");
  6230. </script>';
  6231. }
  6232. //commented ":" for message in step
  6233. //$return .= $lang.': ';
  6234. $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>';
  6235. $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>';
  6236. // commented for now as prerequisites cannot be added to chapters
  6237. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6238. $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>';
  6239. }
  6240. $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>';
  6241. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  6242. //$return.="</td><td valign='top'>";
  6243. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  6244. ob_start();
  6245. $audio_recorder_studentview = 'false';
  6246. $audio_recorder_item_id = $item_id;
  6247. if (api_get_setting('service_visio', 'active') == 'true') {
  6248. include ('audiorecorder.inc.php');
  6249. }
  6250. $return .= ob_get_contents();
  6251. ob_end_clean();
  6252. // end of audiorecorder include
  6253. $return .= '</div>';
  6254. return $return;
  6255. }
  6256. /**
  6257. * Creates the javascript needed for filling up the checkboxes without page reload
  6258. *
  6259. * @return string
  6260. */
  6261. function create_js() {
  6262. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6263. $return .= 'function load_cbo(id){' . "\n";
  6264. $return .= "var cbo = document.getElementById('idPosition');\n";
  6265. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6266. $return .= 'cbo.options[i] = null;' . "\n";
  6267. $return .= 'var k=0;' . "\n";
  6268. $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
  6269. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
  6270. $return .= 'k=i;';
  6271. $return .= '}' . "\n\n";
  6272. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6273. $return .= '}';
  6274. $return .= 'var child_name = new Array();' . "\n";
  6275. $return .= 'var child_value = new Array();' . "\n\n";
  6276. $return .= 'child_name[0] = new Array();' . "\n";
  6277. $return .= 'child_value[0] = new Array();' . "\n\n";
  6278. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6279. $sql_zero = "
  6280. SELECT *
  6281. FROM " . $tbl_lp_item . "
  6282. WHERE
  6283. lp_id = " . $this->lp_id . " AND
  6284. parent_item_id = 0
  6285. ORDER BY display_order ASC";
  6286. $res_zero = Database::query($sql_zero, __FILE__, __LINE__);
  6287. global $charset;
  6288. $i = 0;
  6289. while ($row_zero = Database :: fetch_array($res_zero)) {
  6290. $return .= 'child_name[0][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_zero['title'], $charset, $this->encoding) . '\"";' . "\n";
  6291. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6292. }
  6293. $return .= "\n";
  6294. $sql = "
  6295. SELECT *
  6296. FROM " . $tbl_lp_item . "
  6297. WHERE
  6298. lp_id = " . $this->lp_id;
  6299. $res = Database::query($sql, __FILE__, __LINE__);
  6300. while ($row = Database :: fetch_array($res)) {
  6301. $sql_parent = "
  6302. SELECT *
  6303. FROM " . $tbl_lp_item . "
  6304. WHERE parent_item_id = " . $row['id'] . "
  6305. ORDER BY display_order ASC";
  6306. $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
  6307. $i = 0;
  6308. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6309. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6310. while ($row_parent = Database :: fetch_array($res_parent)) {
  6311. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_parent['title'], $charset, $this->encoding) . '\"";' . "\n";
  6312. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6313. }
  6314. $return .= "\n";
  6315. }
  6316. $return .= '</script>' . "\n";
  6317. return $return;
  6318. }
  6319. /**
  6320. * Display the form to allow moving an item
  6321. *
  6322. * @param integer Item ID
  6323. * @return string HTML form
  6324. */
  6325. function display_move_item($item_id) {
  6326. global $_course; //will disappear
  6327. global $charset;
  6328. $return = '';
  6329. if (is_numeric($item_id)) {
  6330. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6331. $sql = "SELECT *
  6332. FROM " . $tbl_lp_item . "
  6333. WHERE id = " . $item_id;
  6334. $res = Database::query($sql, __FILE__, __LINE__);
  6335. $row = Database :: fetch_array($res);
  6336. switch ($row['item_type']) {
  6337. case 'dokeos_chapter' :
  6338. case 'dir' :
  6339. case 'asset' :
  6340. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6341. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6342. break;
  6343. case 'dokeos_module' :
  6344. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6345. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6346. break;
  6347. case TOOL_DOCUMENT :
  6348. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6349. $return .= $this->display_document_form('move', $item_id, $row);
  6350. break;
  6351. case TOOL_LINK :
  6352. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6353. $return .= $this->display_link_form('move', $item_id, $row);
  6354. break;
  6355. case TOOL_HOTPOTATOES :
  6356. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6357. $return .= $this->display_link_form('move', $item_id, $row);
  6358. break;
  6359. case TOOL_QUIZ :
  6360. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6361. $return .= $this->display_quiz_form('move', $item_id, $row);
  6362. break;
  6363. case TOOL_STUDENTPUBLICATION :
  6364. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6365. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6366. break;
  6367. case TOOL_FORUM :
  6368. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6369. $return .= $this->display_forum_form('move', $item_id, $row);
  6370. }
  6371. }
  6372. return $return;
  6373. }
  6374. /**
  6375. * Displays a basic form on the overview page for changing the item title and the item description.
  6376. *
  6377. * @param string $item_type
  6378. * @param string $title
  6379. * @param array $data
  6380. * @return string
  6381. */
  6382. function display_item_small_form($item_type, $title = '', $data) {
  6383. global $charset;
  6384. $return .= '<div class="lp_small_form">' . "\n";
  6385. $return .= '<p class="lp_title">' . $title . '</p>';
  6386. $return .= '<form method="post">' . "\n";
  6387. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6388. $return .= "\t\t" . '<tr>' . "\n";
  6389. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6390. $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";
  6391. $return .= "\t\t" . '</tr>' . "\n";
  6392. //it said these lines of code - see SVN#11724 and SVN#10770
  6393. //$return .= "\t\t" . '<tr>' . "\n";
  6394. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6395. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6396. //$return .= "\t\t" . '</tr>' . "\n";
  6397. $return .= "\t\t" . '<tr>' . "\n";
  6398. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6399. $return .= "\t\t" . '</tr>' . "\n";
  6400. $return .= "\t\t" . '</table>' . "\n";
  6401. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6402. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6403. $return .= '</form>';
  6404. $return .= '</div>';
  6405. return $return;
  6406. }
  6407. /**
  6408. * Return HTML form to allow prerequisites selection
  6409. *
  6410. * @param integer Item ID
  6411. * @return string HTML form
  6412. */
  6413. function display_item_prerequisites_form($item_id) {
  6414. global $charset;
  6415. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6416. /* current prerequisite */
  6417. $sql = "
  6418. SELECT *
  6419. FROM " . $tbl_lp_item . "
  6420. WHERE id = " . $item_id;
  6421. $result = Database::query($sql, __FILE__, __LINE__);
  6422. $row = Database :: fetch_array($result);
  6423. $preq_id = $row['prerequisite'];
  6424. //$preq_mastery = $row['mastery_score'];
  6425. //$preq_max = $row['max_score'];
  6426. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6427. $return = ' <div class="row">
  6428. <div class="form_header">';
  6429. $return .= get_lang('AddEditPrerequisites');
  6430. $return .= '</div> </div>';
  6431. $return .= '<div class="sectioncomment">';
  6432. $return .= '<form method="POST">';
  6433. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6434. $return .= '<tr style="border-collapse:collapse;">';
  6435. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6436. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6437. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6438. $return .= '</tr>';
  6439. //$return .= '<tr >';
  6440. //$return .= '<td class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6441. //$return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6442. //$return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6443. //$return .= '</td><td colspan="2" />';
  6444. //$return .= '</tr>';
  6445. $sql = "
  6446. SELECT *
  6447. FROM " . $tbl_lp_item . "
  6448. WHERE
  6449. lp_id = " . $this->lp_id;
  6450. $result = Database::query($sql, __FILE__, __LINE__);
  6451. $arrLP = array ();
  6452. while ($row = Database :: fetch_array($result)) {
  6453. $arrLP[] = array (
  6454. 'id' => $row['id'],
  6455. 'item_type' => $row['item_type'],
  6456. 'title' => api_convert_encoding($row['title'], $charset, $this->encoding),
  6457. 'ref' => $row['ref'],
  6458. 'description' => $row['description'],
  6459. 'parent_item_id' => $row['parent_item_id'],
  6460. 'previous_item_id' => $row['previous_item_id'],
  6461. 'next_item_id' => $row['next_item_id'],
  6462. 'max_score' => $row['max_score'],
  6463. 'min_score' => $row['min_score'],
  6464. 'mastery_score' => $row['mastery_score'],
  6465. 'prerequisite' => $row['prerequisite'],
  6466. 'next_item_id' => $row['next_item_id'],
  6467. 'display_order' => $row['display_order']
  6468. );
  6469. if ($row['ref'] == $preq_id) {
  6470. $preq_mastery = $row['mastery_score'];
  6471. $preq_max = $row['max_score'];
  6472. }
  6473. }
  6474. $this->tree_array($arrLP);
  6475. $arrLP = $this->arrMenu;
  6476. unset ($this->arrMenu);
  6477. for ($i = 0; $i < count($arrLP); $i++) {
  6478. if ($arrLP[$i]['id'] == $item_id)
  6479. break;
  6480. $return .= '<tr >';
  6481. $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"' : '') . '>';
  6482. $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'] . '" />';
  6483. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6484. if (file_exists("../img/lp_" . $icon_name . ".png")) {
  6485. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6486. } else
  6487. if (file_exists("../img/lp_" . $icon_name . ".gif")) {
  6488. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6489. } else {
  6490. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6491. }
  6492. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6493. $return .= '</td>';
  6494. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6495. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6496. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6497. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6498. $return .= '</td>';
  6499. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6500. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6501. $return .= '</td>';
  6502. }
  6503. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6504. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6505. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6506. $return .= '</td>';
  6507. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6508. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6509. $return .= '</td>';
  6510. }
  6511. $return .= '</tr>';
  6512. }
  6513. $return .= '<tr>';
  6514. $return .= '<td colspan="3">';
  6515. $return .= '</td>';
  6516. $return .= '</tr>';
  6517. $return .= '</table>';
  6518. $return .= '<div style="padding-top:3px;">';
  6519. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang("ModifyPrerequisites") . ' </button></td>' . "\n";
  6520. $return .= '</div>';
  6521. $return .= '</form>';
  6522. $return .= '</div>';
  6523. return $return;
  6524. }
  6525. /**
  6526. * Creates a list with all the documents in it
  6527. *
  6528. * @return string
  6529. */
  6530. function get_documents() {
  6531. global $_course;
  6532. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6533. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6534. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6535. $path = '/';
  6536. $path = Database::escape_string(str_replace('_', '\_', $path));
  6537. $added_slash = ($path == '/') ? '' : '/';
  6538. //condition for the session
  6539. $current_session_id = api_get_session_id();
  6540. $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]}')))";
  6541. $sql_doc = "SELECT docs.*
  6542. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6543. WHERE docs.id = last.ref
  6544. AND docs.path LIKE '".$path.$added_slash."%'
  6545. AND docs.path NOT LIKE '%_DELETED_%'
  6546. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6547. //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
  6548. $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
  6549. $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>';
  6550. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6551. $resources = Database::store_result($res_doc);
  6552. $resources_sorted = array ();
  6553. // if you want to debug it, I advise you to do "echo" on the eval statements
  6554. foreach ($resources as $resource) {
  6555. $resource_paths = explode('/', $resource['path']);
  6556. array_shift($resource_paths);
  6557. $path_to_eval = $last_path = '';
  6558. $is_file = false;
  6559. foreach ($resource_paths as $key => $resource_path) {
  6560. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // it's a folder
  6561. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6562. } else
  6563. if (strpos($resource_path, '.') !== false)
  6564. $is_file = true;
  6565. $last_path = $resource_path;
  6566. }
  6567. if ($is_file) {
  6568. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6569. } else {
  6570. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6571. }
  6572. }
  6573. $return .= $this->write_resources_tree($resources_sorted);
  6574. $return .= '</div>';
  6575. if (Database :: num_rows($res_doc) == 0)
  6576. $return .= '<div class="lp_resource_element">' . get_lang("NoDocuments") . '</div>';
  6577. return $return;
  6578. }
  6579. /**
  6580. * Generate and return an HTML list of resources based on a given array.
  6581. *
  6582. * This list is used to show the course creator a list of available resources to choose from
  6583. * when creating a learning path.
  6584. * @param array Array of elements to add to the list
  6585. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6586. * @return string The HTML list
  6587. */
  6588. function write_resources_tree($resources_sorted, $num = 0) {
  6589. include_once (api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  6590. if (count($resources_sorted) > 0) {
  6591. foreach ($resources_sorted as $key => $resource) {
  6592. if (is_int($resource['id'])) { // it's a folder
  6593. $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'] . '">';
  6594. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6595. $return .= "</div></div>\r\n";
  6596. } else {
  6597. // it's a file
  6598. $icon = choose_image($resource);
  6599. $position = strrpos($icon, '.');
  6600. $icon = substr($icon, 0, $position) . '_small.gif';
  6601. $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";
  6602. }
  6603. }
  6604. }
  6605. return $return;
  6606. }
  6607. /**
  6608. * Creates a list with all the exercises (quiz) in it
  6609. *
  6610. * @return string
  6611. */
  6612. function get_exercises() {
  6613. // new for hotpotatoes
  6614. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6615. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6616. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6617. $session_id = api_get_session_id();
  6618. $condition_session = api_get_session_condition($session_id);
  6619. $sql_quiz = "
  6620. SELECT *
  6621. FROM " . $tbl_quiz . "
  6622. WHERE active<>'-1' $condition_session
  6623. ORDER BY title ASC";
  6624. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6625. " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
  6626. " ORDER BY id ASC";
  6627. $res_quiz = Database::query($sql_quiz, __FILE__, __LINE__);
  6628. $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
  6629. $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>';
  6630. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6631. while ($row_hot = Database :: fetch_array($res_hot)) {
  6632. $return .= '<div class="lp_resource_element">';
  6633. //display quizhotpotatoes
  6634. $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
  6635. $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>';
  6636. //$return .= $row_quiz['title'];
  6637. $return .= '</div>';
  6638. }
  6639. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6640. $return .= '<div class="lp_resource_element">';
  6641. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6642. $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>';
  6643. //$return .= $row_quiz['title'];
  6644. $return .= '</div>';
  6645. }
  6646. if (Database :: num_rows($res_quiz) == 0)
  6647. $return .= '<div class="lp_resource_element">' . get_lang("NoExercisesAvailable") . '</div>';
  6648. $return .= '<div class="lp_resource_element">';
  6649. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6650. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6651. $return .= '</div>';
  6652. $return .= '</div>';
  6653. return $return;
  6654. }
  6655. /**
  6656. * Creates a list with all the links in it
  6657. *
  6658. * @return string
  6659. */
  6660. function get_links() {
  6661. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6662. $session_id = api_get_session_id();
  6663. $condition_session = api_get_session_condition($session_id,false);
  6664. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6665. $res_link = Database::query($sql_link, __FILE__, __LINE__);
  6666. $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>';
  6667. $return .= '<div class="lp_resource_elements" id="resLink">';
  6668. while ($row_link = Database :: fetch_array($res_link)) {
  6669. $return .= '<div class="lp_resource_element">';
  6670. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6671. $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>';
  6672. $return .= '</div>';
  6673. }
  6674. $return .= '<div class="lp_resource_element">';
  6675. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6676. $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>';
  6677. $return .= '</div>';
  6678. if (Database :: num_rows($res_link) == 0)
  6679. $return .= '<div class="lp_resource_element">' . get_lang("NoLinksAvailable") . '</div>';
  6680. $return .= '</div>';
  6681. return $return;
  6682. }
  6683. /**
  6684. * Creates a list with all the student publications in it
  6685. *
  6686. * @return unknown
  6687. */
  6688. function get_student_publications() {
  6689. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6690. $session_id = api_get_session_id();
  6691. $condition_session = api_get_session_condition($session_id,false);
  6692. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6693. $res_student = Database::query($sql_student, __FILE__, __LINE__);
  6694. $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>';
  6695. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6696. $return .= '<div class="lp_resource_element">';
  6697. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6698. $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>';
  6699. $return .= '</div>';
  6700. $return .= '</div>';
  6701. return $return;
  6702. }
  6703. /**
  6704. * Creates a list with all the forums in it
  6705. *
  6706. * @return string
  6707. */
  6708. function get_forums() {
  6709. include ('../forum/forumfunction.inc.php');
  6710. include ('../forum/forumconfig.inc.php');
  6711. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6712. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6713. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6714. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6715. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6716. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6717. $a_forums = get_forums();
  6718. $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>';
  6719. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6720. foreach ($a_forums as $forum) {
  6721. $return .= '<div class="lp_resource_element">';
  6722. $return .= '<script type="text/javascript">
  6723. function toggle_forum(forum_id){
  6724. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6725. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6726. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6727. }
  6728. else {
  6729. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6730. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6731. }
  6732. }
  6733. </script>
  6734. ';
  6735. if (!empty($forum['forum_id'])) {
  6736. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6737. $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>
  6738. <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">';
  6739. }
  6740. $a_threads = get_threads($forum['forum_id']);
  6741. if (is_array($a_threads)) {
  6742. foreach ($a_threads as $thread) {
  6743. $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>';
  6744. }
  6745. }
  6746. $return .= '</ul></div>';
  6747. }
  6748. $return .= '<div class="lp_resource_element">';
  6749. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6750. $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>';
  6751. $return .= '</div>';
  6752. return $return;
  6753. }
  6754. /**
  6755. * Exports the learning path as a SCORM package. This is the main function that
  6756. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6757. * whole thing and returns the zip.
  6758. *
  6759. * This method needs to be called in PHP5, as it will fail with non-adequate
  6760. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6761. * you need to call it on a learnpath object.
  6762. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6763. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6764. * path has been modified, it should use the generic method here below.
  6765. * @TODO link this function with the export_lp() function in the same class
  6766. * @param string Optional name of zip file. If none, title of learnpath is
  6767. * domesticated and trailed with ".zip"
  6768. * @return string Returns the zip package string, or null if error
  6769. */
  6770. function scorm_export()
  6771. {
  6772. global $_course;
  6773. global $charset;
  6774. if (!class_exists('DomDocument'))
  6775. {
  6776. error_log('DOM functions not supported for PHP version below 5.0',0);
  6777. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6778. return null;
  6779. }
  6780. //remove memory and time limits as much as possible as this might be a long process...
  6781. if(function_exists('ini_set'))
  6782. {
  6783. $mem = ini_get('memory_limit');
  6784. if(substr($mem,-1,1)=='M')
  6785. {
  6786. $mem_num = substr($mem,0,-1);
  6787. if($mem_num<128)
  6788. {
  6789. ini_set('memory_limit','128M');
  6790. }
  6791. }
  6792. else
  6793. {
  6794. ini_set('memory_limit','128M');
  6795. }
  6796. ini_set('max_execution_time',600);
  6797. //}else{
  6798. //error_log('Scorm export: could not change memory and time limits',0);
  6799. }
  6800. //Create the zip handler (this will remain available throughout the method)
  6801. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6802. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6803. $temp_dir_short = uniqid();
  6804. $temp_zip_dir = $archive_path."/".$temp_dir_short;
  6805. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6806. $zip_folder=new PclZip($temp_zip_file);
  6807. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6808. $root_path = $main_path = api_get_path(SYS_PATH);
  6809. $files_cleanup = array();
  6810. //place to temporarily stash the zipfiles
  6811. //create the temp dir if it doesn't exist
  6812. //or do a cleanup befor creating the zipfile
  6813. if(!is_dir($temp_zip_dir))
  6814. {
  6815. mkdir($temp_zip_dir);
  6816. }
  6817. else
  6818. {//cleanup: check the temp dir for old files and delete them
  6819. $handle=opendir($temp_zip_dir);
  6820. while (false!==($file = readdir($handle)))
  6821. {
  6822. if ($file != "." && $file != "..")
  6823. {
  6824. unlink("$temp_zip_dir/$file");
  6825. }
  6826. }
  6827. closedir($handle);
  6828. }
  6829. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6830. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6831. {
  6832. // remove the possible . at the end of the path
  6833. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6834. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6835. $perm = api_get_setting('permissions_for_new_directories');
  6836. $perm = octdec(!empty($perm)?$perm:'0770');
  6837. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6838. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6839. }
  6840. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6841. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6842. //Aggregation Model official document, secion "2.3 Content Packaging"
  6843. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6844. $root = $xmldoc->createElement('manifest');
  6845. $root->setAttribute('identifier','SingleCourseManifest');
  6846. $root->setAttribute('version','1.1');
  6847. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6848. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6849. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6850. $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');
  6851. //Build mandatory sub-root container elements
  6852. $metadata = $xmldoc->createElement('metadata');
  6853. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6854. $metadata->appendChild($md_schema);
  6855. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6856. $metadata->appendChild($md_schemaversion);
  6857. $root->appendChild($metadata);
  6858. $organizations = $xmldoc->createElement('organizations');
  6859. $resources = $xmldoc->createElement('resources');
  6860. //Build the only organization we will use in building our learnpaths
  6861. $organizations->setAttribute('default','dokeos_scorm_export');
  6862. $organization = $xmldoc->createElement('organization');
  6863. $organization->setAttribute('identifier','dokeos_scorm_export');
  6864. //to set the title of the SCORM entity (=organization), we take the name given
  6865. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6866. //learning path charset) as it is the encoding that defines how it is stored
  6867. //in the database. Then we convert it to HTML entities again as the "&" character
  6868. //alone is not authorized in XML (must be &amp;)
  6869. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6870. $org_title = $xmldoc->createElement('title',htmlentities(api_htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6871. $organization->appendChild($org_title);
  6872. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6873. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6874. //format
  6875. $link_updates = array();
  6876. foreach($this->items as $index => $item){
  6877. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6878. {
  6879. //get included documents from this item
  6880. if($item->type=='sco')
  6881. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6882. else
  6883. $inc_docs = $item->get_resources_from_source();
  6884. //give a child element <item> to the <organization> element
  6885. $my_item_id = $item->get_id();
  6886. $my_item = $xmldoc->createElement('item');
  6887. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6888. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6889. $my_item->setAttribute('isvisible','true');
  6890. //give a child element <title> to the <item> element
  6891. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  6892. $my_item->appendChild($my_title);
  6893. //give a child element <adlcp:prerequisites> to the <item> element
  6894. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6895. $my_prereqs->setAttribute('type','aicc_script');
  6896. $my_item->appendChild($my_prereqs);
  6897. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6898. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6899. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6900. //$xmldoc->createElement('adlcp:timelimitaction','');
  6901. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6902. //$xmldoc->createElement('adlcp:datafromlms','');
  6903. //give a child element <adlcp:masteryscore> to the <item> element
  6904. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  6905. $my_item->appendChild($my_masteryscore);
  6906. //attach this item to the organization element or hits parent if there is one
  6907. if(!empty($item->parent) && $item->parent!=0)
  6908. {
  6909. $children = $organization->childNodes;
  6910. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6911. if(is_object($possible_parent))
  6912. {
  6913. $possible_parent->appendChild($my_item);
  6914. }
  6915. else
  6916. {
  6917. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6918. }
  6919. }
  6920. else
  6921. {
  6922. if($this->debug>0){error_log('No parent');}
  6923. $organization->appendChild($my_item);
  6924. }
  6925. //get the path of the file(s) from the course directory root
  6926. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6927. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  6928. $my_sub_dir = dirname($my_file_path);
  6929. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  6930. //give a <resource> child to the <resources> element
  6931. $my_resource = $xmldoc->createElement('resource');
  6932. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6933. $my_resource->setAttribute('type','webcontent');
  6934. $my_resource->setAttribute('href',$my_xml_file_path);
  6935. //adlcp:scormtype can be either 'sco' or 'asset'
  6936. if($item->type=='sco')
  6937. {
  6938. $my_resource->setAttribute('adlcp:scormtype','sco');
  6939. }
  6940. else
  6941. {
  6942. $my_resource->setAttribute('adlcp:scormtype','asset');
  6943. }
  6944. //xml:base is the base directory to find the files declared in this resource
  6945. $my_resource->setAttribute('xml:base','');
  6946. //give a <file> child to the <resource> element
  6947. $my_file = $xmldoc->createElement('file');
  6948. $my_file->setAttribute('href',$my_xml_file_path);
  6949. $my_resource->appendChild($my_file);
  6950. //dependency to other files - not yet supported
  6951. $i = 1;
  6952. foreach($inc_docs as $doc_info)
  6953. {
  6954. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6955. $my_dep = $xmldoc->createElement('resource');
  6956. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6957. $my_dep->setAttribute('identifier',$res_id);
  6958. $my_dep->setAttribute('type','webcontent');
  6959. $my_dep->setAttribute('adlcp:scormtype','asset');
  6960. $my_dep_file = $xmldoc->createElement('file');
  6961. //check type of URL
  6962. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6963. if($doc_info[1] == 'remote')
  6964. { //remote file. Save url as is
  6965. $my_dep_file->setAttribute('href',$doc_info[0]);
  6966. $my_dep->setAttribute('xml:base','');
  6967. }elseif($doc_info[1] == 'local'){
  6968. switch($doc_info[2])
  6969. {
  6970. case 'url': //local URL - save path as url for now, don't zip file
  6971. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6972. $current_dir = dirname($abs_path);
  6973. $file_path = realpath($abs_path);
  6974. $my_dep_file->setAttribute('href',$file_path);
  6975. $my_dep->setAttribute('xml:base','');
  6976. if(strstr($file_path,$main_path) !== false)
  6977. {//the calculated real path is really inside the dokeos root path
  6978. //reduce file path to what's under the DocumentRoot
  6979. $file_path = substr($file_path,strlen($root_path)-1);
  6980. //echo $file_path;echo '<br><br>';
  6981. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6982. $zip_files_abs[] = $file_path;
  6983. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6984. $my_dep_file->setAttribute('href',$file_path);
  6985. $my_dep->setAttribute('xml:base','');
  6986. }
  6987. else if (empty($file_path))
  6988. {
  6989. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6990. if(strpos($document_root,-1)=='/')
  6991. {
  6992. $document_root = substr(0, -1, $document_root);
  6993. }*/
  6994. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6995. $file_path = str_replace('//','/',$file_path);
  6996. if(file_exists($file_path))
  6997. {
  6998. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6999. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7000. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7001. $my_dep_file->setAttribute('href',$file_path);
  7002. $my_dep->setAttribute('xml:base','');
  7003. }
  7004. }
  7005. break;
  7006. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7007. $my_dep_file->setAttribute('href',$doc_info[0]);
  7008. $my_dep->setAttribute('xml:base','');
  7009. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7010. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  7011. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7012. $abs_img_path_without_subdir = $doc_info[0];
  7013. $relp = api_get_path(REL_PATH); //the url-append config param
  7014. $pos = strpos($abs_img_path_without_subdir,$relp);
  7015. if($pos===0)
  7016. {
  7017. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  7018. }
  7019. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7020. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7021. $file_path = str_replace('\\','/',$file_path);
  7022. $file_path = str_replace('//','/',$file_path);
  7023. //error_log(__LINE__.'Abs path: '.$file_path,0);
  7024. //prepare the current directory path (until just under 'document') with a trailing slash
  7025. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  7026. //check if the current document is in that path
  7027. if(strstr($file_path,$cur_path) !== false)
  7028. {
  7029. //the document is in that path, now get the relative path
  7030. //to the containing document
  7031. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7032. $relative_path ='';
  7033. if(strstr($file_path,$cur_path)!==false)
  7034. {
  7035. $relative_path = substr($file_path,strlen($orig_file_path));
  7036. $file_path = substr($file_path,strlen($cur_path));
  7037. }
  7038. else
  7039. {
  7040. //this case is still a problem as it's difficult to calculate a relative path easily
  7041. //might still generate wrong links
  7042. //$file_path = substr($file_path,strlen($cur_path));
  7043. //calculate the directory path to the current file (without trailing slash)
  7044. $my_relative_path = dirname($file_path);
  7045. $my_relative_file = basename($file_path);
  7046. //calculate the directory path to the containing file (without trailing slash)
  7047. $my_orig_file_path = substr($orig_file_path,0,-1);
  7048. $dotdot = '';
  7049. $subdir = '';
  7050. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  7051. {
  7052. $my_relative_path2 = dirname($my_relative_path);
  7053. $my_orig_file_path = dirname($my_orig_file_path);
  7054. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  7055. $dotdot += '../';
  7056. $my_relative_path = $my_relative_path2;
  7057. }
  7058. $relative_path = $dotdot.$subdir.$my_relative_file;
  7059. }
  7060. //put the current document in the zip (this array is the array
  7061. //that will manage documents already in the course folder - relative)
  7062. $zip_files[] = $file_path;
  7063. //update the links to the current document in the containing document (make them relative)
  7064. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  7065. $my_dep_file->setAttribute('href',$file_path);
  7066. $my_dep->setAttribute('xml:base','');
  7067. }
  7068. elseif(strstr($file_path,$main_path) !== false)
  7069. {//the calculated real path is really inside the dokeos root path
  7070. //reduce file path to what's under the DocumentRoot
  7071. $file_path = substr($file_path,strlen($root_path));
  7072. //echo $file_path;echo '<br><br>';
  7073. //error_log('Reduced path: '.$file_path,0);
  7074. $zip_files_abs[] = $file_path;
  7075. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7076. $my_dep_file->setAttribute('href','document/'.$file_path);
  7077. $my_dep->setAttribute('xml:base','');
  7078. }
  7079. else if (empty($file_path))
  7080. {
  7081. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7082. if(strpos($document_root,-1)=='/')
  7083. {
  7084. $document_root = substr(0, -1, $document_root);
  7085. }*/
  7086. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7087. $file_path = str_replace('//','/',$file_path);
  7088. if(file_exists($file_path))
  7089. {
  7090. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7091. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7092. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7093. $my_dep_file->setAttribute('href','document/'.$file_path);
  7094. $my_dep->setAttribute('xml:base','');
  7095. }
  7096. }
  7097. break;
  7098. 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
  7099. if(substr($doc_info[0],0,2)=='..')
  7100. { //relative path going up
  7101. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7102. $file_path = realpath($current_dir.$doc_info[0]);
  7103. //error_log($file_path.' <-> '.$main_path,0);
  7104. if(strstr($file_path,$main_path) !== false)
  7105. {//the calculated real path is really inside the dokeos root path
  7106. //reduce file path to what's under the DocumentRoot
  7107. $file_path = substr($file_path,strlen($root_path));
  7108. //error_log('Reduced path: '.$file_path,0);
  7109. $zip_files_abs[] = $file_path;
  7110. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7111. $my_dep_file->setAttribute('href','document/'.$file_path);
  7112. $my_dep->setAttribute('xml:base','');
  7113. }
  7114. }else{
  7115. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7116. $my_dep_file->setAttribute('href',$doc_info[0]);
  7117. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7118. }
  7119. break;
  7120. default:
  7121. $my_dep_file->setAttribute('href',$doc_info[0]);
  7122. $my_dep->setAttribute('xml:base','');
  7123. break;
  7124. }
  7125. }
  7126. $my_dep->appendChild($my_dep_file);
  7127. $resources->appendChild($my_dep);
  7128. $dependency = $xmldoc->createElement('dependency');
  7129. $dependency->setAttribute('identifierref',$res_id);
  7130. $my_resource->appendChild($dependency);
  7131. $i++;
  7132. }
  7133. //$my_dependency = $xmldoc->createElement('dependency');
  7134. //$my_dependency->setAttribute('identifierref','');
  7135. $resources->appendChild($my_resource);
  7136. $zip_files[] = $my_file_path;
  7137. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  7138. }
  7139. else
  7140. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  7141. if($item->type == TOOL_LINK)
  7142. {
  7143. $my_item = $xmldoc->createElement('item');
  7144. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7145. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7146. $my_item->setAttribute('isvisible','true');
  7147. //give a child element <title> to the <item> element
  7148. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7149. $my_item->appendChild($my_title);
  7150. //give a child element <adlcp:prerequisites> to the <item> element
  7151. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7152. $my_prereqs->setAttribute('type','aicc_script');
  7153. $my_item->appendChild($my_prereqs);
  7154. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  7155. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7156. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  7157. //$xmldoc->createElement('adlcp:timelimitaction','');
  7158. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  7159. //$xmldoc->createElement('adlcp:datafromlms','');
  7160. //give a child element <adlcp:masteryscore> to the <item> element
  7161. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7162. $my_item->appendChild($my_masteryscore);
  7163. //attach this item to the organization element or its parent if there is one
  7164. if(!empty($item->parent) && $item->parent!=0)
  7165. {
  7166. $children = $organization->childNodes;
  7167. for($i=0;$i<$children->length;$i++){
  7168. $item_temp = $children->item($i);
  7169. if ($item_temp -> nodeName == 'item')
  7170. {
  7171. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7172. {
  7173. $item_temp -> appendChild($my_item);
  7174. }
  7175. }
  7176. }
  7177. }
  7178. else
  7179. {
  7180. $organization->appendChild($my_item);
  7181. }
  7182. $my_file_path = 'link_'.$item->get_id().'.html';
  7183. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7184. $rs = Database::query($sql, __FILE__, __LINE__);
  7185. if($link = Database :: fetch_array($rs))
  7186. {
  7187. $url = $link['url'];
  7188. $title = stripslashes($link['title']);
  7189. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  7190. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7191. $my_sub_dir = dirname($my_file_path);
  7192. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7193. //give a <resource> child to the <resources> element
  7194. $my_resource = $xmldoc->createElement('resource');
  7195. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7196. $my_resource->setAttribute('type','webcontent');
  7197. $my_resource->setAttribute('href',$my_xml_file_path);
  7198. //adlcp:scormtype can be either 'sco' or 'asset'
  7199. $my_resource->setAttribute('adlcp:scormtype','asset');
  7200. //xml:base is the base directory to find the files declared in this resource
  7201. $my_resource->setAttribute('xml:base','');
  7202. //give a <file> child to the <resource> element
  7203. $my_file = $xmldoc->createElement('file');
  7204. $my_file->setAttribute('href',$my_xml_file_path);
  7205. $my_resource->appendChild($my_file);
  7206. $resources->appendChild($my_resource);
  7207. }
  7208. }
  7209. elseif($item->type == TOOL_QUIZ)
  7210. {
  7211. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  7212. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  7213. $exe = new Exercise();
  7214. $exe->read($exe_id);
  7215. $my_item = $xmldoc->createElement('item');
  7216. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7217. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7218. $my_item->setAttribute('isvisible','true');
  7219. //give a child element <title> to the <item> element
  7220. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
  7221. $my_item->appendChild($my_title);
  7222. $my_max_score = $xmldoc->createElement('max_score',$item->get_max());
  7223. $my_item->appendChild($my_max_score);
  7224. //give a child element <adlcp:prerequisites> to the <item> element
  7225. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7226. $my_prereqs->setAttribute('type','aicc_script');
  7227. $my_item->appendChild($my_prereqs);
  7228. //give a child element <adlcp:masteryscore> to the <item> element
  7229. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
  7230. $my_item->appendChild($my_masteryscore);
  7231. //attach this item to the organization element or hits parent if there is one
  7232. if(!empty($item->parent) && $item->parent!=0)
  7233. {
  7234. $children = $organization->childNodes;
  7235. for($i=0;$i<$children->length;$i++){
  7236. $item_temp = $children->item($i);
  7237. if ($item_temp -> nodeName == 'item')
  7238. {
  7239. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7240. {
  7241. $item_temp -> appendChild($my_item);
  7242. }
  7243. }
  7244. }
  7245. }
  7246. else
  7247. {
  7248. $organization->appendChild($my_item);
  7249. }
  7250. //include export scripts
  7251. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  7252. //get the path of the file(s) from the course directory root
  7253. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7254. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7255. //write the contents of the exported exercise into a (big) html file
  7256. //to later pack it into the exported SCORM. The file will be removed afterwards
  7257. $contents = export_exercise($exe_id,true);
  7258. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7259. $res = file_put_contents($tmp_file_path,$contents);
  7260. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7261. $files_cleanup[] = $tmp_file_path;
  7262. //error_log($tmp_path);die();
  7263. $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
  7264. $my_sub_dir = dirname($my_file_path);
  7265. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
  7266. //give a <resource> child to the <resources> element
  7267. $my_resource = $xmldoc->createElement('resource');
  7268. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7269. $my_resource->setAttribute('type','webcontent');
  7270. $my_resource->setAttribute('href',$my_xml_file_path);
  7271. //adlcp:scormtype can be either 'sco' or 'asset'
  7272. $my_resource->setAttribute('adlcp:scormtype','sco');
  7273. //xml:base is the base directory to find the files declared in this resource
  7274. $my_resource->setAttribute('xml:base','');
  7275. //give a <file> child to the <resource> element
  7276. $my_file = $xmldoc->createElement('file');
  7277. $my_file->setAttribute('href',$my_xml_file_path);
  7278. $my_resource->appendChild($my_file);
  7279. //get included docs
  7280. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7281. //dependency to other files - not yet supported
  7282. $i = 1;
  7283. foreach($inc_docs as $doc_info)
  7284. {
  7285. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7286. $my_dep = $xmldoc->createElement('resource');
  7287. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7288. $my_dep->setAttribute('identifier',$res_id);
  7289. $my_dep->setAttribute('type','webcontent');
  7290. $my_dep->setAttribute('adlcp:scormtype','asset');
  7291. $my_dep_file = $xmldoc->createElement('file');
  7292. //check type of URL
  7293. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7294. if($doc_info[1] == 'remote')
  7295. { //remote file. Save url as is
  7296. $my_dep_file->setAttribute('href',$doc_info[0]);
  7297. $my_dep->setAttribute('xml:base','');
  7298. }elseif($doc_info[1] == 'local'){
  7299. switch($doc_info[2])
  7300. {
  7301. case 'url': //local URL - save path as url for now, don't zip file
  7302. //save file but as local file (retrieve from URL)
  7303. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7304. $current_dir = dirname($abs_path);
  7305. $file_path = realpath($abs_path);
  7306. $my_dep_file->setAttribute('href','document/'.$file_path);
  7307. $my_dep->setAttribute('xml:base','');
  7308. if(strstr($file_path,$main_path) !== false)
  7309. {//the calculated real path is really inside the dokeos root path
  7310. //reduce file path to what's under the DocumentRoot
  7311. $file_path = substr($file_path,strlen($root_path));
  7312. //echo $file_path;echo '<br><br>';
  7313. //error_log('Reduced path: '.$file_path,0);
  7314. $zip_files_abs[] = $file_path;
  7315. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7316. $my_dep_file->setAttribute('href','document/'.$file_path);
  7317. $my_dep->setAttribute('xml:base','');
  7318. }
  7319. else if (empty($file_path))
  7320. {
  7321. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7322. if(strpos($document_root,-1)=='/')
  7323. {
  7324. $document_root = substr(0, -1, $document_root);
  7325. }*/
  7326. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7327. $file_path = str_replace('//','/',$file_path);
  7328. if(file_exists($file_path))
  7329. {
  7330. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7331. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7332. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7333. $my_dep_file->setAttribute('href','document/'.$file_path);
  7334. $my_dep->setAttribute('xml:base','');
  7335. }
  7336. }
  7337. break;
  7338. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7339. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7340. $file_path = realpath($doc_info[0]);
  7341. $my_dep_file->setAttribute('href',$file_path);
  7342. $my_dep->setAttribute('xml:base','');
  7343. if(strstr($file_path,$main_path) !== false)
  7344. {//the calculated real path is really inside the dokeos root path
  7345. //reduce file path to what's under the DocumentRoot
  7346. $file_path = substr($file_path,strlen($root_path));
  7347. //echo $file_path;echo '<br><br>';
  7348. //error_log('Reduced path: '.$file_path,0);
  7349. $zip_files_abs[] = $file_path;
  7350. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7351. $my_dep_file->setAttribute('href','document/'.$file_path);
  7352. $my_dep->setAttribute('xml:base','');
  7353. }
  7354. else if (empty($file_path))
  7355. {
  7356. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7357. if(strpos($document_root,-1)=='/')
  7358. {
  7359. $document_root = substr(0, -1, $document_root);
  7360. }*/
  7361. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7362. $file_path = str_replace('//','/',$file_path);
  7363. if(file_exists($file_path))
  7364. {
  7365. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7366. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7367. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7368. $my_dep_file->setAttribute('href','document/'.$file_path);
  7369. $my_dep->setAttribute('xml:base','');
  7370. }
  7371. }
  7372. break;
  7373. 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
  7374. if(substr($doc_info[0],0,2)=='..')
  7375. { //relative path going up
  7376. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7377. $file_path = realpath($current_dir.$doc_info[0]);
  7378. //error_log($file_path.' <-> '.$main_path,0);
  7379. if(strstr($file_path,$main_path) !== false)
  7380. {//the calculated real path is really inside the dokeos root path
  7381. //reduce file path to what's under the DocumentRoot
  7382. $file_path = substr($file_path,strlen($root_path));
  7383. $file_path_dest=$file_path;
  7384. //file path is courses/DOKEOS/document/....
  7385. $info_file_path=explode('/',$file_path);
  7386. if ($info_file_path[0]=='courses') {//add character "/" in file path
  7387. $file_path_dest='/'.$file_path;
  7388. }
  7389. //error_log('Reduced path: '.$file_path,0);
  7390. $zip_files_abs[] = $file_path;
  7391. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path_dest);
  7392. $my_dep_file->setAttribute('href','document/'.$file_path);
  7393. $my_dep->setAttribute('xml:base','');
  7394. }
  7395. }else{
  7396. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7397. $my_dep_file->setAttribute('href',$doc_info[0]);
  7398. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7399. }
  7400. break;
  7401. default:
  7402. $my_dep_file->setAttribute('href',$doc_info[0]);// ../../courses/
  7403. $my_dep->setAttribute('xml:base','');
  7404. break;
  7405. }
  7406. }
  7407. $my_dep->appendChild($my_dep_file);
  7408. $resources->appendChild($my_dep);
  7409. $dependency = $xmldoc->createElement('dependency');
  7410. $dependency->setAttribute('identifierref',$res_id);
  7411. $my_resource->appendChild($dependency);
  7412. $i++;
  7413. }
  7414. $resources->appendChild($my_resource);
  7415. $zip_files[] = $my_file_path;
  7416. }
  7417. else
  7418. {
  7419. //get the path of the file(s) from the course directory root
  7420. $my_file_path = 'non_exportable.html';
  7421. $my_xml_file_path = api_htmlentities($my_file_path, ENT_COMPAT, $this->encoding);
  7422. $my_sub_dir = dirname($my_file_path);
  7423. $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_COMPAT, $this->encoding);
  7424. //give a <resource> child to the <resources> element
  7425. $my_resource = $xmldoc->createElement('resource');
  7426. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7427. $my_resource->setAttribute('type','webcontent');
  7428. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7429. //adlcp:scormtype can be either 'sco' or 'asset'
  7430. $my_resource->setAttribute('adlcp:scormtype','asset');
  7431. //xml:base is the base directory to find the files declared in this resource
  7432. $my_resource->setAttribute('xml:base','');
  7433. //give a <file> child to the <resource> element
  7434. $my_file = $xmldoc->createElement('file');
  7435. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7436. $my_resource->appendChild($my_file);
  7437. $resources->appendChild($my_resource);
  7438. }
  7439. }
  7440. }
  7441. $organizations->appendChild($organization);
  7442. $root->appendChild($organizations);
  7443. $root->appendChild($resources);
  7444. $xmldoc->appendChild($root);
  7445. //todo: add a readme file here, with a short description and a link to the Reload player
  7446. //then add the file to the zip, then destroy the file (this is done automatically)
  7447. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7448. //error_log(print_r($zip_files,true),0);
  7449. foreach($zip_files as $file_path)
  7450. {
  7451. if(empty($file_path)){continue;}
  7452. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7453. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7454. $this->create_path($dest_file);
  7455. //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);
  7456. //echo $main_path.$file_path.'<br>';
  7457. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7458. //check if the file needs a link update
  7459. if(in_array($file_path,array_keys($link_updates))){
  7460. $string = file_get_contents($dest_file);
  7461. unlink($dest_file);
  7462. foreach($link_updates[$file_path] as $old_new)
  7463. {
  7464. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7465. //this is an ugly hack that allows .flv files to be found by the flv player that
  7466. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7467. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7468. // ../../.. to return from inc/lib/flv_player to the document/main path
  7469. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7470. {
  7471. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7472. }
  7473. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7474. {
  7475. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7476. }
  7477. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7478. }
  7479. file_put_contents($dest_file,$string);
  7480. }
  7481. }
  7482. foreach($zip_files_abs as $file_path)
  7483. {
  7484. if(empty($file_path)){continue;}
  7485. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7486. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7487. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7488. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7489. $this->create_path($dest_file);
  7490. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path,0);
  7491. //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);
  7492. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7493. copy($main_path.$file_path,$dest_file);
  7494. //check if the file needs a link update
  7495. if(in_array($file_path,array_keys($link_updates)))
  7496. {
  7497. $string = file_get_contents($dest_file);
  7498. unlink($dest_file);
  7499. foreach($link_updates[$file_path] as $old_new)
  7500. {
  7501. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7502. //this is an ugly hack that allows .flv files to be found by the flv player that
  7503. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7504. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7505. // ../../.. to return from inc/lib/flv_player to the document/main path
  7506. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7507. {
  7508. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7509. }
  7510. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7511. }
  7512. file_put_contents($dest_file,$string);
  7513. }
  7514. }
  7515. if(is_array($links_to_create))
  7516. {
  7517. foreach($links_to_create as $file=>$link)
  7518. {
  7519. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7520. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7521. }
  7522. }
  7523. // add non exportable message explanation
  7524. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7525. $file_content =
  7526. <<<EOD
  7527. <html>
  7528. <head>
  7529. <style>
  7530. .error-message {
  7531. font-family: arial, verdana, helvetica, sans-serif;
  7532. border-width: 1px;
  7533. border-style: solid;
  7534. left: 50%;
  7535. margin: 10px auto;
  7536. min-height: 30px;
  7537. padding: 5px;
  7538. right: 50%;
  7539. width: 500px;
  7540. background-color: #FFD1D1;
  7541. border-color: #FF0000;
  7542. color: #000;
  7543. }
  7544. </style>
  7545. <body>
  7546. <div class="error-message">
  7547. $lang_not_exportable
  7548. </div>
  7549. </body>
  7550. </html>
  7551. EOD;
  7552. if(!is_dir($archive_path.$temp_dir_short.'/document'))
  7553. {
  7554. @mkdir($archive_path.$temp_dir_short.'/document');
  7555. }
  7556. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7557. //Add the extra files that go along with a SCORM package
  7558. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7559. $extra_files = scandir($main_code_path);
  7560. foreach ($extra_files as $extra_file) {
  7561. if (strpos($extra_file, '.') === 0)
  7562. continue;
  7563. else {
  7564. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7565. $this->create_path($dest_file);
  7566. copy($main_code_path.$extra_file,$dest_file);
  7567. }
  7568. }
  7569. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7570. $xmldoc->save($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7571. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7572. //clean possible temporary files
  7573. foreach($files_cleanup as $file)
  7574. {
  7575. $res = unlink($file);
  7576. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7577. }
  7578. //Send file to client
  7579. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7580. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7581. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7582. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7583. }
  7584. /**
  7585. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7586. * if it doesn't exist
  7587. */
  7588. function create_path($path) {
  7589. $path_bits = split('/', dirname($path));
  7590. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7591. $path_built = IS_WINDOWS_OS ? '' : '/';
  7592. foreach ($path_bits as $bit) {
  7593. if (!empty ($bit)) {
  7594. $new_path = $path_built . $bit;
  7595. if (is_dir($new_path)) {
  7596. $path_built = $new_path . '/';
  7597. } else {
  7598. mkdir($new_path);
  7599. $path_built = $new_path . '/';
  7600. }
  7601. }
  7602. }
  7603. }
  7604. /**
  7605. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7606. * @return boolean The results of the unlink function, or false if there was no image to start with
  7607. */
  7608. function delete_lp_image() {
  7609. $img = $this->get_preview_image();
  7610. if ($img != '') {
  7611. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7612. $this->set_preview_image('');
  7613. return @ unlink($del_file);
  7614. } else {
  7615. return false;
  7616. }
  7617. }
  7618. /**
  7619. * Uploads an author image to the upload/learning_path/images directory
  7620. * @param array The image array, coming from the $_FILES superglobal
  7621. * @return boolean True on success, false on error
  7622. */
  7623. function upload_image($image_array) {
  7624. $image_moved = false;
  7625. if (!empty ($image_array['name'])) {
  7626. $upload_ok = process_uploaded_file($image_array);
  7627. $has_attachment = true;
  7628. } else {
  7629. $image_moved = true;
  7630. }
  7631. if ($upload_ok) {
  7632. if ($has_attachment) {
  7633. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7634. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7635. $updir = $sys_course_path . $courseDir;
  7636. // Try to add an extension to the file if it hasn't one
  7637. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7638. if (!filter_extension($new_file_name)) {
  7639. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7640. $image_moved = false;
  7641. } else {
  7642. $file_extension = explode('.', $image_array['name']);
  7643. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7644. $new_file_name = uniqid('') . '.' . $file_extension;
  7645. $new_path = $updir . '/' . $new_file_name;
  7646. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7647. // resize the image
  7648. include_once (api_get_path(LIBRARY_PATH) . 'image.lib.php');
  7649. $temp = new image($image_array['tmp_name']);
  7650. $picture_infos=@getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7651. if ($picture_infos[0] > 104) {
  7652. $thumbwidth = 104;
  7653. } else {
  7654. $thumbwidth = $picture_infos[0];
  7655. }
  7656. if ($picture_infos[1] > 96) {
  7657. $new_height = 96;
  7658. } else {
  7659. $new_height = $picture_infos[1];
  7660. }
  7661. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7662. $temp->resize($thumbwidth,$new_height,0);
  7663. $type=$picture_infos[2];
  7664. $result=false;
  7665. switch ($type)
  7666. {
  7667. case 2 :
  7668. $result=$temp->send_image('JPG',$new_path);
  7669. break;
  7670. case 3 :
  7671. $result=$temp->send_image('PNG',$new_path);
  7672. break;
  7673. case 1 :
  7674. $result=$temp->send_image('GIF',$new_path);
  7675. break;
  7676. }
  7677. $temp->resize($thumbwidth, $new_height, 0);
  7678. $type = $picture_infos[2];
  7679. $result = false;
  7680. switch ($type) {
  7681. case 2 :
  7682. $result = $temp->send_image('JPG', $new_path);
  7683. break;
  7684. case 3 :
  7685. $result = $temp->send_image('PNG', $new_path);
  7686. break;
  7687. case 1 :
  7688. $result = $temp->send_image('GIF', $new_path);
  7689. break;
  7690. }
  7691. // Storing the image filename
  7692. if ($result) {
  7693. $image_moved = true;
  7694. $this->set_preview_image($new_file_name);
  7695. return true;
  7696. }
  7697. }
  7698. }
  7699. }
  7700. return false;
  7701. }
  7702. }
  7703. if (!function_exists('trim_value')) {
  7704. function trim_value(& $value) {
  7705. $value = trim($value);
  7706. }
  7707. }