1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001 |
- <?php
- /* For licensing terms, see /dokeos_license.txt */
- /**
- * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
- * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
- * @package dokeos.learnpath
- * @author Yannick Warnier <ywarnier@beeznest.org>
- * @license GNU/GPL - See Dokeos license directory for details
- */
- /**
- * Defines the learnpath parent class
- * @package dokeos.learnpath
- */
- class learnpath {
- var $attempt = 0; //the number for the current ID view
- var $cc; //course (code) this learnpath is located in
- var $current; //id of the current item the user is viewing
- var $current_score; //the score of the current item
- var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
- var $current_time_stop; //the time the user closed this resource
- var $default_status = 'not attempted';
- var $encoding = 'UTF-8';
- var $error = '';
- var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
- var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
- var $index; //the index of the active learnpath_item in $ordered_items array
- var $items = array();
- var $last; //item_id of last item viewed in the learning path
- var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
- var $license; //which license this course has been given - not used yet on 20060522
- var $lp_id; //DB ID for this learnpath
- var $lp_view_id; //DB ID for lp_view
- var $log_file; //file where to log learnpath API msg
- var $maker; //which maker has conceived the content (ENI, Articulate, ...)
- var $message = '';
- var $mode = 'embedded'; //holds the video display mode (fullscreen or embedded)
- var $name; //learnpath name (they generally have one)
- var $ordered_items = array(); //list of the learnpath items in the order they are to be read
- var $path = ''; //path inside the scorm directory (if scorm)
- var $theme; // the current theme of the learning path
- var $preview_image; // the current image of the learning path
- // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
- var $prevent_reinit = 1;
- // Describes the mode of progress bar display
- var $progress_bar_mode = '%';
- // Percentage progress as saved in the db
- var $progress_db = '0';
- var $proximity; //wether the content is distant or local or unknown
- var $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
- //!!!This array (refs_list) is built differently depending on the nature of the LP.
- //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
- var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
- //TODO check if this type variable is useful here (instead of just in the controller script)
- var $user_id; //ID of the user that is viewing/using the course
- var $update_queue = array();
- var $scorm_debug = 0;
- var $arrMenu = array(); //array for the menu items
- var $debug = 0; //logging level
- var $lp_session_id =0;
- /**
- * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
- * Also builds the list of items into $this->items.
- * @param string Course code
- * @param integer Learnpath ID
- * @param integer User ID
- * @return boolean True on success, false on error
- */
- function learnpath($course, $lp_id, $user_id) {
- //check params
- //check course code
- if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
- if(empty($course)){
- $this->error = 'Course code is empty';
- return false;
- }
- else
- {
- $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
- //$course = Database::escape_string($course);
- $course = $this->escape_string($course);
- $sql = "SELECT * FROM $main_table WHERE code = '$course'";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- if(Database::num_rows($res)>0)
- {
- $this->cc = $course;
- }
- else
- {
- $this->error = 'Course code does not exist in database ('.$sql.')';
- return false;
- }
- }
- //check learnpath ID
- if(empty($lp_id))
- {
- $this->error = 'Learnpath ID is empty';
- return false;
- }
- else
- {
- //TODO make it flexible to use any course_code (still using env course code here)
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- //$id = Database::escape_integer($id);
- $lp_id = $this->escape_string($lp_id);
- $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- if(Database::num_rows($res)>0)
- {
- $this->lp_id = $lp_id;
- $row = Database::fetch_array($res);
- $this->type = $row['lp_type'];
- $this->name = stripslashes($row['name']);
- $this->encoding = $row['default_encoding'];
- $this->proximity = $row['content_local'];
- $this->theme = $row['theme'];
- $this->maker = $row['content_maker'];
- $this->prevent_reinit = $row['prevent_reinit'];
- $this->license = $row['content_license'];
- $this->scorm_debug = $row['debug'];
- $this->js_lib = $row['js_lib'];
- $this->path = $row['path'];
- $this->preview_image= $row['preview_image'];
- $this->author= $row['author'];
- $this->lp_session_id = $row['session_id'];
- if($this->type == 2){
- if($row['force_commit'] == 1){
- $this->force_commit = true;
- }
- }
- $this->mode = $row['default_view_mod'];
- }
- else
- {
- $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
- return false;
- }
- }
- //check user ID
- if(empty($user_id)){
- $this->error = 'User ID is empty';
- return false;
- }
- else
- {
- //$main_table = Database::get_main_user_table();
- $main_table = Database::get_main_table(TABLE_MAIN_USER);
- //$user_id = Database::escape_integer($user_id);
- $user_id = $this->escape_string($user_id);
- $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
- if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- if(Database::num_rows($res)>0)
- {
- $this->user_id = $user_id;
- }
- else
- {
- $this->error = 'User ID does not exist in database ('.$sql.')';
- return false;
- }
- }
- //end of variables checking
- //now get the latest attempt from this user on this LP, if available, otherwise create a new one
- $lp_table = Database::get_course_table(TABLE_LP_VIEW);
- //selecting by view_count descending allows to get the highest view_count first
- $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);
- }
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- $view_id = 0; //used later to query lp_item_view
- if (Database :: num_rows($res) > 0) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Found previous view', 0);
- }
- $row = Database :: fetch_array($res);
- $this->attempt = $row['view_count'];
- $this->lp_view_id = $row['id'];
- $this->last_item_seen = $row['last_item'];
- $this->progress_db = $row['progress'];
- } else {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - NOT Found previous view', 0);
- }
- $this->attempt = 1;
- $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
- $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
- $this->lp_view_id = Database :: insert_id();
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
- }
- }
- //initialise items
- $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
- $res = Database::query($sql, __FILE__, __LINE__);
- while($row = Database::fetch_array($res))
- {
- $oItem = '';
- //$this->ordered_items[] = $row['id'];
- switch ($this->type) {
- case 3 : //aicc
- $oItem = new aiccItem('db', $row['id']);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id);
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- case 2 :
- require_once ('scorm.class.php');
- require_once ('scormItem.class.php');
- $oItem = new scormItem('db', $row['id']);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id);
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- case 1 :
- default :
- require_once ('learnpathItem.class.php');
- $oItem = new learnpathItem($row['id'], $user_id);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$my_item_id] = $my_item_id;
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
- }
- }
- break;
- }
- //items is a list of pointers to all items, classified by DB ID, not SCO id
- if ($row['parent_item_id'] == 0 OR empty ($this->items[$row['parent_item_id']])) {
- $this->items[$row['id']]->set_level(0);
- } else {
- $level = $this->items[$row['parent_item_id']]->get_level() + 1;
- $this->items[$row['id']]->set_level($level);
- if (is_object($this->items[$row['parent_item_id']])) {
- //items is a list of pointers from item DB ids to item objects
- $this->items[$row['parent_item_id']]->add_child($row['id']);
- } else {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
- }
- }
- }
- //get last viewing vars
- $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
- //this query should only return one or zero result
- $sql = "SELECT * " .
- "FROM $lp_item_view_table " .
- "WHERE lp_view_id = " . $this->lp_view_id . " " .
- "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() - Selecting item_views: ' . $sql, 0);
- }
- //get the item status
- $res2 = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res2) > 0) {
- //if this learnpath has already been used by this user, get his last attempt count and
- //the last item seen back into this object
- //$max = 0;
- $row2 = Database :: fetch_array($res2);
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() - Got item_view: ' . print_r($row2, true), 0);
- }
- $this->items[$row['id']]->set_status($row2['status']);
- if (empty ($row2['status'])) {
- $this->items[$row['id']]->set_status($this->default_status);
- }
- //$this->attempt = $row['view_count'];
- //$this->last_item = $row['id'];
- } else //no item found in lp_item_view for this view
- {
- //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
- //TODO if the learnpath has not got attempts activated, always use attempt '1'
- //$this->attempt = 1;
- //$this->last_item = 0;
- $this->items[$row['id']]->set_status($this->default_status);
- //Add that row to the lp_item_view table so that we have something to show in the stats page
- $sql_ins = "INSERT INTO $lp_item_view_table " .
- "(lp_item_id, lp_view_id, view_count, status) VALUES " .
- "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
- }
- $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
- }
- //setting the view in the item object
- $this->items[$row['id']]->set_lp_view($this->lp_view_id);
- }
- $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0);
- $this->max_ordered_items = 0;
- foreach ($this->ordered_items as $index => $dummy) {
- if ($index > $this->max_ordered_items AND !empty ($dummy)) {
- $this->max_ordered_items = $index;
- }
- }
- //TODO define the current item better
- $this->first();
- if ($this->debug > 2) {
- error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
- }
- }
- /**
- * 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
- * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
- *
- * @param int $parent
- * @param int $previous
- * @param string $type
- * @param int $id
- * @param string $title
- * @param string $description
- * @return int
- */
- function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $parent = intval($parent);
- $previous = intval($previous);
- $type = $this->escape_string($type);
- $id = intval($id);
- $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
- if (empty ($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- //$title = htmlspecialchars($title, ENT_QUOTES, $charset); // TODO: To be checked for encoding problems.
- //$title = $this->escape_string(api_convert_encoding($title, $this->encoding, $charset));
- $title = $this->escape_string(api_convert_encoding($title, $this->encoding, api_get_system_encoding()));
- $description = $this->escape_string(api_convert_encoding($description, $this->encoding, api_get_system_encoding()));
- $sql_count = " SELECT COUNT(id) AS num
- FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
- $res_count = Database::query($sql_count, __FILE__, __LINE__);
- $row = Database :: fetch_array($res_count);
- $num = $row['num'];
- if ($num > 0) {
- if ($previous == 0) {
- $sql = "SELECT id, next_item_id, display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = 0 OR previous_item_id=" . $parent;
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $tmp_previous = 0;
- $next = $row['id'];
- $display_order = 0;
- } else {
- $previous = (int) $previous;
- $sql = "
- SELECT
- id,
- previous_item_id,
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->get_id() . " AND
- id = " . $previous;
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $tmp_previous = $row['id'];
- $next = $row['next_item_id'];
- $display_order = $row['display_order'];
- }
- } else {
- $tmp_previous = 0;
- $next = 0;
- $display_order = 0;
- }
- $new_item_id = -1;
- $id = $this->escape_string($id);
- if ($type == 'quiz') {
- $sql = 'SELECT SUM(ponderation)
- FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
- INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
- ON quiz_question.id = quiz_rel_question.question_id
- AND quiz_rel_question.exercice_id = ' . $id;
- $rsQuiz = Database::query($sql, __FILE__, __LINE__);
- $max_score = Database :: result($rsQuiz, 0, 0);
- } else {
- $max_score = 100;
- }
- if ($prerequisites != 0) {
- $sql_ins = "
- INSERT INTO " . $tbl_lp_item . " (
- lp_id,
- item_type,
- ref,
- title,
- description,
- path,
- max_score,
- parent_item_id,
- previous_item_id,
- next_item_id,
- display_order,
- prerequisite,
- max_time_allowed
- ) VALUES (
- " . $this->get_id() . ",
- '" . $type . "',
- '',
- '" . $title . "',
- '" . $description . "',
- '" . $id . "',
- '" . $max_score . "',
- " . $parent . ",
- " . $previous . ",
- " . $next . ",
- " . ($display_order +1) . ",
- " . $prerequisites . ",
- " . $max_time_allowed . "
- )";
- } else {
- //insert new item
- $sql_ins = "
- INSERT INTO " . $tbl_lp_item . " (
- lp_id,
- item_type,
- ref,
- title,
- description,
- path,
- max_score,
- parent_item_id,
- previous_item_id,
- next_item_id,
- display_order,
- max_time_allowed
- ) VALUES (
- " . $this->get_id() . ",
- '" . $type . "',
- '',
- '" . $title . "',
- '" . $description . "',
- '" . $id . "',
- '" . $max_score . "',
- " . $parent . ",
- " . $previous . ",
- " . $next . ",
- " . ($display_order +1) . ",
- " . $max_time_allowed . "
- )";
- }
- if ($this->debug > 2) {
- error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
- }
- $res_ins = Database::query($sql_ins, __FILE__, __LINE__);
- if ($res_ins > 0) {
- $new_item_id = Database :: insert_id($res_ins);
- //update the item that should come after the new item
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $new_item_id . "
- WHERE id = " . $next;
- $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
- //update the item that should be before the new item
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $new_item_id . "
- WHERE id = " . $tmp_previous;
- $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
- //update all the items after the new item
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $new_item_id . " AND
- parent_item_id = " . $parent . " AND
- display_order > " . $display_order;
- $res_update_previous = Database::query($sql_update_order, __FILE__, __LINE__);
- //update the item that should come after the new item
- $sql_update_ref = "
- UPDATE " . $tbl_lp_item . "
- SET ref = " . $new_item_id . "
- WHERE id = " . $new_item_id;
- Database::query($sql_update_ref, __FILE__, __LINE__);
- }
- // upload audio
- if (!empty ($_FILES['mp3']['name'])) {
- // create the audio folder if it does not exist yet
- global $_course;
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
- if (!is_dir($filepath . 'audio')) {
- $perm = api_get_setting('permissions_for_new_directories');
- $perm = octdec(!empty ($perm) ? $perm : '0770');
- mkdir($filepath . 'audio', $perm);
- $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
- api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
- }
- // upload the file in the documents tool
- include_once (api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
- $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
- // getting the filename only
- $file_components = explode('/', $file_path);
- $file = $file_components[count($file_components) - 1];
- // store the mp3 file in the lp_item table
- $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
- Database::query($sql_insert_audio, __FILE__, __LINE__);
- }
- return $new_item_id;
- }
- /**
- * Static admin function allowing addition of a learnpath to a course.
- * @param string Course code
- * @param string Learnpath name
- * @param string Learnpath description string, if provided
- * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
- * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
- * @param string Zip file containing the learnpath or directory containing the learnpath
- * @return integer The new learnpath ID on success, 0 on failure
- */
- function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '') {
- global $charset;
- //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
- //TODO
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- //check course code exists
- //check lp_name doesn't exist, otherwise append something
- $i = 0;
- $name = learnpath :: escape_string($name);
- //session_id
- $session_id = api_get_session_id();
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
- //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
- $res_name = Database::query($check_name, __FILE__, __LINE__);
- while (Database :: num_rows($res_name)) {
- //there is already one such name, update the current one a bit
- $i++;
- $name = $name . ' - ' . $i;
- $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
- //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
- $res_name = Database::query($check_name, __FILE__, __LINE__);
- }
- //new name does not exist yet; keep it
- //escape description
- $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); //Kevin: added htmlentities()
- $type = 1;
- switch ($learnpath) {
- case 'guess' :
- break;
- case 'dokeos' :
- $type = 1;
- break;
- case 'aicc' :
- break;
- }
- switch ($origin) {
- case 'zip' :
- //check zipname string. If empty, we are currently creating a new Dokeos learnpath
- break;
- case 'manual' :
- default :
- $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
- $res_max = Database::query($get_max, __FILE__, __LINE__);
- if (Database :: num_rows($res_max) < 1) {
- $dsp = 1;
- } else {
- $row = Database :: fetch_array($res_max);
- $dsp = $row[0] + 1;
- }
- $sql_insert = "INSERT INTO $tbl_lp " .
- "(lp_type,name,description,path,default_view_mod," .
- "default_encoding,display_order,content_maker," .
- "content_local,js_lib,session_id) " .
- "VALUES ($type,'$name','$description','','embedded'," .
- "'UTF-8','$dsp','Dokeos'," .
- "'local','','".Database::escape_string($session_id)."')";
- //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
- $res_insert = Database::query($sql_insert, __FILE__, __LINE__);
- $id = Database :: insert_id();
- if ($id > 0) {
- //insert into item_property
- api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
- return $id;
- }
- break;
- }
- }
- /**
- * Appends a message to the message attribute
- * @param string Message to append.
- */
- function append_message($string) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::append_message()', 0);
- }
- $this->message .= $string;
- }
- /**
- * Autocompletes the parents of an item in case it's been completed or passed
- * @param integer Optional ID of the item from which to look for parents
- */
- function autocomplete_parents($item) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::autocomplete_parents()', 0);
- }
- if (empty ($item)) {
- $item = $this->current;
- }
- $parent_id = $this->items[$item]->get_parent();
- if ($this->debug > 2) {
- error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
- }
- if (is_object($this->items[$item]) and !empty ($parent_id)) {
- //if $item points to an object and there is a parent
- if ($this->debug > 2) {
- error_log('New LP - ' . $item . ' is an item, proceed', 0);
- }
- $current_item = & $this->items[$item];
- $parent = & $this->items[$parent_id]; //get the parent
- //new experiment including failed and browsed in completed status
- $current_status = $current_item->get_status();
- if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
- //if the current item is completed or passes or succeeded
- $completed = true;
- if ($this->debug > 2) {
- error_log('New LP - Status of current item is alright', 0);
- }
- foreach ($parent->get_children() as $child) {
- //check all his brothers (his parent's children) for completion status
- if ($child != $item) {
- if ($this->debug > 2) {
- error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
- }
- //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
- //Trying completing parents of failed and browsed items as well
- if ($this->items[$child]->status_is(array (
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- 'failed'
- ))) {
- //keep completion status to true
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
- }
- $completed = false;
- }
- }
- }
- if ($completed == true) { //if all the children were completed
- $parent->set_status('completed');
- $parent->save(false, $this->prerequisites_match($parent->get_id()));
- $this->update_queue[$parent->get_id()] = $parent->get_status();
- if ($this->debug > 2) {
- error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
- }
- $this->autocomplete_parents($parent->get_id()); //recursive call
- }
- } else {
- //error_log('New LP - status of current item is not enough to get bothered with it',0);
- }
- }
- }
- /**
- * Autosaves the current results into the database for the whole learnpath
- */
- function autosave() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::autosave()', 0);
- }
- //TODO add aditionnal save operations for the learnpath itself
- }
- /**
- * Clears the message attribute
- */
- function clear_message() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::clear_message()', 0);
- }
- $this->message = '';
- }
- /**
- * Closes the current resource
- *
- * Stops the timer
- * Saves into the database if required
- * Clears the current resource data from this object
- * @return boolean True on success, false on failure
- */
- function close() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::close()', 0);
- }
- if (empty ($this->lp_id)) {
- $this->error = 'Trying to close this learnpath but no ID is set';
- return false;
- }
- $this->current_time_stop = time();
- if ($this->save) {
- $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
- /*
- $sql = "UPDATE $learnpath_view_table " .
- "SET " .
- "stop_time = ".$this->current_time_stop.", " .
- "score = ".$this->current_score.", ".
- "WHERE learnpath_id = '".$this->lp_id."'";
- //$res = Database::query($sql);
- $res = Database::query($res);
- if(Database::affected_rows($res)<1)
- {
- $this->error = 'Could not update learnpath_view table while closing learnpath';
- return false;
- }
- */
- }
- $this->ordered_items = array ();
- $this->index = 0;
- unset ($this->lp_id);
- //unset other stuff
- return true;
- }
- /**
- * Static admin function allowing removal of a learnpath
- * @param string Course code
- * @param integer Learnpath ID
- * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
- * @return boolean True on success, false on failure (might change that to return number of elements deleted)
- */
- function delete($course = null, $id = null, $delete = 'keep') {
- //TODO implement a way of getting this to work when the current object is not set
- //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
- //if(empty($course)){$course = api_get_course_id();}
- //if(empty($id)){$id = $this->get_id();}
- //If an ID is specifically given and the current LP is not the same,
- //prevent delete
- if (!empty ($id) && ($id != $this->lp_id)) {
- return false;
- }
- $lp = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
- $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
- $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
- //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
- //delete lp item id
- foreach ($this->items as $id => $dummy) {
- //$this->items[$id]->delete();
- $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
- $res_del_item_view = Database::query($sql_del_view, __FILE__, __LINE__);
- }
- // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
- $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
- $res_del_item = Database::query($sql_del_item, __FILE__, __LINE__);
- $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
- //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
- $res_del_view = Database::query($sql_del_view, __FILE__, __LINE__);
- $this->toggle_publish($this->lp_id, 'i');
- //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
- if ($this->type == 2 OR $this->type == 3) {
- //this is a scorm learning path, delete the files as well
- $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $path = $row['path'];
- $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) { //another learning path uses this directory, so don't delete it
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
- }
- } else {
- //no other LP uses that directory, delete it
- $course_rel_dir = api_get_course_path() . '/scorm/'; //scorm dir web path starting from /courses
- $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; //absolute system path for this course
- if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
- }
- // Proposed by Christophe (clefevre).
- if (strcmp(substr($path, -2), "/.") == 0) {
- $path = substr($path, 0, -1); // Remove "." at the end
- }
- //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
- rmdirr($course_scorm_dir . $path);
- }
- }
- }
- }
- $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
- //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
- $res_del_lp = Database::query($sql_del_lp, __FILE__, __LINE__);
- $this->update_display_order(); //updates the display order of all lps
- api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
- require_once '../gradebook/lib/be.inc.php';
- $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
- //delete link of gradebook tool
- $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($result, 'ASSOC');
-
- //fixing gradebook link deleted see #5229
- if (!empty($row['id'])) {
- $link = LinkFactory :: load($row['id']);
- if ($link[0] != null) {
- $link[0]->delete();
- }
- }
-
- //TODO: also delete items and item-views
- if (api_get_setting('search_enabled') == 'true') {
- require_once (api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
- $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
- }
- }
- /**
- * Removes all the children of one item - dangerous!
- * @param integer Element ID of which children have to be removed
- * @return integer Total number of children removed
- */
- function delete_children_items($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
- }
- $num = 0;
- if (empty ($id) || $id != strval(intval($id))) {
- return false;
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
- $res = Database::query($sql, __FILE__, __LINE__);
- while ($row = Database :: fetch_array($res)) {
- $num += $this->delete_children_items($row['id']);
- $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
- $res_del = Database::query($sql_del, __FILE__, __LINE__);
- $num++;
- }
- return $num;
- }
- /**
- * Removes an item from the current learnpath
- * @param integer Elem ID (0 if first)
- * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
- * @return integer Number of elements moved
- * @todo implement resource removal
- */
- function delete_item($id, $remove = 'keep') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::delete_item()', 0);
- }
- //TODO - implement the resource removal
- if (empty ($id) || $id != strval(intval($id))) {
- return false;
- }
- //first select item to get previous, next, and display order
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
- $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
- if (Database :: num_rows($res_sel) < 1) {
- return false;
- }
- $row = Database :: fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
- //delete children items
- $num = $this->delete_children_items($id);
- if ($this->debug > 2) {
- error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
- }
- //now delete the item
- $sql_del = "DELETE FROM $lp_item WHERE id = $id";
- if ($this->debug > 2) {
- error_log('New LP - Deleting item: ' . $sql_del, 0);
- }
- $res_del = Database::query($sql_del, __FILE__, __LINE__);
- //now update surrounding items
- $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
- $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
- $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
- //now update all following items with new display order
- $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
- $res_all = Database::query($sql_all, __FILE__, __LINE__);
- // remove from search engine if enabled
- if (api_get_setting('search_enabled') == 'true') {
- $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $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';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row2 = Database :: fetch_array($res);
- require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
- $di = new DokeosIndexer();
- $di->remove_document((int) $row2['search_did']);
- }
- $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';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- Database::query($sql, __FILE__, __LINE__);
- }
- }
- /**
- * Updates an item's content in place
- * @param integer Element ID
- * @param integer Parent item ID
- * @param integer Previous item ID
- * @param string Item title
- * @param string Item description
- * @param string Prerequisites (optional)
- * @param string Indexing terms (optional)
- * @param array The array resulting of the $_FILES[mp3] element
- * @return boolean True on success, false on error
- */
- function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = NULL, $max_time_allowed = 0) {
- global $charset;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::edit_item()', 0);
- }
- if (empty ($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- if (empty ($id) or ($id != strval(intval($id))) or empty ($title)) {
- return false;
- }
- $title = api_convert_encoding($title, $this->encoding, $charset);
- $description = api_convert_encoding($description, $this->encoding, $charset);
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
- $res_select = Database::query($sql_select, __FILE__, __LINE__);
- $row_select = Database :: fetch_array($res_select);
- $audio_update_sql = '';
- if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
- // create the audio folder if it does not exist yet
- global $_course;
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
- if (!is_dir($filepath . 'audio')) {
- $perm = api_get_setting('permissions_for_new_directories');
- $perm = octdec(!empty ($perm) ? $perm : '0770');
- mkdir($filepath . 'audio', $perm);
- $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
- api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(),null,null,null,null,api_get_session_id());
- }
- //upload file in documents
- $pi = pathinfo($audio['name']);
- if ($pi['extension'] == 'mp3') {
- $c_det = api_get_course_info($this->cc);
- $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
- $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
- $path = substr($path, 7);
- //update reference in lp_item - audio path is the path from inside de document/audio/ dir
- $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
- }
- }
- $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
- $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
- //TODO: htmlspecialchars to be checked for encoding related problems.
- if ($same_parent && $same_previous) {
- //only update title and description
- $sql_update = " UPDATE " . $tbl_lp_item . "
- SET title = '" . $this->escape_string($title) . "',
- prerequisite = '" . $prerequisites . "',
- description = '" . $this->escape_string($description) . "'
- " . $audio_update_sql . ",
- max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
- WHERE id = " . $id;
- $res_update = Database::query($sql_update, __FILE__, __LINE__);
- } else {
- $old_parent = $row_select['parent_item_id'];
- $old_previous = $row_select['previous_item_id'];
- $old_next = $row_select['next_item_id'];
- $old_order = $row_select['display_order'];
- $old_prerequisite = $row_select['prerequisite'];
- $old_max_time_allowed = $row_select['max_time_allowed'];
- /* BEGIN -- virtually remove the current item id */
- /* for the next and previous item it is like the current item doesn't exist anymore */
- if ($old_previous != 0) {
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $old_next . "
- WHERE id = " . $old_previous;
- $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_next . '</p>';
- }
- if ($old_next != 0) {
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $old_previous . "
- WHERE id = " . $old_next;
- $res_update_previous = Database::query($sql_update_previous, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_previous . '</p>';
- }
- //display_order - 1 for every item with a display_order bigger then the display_order of the current item
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order - 1
- WHERE
- display_order > " . $old_order . " AND
- parent_item_id = " . $old_parent;
- $res_update_order = Database::query($sql_update_order, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_order . '</p>';
- /* END -- virtually remove the current item id */
- /* BEGIN -- update the current item id to his new location */
- if ($previous == 0) {
- //select the data of the item that should come after the current item
- $sql_select_old = "
- SELECT
- id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = " . $parent . " AND
- previous_item_id = " . $previous;
- $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
- $row_select_old = Database :: fetch_array($res_select_old);
- //echo '<p>' . $sql_select_old . '</p>';
- //if the new parent didn't have children before
- if (Database :: num_rows($res_select_old) == 0) {
- $new_next = 0;
- $new_order = 1;
- } else {
- $new_next = $row_select_old['id'];
- $new_order = $row_select_old['display_order'];
- }
- //echo 'New next_item_id of current item: ' . $new_next . '<br />';
- //echo 'New previous_item_id of current item: ' . $previous . '<br />';
- //echo 'New display_order of current item: ' . $new_order . '<br />';
- } else {
- //select the data of the item that should come before the current item
- $sql_select_old = "
- SELECT
- next_item_id,
- display_order
- FROM " . $tbl_lp_item . "
- WHERE id = " . $previous;
- $res_select_old = Database::query($sql_select_old, __FILE__, __LINE__);
- $row_select_old = Database :: fetch_array($res_select_old);
- //echo '<p>' . $sql_select_old . '</p>';
- //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
- //echo 'New previous_item_id of current item: ' . $previous . '<br />';
- //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
- $new_next = $row_select_old['next_item_id'];
- $new_order = $row_select_old['display_order'] + 1;
- }
- //TODO: htmlspecialchars to be checked for encoding related problems.
- //update the current item with the new data
- $sql_update = "
- UPDATE " . $tbl_lp_item . "
- SET
- title = '" . $this->escape_string($title) . "',
- description = '" . $this->escape_string($description) . "',
- parent_item_id = " . $parent . ",
- previous_item_id = " . $previous . ",
- next_item_id = " . $new_next . ",
- display_order = " . $new_order . "
- " . $audio_update_sql . "
- WHERE id = " . $id;
- $res_update_next = Database::query($sql_update, __FILE__, __LINE__);
- //echo '<p>' . $sql_update . '</p>';
- if ($previous != 0) {
- //update the previous item's next_item_id
- $sql_update_previous = "
- UPDATE " . $tbl_lp_item . "
- SET next_item_id = " . $id . "
- WHERE id = " . $previous;
- $res_update_next = Database::query($sql_update_previous, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_previous . '</p>';
- }
- if ($new_next != 0) {
- //update the next item's previous_item_id
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET previous_item_id = " . $id . "
- WHERE id = " . $new_next;
- $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_next . '</p>';
- }
- if ($old_prerequisite != $prerequisites) {
- $sql_update_next = "
- UPDATE " . $tbl_lp_item . "
- SET prerequisite = " . $prerequisites . "
- WHERE id = " . $id;
- $res_update_next = Database::query($sql_update_next, __FILE__, __LINE__);
- }
- if ($old_max_time_allowed != $max_time_allowed) {
- $sql_update_max_time_allowed = "
- UPDATE " . $tbl_lp_item . "
- SET max_time_allowed = " . $max_time_allowed . "
- WHERE id = " . $id;
- $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed, __FILE__, __LINE__);
- }
- //update all the items with the same or a bigger display_order than
- //the current item
- $sql_update_order = "
- UPDATE " . $tbl_lp_item . "
- SET display_order = display_order + 1
- WHERE
- lp_id = " . $this->get_id() . " AND
- id <> " . $id . " AND
- parent_item_id = " . $parent . " AND
- display_order >= " . $new_order;
- $res_update_next = Database::query($sql_update_order, __FILE__, __LINE__);
- //echo '<p>' . $sql_update_order . '</p>';
- /* END -- update the current item id to his new location */
- }
- }
- /**
- * Updates an item's prereq in place
- * @param integer Element ID
- * @param string Prerequisite Element ID
- * @param string Prerequisite item type
- * @param string Prerequisite min score
- * @param string Prerequisite max score
- * @return boolean True on success, false on error
- */
- function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
- }
- if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
- return false;
- }
- $prerequisite_id = $this->escape_string($prerequisite_id);
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if (!is_numeric($mastery_score) || $mastery_score < 0)
- $mastery_score = 0;
- if (!is_numeric($max_score) || $max_score < 0)
- $max_score = 100;
- if ($mastery_score > $max_score)
- $max_score = $mastery_score;
- if (!is_numeric($prerequisite_id))
- $prerequisite_id = 'NULL';
- $sql_upd = " UPDATE " . $tbl_lp_item . "
- SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
- $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
- if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
- $sql_upd = " UPDATE " . $tbl_lp_item . " SET
- mastery_score = " . $mastery_score .
- //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
- " WHERE ref = '" . $prerequisite_id . "'"; //will this be enough to ensure unicity?
- $res_upd = Database::query($sql_upd, __FILE__, __LINE__);
- }
- //TODO update the item object (can be ignored for now because refreshed)
- return true;
- }
- /**
- * Escapes a string with the available database escape function
- * @param string String to escape
- * @return string String escaped
- */
- function escape_string($string) {
- //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
- return Database :: escape_string($string);
- }
- /**
- * Static admin function exporting a learnpath into a zip file
- * @param string Export type (scorm, zip, cd)
- * @param string Course code
- * @param integer Learnpath ID
- * @param string Zip file name
- * @return string Zip file path (or false on error)
- */
- function export_lp($type, $course, $id, $zipname) {
- //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
- //TODO
- if (empty ($type) OR empty ($course) OR empty ($id) OR empty ($zipname)) {
- return false;
- }
- $url = '';
- switch ($type) {
- case 'scorm' :
- break;
- case 'zip' :
- break;
- case 'cdrom' :
- break;
- }
- return $url;
- }
- /**
- * Gets all the chapters belonging to the same parent as the item/chapter given
- * Can also be called as abstract method
- * @param integer Item ID
- * @return array A list of all the "brother items" (or an empty array on failure)
- */
- function get_brother_chapters($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_brother_chapters()', 0);
- }
- if (empty ($id) OR $id != strval(intval($id))) {
- return array ();
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
- $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
- if (Database :: num_rows($res_parent) > 0) {
- $row_parent = Database :: fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
- $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
- $list = array ();
- while ($row_bro = Database :: fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return array ();
- }
- /**
- * Gets all the items belonging to the same parent as the item given
- * Can also be called as abstract method
- * @param integer Item ID
- * @return array A list of all the "brother items" (or an empty array on failure)
- */
- function get_brother_items($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
- }
- if (empty ($id) OR $id != strval(intval($id))) {
- return array ();
- }
- $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
- $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
- if (Database :: num_rows($res_parent) > 0) {
- $row_parent = Database :: fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
- $res_bros = Database::query($sql_bros, __FILE__, __LINE__);
- $list = array ();
- while ($row_bro = Database :: fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return array ();
- }
- /**
- * Get the specific prefix index terms of this learning path
- * @return array Array of terms
- */
- function get_common_index_terms_by_prefix($prefix) {
- require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
- $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
- $prefix_terms = array ();
- foreach ($terms as $term) {
- $prefix_terms[] = $term['value'];
- }
- return $prefix_terms;
- }
- /**
- * Gets the number of items currently completed
- * @return integer The number of items currently completed
- */
- function get_complete_items_count() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_complete_items_count()', 0);
- }
- $i = 0;
- foreach ($this->items as $id => $dummy) {
- //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
- //Trying failed and browsed considered "progressed" as well
- if ($this->items[$id]->status_is(array (
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- 'failed'
- )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
- $i++;
- }
- }
- return $i;
- }
- /**
- * Gets the current item ID
- * @return integer The current learnpath item id
- */
- function get_current_item_id() {
- $current = 0;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_current_item_id()', 0);
- }
- if (!empty ($this->current)) {
- $current = $this->current;
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
- }
- return $current;
- }
- /** Force to get the first learnpath item id
- * @return integer The current learnpath item id
- */
- function get_first_item_id() {
- $current = 0;
- if (is_array($this->ordered_items)) {
- $current = $this->ordered_items[0];
- }
- return $current;
- }
- /**
- * Gets the total number of items available for viewing in this SCORM
- * @return integer The total number of items
- */
- function get_total_items_count() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_total_items_count()', 0);
- }
- return count($this->items);
- }
- /**
- * Gets the total number of items available for viewing in this SCORM but without chapters
- * @return integer The total no-chapters number of items
- */
- function get_total_items_count_without_chapters() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
- }
- $total = 0;
- foreach ($this->items as $temp => $temp2) {
- if (!in_array($temp2->get_type(), array (
- 'dokeos_chapter',
- 'chapter',
- 'dir'
- )))
- $total++;
- }
- return $total;
- }
- /**
- * Gets the first element URL.
- * @return string URL to load into the viewer
- */
- function first() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::first()', 0);
- }
- //test if the last_item_seen exists and is not a dir
- if (count($this->ordered_items) == 0) {
- $this->index = 0;
- }
- 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) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - Last item seen is ' . $this->last_item_seen . ' of type ' . $this->items[$this->last_item_seen]->get_type(), 0);
- }
- $index = -1;
- foreach ($this->ordered_items as $myindex => $item_id) {
- if ($item_id == $this->last_item_seen) {
- $index = $myindex;
- break;
- }
- }
- if ($index == -1) {
- //index hasn't changed, so item not found - panic (this shouldn't happen)
- if ($this->debug > 2) {
- error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
- }
- return false;
- } else {
- $this->last = $this->last_item_seen;
- $this->current = $this->last_item_seen;
- $this->index = $index;
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - No last item seen', 0);
- }
- $index = 0;
- //loop through all ordered items and stop at the first item that is
- //not a directory *and* that has not been completed yet
- 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) {
- $index++;
- }
- $this->last = $this->current;
- //current is
- $this->current = $this->ordered_items[$index];
- $this->index = $index;
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
- }
- }
- /**
- * Gets the information about an item in a format usable as JavaScript to update
- * the JS API by just printing this content into the <head> section of the message frame
- * @param integer Item ID
- * @return string
- */
- function get_js_info($item_id = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
- }
- $info = '';
- $item_id = $this->escape_string($item_id);
- if (!empty ($item_id) && is_object($this->items[$item_id])) {
- //if item is defined, return values from DB
- $oItem = $this->items[$item_id];
- $info .= '<script language="javascript">';
- $info .= "top.set_score(" . $oItem->get_score() . ");\n";
- $info .= "top.set_max(" . $oItem->get_max() . ");\n";
- $info .= "top.set_min(" . $oItem->get_min() . ");\n";
- $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
- $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
- $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
- $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if ($this->debug > 2) {
- error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
- }
- return $info;
- } else {
- //if item_id is empty, just update to default SCORM data
- $info .= '<script language="javascript">';
- $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
- $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
- $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
- $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
- $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
- $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
- $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
- $info .= "top.set_flag_synchronized();";
- $info .= '</script>';
- if ($this->debug > 2) {
- error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
- }
- return $info;
- }
- }
- /**
- * Gets the js library from the database
- * @return string The name of the javascript library to be used
- */
- function get_js_lib() {
- $lib = '';
- if (!empty ($this->js_lib)) {
- $lib = $this->js_lib;
- }
- return $lib;
- }
- /**
- * Gets the learnpath database ID
- * @return integer Learnpath ID in the lp table
- */
- function get_id() {
- //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
- if (!empty ($this->lp_id)) {
- return $this->lp_id;
- } else {
- return 0;
- }
- }
- /**
- * Gets the last element URL.
- * @return string URL to load into the viewer
- */
- function get_last() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_last()', 0);
- }
- $this->index = count($this->ordered_items) - 1;
- return $this->ordered_items[$this->index];
- }
- /**
- * Gets the navigation bar for the learnpath display screen
- * @return string The HTML string to use as a navigation bar
- */
- function get_navigation_bar() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_navigation_bar()', 0);
- }
- //TODO find a good value for the following variables
- $file = '';
- $openDir = '';
- $edoceo = '';
- $time = 0;
- $navbar = '';
- $RequestUri = '';
- $mycurrentitemid = $this->get_current_item_id();
- if ($this->mode == 'fullscreen') {
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
- ' <tr> ' . "\n" .
- ' <td>' . "\n" .
- ' <div class="buttons">' . "\n" .
- ' <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" .
- ' <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" .
- ' <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" .
- //' <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" .
- //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
- ' </div>' . "\n" .
- ' </td>' . "\n" .
- ' </tr>' . "\n" .
- '</table>' . "\n";
- } else {
- $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
- ' <tr> ' . "\n" .
- ' <td>' . "\n" .
- ' <div class="buttons">' . "\n" .
- ' <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" .
- ' <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" .
- ' <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" .
- // ' <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" .
- ' </div>' . "\n" .
- ' </td>' . "\n" .
- ' </tr>' . "\n" .
- '</table>' . "\n";
- }
- return $navbar;
- }
- /**
- * Gets the next resource in queue (url).
- * @return string URL to load into the viewer
- */
- function get_next_index() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_next_index()', 0);
- }
- //TODO
- $index = $this->index;
- $index++;
- if ($this->debug > 2) {
- error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
- }
- 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) {
- $index++;
- if ($index == $this->max_ordered_items) {
- return $this->index;
- }
- }
- if (empty ($this->ordered_items[$index])) {
- return $this->index;
- }
- if ($this->debug > 2) {
- error_log('New LP - index is now ' . $index, 0);
- }
- return $index;
- }
- /**
- * Gets item_id for the next element
- * @return integer Next item (DB) ID
- */
- function get_next_item_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_next_item_id()', 0);
- }
- $new_index = $this->get_next_index();
- if (!empty ($new_index)) {
- if (isset ($this->ordered_items[$new_index])) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
- }
- return $this->ordered_items[$new_index];
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
- }
- return 0;
- }
- /**
- * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
- *
- * Generally, the package provided is in the form of a zip file, so the function
- * has been written to test a zip file. If not a zip, the function will return the
- * default return value: ''
- * @param string the path to the file
- * @param string the original name of the file
- * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
- */
- function get_package_type($file_path, $file_name) {
- //get name of the zip file without the extension
- $file_info = pathinfo($file_name);
- $filename = $file_info['basename']; //name including extension
- $extension = $file_info['extension']; //extension only
- if (!empty ($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
- 'dll',
- 'exe'
- ))) {
- return 'oogie';
- }
- if (!empty ($_POST['woogie']) && !in_array(strtolower($extension), array (
- 'dll',
- 'exe'
- ))) {
- return 'woogie';
- }
- $file_base_name = str_replace('.' . $extension, '', $filename); //filename without its extension
- $zipFile = new pclZip($file_path);
- // Check the zip content (real size and file extension)
- $zipContentArray = $zipFile->listContent();
- $package_type = '';
- $at_root = false;
- $manifest = '';
- //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
- if (is_array($zipContentArray) && count($zipContentArray) > 0) {
- foreach ($zipContentArray as $thisContent) {
- if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
- //New behaviour: Don't do anything. These files will be removed in scorm::import_package
- }
- elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== FALSE) {
- $manifest = $thisContent['filename']; //just the relative directory inside scorm/
- $package_type = 'scorm';
- break; //exit the foreach loop
- }
- elseif (preg_match('/aicc\//i', $thisContent['filename']) != false) {
- //if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
- $package_type = 'aicc';
- //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
- } else {
- $package_type = '';
- }
- }
- }
- return $package_type;
- }
- /**
- * Gets the previous resource in queue (url). Also initialises time values for this viewing
- * @return string URL to load into the viewer
- */
- function get_previous_index() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_previous_index()', 0);
- }
- $index = $this->index;
- if (isset ($this->ordered_items[$index -1])) {
- $index--;
- 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')) {
- $index--;
- if ($index < 0) {
- return $this->index;
- }
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
- }
- //no previous item
- }
- return $index;
- }
- /**
- * Gets item_id for the next element
- * @return integer Previous item (DB) ID
- */
- function get_previous_item_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_previous_item_id()', 0);
- }
- $new_index = $this->get_previous_index();
- return $this->ordered_items[$new_index];
- }
- /**
- * Gets the progress value from the progress_db attribute
- * @return integer Current progress value
- */
- function get_progress() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress()', 0);
- }
- if (!empty ($this->progress_db)) {
- return $this->progress_db;
- }
- return 0;
- }
- /**
- * Gets the progress value from the progress field in the database (allows use as abstract method)
- * @param integer Learnpath ID
- * @param integer User ID
- * @param string Mode of display ('%','abs' or 'both')
- * @param string Course database name (optional, defaults to '')
- * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
- * @return integer Current progress value as found in the database
- */
- function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false) {
- //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
- $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
- $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
- $res = Database::query($sql, __FILE__, __LINE__);
- $view_id = 0;
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $progress = $row['progress'];
- $view_id = $row['id'];
- } else {
- if ($sincere) {
- return null;
- }
- }
- if (empty ($progress)) {
- $progress = '0';
- }
- if ($mode == '%') {
- return $progress . '%';
- } else {
- //get the number of items completed and the number of items total
- $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
- $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
- AND item_type NOT IN('dokeos_chapter','chapter','dir')";
- $res = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($res);
- $total = $row[0];
- $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
- $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
- //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
- //trying as also counting browsed and failed items
- $sql = "SELECT count(distinct(lp_item_id))
- FROM $tbl_item_view as item_view
- INNER JOIN $tbl_item as item
- ON item.id = item_view.lp_item_id
- AND item_type NOT IN('dokeos_chapter','chapter','dir')
- WHERE lp_view_id = " . $view_id . "
- AND status IN ('passed','completed','succeeded','browsed','failed')";
- $res = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($res);
- $completed = $row[0];
- if ($mode == 'abs') {
- return $completed . '/' . $total;
- }
- elseif ($mode == 'both') {
- if ($progress < ($completed / ($total ? $total : 1))) {
- $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
- }
- return $progress . '% (' . $completed . '/' . $total . ')';
- }
- }
- return $progress;
- }
- /**
- * Returns the HTML necessary to print a mediaplayer block inside a page
- * @return string The mediaplayer HTML
- */
- function get_mediaplayer($autostart='true') {
- global $_course;
- // Database table definition
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
- // getting all the information about the item
- $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 " .
- "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = mysql_fetch_assoc($result);
- $output = '';
- if (!empty ($row['audio'])) {
- $list = $_SESSION['oLP']->get_toc();
- $type_quiz = false;
- foreach($list as $toc) {
- if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
- $type_quiz = true;
- }
- }
- if ($type_quiz) {
- if ($_SESSION['oLP']->prevent_reinit == 1) {
- $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
- } else {
- $autostart_audio = $autostart;
- }
- } else {
- $autostart_audio = 'true';
- }
- // the mp3 player
- $output = '<div id="container">';
- $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $output .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
- s1.write("container");
- </script></div>';
- }
- return $output;
- }
- /**
- * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
- * completed so far.
- * @param string Mode in which we want the values
- * @param integer Progress value to display (optional but mandatory if used in abstract context)
- * @param string Text to display near the progress value (optional but mandatory in abstract context)
- * @param boolean true if it comes from a Diplay LP view
- * @return string HTML string containing the progress bar
- */
- function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
- //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
- global $lp_theme_css;
- // Setting up the CSS path of the current style if exists
- if (!empty ($lp_theme_css)) {
- $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
- } else {
- $css_path = '../img/';
- }
- //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
- if (isset ($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
- list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
- }
- $text = $percentage . $text_add;
- //Default progress bar config
- // times that will be greater or shorter
- $factor = 1.2;
- if ($from_lp)
- $progress_height = '26';
- else
- $progress_height = '16';
- $size = str_replace('%', '', $percentage);
- $output = ''
- //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
- . '<table border="0" cellpadding="0" cellspacing="0"><tr><td>' .
- '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
- '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
- '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
- if ($percentage <= 98) {
- $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
- } else {
- $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
- }
- $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></td></tr></table>' .
- '<div class="progresstext" id="progress_text">' . $text . '</div>';
- return $output;
- }
- /**
- * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
- * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
- * //@param integer Additional steps to fake as completed
- * @return list Percentage or number and symbol (% or /xx)
- */
- function get_progress_bar_text($mode = '', $add = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress_bar_text()', 0);
- }
- if (empty ($mode)) {
- $mode = $this->progress_bar_mode;
- }
- $total_items = $this->get_total_items_count_without_chapters();
- if ($this->debug > 2) {
- error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
- }
- $i = $this->get_complete_items_count();
- if ($this->debug > 2) {
- error_log('New LP - Items completed so far: ' . $i, 0);
- }
- if ($add != 0) {
- $i += $add;
- if ($this->debug > 2) {
- error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
- }
- }
- $text = '';
- if ($i > $total_items) {
- $i = $total_items;
- }
- if ($mode == '%') {
- if ($total_items > 0) {
- $percentage = ((float) $i / (float) $total_items) * 100;
- } else {
- $percentage = 0;
- }
- $percentage = number_format($percentage, 0);
- $text = '%';
- }
- elseif ($mode == 'abs') {
- $percentage = $i;
- $text = '/' . $total_items;
- }
- return array (
- $percentage,
- $text
- );
- }
- /**
- * Gets the progress bar mode
- * @return string The progress bar mode attribute
- */
- function get_progress_bar_mode() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
- }
- if (!empty ($this->progress_bar_mode)) {
- return $this->progress_bar_mode;
- } else {
- return '%';
- }
- }
- /**
- * Gets the learnpath proximity (remote or local)
- * @return string Learnpath proximity
- */
- function get_proximity() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_proximity()', 0);
- }
- if (!empty ($this->proximity)) {
- return $this->proximity;
- } else {
- return '';
- }
- }
- /**
- * Gets the learnpath theme (remote or local)
- * @return string Learnpath theme
- */
- function get_theme() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_theme()', 0);
- }
- if (!empty ($this->theme)) {
- return $this->theme;
- } else {
- return '';
- }
- }
- /**
- * Gets the learnpath session id
- * @return string Learnpath theme
- */
- function get_lp_session_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_lp_session_id()', 0);
- }
- if (!empty ($this->lp_session_id)) {
- return $this->lp_session_id;
- } else {
- return 0;
- }
- }
- /**
- * Gets the learnpath image
- * @return string Web URL of the LP image
- */
- function get_preview_image() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_preview_image()', 0);
- }
- if (!empty ($this->preview_image)) {
- return $this->preview_image;
- } else {
- return '';
- }
- }
- /**
- * Gets the learnpath author
- * @return string LP's author
- */
- function get_author() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_author()', 0);
- }
- if (!empty ($this->author)) {
- return $this->author;
- } else {
- return '';
- }
- }
- /**
- * Generate a new prerequisites string for a given item. If this item was a sco and
- * its prerequisites were strings (instead of IDs), then transform those strings into
- * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
- * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
- * same rule as the scorm_export() method
- * @param integer Item ID
- * @return string Prerequisites string ready for the export as SCORM
- */
- function get_scorm_prereq_string($item_id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
- }
- if (!is_object($this->items[$item_id])) {
- return false;
- }
- $oItem = $this->items[$item_id];
- $prereq = $oItem->get_prereq_string();
- if (empty ($prereq)) {
- return '';
- }
- 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,
- //then simply return it (with the ITEM_ prefix)
- return 'ITEM_' . $prereq;
- } else {
- if (isset ($this->refs_list[$prereq])) {
- //it's a simple string item from which the ID can be found in the refs list
- //so we can transform it directly to an ID for export
- return 'ITEM_' . $this->refs_list[$prereq];
- } else {
- //last case, if it's a complex form, then find all the IDs (SCORM strings)
- //and replace them, one by one, by the internal IDs (dokeos db)
- //TODO modify the '*' replacement to replace the multiplier in front of it
- //by a space as well
- $find = array (
- '&',
- '|',
- '~',
- '=',
- '<>',
- '{',
- '}',
- '*',
- '(',
- ')'
- );
- $replace = array (
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' '
- );
- $prereq_mod = str_replace($find, $replace, $prereq);
- $ids = split(' ', $prereq_mod);
- foreach ($ids as $id) {
- $id = trim($id);
- if (isset ($this->refs_list[$id])) {
- $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
- }
- }
- error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
- return $prereq;
- }
- }
- }
- /**
- * Returns the XML DOM document's node
- * @param resource Reference to a list of objects to search for the given ITEM_*
- * @param string The identifier to look for
- * @return mixed The reference to the element found with that identifier. False if not found
- */
- function get_scorm_xml_node(& $children, $id) {
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp->nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == $id) {
- return $item_temp;
- }
- }
- $subchildren = $item_temp->childNodes;
- if ($subchildren->length > 0) {
- $val = $this->get_scorm_xml_node($subchildren, $id);
- if (is_object($val)) {
- return $val;
- }
- }
- }
- return false;
- }
- /**
- * Returns a usable array of stats related to the current learnpath and user
- * @return array Well-formatted array containing status for the current learnpath
- */
- function get_stats() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_stats()', 0);
- }
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course (for all learnpaths and all users)
- * @param string Course code
- * @return array Well-formatted array containing status for the course's learnpaths
- */
- function get_stats_course($course) {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course and learnpath (for all users)
- * @param string Course code
- * @param integer Learnpath ID
- * @return array Well-formatted array containing status for the specified learnpath
- */
- function get_stats_lp($course, $lp) {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course, learnpath and user.
- * @param string Course code
- * @param integer Learnpath ID
- * @param integer User ID
- * @return array Well-formatted array containing status for the specified learnpath and user
- */
- function get_stats_lp_user($course, $lp, $user) {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
- //TODO
- }
- /**
- * Static method. Can be re-implemented by children. Gives an array of statistics for
- * the given course and learnpath (for all users)
- * @param string Course code
- * @param integer User ID
- * @return array Well-formatted array containing status for the user's learnpaths
- */
- function get_stats_user($course, $user) {
- //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
- //TODO
- }
- /**
- * Gets the status list for all LP's items
- * @return array Array of [index] => [item ID => current status]
- */
- function get_items_status_list() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_items_status_list()', 0);
- }
- $list = array ();
- foreach ($this->ordered_items as $item_id) {
- $list[] = array (
- $item_id => $this->items[$item_id]->get_status()
- );
- }
- return $list;
- }
- /**
- * Return the number of interactions for the given learnpath Item View ID.
- * This method can be used as static.
- * @param integer Item View ID
- * @return integer Number of interactions
- */
- function get_interactions_count_from_db($lp_iv_id = 0) {
- if (empty ($lp_iv_id)) {
- return -1;
- }
- $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
- $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
- $res = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($res);
- $num = $row[0];
- return $num;
- }
- /**
- * Return the interactions as an array for the given lp_iv_id.
- * This method can be used as static.
- * @param integer Learnpath Item View ID
- * @return array
- * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
- */
- function get_iv_interactions_array($lp_iv_id = 0) {
- $charset = api_get_setting('platform_charset');
- $list = array ();
- $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
- $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
- $res = Database::query($sql, __FILE__, __LINE__);
- $num = Database :: num_rows($res);
- if ($num > 0) {
- $list[] = array (
- "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
- "id" => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES, $charset),
- "type" => api_htmlentities(get_lang('Type'), ENT_QUOTES, $charset),
- "time" => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES, $charset),
- "correct_responses" => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES, $charset),
- "student_response" => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES, $charset),
- "result" => api_htmlentities(get_lang('Result'), ENT_QUOTES, $charset),
- "latency" => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES, $charset)
- );
- while ($row = Database :: fetch_array($res)) {
- $list[] = array (
- "order_id" => ($row['order_id'] + 1),
- "id" => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
- "type" => $row['interaction_type'],
- "time" => $row['completion_time'],
- //"correct_responses"=>$row['correct_responses'],
- //hide correct responses from students
- "correct_responses" => '',
- "student_response" => $row['student_response'],
- "result" => $row['result'],
- "latency" => $row['latency']
- );
- }
- }
- return $list;
- }
- /**
- * Return the number of objectives for the given learnpath Item View ID.
- * This method can be used as static.
- * @param integer Item View ID
- * @return integer Number of objectives
- */
- function get_objectives_count_from_db($lp_iv_id = 0) {
- if (empty ($lp_iv_id)) {
- return -1;
- }
- $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
- $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
- $res = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($res);
- $num = $row[0];
- return $num;
- }
- /**
- * Return the objectives as an array for the given lp_iv_id.
- * This method can be used as static.
- * @param integer Learnpath Item View ID
- * @return array
- * @todo Translate labels
- */
- function get_iv_objectives_array($lp_iv_id = 0) {
- global $chatset;
- $list = array ();
- $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
- $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
- $res = Database::query($sql, __FILE__, __LINE__);
- $num = Database :: num_rows($res);
- if ($num > 0) {
- $list[] = array (
- "order_id" => api_htmlentities(get_lang('Order'), ENT_QUOTES, $charset),
- "objective_id" => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES, $charset),
- "score_raw" => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES, $charset),
- "score_max" => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES, $charset),
- "score_min" => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES, $charset),
- "status" => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES, $charset)
- );
- while ($row = Database :: fetch_array($res)) {
- $list[] = array (
- "order_id" => ($row['order_id'] + 1),
- "objective_id" => urldecode($row['objective_id']), //urldecode because they often have %2F or stuff like that
- "score_raw" => $row['score_raw'],
- "score_max" => $row['score_max'],
- "score_min" => $row['score_min'],
- "status" => $row['status']
- );
- }
- }
- return $list;
- }
- /**
- * Generate and return the table of contents for this learnpath. The (flat) table returned can be
- * used by get_html_toc() to be ready to display
- * @return array TOC as a table with 4 elements per row: title, link, status and level
- */
- function get_toc() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_toc()', 0);
- }
- $toc = array ();
- //echo "<pre>".print_r($this->items,true)."</pre>";
- foreach ($this->ordered_items as $item_id) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
- }
- //TODO change this link generation and use new function instead
- $toc[] = array (
- 'id' => $item_id,
- 'title' => $this->items[$item_id]->get_title(),
- //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
- 'status' => $this->items[$item_id]->get_status(),
- 'level' => $this->items[$item_id]->get_level(),
- 'type' => $this->items[$item_id]->get_type(),
- 'description' => $this->items[$item_id]->get_description(),
- 'path' => $this->items[$item_id]->get_path(),
- );
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
- }
- return $toc;
- }
- /**
- * Gets the learning path type
- * @param boolean Return the name? If false, return the ID. Default is false.
- * @return mixed Type ID or name, depending on the parameter
- */
- function get_type($get_name = false) {
- $res = false;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_type()', 0);
- }
- if (!empty ($this->type)) {
- if ($get_name) {
- //get it from the lp_type table in main db
- } else {
- $res = $this->type;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_type() - Returning ' . ($res == false ? 'false' : $res), 0);
- }
- return $res;
- }
- /**
- * Gets the learning path type as static method
- * @param boolean Return the name? If false, return the ID. Default is false.
- * @return mixed Type ID or name, depending on the parameter
- */
- function get_type_static($lp_id = 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
- $res = Database::query($sql, __FILE__, __LINE__);
- if ($res === false) {
- return null;
- }
- if (Database :: num_rows($res) <= 0) {
- return null;
- }
- $row = Database :: fetch_array($res);
- return $row['lp_type'];
- }
- /**
- * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
- * This method can be used as abstract and is recursive
- * @param integer Learnpath ID
- * @param integer Parent ID of the items to look for
- * @return mixed Ordered list of item IDs or false on error
- */
- function get_flat_ordered_items_list($lp, $parent = 0) {
- //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
- $list = array ();
- if (empty ($lp)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
- $res = Database::query($sql, __FILE__, __LINE__);
- while ($row = Database :: fetch_array($res)) {
- $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id']);
- $list[] = $row['id'];
- foreach ($sublist as $item) {
- $list[] = $item;
- }
- }
- return $list;
- }
- /**
- * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
- * @return string HTML TOC ready to display
- */
- /*function get_html_toc()
- {
- if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
- $list = $this->get_toc();
- //echo $this->current;
- //$parent = $this->items[$this->current]->get_parent();
- //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
- $html = '<div class="inner_lp_toc">'."\n" ;
- // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
- require_once('resourcelinker.inc.php');
- //temp variables
- $mycurrentitemid = $this->get_current_item_id();
- foreach($list as $item)
- {
- if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
- //TODO complete this
- $icon_name = array('not attempted' => '../img/notattempted.gif',
- 'incomplete' => '../img/incomplete.gif',
- 'failed' => '../img/failed.gif',
- 'completed' => '../img/completed.gif',
- 'passed' => '../img/passed.gif',
- 'succeeded' => '../img/succeeded.gif',
- 'browsed' => '../img/completed.gif');
- $style = 'scorm_item';
- if($item['id'] == $this->current){
- $style = 'scorm_item_highlight';
- }
- //the anchor will let us center the TOC on the currently viewed item &^D
- $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'].'" >' .
- '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
- //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
- $title = $item['title'];
- if(empty($title)){
- $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
- $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
- }
- if(empty($title))$title = '-';
- if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
- //$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>" ;
- $url = $this->get_link('http',$item['id']);
- //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
- //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
- $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
- $mycurrentitemid.',' .
- $item['id'].');' .
- 'return false;" >'.$title.'</a>' ;
- }else{
- $html .= $title;
- }
- $html .= "</div>\n";
- }
- $html .= "</div>\n";
- return $html;
- }*/
- /**
- * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
- * @return string HTML TOC ready to display
- */
- function get_html_toc() {
- $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
- $charset = api_get_setting('platform_charset');
- $display_action_links_with_icons = false;
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_html_toc()', 0);
- }
- $list = $this->get_toc();
- //echo $this->current;
- //$parent = $this->items[$this->current]->get_parent();
- //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
- $html = '<div class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS(api_convert_encoding($this->get_name(), $this->encoding, $charset)) . '</div></div>';
- // build, display
- if ($is_allowed_to_edit) {
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
- //var_dump($this->get_lp_session_id());
- if ($this->get_lp_session_id()==api_get_session_id()) {
- $html .= '<div class="actions_lp">';
- if ($display_action_links_with_icons) {
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=build&lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . "</a>";
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=admin_view&lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . "</a>";
- $html .= '<span>' . Display :: return_icon('learnpath_view_na.gif', get_lang("Display")) . ' <b>' . get_lang("Display") . '</b></span>';
- } else {
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&gradebook=$gradebook&action=build&lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('Build') . "</a>";
- $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&action=admin_view&lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('BasicOverview') . "</a>";
- $html .= '<span><b>' . get_lang('Display') . '</b></span>';
- }
- $html .= '</div>';
- }
- }
- $html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
- require_once ('resourcelinker.inc.php');
- //temp variables
- $mycurrentitemid = $this->get_current_item_id();
- $color_counter = 0;
- $i = 0;
- foreach ($list as $item) {
- if ($this->debug > 2) {
- error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
- }
- //TODO complete this
- $icon_name = array (
- 'not attempted' => '../img/notattempted.gif',
- 'incomplete' => '../img/incomplete.gif',
- 'failed' => '../img/failed.gif',
- 'completed' => '../img/completed.gif',
- 'passed' => '../img/passed.gif',
- 'succeeded' => '../img/succeeded.gif',
- 'browsed' => '../img/completed.gif'
- );
- $style = 'scorm_item';
- $scorm_color_background = 'scorm_item';
- $style_item = 'scorm_item';
- $current = false;
- if ($item['id'] == $this->current) {
- $style = 'scorm_item_highlight';
- $scorm_color_background = 'scorm_item_highlight';
- } else
- if ($color_counter % 2 == 0) {
- $scorm_color_background = 'scorm_item_1';
- } else {
- $scorm_color_background = 'scorm_item_2';
- }
- if ($scorm_color_background != '') {
- $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
- }
- //the anchor will let us center the TOC on the currently viewed item &^D
- if ($item['type'] != 'dokeos_module' AND $item['type'] != 'dokeos_chapter') {
- $html .= '<a name="atoc_' . $item['id'] . '" />';
- $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
- } else {
- $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
- }
- $title = $item['title'];
- if (empty ($title)) {
- $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
- }
- //$title = api_htmlentities($title, ENT_QUOTES, $this->encoding);
- $title = Security::remove_XSS($title);
- if ($item['type'] != 'dokeos_chapter' and $item['type'] != 'dir' AND $item['type'] != 'dokeos_module') {
- //$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>" ;
- $url = $this->get_link('http', $item['id']);
- //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
- //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
- //<img align="absbottom" width="13" height="13" src="../img/lp_document.png"> background:#aaa;
- $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
- $mycurrentitemid . ',' .
- $item['id'] . ');' .
- 'return false;" >' . stripslashes($title) . '</a>';
- } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
- $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'> " . stripslashes($title);
- } elseif ($item['type'] == 'dir') {
- $html .= stripslashes($title);
- }
- $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $user_id = api_get_user_id();
- $course_id = api_get_course_id();
- $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
- WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
- $result = Database::query($sql, __FILE__, __LINE__);
- $count = Database :: num_rows($result);
- if ($item['type'] == 'quiz') {
- if ($item['status'] == 'completed') {
- $html .= " <img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
- }
- } else {
- if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
- $html .= " <img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='12' height='12' />";
- }
- }
- $html .= "</div>";
- if ($scorm_color_background != '') {
- $html .= '</div>';
- }
- $color_counter++;
- }
- $html .= "</div>\n";
- return $html;
- }
- /**
- * Gets the learnpath maker name - generally the editor's name
- * @return string Learnpath maker name
- */
- function get_maker() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_maker()', 0);
- }
- if (!empty ($this->maker)) {
- return $this->maker;
- } else {
- return '';
- }
- }
- /**
- * Gets the user-friendly message stored in $this->message
- * @return string Message
- */
- function get_message() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_message()', 0);
- }
- return $this->message;
- }
- /**
- * Gets the learnpath name/title
- * @return string Learnpath name/title
- */
- function get_name() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_name()', 0);
- }
- if (!empty ($this->name)) {
- return $this->name;
- } else {
- return 'N/A';
- }
- }
- /**
- * Gets a link to the resource from the present location, depending on item ID.
- * @param string Type of link expected
- * @param integer Learnpath item ID
- * @return string Link to the lp_item resource
- */
- function get_link($type = 'http', $item_id = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
- }
- if (empty($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
- }
- $item_id = $this->get_current_item_id();
- }
- if (empty ($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
- }
- //still empty, this means there was no item_id given and we are not in an object context or
- //the object property is empty, return empty link
- $item_id = $this->first();
- return '';
- }
- $file = '';
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
- $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
- $item_id = Database::escape_string($item_id);
- $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
- "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
- }
- $res = Database::query($sel, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- //var_dump($row);
- $lp_type = $row['ltype'];
- $lp_path = $row['lpath'];
- $lp_item_type = $row['litype'];
- $lp_item_path = $row['lipath'];
- $lp_item_params = $row['liparams'];
- if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
- list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
- }
- //$lp_item_params = '?'.$lp_item_params;
- //add ? if none - left commented to give freedom to scorm implementation
- //if(substr($lp_item_params,0,1)!='?'){
- // $lp_item_params = '?'.$lp_item_params;
- //}
- $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
- if ($type == 'http') {
- $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
- } else {
- $course_path = $sys_course_path; //system path
- }
- //now go through the specific cases to get the end of the path
- switch ($lp_type) {
- case 1 :
- if ($lp_item_type == 'dokeos_chapter') {
- $file = 'lp_content.php?type=dir';
- } else {
- require_once ('resourcelinker.inc.php');
- $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
- // check how much attempts of a exercise exits in lp
- $lp_item_id = $this->get_current_item_id();
- $lp_view_id = $this->get_view_id();
- $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
- $list = $this->get_toc();
- $type_quiz = false;
- foreach ($list as $toc) {
- if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
- $type_quiz = true;
- }
- }
- if ($type_quiz) {
- $lp_item_id = Database :: escape_string($lp_item_id);
- $lp_view_id = Database :: escape_string($lp_view_id);
- $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'";
- $result = Database::query($sql, __FILE__, __LINE__);
- $row_count = Database :: fetch_row($result);
- $count_item_view = (int) $row_count[0];
- $not_multiple_attempt = 0;
- if ($prevent_reinit === 1 && $count_item_view > 0) {
- $not_multiple_attempt = 1;
- }
- $file .= '¬_multiple_attempt=' . $not_multiple_attempt;
- }
- $tmp_array = explode("/", $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- }
- }
- break;
- case 2 :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
- }
- if ($lp_item_type != 'dir') {
- //Quite complex here:
- //we want to make sure 'http://' (and similar) links can
- //be loaded as is (withouth the Dokeos path in front) but
- //some contents use this form: resource.htm?resource=http://blablabla
- //which means we have to find a protocol at the path's start, otherwise
- //it should not be considered as an external URL
- //if($this->prerequisites_match($item_id)){
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
- }
- //distant url, return as is
- $file = $lp_item_path;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
- }
- //prevent getting untranslatable urls
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
- //prepare the path
- $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
- //TODO fix this for urls with protocol header
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- if (substr($lp_path, -1) == '/') {
- $lp_path = substr($lp_path, 0, -1);
- }
- if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
- //if file not found
- $decoded = html_entity_decode($lp_item_path);
- list ($decoded) = explode('?', $decoded);
- if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
- require_once ('resourcelinker.inc.php');
- $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
- if (empty($file)) {
- $file = 'blank.php?error=document_not_found';
- } else {
- $tmp_array = explode("/", $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- }
- }
- } else {
- $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
- }
- }
- }
- //}else{
- //prerequisites did not match
- //$file = 'blank.php';
- //}
- //We want to use parameters if they were defined in the imsmanifest
- if ($file != 'blank.php') {
- $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 3 :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
- }
- //formatting AICC HACP append URL
- $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
- if ($lp_item_type != 'dir') {
- //Quite complex here:
- //we want to make sure 'http://' (and similar) links can
- //be loaded as is (withouth the Dokeos path in front) but
- //some contents use this form: resource.htm?resource=http://blablabla
- //which means we have to find a protocol at the path's start, otherwise
- //it should not be considered as an external URL
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
- }
- //distant url, return as is
- $file = $lp_item_path;
- // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
- /*
- if(stristr($file,'<servername>')!==false){
- $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
- }
- */
- if (stripos($file, '<servername>') !== false) {
- //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
- $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
- $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
- }
- //
- $file .= $aicc_append;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
- }
- //prevent getting untranslatable urls
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
- //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
- $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
- //TODO fix this for urls with protocol header
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- $file .= $aicc_append;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 4 :
- break;
- default :
- break;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
- }
- return $file;
- }
- /**
- * Gets the latest usable view or generate a new one
- * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
- * @return integer DB lp_view id
- */
- function get_view($attempt_num = 0) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_view()', 0);
- }
- $search = '';
- //use $attempt_num to enable multi-views management (disabled so far)
- if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
- $search = 'AND view_count = ' . $attempt_num;
- }
- //when missing $attempt_num, search for a unique lp_view record for this lp and user
- $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
- $sql = "SELECT id, view_count FROM $lp_view_table " .
- "WHERE lp_id = " . $this->get_id() . " " .
- "AND user_id = " . $this->get_user_id() . " " .
- $search .
- " ORDER BY view_count DESC";
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $this->lp_view_id = $row['id'];
- } else {
- //no database record, create one
- $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
- "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
- $res = Database::query($sql, __FILE__, __LINE__);
- $id = Database :: insert_id();
- $this->lp_view_id = $id;
- }
- return $this->lp_view_id;
- }
- /**
- * Gets the current view id
- * @return integer View ID (from lp_view)
- */
- function get_view_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_view_id()', 0);
- }
- if (!empty ($this->lp_view_id)) {
- return $this->lp_view_id;
- } else {
- return 0;
- }
- }
- /**
- * Gets the update queue
- * @return array Array containing IDs of items to be updated by JavaScript
- */
- function get_update_queue() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_update_queue()', 0);
- }
- return $this->update_queue;
- }
- /**
- * Gets the user ID
- * @return integer User ID
- */
- function get_user_id() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::get_user_id()', 0);
- }
- if (!empty ($this->user_id)) {
- return $this->user_id;
- } else {
- return false;
- }
- }
- /**
- * Checks if any of the items has an audio element attached
- * @return bool True or false
- */
- function has_audio() {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::has_audio()', 0);
- }
- $has = false;
- foreach ($this->items as $i => $item) {
- if (!empty ($this->items[$i]->audio)) {
- $has = true;
- break;
- }
- }
- return $has;
- }
- /**
- * Logs a message into a file
- * @param string Message to log
- * @return boolean True on success, false on error or if msg empty
- */
- function log($msg) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::log()', 0);
- }
- //TODO
- $this->error .= $msg . "\n";
- return true;
- }
- /**
- * Moves an item up and down at its level
- * @param integer Item to move up and down
- * @param string Direction 'up' or 'down'
- * @return integer New display order, or false on error
- */
- function move_item($id, $direction) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
- }
- if (empty ($id) or empty ($direction)) {
- return false;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_sel = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $id;
- $res_sel = Database::query($sql_sel, __FILE__, __LINE__);
- //check if elem exists
- if (Database :: num_rows($res_sel) < 1) {
- return false;
- }
- //gather data
- $row = Database :: fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
- //update the item (switch with previous/next one)
- switch ($direction) {
- case 'up' :
- if ($this->debug > 2) {
- error_log('Movement up detected', 0);
- }
- if ($display <= 1) { /*do nothing*/
- } else {
- $sql_sel2 = "SELECT *
- FROM $tbl_lp_item
- WHERE id = $previous";
- if ($this->debug > 2) {
- error_log('Selecting previous: ' . $sql_sel2, 0);
- }
- $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
- if (Database :: num_rows($res_sel2) < 1) {
- $previous_previous = 0;
- }
- //gather data
- $row2 = Database :: fetch_array($res_sel2);
- $previous_previous = $row2['previous_item_id'];
- //update previous_previous item (switch "next" with current)
- if ($previous_previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- //update previous item (switch with current)
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- //update current item (switch with previous)
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- //update next item (new previous item)
- if ($next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
- if ($this->debug > 2) {
- error_log($sql_upd2, 0);
- }
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- $display = $display -1;
- }
- break;
- case 'down' :
- if ($this->debug > 2) {
- error_log('Movement down detected', 0);
- }
- if ($next == 0) { /*do nothing*/
- } else {
- $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
- if ($this->debug > 2) {
- error_log('Selecting next: ' . $sql_sel2, 0);
- }
- $res_sel2 = Database::query($sql_sel2, __FILE__, __LINE__);
- if (Database :: num_rows($res_sel2) < 1) {
- $next_next = 0;
- }
- //gather data
- $row2 = Database :: fetch_array($res_sel2);
- $next_next = $row2['next_item_id'];
- //update previous item (switch with current)
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- //update current item (switch with previous)
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- //update next item (new previous item)
- if ($next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- //update next_next item (switch "previous" with current)
- if ($next_next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
- $res_upd2 = Database::query($sql_upd2, __FILE__, __LINE__);
- }
- $display = $display +1;
- }
- break;
- default :
- return false;
- }
- return $display;
- }
- /**
- * Move a learnpath up (display_order)
- * @param integer Learnpath ID
- */
- function move_up($lp_id) {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql, __FILE__, __LINE__);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
- //first check the order is correct, globally (might be wrong because
- //of versions < 1.8.4)
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u, __FILE__, __LINE__);
- }
- $row['display_order'] = $i;
- $lps[$row['id']] = $row;
- $lp_order[$i] = $row['id'];
- $i++;
- }
- }
- if ($num > 1) //if there's only one element, no need to sort
- {
- $order = $lps[$lp_id]['display_order'];
- if ($order > 1) //if it's the first element, no need to move up
- {
- $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order -1];
- $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
- $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order -1) . " WHERE id = " . $lp_id;
- $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
- }
- }
- }
- /**
- * Move a learnpath down (display_order)
- * @param integer Learnpath ID
- */
- function move_down($lp_id) {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql, __FILE__, __LINE__);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
- $max = 0;
- //first check the order is correct, globally (might be wrong because
- //of versions < 1.8.4)
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- $max = $i;
- if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u, __FILE__, __LINE__);
- }
- $row['display_order'] = $i;
- $lps[$row['id']] = $row;
- $lp_order[$i] = $row['id'];
- $i++;
- }
- }
- if ($num > 1) //if there's only one element, no need to sort
- {
- $order = $lps[$lp_id]['display_order'];
- if ($order < $max) //if it's the first element, no need to move up
- {
- $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order +1];
- $res_u1 = Database::query($sql_u1, __FILE__, __LINE__);
- $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order +1) . " WHERE id = " . $lp_id;
- $res_u2 = Database::query($sql_u2, __FILE__, __LINE__);
- }
- }
- }
- /**
- * Updates learnpath attributes to point to the next element
- * The last part is similar to set_current_item but processing the other way around
- */
- function next() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::next()', 0);
- }
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_next_index();
- if ($this->debug > 2) {
- error_log('New LP - New index: ' . $new_index, 0);
- }
- $this->index = $new_index;
- if ($this->debug > 2) {
- error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
- }
- $this->current = $this->ordered_items[$new_index];
- if ($this->debug > 2) {
- error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
- }
- }
- /**
- * Open a resource = initialise all local variables relative to this resource. Depending on the child
- * class, this might be redefined to allow several behaviours depending on the document type.
- * @param integer Resource ID
- * @return boolean True on success, false otherwise
- */
- function open($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::open()', 0);
- }
- //TODO
- //set the current resource attribute to this resource
- //switch on element type (redefine in child class?)
- //set status for this item to "opened"
- //start timer
- //initialise score
- $this->index = 0; //or = the last item seen (see $this->last)
- }
- /**
- * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
- * and the prerequisite string on error.
- * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
- * @param integer Optional item ID. If none given, uses the current open item.
- * @return boolean True if prerequisites are matched, false otherwise
- * @return string Empty string if true returned, prerequisites string otherwise.
- */
- function prerequisites_match($item = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::prerequisites_match()', 0);
- }
- if (empty ($item)) {
- $item = $this->current;
- }
- if (is_object($this->items[$item])) {
- $prereq_string = $this->items[$item]->get_prereq_string();
- if (empty ($prereq_string)) {
- return true;
- }
- //clean spaces
- $prereq_string = str_replace(' ', '', $prereq_string);
- if ($this->debug > 0) {
- error_log('Found prereq_string: ' . $prereq_string, 0);
- }
- //now send to the parse_prereq() function that will check this component's prerequisites
- $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
- if ($result === false) {
- $this->set_error_msg($this->items[$item]->prereq_alert);
- }
- } else {
- $result = true;
- if ($this->debug > 1) {
- error_log('New LP - $this->items[' . $item . '] was not an object', 0);
- }
- }
- if ($this->debug > 1) {
- error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
- }
- return $result;
- }
- /**
- * Updates learnpath attributes to point to the previous element
- * The last part is similar to set_current_item but processing the other way around
- */
- function previous() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::previous()', 0);
- }
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_previous_index();
- $this->index = $new_index;
- $this->current = $this->ordered_items[$new_index];
- }
- /**
- * Publishes a learnpath. This basically means show or hide the learnpath
- * to normal users.
- * Can be used as abstract
- * @param integer Learnpath ID
- * @param string New visibility
- */
- function toggle_visibility($lp_id, $set_visibility = 1) {
- //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
- $action = 'visible';
- if ($set_visibility != 1) {
- $action = 'invisible';
- }
- return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
- }
- /**
- * Publishes a learnpath. This basically means show or hide the learnpath
- * on the course homepage
- * Can be used as abstract
- * @param integer Learnpath ID
- * @param string New visibility
- */
- function toggle_publish($lp_id, $set_visibility = 'v') {
- //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $name = domesticate($row['name']);
- if ($set_visibility == 'i') {
- $s = $name . " " . get_lang('_no_published');
- $dialogBox = $s;
- $v = 0;
- }
- if ($set_visibility == 'v') {
- $s = $name . " " . get_lang('_published');
- $dialogBox = $s;
- $v = 1;
- }
- $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
- $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
- $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
- $result = Database::query($sql, __FILE__, __LINE__);
- $num = Database :: num_rows($result);
- $row2 = Database :: fetch_array($result);
- //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
- if (($set_visibility == 'i') && ($num > 0)) {
- $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
- }
- elseif (($set_visibility == 'v') && ($num == 0)) {
- $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)";
- } else {
- //parameter and database incompatible, do nothing
- }
- $result = Database::query($sql, __FILE__, __LINE__);
- //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
- }
- /**
- * Restart the whole learnpath. Return the URL of the first element.
- * Make sure the results are saved with anoter method. This method should probably be
- * redefined in children classes.
- * To use a similar method statically, use the create_new_attempt() method
- * @return string URL to load in the viewer
- */
- function restart() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::restart()', 0);
- }
- //TODO
- //call autosave method to save the current progress
- //$this->index = 0;
- $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
- $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
- "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ")";
- if ($this->debug > 2) {
- error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
- }
- $res = Database::query($sql, __FILE__, __LINE__);
- if ($view_id = Database :: insert_id($res)) {
- $this->lp_view_id = $view_id;
- $this->attempt = $this->attempt + 1;
- } else {
- $this->error = 'Could not insert into item_view table...';
- return false;
- }
- $this->autocomplete_parents($this->current);
- foreach ($this->items as $index => $dummy) {
- $this->items[$index]->restart();
- $this->items[$index]->set_lp_view($this->lp_view_id);
- }
- $this->first();
- return true;
- }
- /**
- * Saves the current item
- * @return boolean
- */
- function save_current() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_current()', 0);
- }
- //TODO do a better check on the index pointing to the right item (it is supposed to be working
- // on $ordered_items[] but not sure it's always safe to use with $items[])
- if ($this->debug > 2) {
- error_log('New LP - save_current() saving item ' . $this->current, 0);
- }
- if ($this->debug > 2) {
- error_log('' . print_r($this->items, true), 0);
- }
- if (is_object($this->items[$this->current])) {
- //$res = $this->items[$this->current]->save(false);
- $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
- $this->autocomplete_parents($this->current);
- $status = $this->items[$this->current]->get_status();
- $this->append_message('new_item_status: ' . $status);
- $this->update_queue[$this->current] = $status;
- return $res;
- }
- return false;
- }
- /**
- * Saves the given item
- * @param integer Item ID. Optional (will take from $_REQUEST if null)
- * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
- * @return boolean
- */
- function save_item($item_id = null, $from_outside = true) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
- }
- //TODO do a better check on the index pointing to the right item (it is supposed to be working
- // on $ordered_items[] but not sure it's always safe to use with $items[])
- if (empty ($item_id)) {
- $item_id = $this->escape_string($_REQUEST['id']);
- }
- if (empty ($item_id)) {
- $item_id = $this->get_current_item_id();
- }
- if ($this->debug > 2) {
- error_log('New LP - save_current() saving item ' . $item_id, 0);
- }
- if (is_object($this->items[$item_id])) {
- $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
- //$res = $this->items[$item_id]->save($from_outside);
- $this->autocomplete_parents($item_id);
- $status = $this->items[$item_id]->get_status();
- $this->append_message('new_item_status: ' . $status);
- $this->update_queue[$item_id] = $status;
- return $res;
- }
- return false;
- }
- /**
- * Saves the last item seen's ID only in case
- */
- function save_last()
- {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::save_last()', 0);
- }
- $table = Database :: get_course_table(TABLE_LP_VIEW);
- if (isset ($this->current)) {
- if ($this->debug > 2) {
- error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
- }
- $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
- "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id();
- if ($this->debug > 2) {
- error_log('New LP - Saving last item seen : ' . $sql, 0);
- }
- $res = Database::query($sql, __FILE__, __LINE__);
- }
- //save progress
- list ($progress, $text) = $this->get_progress_bar_text('%');
- if ($progress >= 0 AND $progress <= 100) {
- $progress = (int) $progress;
- $sql = "UPDATE $table SET progress = $progress " .
- "WHERE lp_id = " . $this->get_id() . " AND " .
- "user_id = " . $this->get_user_id();
- $res = Database::query($sql, __FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
- $this->progress_db = $progress;
- }
- }
- /**
- * Sets the current item ID (checks if valid and authorized first)
- * @param integer New item ID. If not given or not authorized, defaults to current
- */
- function set_current_item($item_id = null) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
- }
- if (empty ($item_id)) {
- if ($this->debug > 2) {
- error_log('New LP - No new current item given, ignore...', 0);
- }
- //do nothing
- } else {
- if ($this->debug > 2) {
- error_log('New LP - New current item given is ' . $item_id . '...', 0);
- }
- if (is_numeric($item_id)) {
- $item_id = $this->escape_string($item_id);
- //TODO check in database here
- $this->last = $this->current;
- $this->current = $item_id;
- //TODO update $this->index as well
- foreach ($this->ordered_items as $index => $item) {
- if ($item == $this->current) {
- $this->index = $index;
- break;
- }
- }
- if ($this->debug > 2) {
- error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
- }
- } else {
- error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
- }
- }
- }
- /**
- * Sets the encoding
- * @param string New encoding
- */
- function set_encoding($enc = 'ISO-8859-15') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_encoding()', 0);
- }
- $enc = strtoupper($enc);
- $encodings = array (
- 'UTF-8',
- 'ISO-8859-1',
- 'ISO-8859-15',
- 'cp1251',
- 'cp1252',
- 'KOI8-R',
- 'BIG5',
- 'GB2312',
- 'Shift_JIS',
- 'EUC-JP',
- ''
- );
- if (in_array($enc, $encodings)) {
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
- $res = Database::query($sql, __FILE__, __LINE__);
- return $res;
- }
- }
- return false;
- }
- /**
- * Sets the JS lib setting in the database directly.
- * This is the JavaScript library file this lp needs to load on startup
- * @param string Proximity setting
- */
- function set_jslib($lib = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_jslib()', 0);
- }
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
- $res = Database::query($sql, __FILE__, __LINE__);
- return $res;
- } else {
- return false;
- }
- }
- /**
- * Sets the name of the LP maker (publisher) (and save)
- * @param string Optional string giving the new content_maker of this learnpath
- */
- function set_maker($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_maker()', 0);
- }
- if (empty ($name))
- return false;
- $this->maker = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
- }
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- return true;
- }
- /**
- * Sets the name of the current learnpath (and save)
- * @param string Optional string giving the new name of this learnpath
- */
- function set_name($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_name()', 0);
- }
- if (empty ($name))
- return false;
- $this->name = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new name : ' . $this->name, 0);
- }
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- // if the lp is visible on the homepage, change his name there
- if (Database::affected_rows()) {
- $table = Database :: get_course_table(TABLE_TOOL_LIST);
- $sql = 'UPDATE ' . $table . ' SET
- name = "' . $this->name . '"
- WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
- Database::query($sql, __FILE__, __LINE__);
- }
- return true;
- }
- /**
- * Set index specified prefix terms for all items in this path
- * @param string Comma-separated list of terms
- * @param char Xapian term prefix
- * @return boolean False on error, true otherwise
- */
- function set_terms_by_prefix($terms_string, $prefix) {
- if (api_get_setting('search_enabled') !== 'true')
- return FALSE;
- $terms_string = trim($terms_string);
- $terms = explode(',', $terms_string);
- array_walk($terms, 'trim_value');
- $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
- //var_dump($stored_terms);
- //var_dump($terms);
- // don't do anything if no change, verify only at DB, not the search engine
- if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
- return FALSE;
- require_once ('xapian.php'); //TODO try catch every xapian use or make wrappers on api
- require_once (api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
- require_once (api_get_path(LIBRARY_PATH) . 'search/xapian/XapianQuery.php');
- require_once (api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
- $items_table = Database :: get_course_table(TABLE_LP_ITEM);
- //TODO: make query secure agains XSS : use member attr instead of post var
- $lp_id = intval($_POST['lp_id']);
- $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
- $result = Database::query($sql);
- $di = new DokeosIndexer();
- while ($lp_item = Database :: fetch_array($result)) {
- // get search_did
- $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $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';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database::num_rows($res)>0) {
- $se_ref = Database :: fetch_array($res);
- // compare terms
- $doc = $di->get_document($se_ref['search_did']);
- $xapian_terms = xapian_get_doc_terms($doc, $prefix);
- //var_dump($xapian_terms);
- $xterms = array ();
- foreach ($xapian_terms as $xapian_term)
- $xterms[] = substr($xapian_term['name'], 1);
- $dterms = $terms;
- //var_dump($xterms);
- //var_dump($dterms);
- $missing_terms = array_diff($dterms, $xterms);
- $deprecated_terms = array_diff($xterms, $dterms);
- // save it to search engine
- foreach ($missing_terms as $term) {
- $doc->add_term($prefix . $term, 1);
- }
- foreach ($deprecated_terms as $term) {
- $doc->remove_term($prefix . $term);
- }
- $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
- $di->getDb()->flush();
- }
- }
- return true;
- }
- /**
- * Sets the theme of the LP (local/remote) (and save)
- * @param string Optional string giving the new theme of this learnpath
- * @return bool returns true if theme name is not empty
- */
- function set_theme($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_theme()', 0);
- }
- $this->theme = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
- }
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- return true;
- }
- /**
- * Sets the image of an LP (and save)
- * @param string Optional string giving the new image of this learnpath
- * @return bool returns true if theme name is not empty
- */
- function set_preview_image($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_preview_image()', 0);
- }
- $this->preview_image = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
- }
- $res = Database::query($sql, __FILE__, __LINE__);
- return true;
- }
- /**
- * Sets the author of a LP (and save)
- * @param string Optional string giving the new author of this learnpath
- * @return bool returns true if author's name is not empty
- */
- function set_author($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_author()', 0);
- }
- $this->author = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
- }
- $res = Database::query($sql, __FILE__, __LINE__);
- return true;
- }
- /**
- * Sets the location/proximity of the LP (local/remote) (and save)
- * @param string Optional string giving the new location of this learnpath
- */
- function set_proximity($name = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_proximity()', 0);
- }
- if (empty ($name))
- return false;
- $this->proximity = $this->escape_string($name);
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
- if ($this->debug > 2) {
- error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
- }
- //$res = Database::query($sql);
- $res = Database::query($sql, __FILE__, __LINE__);
- return true;
- }
- /**
- * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
- * @param integer DB ID of the item
- */
- function set_previous_item($id) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_previous_item()', 0);
- }
- $this->last = $id;
- }
- /**
- * Sets the object's error message
- * @param string Error message. If empty, reinits the error string
- * @return void
- */
- function set_error_msg($error = '') {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::set_error_msg()', 0);
- }
- if (empty ($error)) {
- $this->error = '';
- } else {
- $this->error .= $error;
- }
- }
- /**
- * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
- *
- */
- function start_current_item($allow_new_attempt = false) {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::start_current_item()', 0);
- }
- if ($this->current != 0 AND is_object($this->items[$this->current])) {
- $type = $this->get_type();
- $item_type = $this->items[$this->current]->get_type();
- if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
- $this->items[$this->current]->open($allow_new_attempt);
- $this->autocomplete_parents($this->current);
- $prereq_check = $this->prerequisites_match($this->current);
- $this->items[$this->current]->save(false, $prereq_check);
- //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
- } else {
- //if sco, then it is supposed to have been updated by some other call
- }
- if ($item_type == 'sco') {
- $this->items[$this->current]->restart();
- }
- }
- if ($this->debug > 0) {
- error_log('New LP - End of learnpath::start_current_item()', 0);
- }
- return true;
- }
- /**
- * Stops the processing and counters for the old item (as held in $this->last)
- * @param
- */
- function stop_previous_item() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::stop_previous_item()', 0);
- }
- if ($this->last != 0 AND $this->last != $this->current AND is_object($this->items[$this->last])) {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
- }
- switch ($this->get_type()) {
- case '3' :
- if ($this->items[$this->last]->get_type() != 'au') {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
- }
- $this->items[$this->last]->close();
- //$this->autocomplete_parents($this->last);
- //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
- }
- }
- case '2' :
- if ($this->items[$this->last]->get_type() != 'sco') {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
- }
- $this->items[$this->last]->close();
- //$this->autocomplete_parents($this->last);
- //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
- }
- }
- break;
- case '1' :
- default :
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
- }
- $this->items[$this->last]->close();
- break;
- }
- } else {
- if ($this->debug > 2) {
- error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
- }
- return false;
- }
- return true;
- }
- /**
- * Updates the default view mode from fullscreen to embedded and inversely
- * @return string The current default view mode ('fullscreen' or 'embedded')
- */
- function update_default_view_mode() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_default_view_mode()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $view_mode = $row['default_view_mod'];
- if ($view_mode == 'fullscreen') {
- $view_mode = 'embedded';
- }
- elseif ($view_mode == 'embedded') {
- $view_mode = 'fullscreen';
- }
- $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- $this->mode = $view_mode;
- return $view_mode;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
- /**
- * Updates the default behaviour about auto-commiting SCORM updates
- * @return boolean True if auto-commit has been set to 'on', false otherwise
- */
- function update_default_scorm_commit() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['force_commit'];
- if ($force == 1) {
- $force = 0;
- $force_return = false;
- }
- elseif ($force == 0) {
- $force = 1;
- $force_return = true;
- }
- $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- $this->force_commit = $force_return;
- return $force_return;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
- /**
- * Updates the order of learning paths (goes through all of them by order and fills the gaps)
- * @return bool True on success, false on failure
- */
- function update_display_order() {
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table ORDER BY display_order";
- $res = Database::query($sql, __FILE__, __LINE__);
- if ($res === false)
- return false;
- $lps = array ();
- $lp_order = array ();
- $num = Database :: num_rows($res);
- //first check the order is correct, globally (might be wrong because
- //of versions < 1.8.4)
- if ($num > 0) {
- $i = 1;
- while ($row = Database :: fetch_array($res)) {
- if ($row['display_order'] != $i) { //if we find a gap in the order, we need to fix it
- $need_fix = true;
- $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
- $res_u = Database::query($sql_u, __FILE__, __LINE__);
- }
- $i++;
- }
- }
- return true;
- }
- /**
- * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
- * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
- */
- function update_reinit() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_reinit()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['prevent_reinit'];
- if ($force == 1) {
- $force = 0;
- }
- elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- $this->prevent_reinit = $force;
- return $force;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
- /**
- * Updates the "scorm_debug" value that shows or hide the debug window
- * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
- */
- function update_scorm_debug() {
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::update_scorm_debug()', 0);
- }
- $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- $force = $row['debug'];
- if ($force == 1) {
- $force = 0;
- }
- elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
- $res = Database::query($sql, __FILE__, __LINE__);
- $this->scorm_debug = $force;
- return $force;
- } else {
- if ($this->debug > 2) {
- error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
- }
- }
- return -1;
- }
- /**
- * Function that makes a call to the function sort_tree_array and create_tree_array
- *
- * @author Kevin Van Den Haute
- *
- * @param unknown_type $array
- */
- function tree_array($array) {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::tree_array()', 0);
- }
- $array = $this->sort_tree_array($array);
- $this->create_tree_array($array);
- }
- /**
- * Creates an array with the elements of the learning path tree in it
- *
- * @author Kevin Van Den Haute
- *
- * @param array $array
- * @param int $parent
- * @param int $depth
- * @param array $tmp
- */
- function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
- if ($this->debug > 1) {
- error_log('New LP - In learnpath::create_tree_array())', 0);
- }
- if (is_array($array)) {
- for ($i = 0; $i < count($array); $i++) {
- if ($array[$i]['parent_item_id'] == $parent) {
- if (!in_array($array[$i]['parent_item_id'], $tmp)) {
- $tmp[] = $array[$i]['parent_item_id'];
- $depth++;
- }
- $preq = (empty ($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
- $this->arrMenu[] = array (
- 'id' => $array[$i]['id'],
- 'item_type' => $array[$i]['item_type'],
- 'title' => $array[$i]['title'],
- 'path' => $array[$i]['path'],
- 'description' => $array[$i]['description'],
- 'parent_item_id' => $array[$i]['parent_item_id'],
- 'previous_item_id' => $array[$i]['previous_item_id'],
- 'next_item_id' => $array[$i]['next_item_id'],
- 'min_score' => $array[$i]['min_score'],
- 'max_score' => $array[$i]['max_score'],
- 'mastery_score' => $array[$i]['mastery_score'],
- 'display_order' => $array[$i]['display_order'],
- 'prerequisite' => $preq,
- 'depth' => $depth,
- 'audio' => $array[$i]['audio']
- );
- $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
- }
- }
- }
- }
- /**
- * Sorts a multi dimensional array by parent id and display order
- * @author Kevin Van Den Haute
- *
- * @param array $array (array with al the learning path items in it)
- *
- * @return array
- */
- function sort_tree_array($array) {
- foreach ($array as $key => $row) {
- $parent[$key] = $row['parent_item_id'];
- $position[$key] = $row['display_order'];
- }
- if (count($array) > 0)
- array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
- return $array;
- }
- /**
- * Function that creates a table structure with a learning path his modules, chapters and documents.
- * Also the actions for the modules, chapters and documents are in this table.
- *
- * @author Kevin Van Den Haute
- *
- * @param int $lp_id
- *
- * @return string
- */
- function overview() {
- $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
- $platform_charset = api_get_system_encoding();
- if ($this->debug > 0) {
- error_log('New LP - In learnpath::overview()', 0);
- }
- global $charset, $_course;
- $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
- $return = '';
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
- $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'display_order' => $row['display_order'],
- 'audio' => $row['audio']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($is_allowed_to_edit) {
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
- $return .= '<div class="actions">';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=build&lp_id=' . $this->lp_id . '" title="' . get_lang("Build") . '">' . Display :: return_icon('learnpath_build.gif', get_lang('Build')) . ' ' . get_lang('Build') . '</a>';
- $return .= '<span>' . Display :: return_icon('learnpath_organize_na.gif', get_lang("BasicOverview")) . ' <b>' . get_lang('BasicOverview') . '</b></span>';
- $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');
- $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=' . Security :: remove_XSS($_GET['action']) . '&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=chapter&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>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=step&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>';
- $return .= '</div>';
- }
- // we need to start a form when we want to update all the mp3 files
- if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
- $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=' . Security :: remove_XSS($_GET['action']) . '&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
- $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
- }
- $return .= '<table class="data_table">' . "\n";
- $return .= "\t" . '<tr>' . "\n";
- $return .= "\t" . '<th width="60%">' . get_lang("Title") . '</th>' . "\n";
- //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
- $return .= "\t" . '<th>' . get_lang("Audio") . '</th>' . "\n";
- $return .= "\t" . '<th>' . get_lang("Move") . '</th>' . "\n";
- $return .= "\t" . '<th>' . get_lang("Actions") . '</th>' . "\n";
- $return .= "\t" . '</tr>' . "\n";
- for ($i = 0; $i < count($arrLP); $i++) {
- $title = $arrLP[$i]['title'];
- if ($arrLP[$i]['description'] == '')
- $arrLP[$i]['description'] = ' ';
- if (($i % 2) == 0) {
- $oddclass = "row_odd";
- } else {
- $oddclass = "row_even";
- }
- $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists("../img/lp_" . $icon_name . ".png")) {
- $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";
- } else
- if (file_exists("../img/lp_" . $icon_name . ".gif")) {
- $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";
- } else {
- //$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";
- $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";
- }
- //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
- // The audio column
- $return .= "\t\t" . '<td align="center">';
- if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
- if (!empty ($arrLP[$i]['audio'])) {
- $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
- $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $return .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
- s1.write("container' . $i . '");
- </script>';
- } else {
- $return .= ' - ';
- }
- } else {
- if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
- $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
- if (!empty ($arrLP[$i]['audio'])) {
- $return .= '<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
- }
- }
- }
- $return .= '</td>' . "\n";
- if ($is_allowed_to_edit) {
- $return .= "\t\t" . '<td align="center">' . "\n";
- if ($arrLP[$i]['previous_item_id'] != 0) {
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=move_item&direction=up&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
- $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
- $return .= '</a>' . "\n";
- } else
- $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
- if ($arrLP[$i]['next_item_id'] != 0) {
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=move_item&direction=down&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
- $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
- $return .= '</a>' . "\n";
- } else
- $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
- $return .= "\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '<td align="center">' . "\n";
- if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=edit_item&view=build&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&path_item=' . $arrLP[$i]['path'] . '">';
- $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- } else {
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=edit_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '&path_item=' . $arrLP[$i]['path'] . '">';
- $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- }
- $return .= "\t\t\t" . '<a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=delete_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($title) . '\');">';
- $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
- $return .= '</a>' . "\n";
- $return .= "\t\t" . '</td>' . "\n";
- }
- $return .= "\t" . '</tr>' . "\n";
- }
- if (count($arrLP) == 0) {
- $return .= "\t" . '<tr>' . "\n";
- $return .= "\t\t" . '<td colspan="4">' . get_lang("NoItemsInLp") . '</td>' . "\n";
- $return .= "\t" . '</tr>' . "\n";
- }
- $return .= '</table>' . "\n";
- // we need to close the form when we are updating the mp3 files
- if ($_GET['updateaudio'] == 'true') {
- $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?
- }
- // we need to close the form when we are updating the mp3 files
- if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
- $return .= '</form>';
- }
- return $return;
- }
- /**
- * This function builds the action menu
- *
- * */
- function build_action_menu() {
- $gradebook = Security :: remove_XSS($_GET['gradebook']);
- echo '<div class="actions">';
- //echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
- echo '<span>' . Display :: return_icon('learnpath_build_na.gif', get_lang('Build')) . ' <b>' . get_lang('Build') . '</b></span>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=admin_view&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("BasicOverview") . '">' . Display :: return_icon('learnpath_organize.gif', get_lang('BasicOverview')) . ' ' . get_lang('BasicOverview') . '</a>';
- echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('learnpath_view.gif', get_lang('Display')) . ' ' . get_lang('Display') . '</a>';
- Display :: display_icon('i.gif');
- echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('edit.gif', get_lang('CourseSettings')) . ' ' . get_lang('CourseSettings') . '</a>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=admin_view&lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&updateaudio=true">' . Display :: return_icon('audio.gif', get_lang('UpdateAllAudioFragments')) . ' ' . get_lang('UpdateAllAudioFragments') . '</a>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=chapter&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>';
- echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&gradebook=' . $gradebook . '&action=add_item&type=step&lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang("NewStep") . '">' . Display :: return_icon('new_test.gif', get_lang('NewStep')) . ' ' . get_lang("NewStep") . '</a>';
- echo '</div>';
- }
- /**
- * This functions builds the LP tree based on data from the database.
- *
- * @return string
- * @uses dtree.js :: necessary javascript for building this tree
- */
- function build_tree() {
- $platform_charset = api_get_system_encoding();
- $return = "<script type=\"text/javascript\">\n";
- $return .= "\tm = new dTree('m');\n\n";
- $return .= "\tm.config.folderLinks = true;\n";
- $return .= "\tm.config.useCookies = true;\n";
- $return .= "\tm.config.useIcons = true;\n";
- $return .= "\tm.config.useLines = true;\n";
- $return .= "\tm.config.useSelection = true;\n";
- $return .= "\tm.config.useStatustext = false;\n\n";
- $menu = 0;
- $parent = '';
- $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = " SELECT * FROM " . $tbl_lp_item . "
- WHERE lp_id = " . Database :: escape_string($this->lp_id);
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], $platform_charset, $this->encoding));
- $row['description'] = Security :: remove_XSS(api_convert_encoding($row['description'], $platform_charset, $this->encoding));
- //$row['title'] = Security :: remove_XSS($row['title']);
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'display_order' => $row['display_order']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- $title = '';
- for ($i = 0; $i < count($arrLP); $i++) {
- $title = addslashes($arrLP[$i]['title']);
- $menu_page = api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $_SESSION['oLP']->lp_id;
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists("../img/lp_" . $icon_name . ".png")) {
- $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";
- } else
- if (file_exists("../img/lp_" . $icon_name . ".gif")) {
- $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";
- } else {
- $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
- }
- if ($menu < $arrLP[$i]['id'])
- $menu = $arrLP[$i]['id'];
- }
- $return .= "\n\tdocument.write(m);\n";
- $return .= "\t if(!m.selectedNode) m.s(1);";
- $return .= "</script>\n";
- return $return;
- }
- /**
- * Create a new document //still needs some finetuning
- *
- * @param array $_course
- * @return string
- */
- function create_document($_course) {
- global $charset;
- $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
- if (strstr($dir, '..'))
- $dir = '/';
- if ($dir[0] == '.')
- $dir = substr($dir, 1);
- if ($dir[0] != '/')
- $dir = '/' . $dir;
- if ($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
- if (!is_dir($filepath)) {
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
- $dir = '/';
- }
- //stripslashes before calling replace_dangerous_char() because $_POST['title']
- //is already escaped twice when it gets here
- $title = replace_dangerous_char(stripslashes($_POST['title']));
- $title = disable_dangerous_file($title);
- $filename = $title;
- $content = $_POST['content_lp'];
- $tmp_filename = $filename;
- $i = 0;
- while (file_exists($filepath . $tmp_filename . '.html'))
- $tmp_filename = $filename . '_' . ++ $i;
- $filename = $tmp_filename . '.html';
- $content = stripslashes(text_filter($content));
- $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH) . 'courses/', $content);
- // change the path of mp3 to absolute
- // first regexp deals with ../../../ urls
- $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
- //second regexp deals with audio/ urls
- $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
- // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
- $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
- if (!file_exists($filepath . $filename)) {
- if ($fp = @ fopen($filepath . $filename, 'w')) {
- fputs($fp, $content);
- fclose($fp);
- $file_size = filesize($filepath . $filename);
- $save_file_path = $dir . $filename;
- $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
- if ($document_id) {
- api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(),null,null,null,null,api_get_session_id());
- //update parent folders
- //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
- $new_comment = (isset ($_POST['comment'])) ? trim($_POST['comment']) : '';
- $new_title = (isset ($_POST['title'])) ? trim($_POST['title']) : '';
- if ($new_comment || $new_title) {
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $ct = '';
- if ($new_comment)
- $ct .= ", comment='" . $new_comment . "'";
- if ($new_title)
- $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
- $sql_update = "
- UPDATE " . $tbl_doc . "
- SET " . substr($ct, 1) . "
- WHERE id = " . $document_id;
- Database::query($sql_update, __FILE__, __LINE__);
- }
- }
- return $document_id;
- }
- }
- }
- /**
- * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
- *
- * @param array $_course array
- * @return void
- */
- function edit_document($_course) {
- global $_configuration;
- $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
- if (strstr($dir, '..'))
- $dir = '/';
- if ($dir[0] == '.')
- $dir = substr($dir, 1);
- if ($dir[0] != '/')
- $dir = '/' . $dir;
- if ($dir[strlen($dir) - 1] != '/')
- $dir .= '/';
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
- if (!is_dir($filepath)) {
- $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
- $dir = '/';
- }
- $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
- if (isset($_POST['path']) && !empty($_POST['path'])) {
- $sql = "SELECT path
- FROM " . $table_doc . "
- WHERE id = " . Database::escape_string($_POST['path']);
- $res = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($res);
- $content = stripslashes($_POST['content_lp']);
- $file = $filepath . $row['path'];
- if ($fp = @ fopen($file, 'w')) {
- $content = text_filter($content);
- $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'] . '/courses/', $content);
- // change the path of mp3 to absolute
- // first regexp deals with ../../../ urls
- $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
- //second regexp deals with audio/ urls
- $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
- fputs($fp, $content);
- fclose($fp);
- }
- }
- }
- /**
- * Displays the selected item, with a panel for manipulating the item
- *
- * @param int $item_id
- * @param string $msg
- * @return string
- */
- function display_item($item_id, $iframe = true, $msg = '') {
- global $_course; //will disappear
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT lp.*
- FROM " . $tbl_lp_item . " as lp
- WHERE lp.id = " . Database :: escape_string($item_id);
- $result = Database::query($sql, __FILE__, __LINE__);
- while ($row = Database :: fetch_array($result)) {
- $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= '<div style="padding:10px;">';
- if ($msg != '')
- $return .= $msg;
- $row['title'] = Security :: remove_XSS(api_convert_encoding($row['title'], api_get_system_encoding(), $this->encoding));
- //$row['title'] = Security::remove_XSS(api_convert_encoding($row['title'], $this->encoding, api_get_system_encoding()));
- $return .= '<p class="lp_title">' . $row['title'] . '</p>';
- //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
- //$return .= '<hr />';
- if ($row['item_type'] == TOOL_DOCUMENT) {
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
- $result = Database::query($sql_doc, __FILE__, __LINE__);
- $path_file = Database :: result($result, 0, 0);
- $path_parts = pathinfo($path_file);
- if (in_array($path_parts['extension'], array (
- 'html',
- 'txt',
- 'png',
- 'jpg',
- 'JPG',
- 'jpeg',
- 'JPEG',
- 'gif',
- 'swf'
- ))) {
- $return .= $this->display_document($row['path'], true, true);
- }
- }
- $return .= '</div>';
- }
- }
- return $return;
- }
- /**
- * Shows the needed forms for editing a specific item
- *
- * @param int $item_id
- * @return string
- */
- function display_edit_item($item_id) {
- global $_course; //will disappear
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . Database :: escape_string($item_id);
- $res = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($res);
- switch ($row['item_type']) {
- case 'dokeos_chapter' :
- case 'dir' :
- case 'asset' :
- case 'sco' :
- if (isset ($_GET['view']) && $_GET['view'] == 'build') {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', 'edit', $item_id, $row);
- } else {
- $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter") . ' :', $row);
- }
- break;
- case TOOL_DOCUMENT :
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_step = " SELECT lp.*, doc.path as dir
- FROM " . $tbl_lp_item . " as lp
- LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
- WHERE lp.id = " . Database :: escape_string($item_id);
- $res_step = Database::query($sql_step, __FILE__, __LINE__);
- $row_step = Database :: fetch_array($res_step);
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('edit', $item_id, $row_step);
- break;
- case TOOL_LINK :
- $link_id = (string) $row['path'];
- if (ctype_digit($link_id)) {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
- $res_link = Database::query($sql_select, __FILE__, __LINE__);
- $row_link = Database :: fetch_array($res_link);
- if (is_array($row_link)) {
- $row['url'] = $row_link['url'];
- }
- }
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('edit', $item_id, $row);
- break;
- case 'dokeos_module' :
- if (isset ($_GET['view']) && $_GET['view'] == 'build') {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule") . ' :', 'edit', $item_id, $row);
- } else {
- $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule") . ' :', $row);
- }
- break;
- case TOOL_QUIZ :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('edit', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('edit', $item_id, $row);
- break;
- case TOOL_FORUM :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('edit', $item_id, $row);
- break;
- case TOOL_THREAD :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_thread_form('edit', $item_id, $row);
- break;
- }
- }
- return $return;
- }
- /**
- * Function that displays a list with al the resources that could be added to the learning path
- *
- * @return string
- */
- function display_resources() {
- global $_course; //TODO: don't use globals
- $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
- $return .= '<div class="sectioncomment"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&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.
- $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
- $return .= '<div class="sectioncomment">';
- /* get all the docs */
- $return .= $this->get_documents();
- /* get all the exercises */
- $return .= $this->get_exercises();
- /* get all the links */
- $return .= $this->get_links();
- /* get al the student publications */
- $return .= $this->get_student_publications();
- /* get al the forums */
- $return .= $this->get_forums();
- $return .= '</div>';
- return $return;
- }
- /**
- * Returns the extension of a document
- *
- * @param unknown_type $filename
- * @return unknown
- */
- function get_extension($filename) {
- $explode = explode('.', $filename);
- return $explode[count($explode) - 1];
- }
- /**
- * Displays a document by id
- *
- * @param unknown_type $id
- * @return unknown
- */
- function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
- global $_course; //temporary
- $return = '';
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT * FROM " . $tbl_doc . "
- WHERE id = " . $id;
- $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
- $row_doc = Database :: fetch_array($res_doc);
- //if($show_title)
- //$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $_GET['file'] . '&edit=true&lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
- //TODO: add a path filter
- if ($iframe) {
- $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>';
- } else {
- $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
- }
- return $return;
- }
- /**
- * Return HTML form to add/edit a quiz
- *
- * @param string Action (add/edit)
- * @param integer Item ID if already exists
- * @param mixed Extra information (quiz ID if integer)
- * @return string HTML form
- */
- function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_quiz = "
- SELECT
- title,
- description
- FROM " . $tbl_quiz . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_quiz, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'max_time_allowed' => $row['max_time_allowed']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang("CreateTheExercise") . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang("MoveTheCurrentExercise") . ' :' . "\n";
- else
- $return .= get_lang("EditCurrentExecice") . ' :' . "\n";
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
- }
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table class="lp_form">' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $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";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- $parent_item_id = $_SESSION['parent_item_id'];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $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>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- /*//comented the prerequisites, only visible in edit (exercise)
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
- foreach($arrHide as $key => $value){
- if($key==$s_selected_position && $action == 'add'){
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- }
- elseif($key==$id_prerequisite && $action == 'edit'){
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- }
- else{
- $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
- }
- }
- $return .= "</select></td>";
- */
- $return .= "\t\t" . '</tr>' . "\n";
- /*$return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
- //Remove temporaly the test description
- //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
- //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n"; */
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
- /**
- * Addition of Hotpotatoes tests
- * @param string Action
- * @param integer Internal ID of the item
- * @param mixed Extra information - can be an array with title and description indexes
- * @return string HTML structure to display the hotpotatoes addition formular
- */
- function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $uploadPath = DIR_HOTPOTATOES; //defined in main_api
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
- $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
- WHERE path LIKE '" . $uploadPath . "/%/%htm%'
- AND id = " . (int) $extra_info . " ORDER BY id ASC";
- $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
- $row = Database :: fetch_array($res_hot);
- $item_title = $row['title'];
- $item_description = $row['description'];
- if (!empty ($row['comment'])) {
- $item_title = $row['comment'];
- }
- } else {
- $item_title = '';
- $item_description = '';
- }
- $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
- $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
- $return = '<div style="margin:3px 12px;">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'max_time_allowed' => $row['max_time_allowed']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= '<p class="lp_title">' . get_lang("CreateTheExercise") . ' :</p>' . "\n";
- elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentExercise") . ' :</p>' . "\n";
- else
- $return .= '<p class="lp_title">' . get_lang("EditCurrentExecice") . ' :</p>' . "\n";
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang("Warning") . ' !</p>' . get_lang("WarningEditingDocument"));
- }
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- if (count($arrLP) > 0) {
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $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>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if (is_array($arrLP) && count($arrLP) > 0) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- }
- $return .= "\t\t" . '<tr>' . "\n";
- //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
- //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
- foreach ($arrHide as $key => $value) {
- if ($key == $s_selected_position && $action == 'add') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- }
- elseif ($key == $id_prerequisite && $action == 'edit') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- } else {
- $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
- }
- }
- $return .= "</select></td>";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- //Remove temporaly the test description
- //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
- //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddHotpotatoes') . '</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
- //fin du hotpot form
- /**
- * Return the form to display the forum edit/add option
- *
- * @param string Action (add/edit)
- * @param integer ID of the lp_item if already exists
- * @param mixed Forum ID or title
- * @return string HTML form
- */
- function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_forum = Database :: get_course_table(TABLE_FORUM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_forum = "
- SELECT
- forum_title as title, forum_comment as comment
- FROM " . $tbl_forum . "
- WHERE forum_id = " . $extra_info;
- $result = Database::query($sql_forum, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['comment'];
- } else {
- $item_title = '';
- $item_description = '';
- }
- $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
- $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang("CreateTheForum") . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang("MoveTheCurrentForum") . ' :' . "\n";
- else
- $return .= get_lang("EditCurrentForum") . ' :' . "\n";
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table class="lp_form">' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $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";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- $parent_item_id = $_SESSION['parent_item_id'];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $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>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- //Remove temporaly the test description
- //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
- //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- /* //comented the prerequisites, only visible in edit (forum)
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
- foreach($arrHide as $key => $value) {
- if($key==$s_selected_position && $action == 'add') {
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- }elseif($key==$id_prerequisite && $action == 'edit') {
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- } else {
- $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
- }
- }
- $return .= "</select></td>";
- */
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td> </td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
- /**
- * Return HTML form to add/edit forum threads
- * @param string Action (add/edit)
- * @param integer Item ID if already exists in learning path
- * @param mixed Extra information (thread ID if integer)
- * @return string HTML form
- */
- function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- echo '
- <style>
- div.row div.label {
- width:110px;
- }
- div.row div.formw {
- width: 82%;
- }
- </style>';
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_forum = "
- SELECT
- thread_title as title
- FROM " . $tbl_forum . "
- WHERE thread_id = " . $extra_info;
- $result = Database::query($sql_forum, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = '';
- } else {
- $item_title = '';
- $item_description = '';
- }
- $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
- $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
- $return = '<div style="margin:3px 12px;">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= '<p class="lp_title">' . get_lang("CreateTheForum") . ' :</p>' . "\n";
- elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang("MoveTheCurrentForum") . ' :</p>' . "\n";
- else
- $return .= '<p class="lp_title">' . get_lang("EditCurrentForum") . ' :</p>' . "\n";
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang("Parent") . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if ($arrLP != null) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang("Position") . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $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>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang("Title") . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- //Remove temporaly the test description
- //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
- //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if ($arrLP != null) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang("Prerequisites") . ' :</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang("NoPrerequisites") . '</option>';
- foreach ($arrHide as $key => $value) {
- if ($key == $s_selected_position && $action == 'add') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- }
- elseif ($key == $id_prerequisite && $action == 'edit') {
- $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
- } else {
- $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
- }
- }
- $return .= "</select></td>";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td colspan="2">
- <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
- /**
- * Return the HTML form to display an item (generally a section/module item)
- *
- * @param string Item type (module/dokeos_module)
- * @param string Title (optional, only when creating)
- * @param string Action ('add'/'edit')
- * @param integer lp_item ID
- * @param mixed Extra info
- * @return string HTML form
- */
- function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
- global $_course;
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = $extra_info['title'];
- $item_description = $extra_info['description'];
- $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
- if ($item_type == 'module')
- $sql .= " AND parent_item_id = 0";
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'display_order' => $row['display_order']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- $return .= $title . "\n";
- $return .= ' </div>
- </div>';
- require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
- $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"]);
- //$defaults["title"] = api_convert_encoding($item_title, $charset, $this->encoding);
- $defaults["title"] = api_html_entity_decode(api_convert_encoding($item_title, $charset, $this->encoding), ENT_QUOTES, $charset);
- $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
- $form->addElement('html', $return);
- //$arrHide = array($id);
- $arrHide[0]['value'] = Security :: remove_XSS(api_convert_encoding($this->name, api_get_system_encoding(), $_SESSION['oLP']->encoding));
- $arrHide[0]['padding'] = 3;
- $charset = api_get_system_encoding();
- if ($item_type != 'module' && $item_type != 'dokeos_module') {
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- }
- }
- if ($action != 'move') {
- $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
- $form->applyFilter('title', 'html_filter');
- $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
- //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
- } else {
- $form->addElement('hidden', 'title');
- }
- $parent_select = & $form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
- foreach ($arrHide as $key => $value) {
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $parent_select->setSelected($s_selected_parent);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = array ();
- //POSITION
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
- $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
- foreach ($arrHide as $key => $value) {
- $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- if (!empty ($s_selected_position)) {
- $position->setSelected($s_selected_position);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
- if ($item_type == 'module' || $item_type == 'dokeos_module') {
- $form->addElement('hidden', 'parent', '0');
- }
- $extension = pathinfo($item_path, PATHINFO_EXTENSION);
- if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
- if ($item_type == 'sco') {
- $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
- }
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
- $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
- $defaults["content_lp"] = file_get_contents($item_path);
- }
- $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->return_form();
- }
- /**
- * Returns the form to update or create a document
- *
- * @param string Action (add/edit)
- * @param integer ID of the lp_item (if already exists)
- * @param mixed Integer if document ID, string if info ('new')
- * @return string HTML form
- */
- function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $path_parts = pathinfo($extra_info['dir']);
- $no_display_edit_textarea = false;
- //If action==edit document
- //We don't display the document form if it's not an editable document (html or txt file)
- if ($action == "edit") {
- if (is_array($extra_info)) {
- if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
- $no_display_edit_textarea = true;
- }
- }
- }
- $no_display_add = false;
- //If action==add an existing document
- //We don't display the document form if it's not an editable document (html or txt file)
- if ($action == "add") {
- if (is_numeric($extra_info)) {
- $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
- $result = Database::query($sql_doc, __FILE__, __LINE__);
- $path_file = Database :: result($result, 0, 0);
- $path_parts = pathinfo($path_file);
- if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
- $no_display_add = true;
- }
- }
- }
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_terms = stripslashes($extra_info['terms']);
- if (empty ($item_title)) {
- $path_parts = pathinfo($extra_info['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- }
- elseif (is_numeric($extra_info)) {
- $sql_doc = "SELECT path, title
- FROM " . $tbl_doc . "
- WHERE id = " . Database :: escape_string($extra_info);
- $result = Database::query($sql_doc, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $explode = explode('.', $row['title']);
- if (count($explode) > 1) {
- for ($i = 0; $i < count($explode) - 1; $i++)
- $item_title .= $explode[$i];
- } else {
- $item_title = $row['title'];
- }
- $item_title = str_replace('_', ' ', $item_title);
- if (empty ($item_title)) {
- $path_parts = pathinfo($row['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- } else {
- $item_title = '';
- $item_description = '';
- }
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add') {
- $return .= get_lang("CreateTheDocument") . "\n";
- }
- elseif ($action == 'move') {
- $return .= get_lang("MoveTheCurrentDocument") . "\n";
- } else {
- $return .= get_lang("EditTheCurrentDocument") . "\n";
- }
- $return .= ' </div>
- </div>';
- if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display :: return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
- }
- require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php');
- $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
- $defaults["title"] = Security :: remove_XSS(api_convert_encoding($item_title, api_get_system_encoding() ,$this->encoding));
- if (empty ($item_title)) {
- $defaults["title"] = Security :: remove_XSS($item_title);
- }
- $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
- $form->addElement('html', $return);
- if ($action != 'move') {
- $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
- $form->applyFilter('title', 'html_filter');
- }
- //$arrHide = array($id);
- $arrHide[0]['value'] = $this->name;
- $arrHide[0]['padding'] = 3;
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- }
- }
- $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
- $my_count=0;
- foreach ($arrHide as $key => $value) {
- if ($my_count!=0) {
- // the LP name is also the first section and is not in the same charset like the other sections
- $value['value'] = Security :: remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- } else {
- $value['value'] = Security :: remove_XSS($value['value']);
- $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $my_count++;
- }
- if (!empty ($id)) {
- $parent_select->setSelected($parent);
- } else {
- $parent_item_id = $_SESSION['parent_item_id'];
- $parent_select->setSelected($parent_item_id);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = array ();
- //POSITION
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
- }
- }
- $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
- $position->addOption(get_lang("FirstPosition"), 0);
- foreach ($arrHide as $key => $value) {
- $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
- }
- $position->setSelected($s_selected_position);
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- //comented the prerequisites, only visible in edit (new document)
- //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
- //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
- // form element for uploading an mp3 file
- //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
- //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
- /* Code deprecated - moved to lp level (not lp-item)
- if ( api_get_setting('search_enabled') === 'true' )
- {
- //add terms field
- $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').' :','id="idTerms" class="learnpath_item_form"');
- $terms->setValue($item_terms);
- }
- */
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- /* foreach($arrHide as $key => $value){
- $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
- if($key==$s_selected_position && $action == 'add'){
- $select_prerequisites -> setSelected(0);
- }
- elseif($key==$id_prerequisite && $action == 'edit'){
- $select_prerequisites -> setSelected($id_prerequisite);
- }
- }
- */
- if (!$no_display_add) {
- if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
- if (isset ($_POST['content']))
- $content = stripslashes($_POST['content']);
- elseif (is_array($extra_info)) {
- //If it's an html document or a text file
- if (!$no_display_edit_textarea) {
- $content = $this->display_document($extra_info['path'], false, false);
- }
- }
- elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
- else
- $content = '';
- if (!$no_display_edit_textarea) {
- // We need to claculate here some specific settings for the online editor.
- // The calculated settings work for documents in the Documents tool
- // (on the root or in subfolders).
- // For documents in native scorm packages it is unclear whether the
- // online editor should be activated or not.
- $relative_path = $extra_info['dir'];
- if ($relative_path == 'n/') {
- // A new document, it is in the root of the repository.
- $relative_path = '';
- $relative_prefix = '';
- } else {
- // The document already exists. Whe have to determine its relative path towards the repository root.
- $relative_path = explode('/', $relative_path);
- $cnt = count($relative_path) - 2;
- if ($cnt < 0) {
- $cnt = 0;
- }
- $relative_prefix = str_repeat('../', $cnt);
- $relative_path = array_slice($relative_path, 1, $cnt);
- $relative_path = implode('/', $relative_path);
- if (strlen($relative_path) > 0) {
- $relative_path = $relative_path . '/';
- }
- }
- $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
- 'CreateDocumentDir' => $relative_prefix,
- 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/',
- 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path
- );
- if ($_GET['action'] == 'add_item') {
- $class = 'add';
- $text = get_lang('LPCreateDocument');
- } else
- if ($_GET['action'] == 'edit_item') {
- $class = 'save';
- $text = get_lang('SaveDocument');
- }
- $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
- $form->addElement('html', '<div style="margin:3px 12px">');
- $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
- $form->addElement('html', '</div>');
- $defaults["content_lp"] = $content;
- }
- }
- elseif (is_numeric($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
- $return = $this->display_document($extra_info, true, true, true);
- $form->addElement('html', $return);
- }
- }
- }
- if ($action == 'move') {
- $form->addElement('hidden', 'title', $item_title);
- $form->addElement('hidden', 'description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
- $form->addElement('hidden', 'path', $extra_info);
- }
- elseif (is_array($extra_info)) {
- $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
- $form->addElement('hidden', 'path', $extra_info['path']);
- }
- $form->addElement('hidden', 'type', TOOL_DOCUMENT);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->return_form();
- }
- /**
- * Return HTML form to add/edit a link item
- *
- * @param string Action (add/edit)
- * @param integer Item ID if exists
- * @param mixed Extra info
- * @return string HTML form
- */
- function display_link_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_url = stripslashes($extra_info['url']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_link = "
- SELECT
- title,
- description,
- url
- FROM " . $tbl_link . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_link, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- $item_url = $row['url'];
- } else {
- $item_title = '';
- $item_description = '';
- $item_url = '';
- }
- $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
- $item_description = api_convert_encoding($item_description, $charset, $this->encoding);
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang("CreateTheLink") . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang("MoveCurrentLink") . ' :' . "\n";
- else
- $return .= get_lang("EditCurrentLink") . ' :' . "\n";
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table>' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $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";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- $parent_item_id = $_SESSION['parent_item_id'];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $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>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- //Description filed is commentd for link
- /*$return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
- $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";
- $return .= "\t\t" . '</tr>' . "\n";*/
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
- $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";
- $return .= "\t\t" . '</tr>' . "\n";
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- /*//comented the prerequisites, only visible in edit (link)
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
- foreach($arrHide as $key => $value)
- {
- if($key==$s_selected_position && $action == 'add')
- {
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- }
- elseif($key==$id_prerequisite && $action == 'edit'){
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- }
- else{
- $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
- }
- }
- $return .= "</select></td>";
- */
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang("AddLinkToCourse") . '</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
- /**
- * Return HTML form to add/edit a student publication (work)
- *
- * @param string Action (add/edit)
- * @param integer Item ID if already exists
- * @param mixed Extra info (work ID if integer)
- * @return string HTML form
- */
- function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- }
- elseif (is_numeric($extra_info)) {
- $sql_publication = "
- SELECT
- title,
- description
- FROM " . $tbl_publication . "
- WHERE id = " . $extra_info;
- $result = Database::query($sql_publication, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $item_title = $row['title'];
- } else {
- $item_title = get_lang('Student_publication');
- }
- $item_title = api_convert_encoding($item_title, $charset, $this->encoding);
- $return = ' <div class="row">
- <div class="form_header">';
- if ($id != 0 && is_array($extra_info))
- $parent = $extra_info['parent_item_id'];
- else
- $parent = 0;
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => $row['title'],
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite']
- );
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- if ($action == 'add')
- $return .= get_lang("Student_publication") . ' :' . "\n";
- elseif ($action == 'move') $return .= get_lang("MoveCurrentStudentPublication") . ' :' . "\n";
- else
- $return .= get_lang("EditCurrentStudentPublication") . ' :' . "\n";
- $return .= ' </div>
- </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">' . "\n";
- $return .= "\t" . '<table class="lp_form">' . "\n";
- if ($action != 'move') {
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
- $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";
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
- $parent_item_id = $_SESSION['parent_item_id'];
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
- $arrHide = array (
- $id
- );
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- 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)) {
- $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>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
- $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>';
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input">' . "\n";
- $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
- $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang("FirstPosition") . '</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $selected = 'selected="selected" ';
- elseif ($action == 'add') $selected = 'selected="selected" ';
- else
- $selected = '';
- $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>';
- }
- }
- $return .= "\t\t\t\t" . '</select>';
- $return .= "\t\t\t" . '</td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = array ();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
- $s_selected_position = $arrLP[$i]['id'];
- elseif ($action == 'add') $s_selected_position = 0;
- $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
- }
- }
- //comented the prerequisites, only visible in edit (work)
- /*
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
- $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
- foreach($arrHide as $key => $value){
- if($key==$s_selected_position && $action == 'add'){
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- }
- elseif($key==$id_prerequisite && $action == 'edit'){
- $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
- }
- else{
- $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
- }
- }
- $return .= "</select></td>";
- */
- $return .= "\t\t" . '</tr>' . "\n";
- }
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td> </td><td><button class="save" name="submit_button" type="submit">' . get_lang("AddAssignmentToCourse") . '</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t" . '</table>' . "\n";
- if ($action == 'move') {
- $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
- $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
- }
- if (is_numeric($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
- }
- elseif (is_array($extra_info)) {
- $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
- }
- $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
- $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
- $return .= '</form>' . "\n";
- $return .= '</div>' . "\n";
- return $return;
- }
- /**
- * Displays the menu for manipulating a step
- *
- * @return unknown
- */
- function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
- global $charset, $_course;
- $return = '<div class="actions">';
- switch ($item_type) {
- case 'dokeos_chapter' :
- case 'chapter' :
- //comented the message cause should not show it
- //$lang = get_lang('TitleManipulateChapter');
- break;
- case 'dokeos_module' :
- case 'module' :
- //comented the message cause should not show it
- //$lang = get_lang('TitleManipulateModule');
- break;
- case TOOL_DOCUMENT :
- //comented the message cause should not show it
- //$lang = get_lang('TitleManipulateDocument');
- break;
- case TOOL_LINK :
- case 'link' :
- //comented the message cause should not show it
- //$lang = get_lang('TitleManipulateLink');
- break;
- case TOOL_QUIZ :
- //comented the message cause should not show it
- //$lang = get_lang('TitleManipulateQuiz');
- break;
- case TOOL_STUDENTPUBLICATION :
- //comented the message cause should not show it
- //$lang = get_lang('TitleManipulateStudentPublication');
- break;
- }
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "
- SELECT
- *
- FROM " . $tbl_lp_item . " as lp
- WHERE
- lp.id = " . $item_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = mysql_fetch_assoc($result);
- $s_title = $row['title'];
- $s_title = api_convert_encoding($s_title, $charset, $this->encoding);
- // we display an audio player if needed
- if (!empty ($row['audio'])) {
- $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>';
- $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
- $return .= '<script type="text/javascript">
- var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
- s1.addParam("allowscriptaccess","always");
- s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
- s1.write("container");
- </script>';
- }
- //commented ":" for message in step
- //$return .= $lang.': ';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item&view=build&id=' . $item_id . '&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>';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=move_item&view=build&id=' . $item_id . '&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>';
- // commented for now as prerequisites cannot be added to chapters
- if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=edit_item_prereq&view=build&id=' . $item_id . '&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>';
- }
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=delete_item&view=build&id=' . $item_id . '&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>';
- //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
- //$return.="</td><td valign='top'>";
- // get the audiorecorder. Use of ob_* functions since there are echos in the file
- ob_start();
- $audio_recorder_studentview = 'false';
- $audio_recorder_item_id = $item_id;
- if (api_get_setting('service_visio', 'active') == 'true') {
- include ('audiorecorder.inc.php');
- }
- $return .= ob_get_contents();
- ob_end_clean();
- // end of audiorecorder include
- $return .= '</div>';
- return $return;
- }
- /**
- * Creates the javascript needed for filling up the checkboxes without page reload
- *
- * @return string
- */
- function create_js() {
- $return = '<script language="javascript" type="text/javascript">' . "\n";
- $return .= 'function load_cbo(id){' . "\n";
- $return .= "var cbo = document.getElementById('idPosition');\n";
- $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
- $return .= 'cbo.options[i] = null;' . "\n";
- $return .= 'var k=0;' . "\n";
- $return .= 'for(var i = 1; i <= child_name[id].length; i++){' . "\n";
- $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' . "\n";
- $return .= 'k=i;';
- $return .= '}' . "\n\n";
- $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
- $return .= '}';
- $return .= 'var child_name = new Array();' . "\n";
- $return .= 'var child_value = new Array();' . "\n\n";
- $return .= 'child_name[0] = new Array();' . "\n";
- $return .= 'child_value[0] = new Array();' . "\n\n";
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql_zero = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id . " AND
- parent_item_id = 0
- ORDER BY display_order ASC";
- $res_zero = Database::query($sql_zero, __FILE__, __LINE__);
- global $charset;
- $i = 0;
- while ($row_zero = Database :: fetch_array($res_zero)) {
- $return .= 'child_name[0][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_zero['title'], $charset, $this->encoding) . '\"";' . "\n";
- $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
- }
- $return .= "\n";
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $res = Database::query($sql, __FILE__, __LINE__);
- while ($row = Database :: fetch_array($res)) {
- $sql_parent = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE parent_item_id = " . $row['id'] . "
- ORDER BY display_order ASC";
- $res_parent = Database::query($sql_parent, __FILE__, __LINE__);
- $i = 0;
- $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
- $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
- while ($row_parent = Database :: fetch_array($res_parent)) {
- $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang("After") . ' \"' . api_convert_encoding($row_parent['title'], $charset, $this->encoding) . '\"";' . "\n";
- $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
- }
- $return .= "\n";
- }
- $return .= '</script>' . "\n";
- return $return;
- }
- /**
- * Display the form to allow moving an item
- *
- * @param integer Item ID
- * @return string HTML form
- */
- function display_move_item($item_id) {
- global $_course; //will disappear
- global $charset;
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
- $res = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($res);
- switch ($row['item_type']) {
- case 'dokeos_chapter' :
- case 'dir' :
- case 'asset' :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
- break;
- case 'dokeos_module' :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
- break;
- case TOOL_DOCUMENT :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('move', $item_id, $row);
- break;
- case TOOL_LINK :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_QUIZ :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('move', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('move', $item_id, $row);
- break;
- case TOOL_FORUM :
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
- }
- }
- return $return;
- }
- /**
- * Displays a basic form on the overview page for changing the item title and the item description.
- *
- * @param string $item_type
- * @param string $title
- * @param array $data
- * @return string
- */
- function display_item_small_form($item_type, $title = '', $data) {
- global $charset;
- $return .= '<div class="lp_small_form">' . "\n";
- $return .= '<p class="lp_title">' . $title . '</p>';
- $return .= '<form method="post">' . "\n";
- $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title :</label></td>' . "\n";
- $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";
- $return .= "\t\t" . '</tr>' . "\n";
- //it said these lines of code - see SVN#11724 and SVN#10770
- //$return .= "\t\t" . '<tr>' . "\n";
- //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description :</label></td>' . "\n";
- //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
- //$return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '<tr>' . "\n";
- $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
- $return .= "\t\t" . '</tr>' . "\n";
- $return .= "\t\t" . '</table>' . "\n";
- $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
- $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
- /**
- * Return HTML form to allow prerequisites selection
- *
- * @param integer Item ID
- * @return string HTML form
- */
- function display_item_prerequisites_form($item_id) {
- global $charset;
- $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
- /* current prerequisite */
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE id = " . $item_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = Database :: fetch_array($result);
- $preq_id = $row['prerequisite'];
- //$preq_mastery = $row['mastery_score'];
- //$preq_max = $row['max_score'];
- $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
- $return = ' <div class="row">
- <div class="form_header">';
- $return .= get_lang('AddEditPrerequisites');
- $return .= '</div> </div>';
- $return .= '<div class="sectioncomment">';
- $return .= '<form method="POST">';
- $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
- $return .= '<tr style="border-collapse:collapse;">';
- $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
- $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
- $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
- $return .= '</tr>';
- //$return .= '<tr >';
- //$return .= '<td class="radio" style="border:1px solid gray;border-collapse:collapse;">';
- //$return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
- //$return .= '<label for="idNone">' . get_lang('None') . '</label>';
- //$return .= '</td><td colspan="2" />';
- //$return .= '</tr>';
- $sql = "
- SELECT *
- FROM " . $tbl_lp_item . "
- WHERE
- lp_id = " . $this->lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $arrLP = array ();
- while ($row = Database :: fetch_array($result)) {
- $arrLP[] = array (
- 'id' => $row['id'],
- 'item_type' => $row['item_type'],
- 'title' => api_convert_encoding($row['title'], $charset, $this->encoding),
- 'ref' => $row['ref'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order']
- );
- if ($row['ref'] == $preq_id) {
- $preq_mastery = $row['mastery_score'];
- $preq_max = $row['max_score'];
- }
- }
- $this->tree_array($arrLP);
- $arrLP = $this->arrMenu;
- unset ($this->arrMenu);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] == $item_id)
- break;
- $return .= '<tr >';
- $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"' : '') . '>';
- $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'] . '" />';
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists("../img/lp_" . $icon_name . ".png")) {
- $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
- } else
- if (file_exists("../img/lp_" . $icon_name . ".gif")) {
- $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
- } else {
- $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
- }
- $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
- $return .= '</td>';
- //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
- if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
- $return .= '</td>';
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
- $return .= '</td>';
- }
- if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
- $return .= '</td>';
- $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
- $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
- $return .= '</td>';
- }
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '<td colspan="3">';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '</table>';
- $return .= '<div style="padding-top:3px;">';
- $return .= '<button class="save" name="submit_button" type="submit">' . get_lang("ModifyPrerequisites") . ' </button></td>' . "\n";
- $return .= '</div>';
- $return .= '</form>';
- $return .= '</div>';
- return $return;
- }
- /**
- * Creates a list with all the documents in it
- *
- * @return string
- */
- function get_documents() {
- global $_course;
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $path = '/';
- $path = Database::escape_string(str_replace('_', '\_', $path));
- $added_slash = ($path == '/') ? '' : '/';
- //condition for the session
- $current_session_id = api_get_session_id();
- $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]}')))";
- $sql_doc = "SELECT docs.*
- FROM $tbl_item_prop AS last, $tbl_doc AS docs
- WHERE docs.id = last.ref
- AND docs.path LIKE '".$path.$added_slash."%'
- AND docs.path NOT LIKE '%_DELETED_%'
- AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
- //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
- $res_doc = Database::query($sql_doc, __FILE__, __LINE__);
- $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>';
- $return .= '<div class="lp_resource_elements" id="resDoc">';
- $resources = Database::store_result($res_doc);
- $resources_sorted = array ();
- // if you want to debug it, I advise you to do "echo" on the eval statements
- foreach ($resources as $resource) {
- $resource_paths = explode('/', $resource['path']);
- array_shift($resource_paths);
- $path_to_eval = $last_path = '';
- $is_file = false;
- foreach ($resource_paths as $key => $resource_path) {
- if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // it's a folder
- $path_to_eval .= '["' . $resource_path . '"]["files"]';
- } else
- if (strpos($resource_path, '.') !== false)
- $is_file = true;
- $last_path = $resource_path;
- }
- if ($is_file) {
- eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
- } else {
- eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
- }
- }
- $return .= $this->write_resources_tree($resources_sorted);
- $return .= '</div>';
- if (Database :: num_rows($res_doc) == 0)
- $return .= '<div class="lp_resource_element">' . get_lang("NoDocuments") . '</div>';
- return $return;
- }
- /**
- * Generate and return an HTML list of resources based on a given array.
- *
- * This list is used to show the course creator a list of available resources to choose from
- * when creating a learning path.
- * @param array Array of elements to add to the list
- * @param integer Enables the tree display by shifting the new elements a certain distance to the right
- * @return string The HTML list
- */
- function write_resources_tree($resources_sorted, $num = 0) {
- include_once (api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
- if (count($resources_sorted) > 0) {
- foreach ($resources_sorted as $key => $resource) {
- if (is_int($resource['id'])) { // it's a folder
- $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" /> <span onclick="testResources(\'' . $resource["id"] . '\',\'img_' . $resource["id"] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
- $return .= $this->write_resources_tree($resource['files'], $num +1);
- $return .= "</div></div>\r\n";
- } else {
- // it's a file
- $icon = choose_image($resource);
- $position = strrpos($icon, '.');
- $icon = substr($icon, 0, $position) . '_small.gif';
- $return .= '<div><div style="margin-left:' . (($num +1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $key . '&lp_id=' . $this->lp_id . '"><img alt="" src="../img/' . $icon . '" title="" /> ' . $resource . "</a></div></div>\r\n";
- }
- }
- }
- return $return;
- }
- /**
- * Creates a list with all the exercises (quiz) in it
- *
- * @return string
- */
- function get_exercises() {
- // new for hotpotatoes
- $uploadPath = DIR_HOTPOTATOES; //defined in main_api
- $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
- $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id);
- $sql_quiz = "
- SELECT *
- FROM " . $tbl_quiz . "
- WHERE active<>'-1' $condition_session
- ORDER BY title ASC";
- $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
- " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
- " ORDER BY id ASC";
- $res_quiz = Database::query($sql_quiz, __FILE__, __LINE__);
- $res_hot = Database::query($sql_hot, __FILE__, __LINE__);
- $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>';
- $return .= '<div class="lp_resource_elements" id="resExercise">';
- while ($row_hot = Database :: fetch_array($res_hot)) {
- $return .= '<div class="lp_resource_element">';
- //display quizhotpotatoes
- $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_HOTPOTATOES . '&file=' . $row_hot['id'] . '&lp_id=' . $this->lp_id . '">' . ((!empty ($row_hot['comment'])) ? $row_hot['comment'] : $row_hot['title']) . '</a>';
- //$return .= $row_quiz['title'];
- $return .= '</div>';
- }
- while ($row_quiz = Database :: fetch_array($res_quiz)) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_QUIZ . '&file=' . $row_quiz['id'] . '&lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
- //$return .= $row_quiz['title'];
- $return .= '</div>';
- }
- if (Database :: num_rows($res_quiz) == 0)
- $return .= '<div class="lp_resource_element">' . get_lang("NoExercisesAvailable") . '</div>';
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
- $return .= '</div>';
- $return .= '</div>';
- return $return;
- }
- /**
- * Creates a list with all the links in it
- *
- * @return string
- */
- function get_links() {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id,false);
-
- $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
- $res_link = Database::query($sql_link, __FILE__, __LINE__);
- $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>';
- $return .= '<div class="lp_resource_elements" id="resLink">';
- while ($row_link = Database :: fetch_array($res_link)) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_LINK . '&file=' . $row_link['id'] . '&lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
- $return .= '</div>';
- }
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
- $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>';
- $return .= '</div>';
- if (Database :: num_rows($res_link) == 0)
- $return .= '<div class="lp_resource_element">' . get_lang("NoLinksAvailable") . '</div>';
- $return .= '</div>';
- return $return;
- }
- /**
- * Creates a list with all the student publications in it
- *
- * @return unknown
- */
- function get_student_publications() {
- $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id,false);
-
- $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
- $res_student = Database::query($sql_student, __FILE__, __LINE__);
- $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>';
- $return .= '<div class="lp_resource_elements" id="resStudent">';
- $return .= '<div class="lp_resource_element">';
- $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_STUDENTPUBLICATION . '&lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
- $return .= '</div>';
- $return .= '</div>';
- return $return;
- }
- /**
- * Creates a list with all the forums in it
- *
- * @return string
- */
- function get_forums() {
- include ('../forum/forumfunction.inc.php');
- include ('../forum/forumconfig.inc.php');
- global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $a_forums = get_forums();
- $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>';
- $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
- foreach ($a_forums as $forum) {
- $return .= '<div class="lp_resource_element">';
- $return .= '<script type="text/javascript">
- function toggle_forum(forum_id){
- if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
- document.getElementById("forum_"+forum_id+"_content").style.display = "block";
- document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
- }
- else {
- document.getElementById("forum_"+forum_id+"_content").style.display = "none";
- document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
- }
- }
- </script>
- ';
- if (!empty($forum['forum_id'])) {
- $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
- $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>
- <a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_FORUM . '&forum_id=' . $forum['forum_id'] . '&lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
- }
-
- $a_threads = get_threads($forum['forum_id']);
- if (is_array($a_threads)) {
- foreach ($a_threads as $thread) {
- $return .= '<li><a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_THREAD . '&thread_id=' . $thread['thread_id'] . '&lp_id=' . $this->lp_id . '">' . $thread['thread_title'] . '</a></li>';
- }
- }
- $return .= '</ul></div>';
- }
- $return .= '<div class="lp_resource_element">';
- $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
- $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&content=forum" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
- $return .= '</div>';
- return $return;
- }
- /**
- * Exports the learning path as a SCORM package. This is the main function that
- * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
- * whole thing and returns the zip.
- *
- * This method needs to be called in PHP5, as it will fail with non-adequate
- * XML package (like the ones for PHP4), and it is *not* a static method, so
- * you need to call it on a learnpath object.
- * @TODO The method might be redefined later on in the scorm class itself to avoid
- * creating a SCORM structure if there is one already. However, if the initial SCORM
- * path has been modified, it should use the generic method here below.
- * @TODO link this function with the export_lp() function in the same class
- * @param string Optional name of zip file. If none, title of learnpath is
- * domesticated and trailed with ".zip"
- * @return string Returns the zip package string, or null if error
- */
- function scorm_export()
- {
- global $_course;
- global $charset;
- if (!class_exists('DomDocument'))
- {
- error_log('DOM functions not supported for PHP version below 5.0',0);
- $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
- return null;
- }
- //remove memory and time limits as much as possible as this might be a long process...
- if(function_exists('ini_set'))
- {
- $mem = ini_get('memory_limit');
- if(substr($mem,-1,1)=='M')
- {
- $mem_num = substr($mem,0,-1);
- if($mem_num<128)
- {
- ini_set('memory_limit','128M');
- }
- }
- else
- {
- ini_set('memory_limit','128M');
- }
- ini_set('max_execution_time',600);
- //}else{
- //error_log('Scorm export: could not change memory and time limits',0);
- }
- //Create the zip handler (this will remain available throughout the method)
- $archive_path = api_get_path(SYS_ARCHIVE_PATH);
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $temp_dir_short = uniqid();
- $temp_zip_dir = $archive_path."/".$temp_dir_short;
- $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
- $zip_folder=new PclZip($temp_zip_file);
- $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
- $root_path = $main_path = api_get_path(SYS_PATH);
- $files_cleanup = array();
- //place to temporarily stash the zipfiles
- //create the temp dir if it doesn't exist
- //or do a cleanup befor creating the zipfile
- if(!is_dir($temp_zip_dir))
- {
- mkdir($temp_zip_dir);
- }
- else
- {//cleanup: check the temp dir for old files and delete them
- $handle=opendir($temp_zip_dir);
- while (false!==($file = readdir($handle)))
- {
- if ($file != "." && $file != "..")
- {
- unlink("$temp_zip_dir/$file");
- }
- }
- closedir($handle);
- }
- $zip_files = $zip_files_abs = $zip_files_dist = array();
- if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
- {
- // remove the possible . at the end of the path
- $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
- $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
- $perm = api_get_setting('permissions_for_new_directories');
- $perm = octdec(!empty($perm)?$perm:'0770');
- mkdir ($dest_path_to_scorm_folder, $perm, true);
- $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
- }
- //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
- //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
- //Aggregation Model official document, secion "2.3 Content Packaging"
- $xmldoc = new DOMDocument('1.0',$this->encoding);
- $root = $xmldoc->createElement('manifest');
- $root->setAttribute('identifier','SingleCourseManifest');
- $root->setAttribute('version','1.1');
- $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
- $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
- $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
- $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');
- //Build mandatory sub-root container elements
- $metadata = $xmldoc->createElement('metadata');
- $md_schema = $xmldoc->createElement('schema','ADL SCORM');
- $metadata->appendChild($md_schema);
- $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
- $metadata->appendChild($md_schemaversion);
- $root->appendChild($metadata);
- $organizations = $xmldoc->createElement('organizations');
- $resources = $xmldoc->createElement('resources');
- //Build the only organization we will use in building our learnpaths
- $organizations->setAttribute('default','dokeos_scorm_export');
- $organization = $xmldoc->createElement('organization');
- $organization->setAttribute('identifier','dokeos_scorm_export');
- //to set the title of the SCORM entity (=organization), we take the name given
- //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
- //learning path charset) as it is the encoding that defines how it is stored
- //in the database. Then we convert it to HTML entities again as the "&" character
- //alone is not authorized in XML (must be &)
- //The title is then decoded twice when extracting (see scorm::parse_manifest)
- $org_title = $xmldoc->createElement('title',htmlentities(api_htmlentities($this->get_name(),ENT_QUOTES,$charset)));
- $organization->appendChild($org_title);
- //For each element, add it to the imsmanifest structure, then add it to the zip.
- //Always call the learnpathItem->scorm_export() method to change it to the SCORM
- //format
- $link_updates = array();
- foreach($this->items as $index => $item){
- if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
- {
- //get included documents from this item
- if($item->type=='sco')
- $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
- else
- $inc_docs = $item->get_resources_from_source();
- //give a child element <item> to the <organization> element
- $my_item_id = $item->get_id();
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
- $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
- $my_item->setAttribute('isvisible','true');
- //give a child element <title> to the <item> element
- $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
- $my_item->appendChild($my_title);
- //give a child element <adlcp:prerequisites> to the <item> element
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
- $my_prereqs->setAttribute('type','aicc_script');
- $my_item->appendChild($my_prereqs);
- //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
- //$xmldoc->createElement('adlcp:maxtimeallowed','');
- //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
- //$xmldoc->createElement('adlcp:timelimitaction','');
- //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
- //$xmldoc->createElement('adlcp:datafromlms','');
- //give a child element <adlcp:masteryscore> to the <item> element
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
- //attach this item to the organization element or hits parent if there is one
- if(!empty($item->parent) && $item->parent!=0)
- {
- $children = $organization->childNodes;
- $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
- if(is_object($possible_parent))
- {
- $possible_parent->appendChild($my_item);
- }
- else
- {
- if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
- }
- }
- else
- {
- if($this->debug>0){error_log('No parent');}
- $organization->appendChild($my_item);
- }
- //get the path of the file(s) from the course directory root
- $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
- $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
- $my_sub_dir = dirname($my_file_path);
- $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
- //give a <resource> child to the <resources> element
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type','webcontent');
- $my_resource->setAttribute('href',$my_xml_file_path);
- //adlcp:scormtype can be either 'sco' or 'asset'
- if($item->type=='sco')
- {
- $my_resource->setAttribute('adlcp:scormtype','sco');
- }
- else
- {
- $my_resource->setAttribute('adlcp:scormtype','asset');
- }
- //xml:base is the base directory to find the files declared in this resource
- $my_resource->setAttribute('xml:base','');
- //give a <file> child to the <resource> element
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href',$my_xml_file_path);
- $my_resource->appendChild($my_file);
- //dependency to other files - not yet supported
- $i = 1;
- foreach($inc_docs as $doc_info)
- {
- if(count($doc_info)<1 or empty($doc_info[0])){continue;}
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier',$res_id);
- $my_dep->setAttribute('type','webcontent');
- $my_dep->setAttribute('adlcp:scormtype','asset');
- $my_dep_file = $xmldoc->createElement('file');
- //check type of URL
- //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
- if($doc_info[1] == 'remote')
- { //remote file. Save url as is
- $my_dep_file->setAttribute('href',$doc_info[0]);
- $my_dep->setAttribute('xml:base','');
- }elseif($doc_info[1] == 'local'){
- switch($doc_info[2])
- {
- case 'url': //local URL - save path as url for now, don't zip file
- $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
- $current_dir = dirname($abs_path);
- $file_path = realpath($abs_path);
- $my_dep_file->setAttribute('href',$file_path);
- $my_dep->setAttribute('xml:base','');
- if(strstr($file_path,$main_path) !== false)
- {//the calculated real path is really inside the dokeos root path
- //reduce file path to what's under the DocumentRoot
- $file_path = substr($file_path,strlen($root_path)-1);
- //echo $file_path;echo '<br><br>';
- //error_log(__LINE__.'Reduced url path: '.$file_path,0);
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
- $my_dep_file->setAttribute('href',$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- else if (empty($file_path))
- {
- /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
- if(strpos($document_root,-1)=='/')
- {
- $document_root = substr(0, -1, $document_root);
- }*/
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//','/',$file_path);
- if(file_exists($file_path))
- {
- $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
- $my_dep_file->setAttribute('href',$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- }
- break;
- case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
- $my_dep_file->setAttribute('href',$doc_info[0]);
- $my_dep->setAttribute('xml:base','');
- //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
- //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
- $abs_img_path_without_subdir = $doc_info[0];
- $relp = api_get_path(REL_PATH); //the url-append config param
- $pos = strpos($abs_img_path_without_subdir,$relp);
- if($pos===0)
- {
- $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
- }
- //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
- $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
- $file_path = str_replace('\\','/',$file_path);
- $file_path = str_replace('//','/',$file_path);
- //error_log(__LINE__.'Abs path: '.$file_path,0);
- //prepare the current directory path (until just under 'document') with a trailing slash
- $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
- //check if the current document is in that path
- if(strstr($file_path,$cur_path) !== false)
- {
- //the document is in that path, now get the relative path
- //to the containing document
- $orig_file_path = dirname($cur_path.$my_file_path).'/';
- $relative_path ='';
- if(strstr($file_path,$cur_path)!==false)
- {
- $relative_path = substr($file_path,strlen($orig_file_path));
- $file_path = substr($file_path,strlen($cur_path));
- }
- else
- {
- //this case is still a problem as it's difficult to calculate a relative path easily
- //might still generate wrong links
- //$file_path = substr($file_path,strlen($cur_path));
- //calculate the directory path to the current file (without trailing slash)
- $my_relative_path = dirname($file_path);
- $my_relative_file = basename($file_path);
- //calculate the directory path to the containing file (without trailing slash)
- $my_orig_file_path = substr($orig_file_path,0,-1);
- $dotdot = '';
- $subdir = '';
- while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
- {
- $my_relative_path2 = dirname($my_relative_path);
- $my_orig_file_path = dirname($my_orig_file_path);
- $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
- $dotdot += '../';
- $my_relative_path = $my_relative_path2;
- }
- $relative_path = $dotdot.$subdir.$my_relative_file;
- }
- //put the current document in the zip (this array is the array
- //that will manage documents already in the course folder - relative)
- $zip_files[] = $file_path;
- //update the links to the current document in the containing document (make them relative)
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
- $my_dep_file->setAttribute('href',$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- elseif(strstr($file_path,$main_path) !== false)
- {//the calculated real path is really inside the dokeos root path
- //reduce file path to what's under the DocumentRoot
- $file_path = substr($file_path,strlen($root_path));
- //echo $file_path;echo '<br><br>';
- //error_log('Reduced path: '.$file_path,0);
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- else if (empty($file_path))
- {
- /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
- if(strpos($document_root,-1)=='/')
- {
- $document_root = substr(0, -1, $document_root);
- }*/
- $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
- $file_path = str_replace('//','/',$file_path);
- if(file_exists($file_path))
- {
- $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- }
- break;
- 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
- if(substr($doc_info[0],0,2)=='..')
- { //relative path going up
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $file_path = realpath($current_dir.$doc_info[0]);
- //error_log($file_path.' <-> '.$main_path,0);
- if(strstr($file_path,$main_path) !== false)
- {//the calculated real path is really inside the dokeos root path
- //reduce file path to what's under the DocumentRoot
- $file_path = substr($file_path,strlen($root_path));
- //error_log('Reduced path: '.$file_path,0);
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- }else{
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href',$doc_info[0]);
- $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href',$doc_info[0]);
- $my_dep->setAttribute('xml:base','');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref',$res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
- //$my_dependency = $xmldoc->createElement('dependency');
- //$my_dependency->setAttribute('identifierref','');
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
- //error_log('File '.$my_file_path. ' added to $zip_files',0);
- }
- else
- { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
- if($item->type == TOOL_LINK)
- {
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible','true');
- //give a child element <title> to the <item> element
- $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
- $my_item->appendChild($my_title);
- //give a child element <adlcp:prerequisites> to the <item> element
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
- $my_prereqs->setAttribute('type','aicc_script');
- $my_item->appendChild($my_prereqs);
- //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
- //$xmldoc->createElement('adlcp:maxtimeallowed','');
- //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
- //$xmldoc->createElement('adlcp:timelimitaction','');
- //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
- //$xmldoc->createElement('adlcp:datafromlms','');
- //give a child element <adlcp:masteryscore> to the <item> element
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
- //attach this item to the organization element or its parent if there is one
- if(!empty($item->parent) && $item->parent!=0)
- {
- $children = $organization->childNodes;
- for($i=0;$i<$children->length;$i++){
- $item_temp = $children->item($i);
- if ($item_temp -> nodeName == 'item')
- {
- if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
- {
- $item_temp -> appendChild($my_item);
- }
- }
- }
- }
- else
- {
- $organization->appendChild($my_item);
- }
- $my_file_path = 'link_'.$item->get_id().'.html';
- $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
- $rs = Database::query($sql, __FILE__, __LINE__);
- if($link = Database :: fetch_array($rs))
- {
- $url = $link['url'];
- $title = stripslashes($link['title']);
- $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
- $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
- $my_sub_dir = dirname($my_file_path);
- $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
- //give a <resource> child to the <resources> element
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type','webcontent');
- $my_resource->setAttribute('href',$my_xml_file_path);
- //adlcp:scormtype can be either 'sco' or 'asset'
- $my_resource->setAttribute('adlcp:scormtype','asset');
- //xml:base is the base directory to find the files declared in this resource
- $my_resource->setAttribute('xml:base','');
- //give a <file> child to the <resource> element
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href',$my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- }
- }
- elseif($item->type == TOOL_QUIZ)
- {
- require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
- $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
- $exe = new Exercise();
- $exe->read($exe_id);
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible','true');
- //give a child element <title> to the <item> element
- $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(), ENT_QUOTES, $this->encoding));
- $my_item->appendChild($my_title);
- $my_max_score = $xmldoc->createElement('max_score',$item->get_max());
- $my_item->appendChild($my_max_score);
- //give a child element <adlcp:prerequisites> to the <item> element
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
- $my_prereqs->setAttribute('type','aicc_script');
- $my_item->appendChild($my_prereqs);
- //give a child element <adlcp:masteryscore> to the <item> element
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
- //attach this item to the organization element or hits parent if there is one
- if(!empty($item->parent) && $item->parent!=0)
- {
- $children = $organization->childNodes;
- for($i=0;$i<$children->length;$i++){
- $item_temp = $children->item($i);
- if ($item_temp -> nodeName == 'item')
- {
- if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
- {
- $item_temp -> appendChild($my_item);
- }
- }
- }
- }
- else
- {
- $organization->appendChild($my_item);
- }
- //include export scripts
- require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
- //get the path of the file(s) from the course directory root
- //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
- $my_file_path = 'quiz_'.$item->get_id().'.html';
- //write the contents of the exported exercise into a (big) html file
- //to later pack it into the exported SCORM. The file will be removed afterwards
- $contents = export_exercise($exe_id,true);
- $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
- $res = file_put_contents($tmp_file_path,$contents);
- if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
- $files_cleanup[] = $tmp_file_path;
- //error_log($tmp_path);die();
- $my_xml_file_path = api_htmlentities($my_file_path, ENT_QUOTES, $this->encoding);
- $my_sub_dir = dirname($my_file_path);
- $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_QUOTES, $this->encoding);
- //give a <resource> child to the <resources> element
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type','webcontent');
- $my_resource->setAttribute('href',$my_xml_file_path);
- //adlcp:scormtype can be either 'sco' or 'asset'
- $my_resource->setAttribute('adlcp:scormtype','sco');
- //xml:base is the base directory to find the files declared in this resource
- $my_resource->setAttribute('xml:base','');
- //give a <file> child to the <resource> element
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href',$my_xml_file_path);
- $my_resource->appendChild($my_file);
- //get included docs
- $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
- //dependency to other files - not yet supported
- $i = 1;
- foreach($inc_docs as $doc_info)
- {
- if(count($doc_info)<1 or empty($doc_info[0])){continue;}
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier',$res_id);
- $my_dep->setAttribute('type','webcontent');
- $my_dep->setAttribute('adlcp:scormtype','asset');
- $my_dep_file = $xmldoc->createElement('file');
- //check type of URL
- //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
- if($doc_info[1] == 'remote')
- { //remote file. Save url as is
- $my_dep_file->setAttribute('href',$doc_info[0]);
- $my_dep->setAttribute('xml:base','');
- }elseif($doc_info[1] == 'local'){
- switch($doc_info[2])
- {
- case 'url': //local URL - save path as url for now, don't zip file
- //save file but as local file (retrieve from URL)
- $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
- $current_dir = dirname($abs_path);
- $file_path = realpath($abs_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- if(strstr($file_path,$main_path) !== false)
- {//the calculated real path is really inside the dokeos root path
- //reduce file path to what's under the DocumentRoot
- $file_path = substr($file_path,strlen($root_path));
- //echo $file_path;echo '<br><br>';
- //error_log('Reduced path: '.$file_path,0);
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- else if (empty($file_path))
- {
- /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
- if(strpos($document_root,-1)=='/')
- {
- $document_root = substr(0, -1, $document_root);
- }*/
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//','/',$file_path);
- if(file_exists($file_path))
- {
- $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- }
- break;
- case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $file_path = realpath($doc_info[0]);
- $my_dep_file->setAttribute('href',$file_path);
- $my_dep->setAttribute('xml:base','');
- if(strstr($file_path,$main_path) !== false)
- {//the calculated real path is really inside the dokeos root path
- //reduce file path to what's under the DocumentRoot
- $file_path = substr($file_path,strlen($root_path));
- //echo $file_path;echo '<br><br>';
- //error_log('Reduced path: '.$file_path,0);
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- else if (empty($file_path))
- {
- /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
- if(strpos($document_root,-1)=='/')
- {
- $document_root = substr(0, -1, $document_root);
- }*/
- $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
- $file_path = str_replace('//','/',$file_path);
- if(file_exists($file_path))
- {
- $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- }
- break;
- 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
- if(substr($doc_info[0],0,2)=='..')
- { //relative path going up
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $file_path = realpath($current_dir.$doc_info[0]);
- //error_log($file_path.' <-> '.$main_path,0);
- if(strstr($file_path,$main_path) !== false)
- {//the calculated real path is really inside the dokeos root path
- //reduce file path to what's under the DocumentRoot
- $file_path = substr($file_path,strlen($root_path));
- $file_path_dest=$file_path;
- //file path is courses/DOKEOS/document/....
- $info_file_path=explode('/',$file_path);
- if ($info_file_path[0]=='courses') {//add character "/" in file path
- $file_path_dest='/'.$file_path;
- }
- //error_log('Reduced path: '.$file_path,0);
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path_dest);
- $my_dep_file->setAttribute('href','document/'.$file_path);
- $my_dep->setAttribute('xml:base','');
- }
- }else{
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href',$doc_info[0]);
- $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href',$doc_info[0]);// ../../courses/
- $my_dep->setAttribute('xml:base','');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref',$res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
- }
- else
- {
- //get the path of the file(s) from the course directory root
- $my_file_path = 'non_exportable.html';
- $my_xml_file_path = api_htmlentities($my_file_path, ENT_COMPAT, $this->encoding);
- $my_sub_dir = dirname($my_file_path);
- $my_xml_sub_dir = api_htmlentities($my_sub_dir, ENT_COMPAT, $this->encoding);
- //give a <resource> child to the <resources> element
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type','webcontent');
- $my_resource->setAttribute('href','document/'.$my_xml_file_path);
- //adlcp:scormtype can be either 'sco' or 'asset'
- $my_resource->setAttribute('adlcp:scormtype','asset');
- //xml:base is the base directory to find the files declared in this resource
- $my_resource->setAttribute('xml:base','');
- //give a <file> child to the <resource> element
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href','document/'.$my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- }
- }
- }
- $organizations->appendChild($organization);
- $root->appendChild($organizations);
- $root->appendChild($resources);
- $xmldoc->appendChild($root);
- //todo: add a readme file here, with a short description and a link to the Reload player
- //then add the file to the zip, then destroy the file (this is done automatically)
- // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
- //error_log(print_r($zip_files,true),0);
- foreach($zip_files as $file_path)
- {
- if(empty($file_path)){continue;}
- //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
- $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
- $this->create_path($dest_file);
- //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);
- //echo $main_path.$file_path.'<br>';
- @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
- //check if the file needs a link update
- if(in_array($file_path,array_keys($link_updates))){
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach($link_updates[$file_path] as $old_new)
- {
- //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
- //this is an ugly hack that allows .flv files to be found by the flv player that
- // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
- // to find the flv to play in document/main/, so we replace main/ in the flv path by
- // ../../.. to return from inc/lib/flv_player to the document/main path
- if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
- {
- $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
- }
- elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
- {
- $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
- }
- $string = str_replace($old_new['orig'],$old_new['dest'],$string);
- }
- file_put_contents($dest_file,$string);
- }
- }
- foreach($zip_files_abs as $file_path)
- {
- if(empty($file_path)){continue;}
- //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
- if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
- //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
- $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
- $this->create_path($dest_file);
- //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path,0);
- //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);
- //echo $main_path.$file_path.' - '.$dest_file.'<br>';
- copy($main_path.$file_path,$dest_file);
- //check if the file needs a link update
- if(in_array($file_path,array_keys($link_updates)))
- {
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach($link_updates[$file_path] as $old_new)
- {
- //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
- //this is an ugly hack that allows .flv files to be found by the flv player that
- // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
- // to find the flv to play in document/main/, so we replace main/ in the flv path by
- // ../../.. to return from inc/lib/flv_player to the document/main path
- if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
- {
- $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
- }
- $string = str_replace($old_new['orig'],$old_new['dest'],$string);
- }
- file_put_contents($dest_file,$string);
- }
- }
- if(is_array($links_to_create))
- {
- foreach($links_to_create as $file=>$link)
- {
- $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
- file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
- }
- }
- // add non exportable message explanation
- $lang_not_exportable = get_lang('ThisItemIsNotExportable');
- $file_content =
- <<<EOD
- <html>
- <head>
- <style>
- .error-message {
- font-family: arial, verdana, helvetica, sans-serif;
- border-width: 1px;
- border-style: solid;
- left: 50%;
- margin: 10px auto;
- min-height: 30px;
- padding: 5px;
- right: 50%;
- width: 500px;
- background-color: #FFD1D1;
- border-color: #FF0000;
- color: #000;
- }
- </style>
- <body>
- <div class="error-message">
- $lang_not_exportable
- </div>
- </body>
- </html>
- EOD;
- if(!is_dir($archive_path.$temp_dir_short.'/document'))
- {
- @mkdir($archive_path.$temp_dir_short.'/document');
- }
- file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
- //Add the extra files that go along with a SCORM package
- $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
- $extra_files = scandir($main_code_path);
- foreach ($extra_files as $extra_file) {
- if (strpos($extra_file, '.') === 0)
- continue;
- else {
- $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
- $this->create_path($dest_file);
- copy($main_code_path.$extra_file,$dest_file);
- }
- }
- //Finalize the imsmanifest structure, add to the zip, then return the zip
- $xmldoc->save($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml');
- $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
- //clean possible temporary files
- foreach($files_cleanup as $file)
- {
- $res = unlink($file);
- if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
- }
- //Send file to client
- //$name = 'scorm_export_'.$this->lp_id.'.zip';
- require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
- $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
- DocumentManager::file_send_for_download($temp_zip_file,true,$name);
- }
- /**
- * Temp function to be moved in main_api or the best place around for this. Creates a file path
- * if it doesn't exist
- */
- function create_path($path) {
- $path_bits = split('/', dirname($path));
- // IS_WINDOWS_OS has been defined in main_api.lib.php
- $path_built = IS_WINDOWS_OS ? '' : '/';
- foreach ($path_bits as $bit) {
- if (!empty ($bit)) {
- $new_path = $path_built . $bit;
- if (is_dir($new_path)) {
- $path_built = $new_path . '/';
- } else {
- mkdir($new_path);
- $path_built = $new_path . '/';
- }
- }
- }
- }
- /**
- * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
- * @return boolean The results of the unlink function, or false if there was no image to start with
- */
- function delete_lp_image() {
- $img = $this->get_preview_image();
- if ($img != '') {
- $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
- $this->set_preview_image('');
- return @ unlink($del_file);
- } else {
- return false;
- }
- }
- /**
- * Uploads an author image to the upload/learning_path/images directory
- * @param array The image array, coming from the $_FILES superglobal
- * @return boolean True on success, false on error
- */
- function upload_image($image_array) {
- $image_moved = false;
- if (!empty ($image_array['name'])) {
- $upload_ok = process_uploaded_file($image_array);
- $has_attachment = true;
- } else {
- $image_moved = true;
- }
- if ($upload_ok) {
- if ($has_attachment) {
- $courseDir = api_get_course_path() . '/upload/learning_path/images';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path . $courseDir;
- // Try to add an extension to the file if it hasn't one
- $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
- if (!filter_extension($new_file_name)) {
- //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- $image_moved = false;
- } else {
- $file_extension = explode('.', $image_array['name']);
- $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
- $new_file_name = uniqid('') . '.' . $file_extension;
- $new_path = $updir . '/' . $new_file_name;
- //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
- // resize the image
- include_once (api_get_path(LIBRARY_PATH) . 'image.lib.php');
- $temp = new image($image_array['tmp_name']);
- $picture_infos=@getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
- if ($picture_infos[0] > 104) {
- $thumbwidth = 104;
- } else {
- $thumbwidth = $picture_infos[0];
- }
- if ($picture_infos[1] > 96) {
- $new_height = 96;
- } else {
- $new_height = $picture_infos[1];
- }
- //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
- $temp->resize($thumbwidth,$new_height,0);
- $type=$picture_infos[2];
- $result=false;
- switch ($type)
- {
- case 2 :
- $result=$temp->send_image('JPG',$new_path);
- break;
- case 3 :
- $result=$temp->send_image('PNG',$new_path);
- break;
- case 1 :
- $result=$temp->send_image('GIF',$new_path);
- break;
- }
- $temp->resize($thumbwidth, $new_height, 0);
- $type = $picture_infos[2];
- $result = false;
- switch ($type) {
- case 2 :
- $result = $temp->send_image('JPG', $new_path);
- break;
- case 3 :
- $result = $temp->send_image('PNG', $new_path);
- break;
- case 1 :
- $result = $temp->send_image('GIF', $new_path);
- break;
- }
- // Storing the image filename
- if ($result) {
- $image_moved = true;
- $this->set_preview_image($new_file_name);
- return true;
- }
- }
- }
- }
- return false;
- }
- }
- if (!function_exists('trim_value')) {
- function trim_value(& $value) {
- $value = trim($value);
- }
- }
|