learnpath.class.php 199 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517
  1. <?php //$id:$
  2. /**
  3. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  4. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  5. * @package dokeos.learnpath
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. * @license GNU/GPL - See Dokeos license directory for details
  8. */
  9. /**
  10. * Defines the learnpath parent class
  11. * @package dokeos.learnpath
  12. */
  13. class learnpath {
  14. var $attempt = 0; //the number for the current ID view
  15. var $cc; //course (code) this learnpath is located in
  16. var $current; //id of the current item the user is viewing
  17. var $current_score; //the score of the current item
  18. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  19. var $current_time_stop; //the time the user closed this resource
  20. var $default_status = 'not attempted';
  21. var $encoding = 'ISO-8859-1';
  22. var $error = '';
  23. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  24. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  25. var $index; //the index of the active learnpath_item in $ordered_items array
  26. var $items = array();
  27. var $last; //item_id of last item viewed in the learning path
  28. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  29. var $license; //which license this course has been given - not used yet on 20060522
  30. var $lp_id; //DB ID for this learnpath
  31. var $lp_view_id; //DB ID for lp_view
  32. var $log_file; //file where to log learnpath API msg
  33. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  34. var $message = '';
  35. var $mode='embedded'; //holds the video display mode (fullscreen or embedded)
  36. var $name; //learnpath name (they generally have one)
  37. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  38. var $path = ''; //path inside the scorm directory (if scorm)
  39. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  40. var $prevent_reinit = 1;
  41. // Describes the mode of progress bar display
  42. var $progress_bar_mode = '%';
  43. // Percentage progress as saved in the db
  44. var $progress_db = '0';
  45. var $proximity; //wether the content is distant or local or unknown
  46. var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
  47. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  48. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  49. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  50. //TODO check if this type variable is useful here (instead of just in the controller script)
  51. var $user_id; //ID of the user that is viewing/using the course
  52. var $update_queue = array();
  53. var $scorm_debug = 0;
  54. var $arrMenu = array(); //array for the menu items
  55. var $debug = 0; //logging level
  56. /**
  57. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  58. * Also builds the list of items into $this->items.
  59. * @param string Course code
  60. * @param integer Learnpath ID
  61. * @param integer User ID
  62. * @return boolean True on success, false on error
  63. */
  64. function learnpath($course, $lp_id, $user_id) {
  65. //check params
  66. //check course code
  67. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  68. if(empty($course)){
  69. $this->error = 'Course code is empty';
  70. return false;
  71. }
  72. else
  73. {
  74. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  75. //$course = Database::escape_string($course);
  76. $course = $this->escape_string($course);
  77. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  78. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  79. //$res = Database::query($sql);
  80. $res = api_sql_query($sql);
  81. if(Database::num_rows($res)>0)
  82. {
  83. $this->cc = $course;
  84. }
  85. else
  86. {
  87. $this->error = 'Course code does not exist in database ('.$sql.')';
  88. return false;
  89. }
  90. }
  91. //check learnpath ID
  92. if(empty($lp_id))
  93. {
  94. $this->error = 'Learnpath ID is empty';
  95. return false;
  96. }
  97. else
  98. {
  99. //TODO make it flexible to use any course_code (still using env course code here)
  100. //$lp_table = Database::get_course_table(LEARNPATH_TABLE);
  101. $lp_db = Database::get_current_course_database();
  102. $lp_pref = Database::get_course_table_prefix();
  103. $lp_table = $lp_db.'.'.$lp_pref.'lp';
  104. //$id = Database::escape_integer($id);
  105. $lp_id = $this->escape_string($lp_id);
  106. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  107. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  108. //$res = Database::query($sql);
  109. $res = api_sql_query($sql);
  110. if(Database::num_rows($res)>0)
  111. {
  112. $this->lp_id = $lp_id;
  113. $row = Database::fetch_array($res);
  114. $this->type = $row['lp_type'];
  115. $this->name = stripslashes($row['name']);
  116. $this->encoding = $row['default_encoding'];
  117. $this->proximity = $row['content_local'];
  118. $this->maker = $row['content_maker'];
  119. $this->prevent_reinit = $row['prevent_reinit'];
  120. $this->license = $row['content_license'];
  121. $this->scorm_debug = $row['debug'];
  122. $this->js_lib = $row['js_lib'];
  123. $this->path = $row['path'];
  124. if($this->type == 2){
  125. if($row['force_commit'] == 1){
  126. $this->force_commit = true;
  127. }
  128. }
  129. $this->mode = $row['default_view_mod'];
  130. }
  131. else
  132. {
  133. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  134. return false;
  135. }
  136. }
  137. //check user ID
  138. if(empty($user_id)){
  139. $this->error = 'User ID is empty';
  140. return false;
  141. }
  142. else
  143. {
  144. //$main_table = Database::get_main_user_table();
  145. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  146. //$user_id = Database::escape_integer($user_id);
  147. $user_id = $this->escape_string($user_id);
  148. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  149. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  150. //$res = Database::query($sql);
  151. $res = api_sql_query($sql);
  152. if(Database::num_rows($res)>0)
  153. {
  154. $this->user_id = $user_id;
  155. }
  156. else
  157. {
  158. $this->error = 'User ID does not exist in database ('.$sql.')';
  159. return false;
  160. }
  161. }
  162. //end of variables checking
  163. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  164. //$lp_table = Database::get_course_table(LEARNPATH_VIEW_TABLE);
  165. $lp_db = Database::get_current_course_database();
  166. $lp_pref = Database::get_course_table_prefix();
  167. $lp_table = $lp_db.'.'.$lp_pref.'lp_view';
  168. //selecting by view_count descending allows to get the highest view_count first
  169. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  170. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
  171. //$res = Database::query($sql);
  172. $res = api_sql_query($sql);
  173. $view_id = 0; //used later to query lp_item_view
  174. if(Database::num_rows($res)>0)
  175. {
  176. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
  177. $row = Database::fetch_array($res);
  178. $this->attempt = $row['view_count'];
  179. $this->lp_view_id = $row['id'];
  180. $this->last_item_seen = $row['last_item'];
  181. $this->progress_db = $row['progress'];
  182. }
  183. else
  184. {
  185. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
  186. $this->attempt = 1;
  187. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  188. $res_ins = api_sql_query($sql_ins);
  189. $this->lp_view_id = Database::get_last_insert_id();
  190. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
  191. }
  192. //initialise items
  193. $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item';
  194. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  195. $res = api_sql_query($sql);
  196. while($row = Database::fetch_array($res))
  197. {
  198. $oItem = '';
  199. //$this->ordered_items[] = $row['id'];
  200. switch($this->type){
  201. case 3: //aicc
  202. $oItem = new aiccItem('db',$row['id']);
  203. if(is_object($oItem)){
  204. $oItem->set_lp_view($this->lp_view_id);
  205. $oItem->set_prevent_reinit($this->prevent_reinit);
  206. $id = $oItem->get_id();
  207. // Don't use reference here as the next loop will make the pointed object change
  208. $this->items[$id] = $oItem;
  209. $this->refs_list[$oItem->ref]=$id;
  210. if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$id.' set in items[]',0);}
  211. }
  212. break;
  213. case 2:
  214. require_once('scorm.class.php');
  215. require_once('scormItem.class.php');
  216. $oItem = new scormItem('db',$row['id']);
  217. if(is_object($oItem)){
  218. $oItem->set_lp_view($this->lp_view_id);
  219. $oItem->set_prevent_reinit($this->prevent_reinit);
  220. // Don't use reference here as the next loop will make the pointed object change
  221. $this->items[$oItem->get_id()] = $oItem;
  222. $this->refs_list[$oItem->ref]=$oItem->get_id();
  223. if($this->debug>2){error_log('New LP - object with id '.$oItem->get_id().' set in items[]',0);}
  224. }
  225. break;
  226. case 1:
  227. default:
  228. require_once('learnpathItem.class.php');
  229. $oItem = new learnpathItem($row['id'],$user_id);
  230. if(is_object($oItem)){
  231. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  232. $oItem->set_prevent_reinit($this->prevent_reinit);
  233. // Don't use reference here as the next loop will make the pointed object change
  234. $this->items[$oItem->get_id()] = $oItem;
  235. $this->refs_list[$oItem->get_id()]=$oItem->get_id();
  236. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$oItem->get_id().' set in items[]',0);}
  237. }
  238. break;
  239. }
  240. //items is a list of pointers to all items, classified by DB ID, not SCO id
  241. if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
  242. $this->items[$row['id']]->set_level(0);
  243. }else{
  244. $level = $this->items[$row['parent_item_id']]->get_level()+1;
  245. $this->items[$row['id']]->set_level($level);
  246. if(is_object($this->items[$row['parent_item_id']])){
  247. //items is a list of pointers from item DB ids to item objects
  248. $this->items[$row['parent_item_id']]->add_child($row['id']);
  249. }else{
  250. 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);}
  251. }
  252. }
  253. //get last viewing vars
  254. //$learnpath_items_view_table = Database::get_course_table(LEARNPATH_ITEM_VIEW_TABLE);
  255. $lp_item_view_table = $lp_db.'.'.$lp_pref.'lp_item_view';
  256. //this query should only return one or zero result
  257. $sql = "SELECT * " .
  258. "FROM $lp_item_view_table " .
  259. "WHERE lp_view_id = ".$this->lp_view_id." " .
  260. "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
  261. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
  262. //get the item status
  263. $res2 = api_sql_query($sql);
  264. if(Database::num_rows($res2)>0)
  265. {
  266. //if this learnpath has already been used by this user, get his last attempt count and
  267. //the last item seen back into this object
  268. //$max = 0;
  269. $row2 = Database::fetch_array($res2);
  270. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
  271. $this->items[$row['id']]->set_status($row2['status']);
  272. if(empty($row2['status'])){
  273. $this->items[$row['id']]->set_status($this->default_status);
  274. }
  275. //$this->attempt = $row['view_count'];
  276. //$this->last_item = $row['id'];
  277. }
  278. else //no item found in lp_item_view for this view
  279. {
  280. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  281. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  282. //$this->attempt = 1;
  283. //$this->last_item = 0;
  284. $this->items[$row['id']]->set_status($this->default_status);
  285. //Add that row to the lp_item_view table so that we have something to show in the stats page
  286. $sql_ins = "INSERT INTO $lp_item_view_table " .
  287. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  288. "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
  289. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
  290. $res_ins = api_sql_query($sql_ins);
  291. }
  292. //setting the view in the item object
  293. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  294. }
  295. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
  296. $this->max_ordered_items = 0;
  297. foreach($this->ordered_items as $index=>$dummy){
  298. if($index > $this->max_ordered_items AND !empty($dummy)){
  299. $this->max_ordered_items = $index;
  300. }
  301. }
  302. //TODO define the current item better
  303. $this->first();
  304. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
  305. }
  306. /**
  307. * 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
  308. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  309. *
  310. * @param int $parent
  311. * @param int $previous
  312. * @param string $type
  313. * @param int $id
  314. * @param string $title
  315. * @param string $description
  316. * @return int
  317. */
  318. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description)
  319. {
  320. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  321. $tbl_lp_item = Database::get_course_table('lp_item');
  322. $parent = (int) $parent;
  323. $sql_count = "
  324. SELECT COUNT(id) AS num
  325. FROM " . $tbl_lp_item . "
  326. WHERE
  327. lp_id = " . $this->get_id() . " AND
  328. parent_item_id = " . $parent;
  329. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  330. $row = Database::fetch_array($res_count);
  331. $num = $row['num'];
  332. if($num > 0)
  333. {
  334. if($previous == 0)
  335. {
  336. $sql = "
  337. SELECT
  338. id,
  339. next_item_id,
  340. display_order
  341. FROM " . $tbl_lp_item . "
  342. WHERE
  343. lp_id = " . $this->get_id() . " AND
  344. parent_item_id = " . $parent . " AND
  345. previous_item_id = 0";
  346. $result = api_sql_query($sql, __FILE__, __LINE__);
  347. $row = Database::fetch_array($result);
  348. $tmp_previous = 0;
  349. $next = $row['id'];
  350. $display_order = 0;
  351. }
  352. else
  353. {
  354. $previous = (int) $previous;
  355. $sql = "
  356. SELECT
  357. id,
  358. previous_item_id,
  359. next_item_id,
  360. display_order
  361. FROM " . $tbl_lp_item . "
  362. WHERE
  363. lp_id = " . $this->get_id() . " AND
  364. id = " . $previous;
  365. $result = api_sql_query($sql, __FILE__, __LINE__);
  366. $row = Database::fetch_array($result);
  367. $tmp_previous = $row['id'];
  368. $next = $row['next_item_id'];
  369. $display_order = $row['display_order'];
  370. }
  371. }
  372. else
  373. {
  374. $tmp_previous = 0;
  375. $next = 0;
  376. $display_order = 0;
  377. }
  378. $new_item_id = -1;
  379. $id = $this->escape_string($id);
  380. //insert new item
  381. $sql_ins = "
  382. INSERT INTO " . $tbl_lp_item . " (
  383. lp_id,
  384. item_type,
  385. ref,
  386. title,
  387. description,
  388. path,
  389. parent_item_id,
  390. previous_item_id,
  391. next_item_id,
  392. display_order
  393. ) VALUES (
  394. " . $this->get_id() . ",
  395. '" . $type . "',
  396. '',
  397. '" . $this->escape_string(htmlentities($title)) . "',
  398. '" . $this->escape_string(htmlentities($description)) . "',
  399. '" . $id . "',
  400. " . $parent . ",
  401. " . $previous . ",
  402. " . $next . ",
  403. " . ($display_order + 1) . "
  404. )";
  405. //echo $sql_ins; // for debug
  406. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  407. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  408. if($res_ins > 0)
  409. {
  410. $new_item_id = Database::get_last_insert_id($res_ins);
  411. //update the item that should come after the new item
  412. $sql_update_next = "
  413. UPDATE " . $tbl_lp_item . "
  414. SET previous_item_id = " . $new_item_id . "
  415. WHERE id = " . $next;
  416. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  417. //update the item that should be before the new item
  418. $sql_update_previous = "
  419. UPDATE " . $tbl_lp_item . "
  420. SET next_item_id = " . $new_item_id . "
  421. WHERE id = " . $tmp_previous;
  422. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  423. //update all the items after the new item
  424. $sql_update_order = "
  425. UPDATE " . $tbl_lp_item . "
  426. SET display_order = display_order + 1
  427. WHERE
  428. lp_id = " . $this->get_id() . " AND
  429. id <> " . $new_item_id . " AND
  430. parent_item_id = " . $parent . " AND
  431. display_order > " . $display_order;
  432. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  433. }
  434. return $new_item_id;
  435. }
  436. /**
  437. * Adds an item to the current learnpath
  438. * @param integer Parent ID
  439. * @param integer Previous elem ID (0 if first)
  440. * @param string Resource type to add ('file','dokeos_item')
  441. * @param string Resource ID or path if 'file' or name if 'dokeos_chapter'
  442. * @return integer New element ID
  443. */
  444. function old_add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title)
  445. {
  446. //TODO
  447. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  448. $tbl_lp_item = Database::get_course_table('lp_item');
  449. $parent = (int) $parent;
  450. $display_order = 1;
  451. if($previous == -1){
  452. //insert in latest position available
  453. $sql_check = "SELECT MAX(previous_item_id) as prev, id FROM $tbl_lp_item WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  454. if($this->debug>1){error_log('New LP - checking for latest item at this level: '.$sql_check,0);}
  455. $res = mysql_query($sql_check) or die(mysql_error());
  456. $res_check = api_sql_query($sql_check, __FILE__, __LINE__);
  457. $num = Database::num_rows($res_check);
  458. if($num>0){
  459. $row = Database::fetch_array($res_check);
  460. $previous = $row['id'];
  461. }else{
  462. $previous = 0;
  463. }
  464. }else{
  465. $previous = (int) $previous;
  466. }
  467. $new_item_id = -1;
  468. //check type
  469. switch ($type){
  470. case 'dokeos_step':
  471. $id = $this->escape_string($id);
  472. //check the next item
  473. $sql_check = "SELECT * FROM $tbl_lp_item " .
  474. "WHERE lp_id = ".$this->get_id()." " .
  475. "AND previous_item_id = $previous " .
  476. "AND parent_item_id = $parent";
  477. if($this->debug>2){error_log('New LP - Getting info from the next element: '.$sql_check,0);}
  478. $res_check = api_sql_query($sql_check);
  479. if(Database::num_rows($res_check)){
  480. $row = Database::fetch_array($res_check);
  481. $next = $row['id'];
  482. //TODO check display_order
  483. $display_order = $row['display_order']+1;
  484. }else{
  485. $next = 0;
  486. $display_order = 1;
  487. }
  488. //insert new item
  489. $sql_ins = "INSERT INTO $tbl_lp_item " .
  490. "(lp_id,item_type,ref,title," .
  491. "path,parent_item_id," .
  492. "previous_item_id,next_item_id,display_order)" .
  493. "VALUES" .
  494. "(".$this->get_id().",'$type','','$title','$id'," .
  495. "$parent," .
  496. "$previous,$next,$display_order)";
  497. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  498. $res_ins = api_sql_query($sql_ins);
  499. if($res_ins>0){
  500. $new_item_id = Database::get_last_insert_id($res_ins);
  501. //now update previous item
  502. $sql_upd = "UPDATE $tbl_lp_item " .
  503. "SET next_item_id = $new_item_id " .
  504. "WHERE lp_id = ".$this->get_id()." " .
  505. "AND id = $previous AND parent_item_id = $parent";
  506. if($this->debug>2){error_log('New LP - Updating previous item: '.$sql_upd,0);}
  507. $res_upd = api_sql_query($sql_upd);
  508. //now update next item
  509. $sql_upd = "UPDATE $tbl_lp_item " .
  510. "SET previous_item_id = $new_item_id " .
  511. "WHERE lp_id = ".$this->get_id()." " .
  512. "AND id = $next AND parent_item_id = $parent";
  513. if($this->debug>2){error_log('New LP - Updating next item: '.$sql_upd,0);}
  514. $res_upd = api_sql_query($sql_upd);
  515. }
  516. break;
  517. default:
  518. break;
  519. }
  520. return $new_item_id;
  521. }
  522. /**
  523. * Static admin function allowing addition of a learnpath to a course.
  524. * @param string Course code
  525. * @param string Learnpath name
  526. * @param string Learnpath description string, if provided
  527. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  528. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  529. * @param string Zip file containing the learnpath or directory containing the learnpath
  530. * @return integer The new learnpath ID on success, 0 on failure
  531. */
  532. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  533. {
  534. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  535. //TODO
  536. $tbl_lp = Database::get_course_table('lp');
  537. //check course code exists
  538. //check lp_name doesn't exist, otherwise append something
  539. $i = 0;
  540. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  541. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  542. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  543. $res_name = api_sql_query($check_name);
  544. while(Database::num_rows($res_name)){
  545. //there is already one such name, update the current one a bit
  546. $i++;
  547. $name = $name.' - '.$i;
  548. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  549. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  550. $res_name = api_sql_query($check_name);
  551. }
  552. //new name does not exist yet; keep it
  553. //escape description
  554. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  555. $type = 1;
  556. switch($learnpath){
  557. case 'guess':
  558. break;
  559. case 'dokeos':
  560. $type = 1;
  561. break;
  562. case 'aicc':
  563. break;
  564. }
  565. switch($origin){
  566. case 'zip':
  567. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  568. break;
  569. case 'manual':
  570. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  571. $res_max = api_sql_query($get_max);
  572. if(Database::num_rows($res_max)<1){
  573. $dsp = 1;
  574. }else{
  575. $row = Database::fetch_array($res_max);
  576. $dsp = $row[0]+1;
  577. }
  578. $sql_insert = "INSERT INTO $tbl_lp " .
  579. "(lp_type,name,description,path,default_view_mod," .
  580. "default_encoding,display_order,content_maker," .
  581. "content_local,js_lib) " .
  582. "VALUES ($type,'$name','$description','','embedded'," .
  583. "'ISO-8859-1','$dsp','Dokeos'," .
  584. "'local','')";
  585. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  586. $res_insert = api_sql_query($sql_insert);
  587. $id = Database::get_last_insert_id();
  588. if($id>0){
  589. return $id;
  590. }
  591. break;
  592. }
  593. }
  594. /**
  595. * Appends a message to the message attribute
  596. * @param string Message to append.
  597. */
  598. function append_message($string)
  599. {
  600. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  601. $this->message .= $string;
  602. }
  603. /**
  604. * Autocompletes the parents of an item in case it's been completed or passed
  605. * @param integer Optional ID of the item from which to look for parents
  606. */
  607. function autocomplete_parents($item)
  608. {
  609. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  610. if(empty($item)){
  611. $item = $this->current;
  612. }
  613. $parent_id = $this->items[$item]->get_parent();
  614. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  615. if(is_object($this->items[$item]) and !empty($parent_id))
  616. {//if $item points to an object and there is a parent
  617. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  618. $current_item =& $this->items[$item];
  619. $parent =& $this->items[$parent_id]; //get the parent
  620. //new experiment including failed and browsed in completed status
  621. $current_status = $current_item->get_status();
  622. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed'){
  623. //if the current item is completed or passes or succeeded
  624. $completed = true;
  625. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  626. foreach($parent->get_children() as $child){
  627. //check all his brothers (his parent's children) for completion status
  628. if($child!= $item){
  629. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  630. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  631. //Trying completing parents of failed and browsed items as well
  632. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  633. {
  634. //keep completion status to true
  635. }else{
  636. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  637. $completed = false;
  638. }
  639. }
  640. }
  641. if($completed == true){ //if all the children were completed
  642. $parent->set_status('completed');
  643. $parent->save(false);
  644. $this->update_queue[$parent->get_id()] = $parent->get_status();
  645. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  646. $this->autocomplete_parents($parent->get_id()); //recursive call
  647. }
  648. }else{
  649. //error_log('New LP - status of current item is not enough to get bothered',0);
  650. }
  651. }
  652. }
  653. /**
  654. * Autosaves the current results into the database for the whole learnpath
  655. */
  656. function autosave()
  657. {
  658. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  659. //TODO add aditionnal save operations for the learnpath itself
  660. }
  661. /**
  662. * Clears the message attribute
  663. */
  664. function clear_message()
  665. {
  666. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  667. $this->message = '';
  668. }
  669. /**
  670. * Closes the current resource
  671. *
  672. * Stops the timer
  673. * Saves into the database if required
  674. * Clears the current resource data from this object
  675. * @return boolean True on success, false on failure
  676. */
  677. function close()
  678. {
  679. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  680. if(empty($this->lp_id))
  681. {
  682. $this->error = 'Trying to close this learnpath but no ID is set';
  683. return false;
  684. }
  685. $this->current_time_stop = time();
  686. if($this->save)
  687. {
  688. $learnpath_view_table = Database::get_course_table(LEARNPATH_VIEW_TABLE);
  689. /*
  690. $sql = "UPDATE $learnpath_view_table " .
  691. "SET " .
  692. "stop_time = ".$this->current_time_stop.", " .
  693. "score = ".$this->current_score.", ".
  694. "WHERE learnpath_id = '".$this->lp_id."'";
  695. //$res = Database::query($sql);
  696. $res = api_sql_query($res);
  697. if(mysql_affected_rows($res)<1)
  698. {
  699. $this->error = 'Could not update learnpath_view table while closing learnpath';
  700. return false;
  701. }
  702. */
  703. }
  704. $this->ordered_items = array();
  705. $this->index=0;
  706. unset($this->lp_id);
  707. //unset other stuff
  708. return true;
  709. }
  710. /**
  711. * Static admin function allowing removal of a learnpath
  712. * @param string Course code
  713. * @param integer Learnpath ID
  714. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  715. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  716. */
  717. function delete($course=null,$id=null,$delete='keep')
  718. {
  719. //TODO implement a way of getting this to work when the current object is not set
  720. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  721. //if(empty($course)){$course = api_get_course_id();}
  722. //if(empty($id)){$id = $this->get_id();}
  723. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  724. foreach($this->items as $id => $dummy)
  725. {
  726. $this->items[$id]->delete();
  727. }
  728. $lp = Database::get_course_table('lp');
  729. $lp_view = Database::get_course_table('lp_view');
  730. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  731. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  732. $res_del_view = api_sql_query($sql_del_view);
  733. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  734. if($this->type == 2 OR $this->type==3){
  735. //this is a scorm learning path, delete the files as well
  736. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  737. $res = api_sql_query($sql);
  738. if(Database::num_rows($res)>0){
  739. $row = Database::fetch_array($res);
  740. $path = $row['path'];
  741. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  742. $res = api_sql_query($sql);
  743. if(Database::num_rows($res)>0)
  744. { //another learning path uses this directory, so don't delete it
  745. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  746. }else{
  747. //no other LP uses that directory, delete it
  748. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  749. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  750. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  751. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  752. exec('rm -rf '.$course_scorm_dir.$path);
  753. }
  754. }
  755. }
  756. }
  757. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  758. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  759. $res_del_lp = api_sql_query($sql_del_lp);
  760. //TODO: also delete items and item-views
  761. }
  762. /**
  763. * Removes all the children of one item - dangerous!
  764. * @param integer Element ID of which children have to be removed
  765. * @return integer Total number of children removed
  766. */
  767. function delete_children_items($id){
  768. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  769. $num = 0;
  770. if(empty($id) || $id != strval(intval($id))){return false;}
  771. $lp_item = Database::get_course_table('lp_item');
  772. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  773. $res = api_sql_query($sql);
  774. while($row = Database::fetch_array($res)){
  775. $num += $this->delete_children_items($row['id']);
  776. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  777. $res_del = api_sql_query($sql_del);
  778. $num++;
  779. }
  780. return $num;
  781. }
  782. /**
  783. * Removes an item from the current learnpath
  784. * @param integer Elem ID (0 if first)
  785. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  786. * @return integer Number of elements moved
  787. * @todo implement resource removal
  788. */
  789. function delete_item($id, $remove='keep')
  790. {
  791. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  792. //TODO - implement the resource removal
  793. if(empty($id) || $id != strval(intval($id))){return false;}
  794. //first select item to get previous, next, and display order
  795. $lp_item = Database::get_course_table('lp_item');
  796. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  797. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  798. if(Database::num_rows($res_sel)<1){return false;}
  799. $row = Database::fetch_array($res_sel);
  800. $previous = $row['previous_item_id'];
  801. $next = $row['next_item_id'];
  802. $display = $row['display_order'];
  803. $parent = $row['parent_item_id'];
  804. $lp = $row['lp_id'];
  805. //delete children items
  806. $num = $this->delete_children_items($id);
  807. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  808. //now delete the item
  809. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  810. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  811. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  812. //now update surrounding items
  813. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  814. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  815. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  816. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  817. //now update all following items with new display order
  818. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  819. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  820. }
  821. /**
  822. * Updates an item's content in place
  823. * @param integer Element ID
  824. * @param string New content
  825. * @return boolean True on success, false on error
  826. */
  827. function old_edit_item($id,$content)
  828. {
  829. if($this->debug>0){error_log('New LP - In learnpath::edit_item()',0);}
  830. if(empty($id) or ($id != strval(intval($id))) or empty($content)){ return false; }
  831. $content = $this->escape_string($content);
  832. $lp_item = Database::get_course_table('lp_item');
  833. $sql_upd = "UPDATE $lp_item SET title = '$content' WHERE id = $id";
  834. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  835. //TODO update the item object (can be ignored for now because refreshed)
  836. return true;
  837. }
  838. function edit_item($id, $parent, $previous, $title, $description)
  839. {
  840. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  841. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  842. $tbl_lp_item = Database::get_course_table('lp_item');
  843. $sql_select = "
  844. SELECT *
  845. FROM " . $tbl_lp_item . "
  846. WHERE id = " . $id;
  847. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  848. $row_select = Database::fetch_array($res_select);
  849. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  850. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  851. if($same_parent && $same_previous)
  852. {
  853. //only update title and description
  854. $sql_update = "
  855. UPDATE " . $tbl_lp_item . "
  856. SET
  857. title = '" . $this->escape_string(htmlentities($title)) . "',
  858. description = '" . $this->escape_string(htmlentities($description)) . "'
  859. WHERE id = " . $id;
  860. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  861. }
  862. else
  863. {
  864. $old_parent = $row_select['parent_item_id'];
  865. $old_previous = $row_select['previous_item_id'];
  866. $old_next = $row_select['next_item_id'];
  867. $old_order = $row_select['display_order'];
  868. /* BEGIN -- virtually remove the current item id */
  869. /* for the next and previous item it is like the current item doesn't exist anymore */
  870. if($old_previous != 0)
  871. {
  872. $sql_update_next = "
  873. UPDATE " . $tbl_lp_item . "
  874. SET next_item_id = " . $old_next . "
  875. WHERE id = " . $old_previous;
  876. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  877. //echo '<p>' . $sql_update_next . '</p>';
  878. }
  879. if($old_next != 0)
  880. {
  881. $sql_update_previous = "
  882. UPDATE " . $tbl_lp_item . "
  883. SET previous_item_id = " . $old_previous . "
  884. WHERE id = " . $old_next;
  885. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  886. //echo '<p>' . $sql_update_previous . '</p>';
  887. }
  888. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  889. $sql_update_order = "
  890. UPDATE " . $tbl_lp_item . "
  891. SET display_order = display_order - 1
  892. WHERE
  893. display_order > " . $old_order . " AND
  894. parent_item_id = " . $old_parent;
  895. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  896. //echo '<p>' . $sql_update_order . '</p>';
  897. /* END -- virtually remove the current item id */
  898. /* BEGIN -- update the current item id to his new location */
  899. if($previous == 0)
  900. {
  901. //select the data of the item that should come after the current item
  902. $sql_select_old = "
  903. SELECT
  904. id,
  905. display_order
  906. FROM " . $tbl_lp_item . "
  907. WHERE
  908. lp_id = " . $this->lp_id . " AND
  909. parent_item_id = " . $parent . " AND
  910. previous_item_id = " . $previous;
  911. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  912. $row_select_old = Database::fetch_array($res_select_old);
  913. //echo '<p>' . $sql_select_old . '</p>';
  914. //if the new parent doesn't had children before
  915. if(Database::num_rows($res_select_old) == 0)
  916. {
  917. $new_next = 0;
  918. $new_order = 1;
  919. }
  920. else
  921. {
  922. $new_next = $row_select_old['id'];
  923. $new_order = $row_select_old['display_order'];
  924. }
  925. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  926. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  927. //echo 'New display_order of current item: ' . $new_order . '<br />';
  928. }
  929. else
  930. {
  931. //select the data of the item that should come before the current item
  932. $sql_select_old = "
  933. SELECT
  934. next_item_id,
  935. display_order
  936. FROM " . $tbl_lp_item . "
  937. WHERE id = " . $previous;
  938. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  939. $row_select_old = Database::fetch_array($res_select_old);
  940. //echo '<p>' . $sql_select_old . '</p>';
  941. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  942. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  943. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  944. $new_next = $row_select_old['next_item_id'];
  945. $new_order = $row_select_old['display_order'] + 1;
  946. }
  947. //update the current item with the new data
  948. $sql_update = "
  949. UPDATE " . $tbl_lp_item . "
  950. SET
  951. title = '" . $this->escape_string(htmlentities($title)) . "',
  952. description = '" . $this->escape_string(htmlentities($description)) . "',
  953. parent_item_id = " . $parent . ",
  954. previous_item_id = " . $previous . ",
  955. next_item_id = " . $new_next . ",
  956. display_order = " . $new_order . "
  957. WHERE id = " . $id;
  958. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  959. //echo '<p>' . $sql_update . '</p>';
  960. if($previous != 0)
  961. {
  962. //update the previous item his next_item_id
  963. $sql_update_previous = "
  964. UPDATE " . $tbl_lp_item . "
  965. SET next_item_id = " . $id . "
  966. WHERE id = " . $previous;
  967. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  968. //echo '<p>' . $sql_update_previous . '</p>';
  969. }
  970. if($new_next != 0)
  971. {
  972. //update the next item his previous_item_id
  973. $sql_update_next = "
  974. UPDATE " . $tbl_lp_item . "
  975. SET previous_item_id = " . $id . "
  976. WHERE id = " . $new_next;
  977. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  978. //echo '<p>' . $sql_update_next . '</p>';
  979. }
  980. //update all the items with the same or a bigger display_order then the current item
  981. $sql_update_order = "
  982. UPDATE " . $tbl_lp_item . "
  983. SET display_order = display_order + 1
  984. WHERE
  985. lp_id = " . $this->get_id() . " AND
  986. id <> " . $id . " AND
  987. parent_item_id = " . $parent . " AND
  988. display_order >= " . $new_order;
  989. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  990. //echo '<p>' . $sql_update_order . '</p>';
  991. /* END -- update the current item id to his new location */
  992. }
  993. }
  994. /**
  995. * Updates an item's prereq in place
  996. * @param integer Element ID
  997. * @param string Prerequisite Element ID
  998. *
  999. * @param string Prerequisite item type
  1000. *
  1001. * @param string Prerequisite min score
  1002. *
  1003. * @param string Prerequisite max score
  1004. * @return boolean True on success, false on error
  1005. */
  1006. function edit_item_prereq($id, $prerequisite_id, $min_score = 0, $max_score = 100)
  1007. {
  1008. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq()',0);}
  1009. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  1010. $prerequisite_id = $this->escape_string($prerequisite_id);
  1011. $tbl_lp_item = Database::get_course_table('lp_item');
  1012. if(!is_numeric($min_score) || $min_score < 0 || $min_score > 100)
  1013. $min_score = 0;
  1014. if(!is_numeric($max_score) || $max_score < 0 || $max_score > 100)
  1015. $max_score = 100;
  1016. if($min_score > $max_score)
  1017. $max_score = $min_score;
  1018. if(!is_numeric($prerequisite_id))
  1019. $prerequisite_id = 'NULL';
  1020. $sql_upd = "
  1021. UPDATE " . $tbl_lp_item . "
  1022. SET
  1023. min_score = " . $min_score . ",
  1024. max_score = " . $max_score . ",
  1025. prerequisite = " . $prerequisite_id . "
  1026. WHERE id = " . $id;
  1027. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1028. //TODO update the item object (can be ignored for now because refreshed)
  1029. return true;
  1030. }
  1031. /**
  1032. * Escapes a string with the available database escape function
  1033. * @param string String to escape
  1034. * @return string String escaped
  1035. */
  1036. function escape_string($string){
  1037. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1038. return mysql_real_escape_string($string);
  1039. }
  1040. /**
  1041. * Static admin function exporting a learnpath into a zip file
  1042. * @param string Export type (scorm, zip, cd)
  1043. * @param string Course code
  1044. * @param integer Learnpath ID
  1045. * @param string Zip file name
  1046. * @return string Zip file path (or false on error)
  1047. */
  1048. function export_lp($type, $course, $id, $zipname)
  1049. {
  1050. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1051. //TODO
  1052. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1053. $url = '';
  1054. switch($type){
  1055. case 'scorm':
  1056. break;
  1057. case 'zip':
  1058. break;
  1059. case 'cdrom':
  1060. break;
  1061. }
  1062. return $url;
  1063. }
  1064. /**
  1065. * Gets all the chapters belonging to the same parent as the item/chapter given
  1066. * Can also be called as abstract method
  1067. * @param integer Item ID
  1068. * @return array A list of all the "brother items" (or an empty array on failure)
  1069. */
  1070. function get_brother_chapters($id){
  1071. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1072. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1073. $lp_item = Database::get_course_table('lp_item');
  1074. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1075. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1076. if(Database::num_rows($res_parent)>0){
  1077. $row_parent = Database::fetch_array($res_parent);
  1078. $parent = $row_parent['parent_item_id'];
  1079. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1080. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1081. $list = array();
  1082. while ($row_bro = Database::fetch_array($res_bros)){
  1083. $list[] = $row_bro;
  1084. }
  1085. return $list;
  1086. }
  1087. return array();
  1088. }
  1089. /**
  1090. * Gets all the items belonging to the same parent as the item given
  1091. * Can also be called as abstract method
  1092. * @param integer Item ID
  1093. * @return array A list of all the "brother items" (or an empty array on failure)
  1094. */
  1095. function get_brother_items($id){
  1096. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1097. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1098. $lp_item = Database::get_course_table('lp_item');
  1099. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1100. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1101. if(Database::num_rows($res_parent)>0){
  1102. $row_parent = Database::fetch_array($res_parent);
  1103. $parent = $row_parent['parent_item_id'];
  1104. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1105. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1106. $list = array();
  1107. while ($row_bro = Database::fetch_array($res_bros)){
  1108. $list[] = $row_bro;
  1109. }
  1110. return $list;
  1111. }
  1112. return array();
  1113. }
  1114. /**
  1115. * Gets the number of items currently completed
  1116. * @return integer The number of items currently completed
  1117. */
  1118. function get_complete_items_count()
  1119. {
  1120. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1121. $i = 0;
  1122. foreach($this->items as $id => $dummy){
  1123. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1124. //Trying failed and browsed considered "progressed" as well
  1125. if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))){
  1126. $i++;
  1127. }
  1128. }
  1129. return $i;
  1130. }
  1131. /**
  1132. * Gets the current item ID
  1133. * @return integer The current learnpath item id
  1134. */
  1135. function get_current_item_id()
  1136. {
  1137. $current = 0;
  1138. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1139. if(!empty($this->current))
  1140. {
  1141. $current = $this->current;
  1142. }
  1143. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1144. return $current;
  1145. }
  1146. /**
  1147. * Gets the total number of items available for viewing in this SCORM
  1148. * @return integer The total number of items
  1149. */
  1150. function get_total_items_count()
  1151. {
  1152. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1153. return count($this->items);
  1154. }
  1155. /**
  1156. * Gets the first element URL.
  1157. * @return string URL to load into the viewer
  1158. */
  1159. function first()
  1160. {
  1161. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1162. //test if the last_item_seen exists and is not a dir
  1163. if(!empty($this->last_item_seen)
  1164. && !empty($this->items[$this->last_item_seen])
  1165. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1166. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1167. && $this->items[$this->last_item_seen]->is_done() != true
  1168. ){
  1169. 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);}
  1170. $index = -1;
  1171. foreach($this->ordered_items as $myindex => $item_id){
  1172. if($item_id == $this->last_item_seen){
  1173. $index = $myindex;
  1174. break;
  1175. }
  1176. }
  1177. if($index==-1){
  1178. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1179. 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);}
  1180. return false;
  1181. }else{
  1182. $this->last = $this->last_item_seen;
  1183. $this->current = $this->last_item_seen;
  1184. $this->index = $index;
  1185. }
  1186. }else{
  1187. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1188. $index = 0;
  1189. while (!empty($this->ordered_items[$index])
  1190. AND
  1191. (
  1192. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1193. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1194. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1195. )
  1196. AND $index < $this->max_ordered_items)
  1197. {
  1198. $index ++;
  1199. }
  1200. $this->last = $this->current;
  1201. //current is
  1202. $this->current = $this->ordered_items[$index];
  1203. $this->index = $index;
  1204. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1205. }
  1206. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1207. }
  1208. /**
  1209. * Gets the information about an item in a format usable as JavaScript to update
  1210. * the JS API by just printing this content into the <head> section of the message frame
  1211. * @param integer Item ID
  1212. * @return string
  1213. */
  1214. function get_js_info($item_id=''){
  1215. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1216. $info = '';
  1217. $item_id = $this->escape_string($item_id);
  1218. if(!empty($item_id) && is_object($this->items[$item_id])){
  1219. //if item is defined, return values from DB
  1220. $oItem = $this->items[$item_id];
  1221. $info .= '<script language="javascript">';
  1222. $info .= "top.set_score(".$oItem->get_score().");\n";
  1223. $info .= "top.set_max(".$oItem->get_max().");\n";
  1224. $info .= "top.set_min(".$oItem->get_min().");\n";
  1225. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1226. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1227. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1228. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1229. $info .= "top.set_flag_synchronized();";
  1230. $info .= '</script>';
  1231. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1232. return $info;
  1233. }else{
  1234. //if item_id is empty, just update to default SCORM data
  1235. $info .= '<script language="javascript">';
  1236. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1237. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1238. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1239. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1240. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1241. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1242. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1243. $info .= "top.set_flag_synchronized();";
  1244. $info .= '</script>';
  1245. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1246. return $info;
  1247. }
  1248. }
  1249. /**
  1250. * Gets the js library from the database
  1251. * @return string The name of the javascript library to be used
  1252. */
  1253. function get_js_lib(){
  1254. $lib = '';
  1255. if(!empty($this->js_lib)){
  1256. $lib = $this->js_lib;
  1257. }
  1258. return $lib;
  1259. }
  1260. /**
  1261. * Gets the learnpath database ID
  1262. * @return integer Learnpath ID in the lp table
  1263. */
  1264. function get_id()
  1265. {
  1266. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1267. if(!empty($this->lp_id))
  1268. {
  1269. return $this->lp_id;
  1270. }else{
  1271. return 0;
  1272. }
  1273. }
  1274. /**
  1275. * Gets the last element URL.
  1276. * @return string URL to load into the viewer
  1277. */
  1278. function get_last()
  1279. {
  1280. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1281. $this->index = count($this->ordered_items)-1;
  1282. return $this->ordered_items[$this->index];
  1283. }
  1284. /**
  1285. * Gets the navigation bar for the learnpath display screen
  1286. * @return string The HTML string to use as a navigation bar
  1287. */
  1288. function get_navigation_bar()
  1289. {
  1290. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1291. //TODO find a good value for the following variables
  1292. $file = '';
  1293. $openDir = '';
  1294. $edoceo = '';
  1295. $time = 0;
  1296. $navbar = '';
  1297. $RequestUri = '';
  1298. $mycurrentitemid = $this->get_current_item_id();
  1299. if($this->mode == 'fullscreen'){
  1300. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1301. ' <tr> '."\n" .
  1302. ' <td>'."\n" .
  1303. ' <div class="buttons">'."\n" .
  1304. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/previous.gif" title="'.get_lang('ScormPrevious').'"></a>&nbsp;'."\n" .
  1305. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/next.gif" title="'.get_lang('ScormNext').'"></a>&nbsp;'."\n" .
  1306. ' <a href="lp_controller.php?action=switch_view_mode" target="_top" title="embedded mode"><img border="0" src="../img/scormexitfullscreen.jpg" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1307. ' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1308. ' </div>'."\n" .
  1309. ' </td>'."\n" .
  1310. ' </tr>'."\n" .
  1311. '</table>'."\n" ;
  1312. }else{
  1313. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1314. ' <tr> '."\n" .
  1315. ' <td>'."\n" .
  1316. ' <div class="buttons">'."\n" .
  1317. ' <a href="lp_controller.php?action=stats" target="content_name" title="stats"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('ScormMystatus').'"></a>&nbsp;'."\n" .
  1318. ' <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>&nbsp;'."\n" .
  1319. ' <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>&nbsp;'."\n" .
  1320. ' <a href="lp_controller.php?action=switch_view_mode" target="_top" title="fullscreen"><img border="0" src="../img/view_fullscreen.gif" width="18" height="18" title="'.get_lang('ScormFullScreen').'"></a>'."\n" .
  1321. ' </div>'."\n" .
  1322. ' </td>'."\n" .
  1323. ' </tr>'."\n" .
  1324. '</table>'."\n" ;
  1325. }
  1326. return $navbar;
  1327. }
  1328. /**
  1329. * Gets the next resource in queue (url).
  1330. * @return string URL to load into the viewer
  1331. */
  1332. function get_next_index()
  1333. {
  1334. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1335. //TODO
  1336. $index = $this->index;
  1337. $index ++;
  1338. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]['type'],0);}
  1339. while(!empty($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir' AND $index < $this->max_ordered_items)
  1340. {
  1341. $index ++;
  1342. if($index == $this->max_ordered_items)
  1343. {
  1344. return $this->index;
  1345. }
  1346. }
  1347. if(empty($this->ordered_items[$index])){
  1348. return $this->index;
  1349. }
  1350. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1351. return $index;
  1352. }
  1353. /**
  1354. * Gets item_id for the next element
  1355. * @return integer Next item (DB) ID
  1356. */
  1357. function get_next_item_id()
  1358. {
  1359. $new_index = $this->get_next_index();
  1360. return $this->ordered_items[$new_index];
  1361. }
  1362. /**
  1363. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1364. *
  1365. * Generally, the package provided is in the form of a zip file, so the function
  1366. * has been written to test a zip file. If not a zip, the function will return the
  1367. * default return value: ''
  1368. * @param string the path to the file
  1369. * @param string the original name of the file
  1370. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1371. */
  1372. function get_package_type($file_path,$file_name){
  1373. //get name of the zip file without the extension
  1374. $file_info = pathinfo($file_name);
  1375. $filename = $file_info['basename'];//name including extension
  1376. $extension = $file_info['extension'];//extension only
  1377. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1378. {
  1379. return 'ppt';
  1380. }
  1381. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1382. $zipFile = new pclZip($file_path);
  1383. // Check the zip content (real size and file extension)
  1384. $zipContentArray = $zipFile->listContent();
  1385. $package_type='';
  1386. $at_root = false;
  1387. $manifest = '';
  1388. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1389. foreach($zipContentArray as $thisContent)
  1390. {
  1391. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1392. {
  1393. return '';
  1394. }
  1395. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1396. {
  1397. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1398. $package_type = 'scorm';
  1399. break;//exit the foreach loop
  1400. }
  1401. elseif(preg_match('/aicc\//i',$thisContent['filename'])!==FALSE)
  1402. {//if found an aicc directory...
  1403. $package_type='aicc';
  1404. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1405. }
  1406. else
  1407. {
  1408. $package_type = '';
  1409. }
  1410. }
  1411. return $package_type;
  1412. }
  1413. /**
  1414. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1415. * @return string URL to load into the viewer
  1416. */
  1417. function get_previous_index()
  1418. {
  1419. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1420. $index = $this->index;
  1421. if(isset($this->ordered_items[$index-1])){
  1422. $index --;
  1423. while(isset($this->ordered_items[$index]) AND $this->items[$this->ordered_items[$index]]->get_type() == 'dir')
  1424. {
  1425. $index --;
  1426. if($index < 0){
  1427. return $this->index;
  1428. }
  1429. }
  1430. }else{
  1431. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1432. //no previous item
  1433. }
  1434. return $index;
  1435. }
  1436. /**
  1437. * Gets item_id for the next element
  1438. * @return integer Previous item (DB) ID
  1439. */
  1440. function get_previous_item_id()
  1441. {
  1442. $new_index = $this->get_previous_index();
  1443. return $this->ordered_items[$new_index];
  1444. }
  1445. /**
  1446. * Gets the progress value from the progress_db attribute
  1447. * @return integer Current progress value
  1448. */
  1449. function get_progress(){
  1450. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1451. if(!empty($this->progress_db)){
  1452. return $this->progress_db;
  1453. }
  1454. return 0;
  1455. }
  1456. /**
  1457. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1458. * @param integer Learnpath ID
  1459. * @param integer User ID
  1460. * @param string Mode of display ('%','abs' or 'both')
  1461. * @return integer Current progress value as found in the database
  1462. */
  1463. function get_db_progress($lp_id,$user_id,$mode='%'){
  1464. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1465. $table = Database::get_course_table('lp_view');
  1466. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1467. $res = api_sql_query($sql,__FILE__,__LINE__);
  1468. $view_id = 0;
  1469. if(Database::num_rows($res)>0){
  1470. $row = Database::fetch_array($res);
  1471. $progress = $row['progress'];
  1472. $view_id = $row['id'];
  1473. }
  1474. if(!$progress){
  1475. $progress = '0';
  1476. }
  1477. if($mode == '%'){
  1478. return $progress.'%';
  1479. }else{
  1480. //get the number of items completed and the number of items total
  1481. $tbl = Database::get_course_table('lp_item');
  1482. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id;
  1483. $res = api_sql_query($sql);
  1484. $row = Database::fetch_array($res);
  1485. $total = $row[0];
  1486. $tbl = Database::get_course_table('lp_item_view');
  1487. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1488. //trying as also counting browsed and failed items
  1489. $sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded','browsed','failed')";
  1490. $res = api_sql_query($sql);
  1491. $row = Database::fetch_array($res);
  1492. $completed = $row[0];
  1493. if($mode == 'abs'){
  1494. return $completed.'/'.$total;
  1495. }
  1496. elseif($mode == 'both')
  1497. {
  1498. if($progress<($completed/($total?$total:1))){
  1499. $progress = number_format(($completed/($total?$total:1))*100,0);
  1500. }
  1501. return $progress.'% ('.$completed.'/'.$total.')';
  1502. }
  1503. }
  1504. return $progress;
  1505. }
  1506. /**
  1507. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1508. * completed so far.
  1509. * @param string Mode in which we want the values
  1510. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1511. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1512. * @return string HTML string containing the progress bar
  1513. */
  1514. function get_progress_bar($mode='',$percentage=-1,$text_add='')
  1515. {
  1516. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1517. if($percentage=='-1' OR $text_add==''){
  1518. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1519. }
  1520. $text = $percentage.$text_add;
  1521. $output = ''
  1522. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1523. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1524. .'<img id="progress_img_limit_left" src="../img/bar_1.gif" width="1" height="12">'
  1525. .'<img id="progress_img_full" src="../img/bar_1u.gif" width="'.$percentage.'" height="12" id="full_portion">'
  1526. .'<img id="progress_img_limit_middle" src="../img/bar_1m.gif" width="1" height="12">';
  1527. if($percentage <= 98){
  1528. $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="'.(100-$percentage).'" height="12" id="empty_portion">';
  1529. }else{
  1530. $output .= '<img id="progress_img_empty" src="../img/bar_1r.gif" width="0" height="12" id="empty_portion">';
  1531. }
  1532. $output .= '<img id="progress_bar_img_limit_right" src="../img/bar_1.gif" width="1" height="12"></td></tr></table>'
  1533. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1534. return $output;
  1535. }
  1536. /**
  1537. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1538. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1539. * //@param integer Additional steps to fake as completed
  1540. * @return list Percentage or number and symbol (% or /xx)
  1541. */
  1542. function get_progress_bar_text($mode='',$add=0)
  1543. {
  1544. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1545. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1546. $total_items = $this->get_total_items_count();
  1547. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1548. $i = $this->get_complete_items_count();
  1549. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1550. if($add != 0){
  1551. $i += $add;
  1552. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1553. }
  1554. $text = '';
  1555. if($i>$total_items){
  1556. $i = $total_items;
  1557. }
  1558. if($mode == '%'){
  1559. $percentage = ((float)$i/(float)$total_items)*100;
  1560. $percentage = number_format($percentage,0);
  1561. $text = '%';
  1562. }elseif($mode == 'abs'){
  1563. $percentage = $i;
  1564. $text = '/'.$total_items;
  1565. }
  1566. return array($percentage,$text);
  1567. }
  1568. /**
  1569. * Gets the progress bar mode
  1570. * @return string The progress bar mode attribute
  1571. */
  1572. function get_progress_bar_mode()
  1573. {
  1574. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1575. if(!empty($this->progress_bar_mode))
  1576. {
  1577. return $this->progress_bar_mode;
  1578. }else{
  1579. return '%';
  1580. }
  1581. }
  1582. /**
  1583. * Returns a usable array of stats related to the current learnpath and user
  1584. * @return array Well-formatted array containing status for the current learnpath
  1585. */
  1586. function get_stats()
  1587. {
  1588. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1589. //TODO
  1590. }
  1591. /**
  1592. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1593. * the given course (for all learnpaths and all users)
  1594. * @param string Course code
  1595. * @return array Well-formatted array containing status for the course's learnpaths
  1596. */
  1597. function get_stats_course($course)
  1598. {
  1599. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1600. //TODO
  1601. }
  1602. /**
  1603. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1604. * the given course and learnpath (for all users)
  1605. * @param string Course code
  1606. * @param integer Learnpath ID
  1607. * @return array Well-formatted array containing status for the specified learnpath
  1608. */
  1609. function get_stats_lp($course,$lp)
  1610. {
  1611. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1612. //TODO
  1613. }
  1614. /**
  1615. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1616. * the given course, learnpath and user.
  1617. * @param string Course code
  1618. * @param integer Learnpath ID
  1619. * @param integer User ID
  1620. * @return array Well-formatted array containing status for the specified learnpath and user
  1621. */
  1622. function get_stats_lp_user($course,$lp,$user)
  1623. {
  1624. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1625. //TODO
  1626. }
  1627. /**
  1628. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1629. * the given course and learnpath (for all users)
  1630. * @param string Course code
  1631. * @param integer User ID
  1632. * @return array Well-formatted array containing status for the user's learnpaths
  1633. */
  1634. function get_stats_user($course,$user)
  1635. {
  1636. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1637. //TODO
  1638. }
  1639. /**
  1640. * Gets the status list for all LP's items
  1641. * @return array Array of [index] => [item ID => current status]
  1642. */
  1643. function get_items_status_list(){
  1644. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1645. $list = array();
  1646. foreach($this->ordered_items as $item_id)
  1647. {
  1648. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1649. }
  1650. return $list;
  1651. }
  1652. /**
  1653. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  1654. * used by get_html_toc() to be ready to display
  1655. * @return array TOC as a table with 4 elements per row: title, link, status and level
  1656. */
  1657. function get_toc()
  1658. {
  1659. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  1660. $toc = array();
  1661. //echo "<pre>".print_r($this->items,true)."</pre>";
  1662. foreach($this->ordered_items as $item_id)
  1663. {
  1664. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  1665. //TODO change this link generation and use new function instead
  1666. $toc[] = array(
  1667. 'id'=>$item_id,
  1668. 'title'=>$this->items[$item_id]->get_title(),
  1669. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  1670. 'status'=>$this->items[$item_id]->get_status(),
  1671. 'level'=>$this->items[$item_id]->get_level(),
  1672. 'type' =>$this->items[$item_id]->get_type(),
  1673. );
  1674. }
  1675. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  1676. return $toc;
  1677. }
  1678. /**
  1679. * Gets the learning path type
  1680. * @param boolean Return the name? If false, return the ID. Default is false.
  1681. * @return mixed Type ID or name, depending on the parameter
  1682. */
  1683. function get_type($get_name = false)
  1684. {
  1685. $res = false;
  1686. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  1687. if(!empty($this->type))
  1688. {
  1689. if($get_name)
  1690. {
  1691. //get it from the lp_type table in main db
  1692. }else{
  1693. $res = $this->type;
  1694. }
  1695. }
  1696. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  1697. return $res;
  1698. }
  1699. /**
  1700. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  1701. * This method can be used as abstract and is recursive
  1702. * @param integer Learnpath ID
  1703. * @param integer Parent ID of the items to look for
  1704. * @return mixed Ordered list of item IDs or false on error
  1705. */
  1706. function get_flat_ordered_items_list($lp,$parent=0){
  1707. if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  1708. $list = array();
  1709. if(empty($lp)){return false;}
  1710. $tbl_lp_item = Database::get_course_table('lp_item');
  1711. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  1712. $res = api_sql_query($sql,__FILE__,__LINE__);
  1713. while($row = Database::fetch_array($res)){
  1714. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  1715. $list[] = $row['id'];
  1716. foreach($sublist as $item){
  1717. $list[] = $item;
  1718. }
  1719. }
  1720. return $list;
  1721. }
  1722. /**
  1723. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  1724. * @return string HTML TOC ready to display
  1725. */
  1726. /*function get_html_toc()
  1727. {
  1728. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  1729. $list = $this->get_toc();
  1730. //echo $this->current;
  1731. //$parent = $this->items[$this->current]->get_parent();
  1732. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  1733. $html = '<div class="inner_lp_toc">'."\n" ;
  1734. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  1735. require_once('resourcelinker.inc.php');
  1736. //temp variables
  1737. $mycurrentitemid = $this->get_current_item_id();
  1738. foreach($list as $item)
  1739. {
  1740. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  1741. //TODO complete this
  1742. $icon_name = array('not attempted' => 'notattempted.png',
  1743. 'incomplete' => 'incomplete.png',
  1744. 'failed' => 'failed.png',
  1745. 'completed' => 'completed.png',
  1746. 'passed' => 'passed.png',
  1747. 'succeeded' => 'succeeded.png',
  1748. 'browsed' => 'completed.png');
  1749. $style = 'scorm_item';
  1750. if($item['id'] == $this->current){
  1751. $style = 'scorm_item_highlight';
  1752. }
  1753. //the anchor will let us center the TOC on the currently viewed item &^D
  1754. $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'].'" >' .
  1755. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  1756. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  1757. $title = $item['title'];
  1758. if(empty($title)){
  1759. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  1760. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  1761. }
  1762. if(empty($title))$title = '-';
  1763. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  1764. //$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>" ;
  1765. $url = $this->get_link('http',$item['id']);
  1766. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  1767. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  1768. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  1769. $mycurrentitemid.',' .
  1770. $item['id'].');' .
  1771. 'return false;" >'.$title.'</a>' ;
  1772. }else{
  1773. $html .= $title;
  1774. }
  1775. $html .= "</div>\n";
  1776. }
  1777. $html .= "</div>\n";
  1778. return $html;
  1779. }*/
  1780. /**
  1781. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  1782. * @return string HTML TOC ready to display
  1783. */
  1784. function get_html_toc()
  1785. {
  1786. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  1787. $list = $this->get_toc();
  1788. //echo $this->current;
  1789. //$parent = $this->items[$this->current]->get_parent();
  1790. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  1791. $html .= '<div class="inner_lp_toc">'."\n" ;
  1792. if($_SESSION["is_courseAdmin"]==1){
  1793. $html.="<a style='font-size: 11px' href='lp_controller.php?cidReq=".$_SESSION['_cid']."&action=admin_view&lp_id=".$this->lp_id."' target='_parent'>".get_lang("BasicOverview")."</a> - <a href='lp_controller.php?cidReq=".$_SESSION['_cid']."&action=build&lp_id=".$this->lp_id."' style='font-size: 11px' target='_parent'>".get_lang("Advanced")."</a><br><br>";
  1794. }
  1795. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  1796. require_once('resourcelinker.inc.php');
  1797. //temp variables
  1798. $mycurrentitemid = $this->get_current_item_id();
  1799. foreach($list as $item)
  1800. {
  1801. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  1802. //TODO complete this
  1803. $icon_name = array('not attempted' => 'notattempted.png',
  1804. 'incomplete' => 'incomplete.png',
  1805. 'failed' => 'failed.png',
  1806. 'completed' => 'completed.png',
  1807. 'passed' => 'passed.png',
  1808. 'succeeded' => 'succeeded.png',
  1809. 'browsed' => 'completed.png');
  1810. $style = 'scorm_item';
  1811. if($item['id'] == $this->current){
  1812. $style = 'scorm_item_highlight';
  1813. }
  1814. //the anchor will let us center the TOC on the currently viewed item &^D
  1815. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter'){
  1816. $html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
  1817. '';
  1818. }
  1819. else{
  1820. $html .= '<div class="'.$style.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" id="toc_'.$item['id'].'" >' .
  1821. '';
  1822. }
  1823. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  1824. $title = $item['title'];
  1825. if(empty($title)){
  1826. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  1827. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  1828. }
  1829. if(empty($title))$title = '-';
  1830. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module'){
  1831. //$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>" ;
  1832. $url = $this->get_link('http',$item['id']);
  1833. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  1834. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  1835. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  1836. $mycurrentitemid.',' .
  1837. $item['id'].');' .
  1838. 'return false;" ><img align="absbottom" width="13" height="13" src="img/lp_document.png">&nbsp;'.stripslashes($title).'</a>' ;
  1839. }
  1840. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter'){
  1841. $html .= "<img align='absbottom' width='13' height='13' src='img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  1842. }
  1843. elseif($item['type']=='dir'){
  1844. $html .= stripslashes($title);
  1845. }
  1846. $html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' /></div>\n";
  1847. }
  1848. $html .= "</div>\n";
  1849. return $html;
  1850. }
  1851. /**
  1852. * Gets the user-friendly message stored in $this->message
  1853. * @return string Message
  1854. */
  1855. function get_message(){
  1856. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  1857. return $this->message;
  1858. }
  1859. /**
  1860. * Gets the learnpath name/title
  1861. * @return string Learnpath name/title
  1862. */
  1863. function get_name()
  1864. {
  1865. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  1866. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  1867. }
  1868. /**
  1869. * Gets a link to the resource from the present location, depending on item ID.
  1870. * @param string Type of link expected
  1871. * @param integer Learnpath item ID
  1872. * @return string Link to the lp_item resource
  1873. */
  1874. function get_link($type='http',$item_id=null)
  1875. {
  1876. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  1877. if(empty($item_id))
  1878. {
  1879. 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);}
  1880. $item_id = $this->get_current_item_id();
  1881. }
  1882. if(empty($item_id)){
  1883. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  1884. //still empty, this means there was no item_id given and we are not in an object context or
  1885. //the object property is empty, return empty link
  1886. $item_id = $this->first();
  1887. return '';
  1888. }
  1889. $file = '';
  1890. $lp_db = Database::get_current_course_database();
  1891. $lp_pref = Database::get_course_table_prefix();
  1892. $lp_table = $lp_db.'.'.$lp_pref.'lp';
  1893. $lp_item_table = $lp_db.'.'.$lp_pref.'lp_item';
  1894. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath " .
  1895. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  1896. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  1897. $res = api_sql_query($sel);
  1898. if(Database::num_rows($res)>0)
  1899. {
  1900. $row = Database::fetch_array($res);
  1901. //var_dump($row);
  1902. $lp_type = $row['ltype'];
  1903. $lp_path = $row['lpath'];
  1904. $lp_item_type = $row['litype'];
  1905. $lp_item_path = $row['lipath'];
  1906. if($type == 'http'){
  1907. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  1908. }else{
  1909. $course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path(); //system path
  1910. }
  1911. //now go through the specific cases to get the end of the path
  1912. switch($lp_type){
  1913. case 1:
  1914. if($lp_item_type == 'dokeos_chapter'){
  1915. $file = 'lp_content.php?type=dir';
  1916. }else{
  1917. require_once('resourcelinker.inc.php');
  1918. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  1919. }
  1920. break;
  1921. case 2:
  1922. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  1923. if($lp_item_type!='dir'){
  1924. //Quite complex here:
  1925. //we want to make sure 'http://' (and similar) links can
  1926. //be loaded as is (withouth the Dokeos path in front) but
  1927. //some contents use this form: resource.htm?resource=http://blablabla
  1928. //which means we have to find a protocol at the path's start, otherwise
  1929. //it should not be considered as an external URL
  1930. //if($this->prerequisites_match($item_id)){
  1931. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  1932. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  1933. //distant url, return as is
  1934. $file = $lp_item_path;
  1935. }else{
  1936. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  1937. //prevent getting untranslatable urls
  1938. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  1939. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  1940. //prepare the path
  1941. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  1942. //TODO fix this for urls with protocol header
  1943. $file = str_replace('//','/',$file);
  1944. $file = str_replace(':/','://',$file);
  1945. }
  1946. //}else{
  1947. //prerequisites did not match
  1948. //$file = 'blank.php';
  1949. //}
  1950. }else{
  1951. $file = 'lp_content.php?type=dir';
  1952. }
  1953. break;
  1954. case 3:
  1955. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  1956. //formatting AICC HACP append URL
  1957. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  1958. if($lp_item_type!='dir'){
  1959. //Quite complex here:
  1960. //we want to make sure 'http://' (and similar) links can
  1961. //be loaded as is (withouth the Dokeos path in front) but
  1962. //some contents use this form: resource.htm?resource=http://blablabla
  1963. //which means we have to find a protocol at the path's start, otherwise
  1964. //it should not be considered as an external URL
  1965. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  1966. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  1967. //distant url, return as is
  1968. $file = $lp_item_path;
  1969. /*
  1970. if(stristr($file,'<servername>')!==false){
  1971. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  1972. }
  1973. */
  1974. $file .= $aicc_append;
  1975. }else{
  1976. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  1977. //prevent getting untranslatable urls
  1978. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  1979. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  1980. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  1981. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  1982. //TODO fix this for urls with protocol header
  1983. $file = str_replace('//','/',$file);
  1984. $file = str_replace(':/','://',$file);
  1985. $file .= $aicc_append;
  1986. }
  1987. }else{
  1988. $file = 'lp_content.php?type=dir';
  1989. }
  1990. break;
  1991. case 4:
  1992. break;
  1993. default:
  1994. break;
  1995. }
  1996. }
  1997. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  1998. return $file;
  1999. }
  2000. /**
  2001. * Gets the latest usable view or generate a new one
  2002. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2003. * @return integer DB lp_view id
  2004. */
  2005. function get_view($attempt_num=0)
  2006. {
  2007. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2008. $search = '';
  2009. //use $attempt_num to enable multi-views management (disabled so far)
  2010. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2011. {
  2012. $search = 'AND view_count = '.$attempt_num;
  2013. }
  2014. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2015. $lp_view_table = Database::get_course_table('lp_view');
  2016. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2017. "WHERE lp_id = ".$this->get_id()." " .
  2018. "AND user_id = ".$this->get_user_id()." " .
  2019. $search .
  2020. " ORDER BY view_count DESC";
  2021. $res = api_sql_query($sql);
  2022. if(Database::num_rows($res)>0)
  2023. {
  2024. $row = Database::fetch_array($res);
  2025. $this->lp_view_id = $row['id'];
  2026. }else{
  2027. //no database record, create one
  2028. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2029. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2030. $res = api_sql_query($sql);
  2031. $id = Database::get_last_insert_id();
  2032. $this->lp_view_id = $id;
  2033. }
  2034. }
  2035. /**
  2036. * Gets the current view id
  2037. * @return integer View ID (from lp_view)
  2038. */
  2039. function get_view_id()
  2040. {
  2041. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2042. if(!empty($this->lp_view_id))
  2043. {
  2044. return $this->lp_view_id;
  2045. }else{
  2046. return 0;
  2047. }
  2048. }
  2049. /**
  2050. * Gets the update queue
  2051. * @return array Array containing IDs of items to be updated by JavaScript
  2052. */
  2053. function get_update_queue()
  2054. {
  2055. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2056. return $this->update_queue;
  2057. }
  2058. /**
  2059. * Gets the user ID
  2060. * @return integer User ID
  2061. */
  2062. function get_user_id()
  2063. {
  2064. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2065. if(!empty($this->user_id))
  2066. {
  2067. return $this->user_id;
  2068. }else{
  2069. return false;
  2070. }
  2071. }
  2072. /**
  2073. * Logs a message into a file
  2074. * @param string Message to log
  2075. * @return boolean True on success, false on error or if msg empty
  2076. */
  2077. function log($msg)
  2078. {
  2079. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2080. //TODO
  2081. $this->error .= $msg."\n";
  2082. return true;
  2083. }
  2084. /**
  2085. * Moves an item up and down at its level
  2086. * @param integer Item to move up and down
  2087. * @param string Direction 'up' or 'down'
  2088. * @return integer New display order, or false on error
  2089. */
  2090. function move_item($id, $direction){
  2091. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2092. if(empty($id) or empty($direction)){return false;}
  2093. $tbl_lp_item = Database::get_course_table('lp_item');
  2094. $sql_sel = "
  2095. SELECT *
  2096. FROM " . $tbl_lp_item . "
  2097. WHERE id = " . $id;
  2098. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2099. //check if elem exists
  2100. if(Database::num_rows($res_sel)<1){return false;}
  2101. //gather data
  2102. $row = Database::fetch_array($res_sel);
  2103. $previous = $row['previous_item_id'];
  2104. $next = $row['next_item_id'];
  2105. $display = $row['display_order'];
  2106. $parent = $row['parent_item_id'];
  2107. $lp = $row['lp_id'];
  2108. //update the item (switch with previous/next one)
  2109. switch($direction)
  2110. {
  2111. case 'up':
  2112. if($this->debug>2){error_log('Movement up detected',0);}
  2113. if($display <= 1){/*do nothing*/}
  2114. else{
  2115. $sql_sel2 = "SELECT *
  2116. FROM $tbl_lp_item
  2117. WHERE id = $previous";
  2118. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2119. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2120. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2121. //gather data
  2122. $row2 = Database::fetch_array($res_sel2);
  2123. $previous_previous = $row2['previous_item_id'];
  2124. //update previous_previous item (switch "next" with current)
  2125. if($previous_previous != 0){
  2126. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_$previous";
  2127. if($this->debug>2){error_log($sql_upd2,0);}
  2128. $res_upd2 = api_sql_query($sql_upd2);
  2129. }
  2130. //update previous item (switch with current)
  2131. if($previous != 0){
  2132. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2133. if($this->debug>2){error_log($sql_upd2,0);}
  2134. $res_upd2 = api_sql_query($sql_upd2);
  2135. }
  2136. //update current item (switch with previous)
  2137. if($id != 0){
  2138. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2139. if($this->debug>2){error_log($sql_upd2,0);}
  2140. $res_upd2 = api_sql_query($sql_upd2);
  2141. }
  2142. //update next item (new previous item)
  2143. if($next != 0){
  2144. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2145. if($this->debug>2){error_log($sql_upd2,0);}
  2146. $res_upd2 = api_sql_query($sql_upd2);
  2147. }
  2148. $display = $display-1;
  2149. }
  2150. break;
  2151. case 'down':
  2152. if($this->debug>2){error_log('Movement down detected',0);}
  2153. if($next == 0){/*do nothing*/}
  2154. else{
  2155. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2156. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2157. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2158. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2159. //gather data
  2160. $row2 = Database::fetch_array($res_sel2);
  2161. $next_next = $row2['next_item_id'];
  2162. //update previous item (switch with current)
  2163. if($previous != 0){
  2164. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2165. $res_upd2 = api_sql_query($sql_upd2);
  2166. }
  2167. //update current item (switch with previous)
  2168. if($id != 0){
  2169. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2170. $res_upd2 = api_sql_query($sql_upd2);
  2171. }
  2172. //update next item (new previous item)
  2173. if($next != 0){
  2174. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2175. $res_upd2 = api_sql_query($sql_upd2);
  2176. }
  2177. //update next_next item (switch "previous" with current)
  2178. if($next_next != 0){
  2179. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2180. $res_upd2 = api_sql_query($sql_upd2);
  2181. }
  2182. $display = $display+1;
  2183. }
  2184. break;
  2185. default:
  2186. return false;
  2187. }
  2188. return $display;
  2189. }
  2190. /**
  2191. * Updates learnpath attributes to point to the next element
  2192. * The last part is similar to set_current_item but processing the other way around
  2193. */
  2194. function next(){
  2195. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2196. $this->last = $this->get_current_item_id();
  2197. $this->items[$this->last]->save(false);
  2198. $this->autocomplete_parents($this->last);
  2199. $new_index = $this->get_next_index();
  2200. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2201. $this->index = $new_index;
  2202. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2203. $this->current = $this->ordered_items[$new_index];
  2204. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2205. }
  2206. /**
  2207. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2208. * class, this might be redefined to allow several behaviours depending on the document type.
  2209. * @param integer Resource ID
  2210. * @return boolean True on success, false otherwise
  2211. */
  2212. function open($id)
  2213. {
  2214. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2215. //TODO
  2216. //set the current resource attribute to this resource
  2217. //switch on element type (redefine in child class?)
  2218. //set status for this item to "opened"
  2219. //start timer
  2220. //initialise score
  2221. $this->index = 0; //or = the last item seen (see $this->last)
  2222. }
  2223. /**
  2224. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2225. * and the prerequisite string on error.
  2226. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2227. * @param integer Optional item ID. If none given, uses the current open item.
  2228. * @return boolean True if prerequisites are matched, false otherwise
  2229. * @return string Empty string if true returned, prerequisites string otherwise.
  2230. */
  2231. function prerequisites_match($item = null){
  2232. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2233. if(empty($item)){$item = $this->current;}
  2234. if(is_object($this->items[$item])){
  2235. $prereq_string = $this->items[$item]->get_prereq_string();
  2236. if(empty($prereq_string)){return true;}
  2237. //clean spaces
  2238. $prereq_string = str_replace(' ','',$prereq_string);
  2239. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2240. //now send to the parse_prereq() function that will check this component's prerequisites
  2241. $result = $this->items[$item]->parse_prereq($prereq_string,$this);
  2242. if($result === false){
  2243. $this->set_error_msg($this->items[$item]->prereq_alert);
  2244. }
  2245. }else{
  2246. $result = true;
  2247. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2248. }
  2249. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2250. return $result;
  2251. }
  2252. /**
  2253. * Updates learnpath attributes to point to the previous element
  2254. * The last part is similar to set_current_item but processing the other way around
  2255. */
  2256. function previous(){
  2257. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2258. $this->last = $this->get_current_item_id();
  2259. $this->items[$this->last]->save(false);
  2260. $this->autocomplete_parents($this->last);
  2261. $new_index = $this->get_previous_index();
  2262. $this->index = $new_index;
  2263. $this->current = $this->ordered_items[$new_index];
  2264. }
  2265. /**
  2266. * Publishes a learnpath. This basically means show or hide the learnpath
  2267. * to normal users.
  2268. * Can be used as abstract
  2269. * @param integer Learnpath ID
  2270. * @param string New visibility
  2271. */
  2272. function toggle_visibility($lp_id,$set_visibility='v')
  2273. {
  2274. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2275. $tbl_lp = Database::get_course_table('lp');
  2276. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2277. $result=api_sql_query($sql,__FILE__,__LINE__);
  2278. $row=Database::fetch_array($result);
  2279. $name=domesticate($row['name']);
  2280. if($set_visibility == 'i') {
  2281. $s=$name." ".get_lang('_no_published');
  2282. $dialogBox=$s;
  2283. $v=0;
  2284. }
  2285. if($set_visibility == 'v') {
  2286. $s=$name." ".get_lang('_published');
  2287. $dialogBox=$s;
  2288. $v=1;
  2289. }
  2290. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  2291. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  2292. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  2293. $result=api_sql_query($sql,__FILE__,__LINE__);
  2294. $num=Database::num_rows($result);
  2295. $row2=Database::fetch_array($result);
  2296. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2297. if(($set_visibility == 'i') && ($num>0))
  2298. {
  2299. //it is visible or hidden but once was published
  2300. if(($row2['visibility'])==1)
  2301. {
  2302. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2303. }
  2304. else
  2305. {
  2306. $sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2307. }
  2308. }
  2309. elseif(($set_visibility == 'v') && ($num==0))
  2310. {
  2311. $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)";
  2312. }
  2313. else
  2314. {
  2315. //parameter and database incompatible, do nothing
  2316. }
  2317. $result=api_sql_query($sql,__FILE__,__LINE__);
  2318. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  2319. }
  2320. /**
  2321. * Restart the whole learnpath. Return the URL of the first element.
  2322. * Make sure the results are saved with anoter method. This method should probably be
  2323. * redefined in children classes.
  2324. * @return string URL to load in the viewer
  2325. */
  2326. function restart()
  2327. {
  2328. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  2329. //TODO
  2330. //call autosave method to save the current progress
  2331. //$this->index = 0;
  2332. $lp_view_table = Database::get_course_table('lp_view');
  2333. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  2334. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  2335. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  2336. $res = api_sql_query($sql);
  2337. if($view_id = Database::get_last_insert_id($res))
  2338. {
  2339. $this->lp_view_id = $view_id;
  2340. $this->attempt = $this->attempt+1;
  2341. }else{
  2342. $this->error = 'Could not insert into item_view table...';
  2343. return false;
  2344. }
  2345. $this->autocomplete_parents($this->current);
  2346. foreach($this->items as $index=>$dummy){
  2347. $this->items[$index]->restart();
  2348. $this->items[$index]->set_lp_view($this->lp_view_id);
  2349. }
  2350. $this->first();
  2351. return true;
  2352. }
  2353. /**
  2354. * Saves the current item
  2355. * @return boolean
  2356. */
  2357. function save_current(){
  2358. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  2359. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2360. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2361. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  2362. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  2363. if(is_object($this->items[$this->current])){
  2364. $res = $this->items[$this->current]->save(false);
  2365. $this->autocomplete_parents($this->current);
  2366. $status = $this->items[$this->current]->get_status();
  2367. $this->append_message('new_item_status: '.$status);
  2368. $this->update_queue[$this->current] = $status;
  2369. return $res;
  2370. }
  2371. return false;
  2372. }
  2373. /**
  2374. * Saves the given item
  2375. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  2376. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  2377. * @return boolean
  2378. */
  2379. function save_item($item_id=null,$from_outside=true){
  2380. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  2381. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  2382. // on $ordered_items[] but not sure it's always safe to use with $items[])
  2383. if(empty($item_id)){
  2384. $item_id = $this->escape_string($_REQUEST['id']);
  2385. }
  2386. if(empty($item_id))
  2387. {
  2388. $item_id = $this->get_current_item_id();
  2389. }
  2390. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  2391. if(is_object($this->items[$item_id])){
  2392. $res = $this->items[$item_id]->save($from_outside);
  2393. $this->autocomplete_parents($item_id);
  2394. $status = $this->items[$item_id]->get_status();
  2395. $this->append_message('new_item_status: '.$status);
  2396. $this->update_queue[$item_id] = $status;
  2397. return $res;
  2398. }
  2399. return false;
  2400. }
  2401. /**
  2402. * Saves the last item seen's ID only in case
  2403. */
  2404. function save_last(){
  2405. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  2406. $table = Database::get_course_table('lp_view');
  2407. if(isset($this->current)){
  2408. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  2409. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  2410. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  2411. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  2412. $res = api_sql_query($sql,__FILE__,__LINE__);
  2413. }
  2414. //save progress
  2415. list($progress,$text) = $this->get_progress_bar_text('%');
  2416. if($progress>=0 AND $progress<=100){
  2417. $progress= (int)$progress;
  2418. $sql = "UPDATE $table SET progress = $progress " .
  2419. "WHERE lp_id = ".$this->get_id()." AND " .
  2420. "user_id = ".$this->get_user_id();
  2421. $res = @mysql_query($sql); //ignore errors as some tables might not have the progress field just yet
  2422. $this->progress_db = $progress;
  2423. }
  2424. }
  2425. /**
  2426. * Sets the current item ID (checks if valid and authorized first)
  2427. * @param integer New item ID. If not given or not authorized, defaults to current
  2428. */
  2429. function set_current_item($item_id=null)
  2430. {
  2431. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  2432. if(empty($item_id)){
  2433. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  2434. //do nothing
  2435. }else{
  2436. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  2437. $item_id = $this->escape_string($item_id);
  2438. //TODO check in database here
  2439. $this->last = $this->current;
  2440. $this->current = $item_id;
  2441. //TODO update $this->index as well
  2442. foreach($this->ordered_items as $index => $item)
  2443. {
  2444. if($item == $this->current)
  2445. {
  2446. $this->index = $index;
  2447. break;
  2448. }
  2449. }
  2450. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  2451. }
  2452. }
  2453. /**
  2454. * Sets the encoding
  2455. * @param string New encoding
  2456. */
  2457. function set_encoding($enc='ISO-8859-1'){
  2458. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  2459. $enc = strtoupper($enc);
  2460. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
  2461. if(in_array($enc,$encodings)){
  2462. $lp = $this->get_id();
  2463. if($lp!=0){
  2464. $tbl_lp = Database::get_course_table('lp');
  2465. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  2466. $res = api_sql_query($sql);
  2467. return $res;
  2468. }
  2469. }
  2470. return false;
  2471. }
  2472. /**
  2473. * Sets the JS lib setting in the database directly.
  2474. * This is the JavaScript library file this lp needs to load on startup
  2475. * @param string Proximity setting
  2476. */
  2477. function set_jslib($lib=''){
  2478. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  2479. $lp = $this->get_id();
  2480. if($lp!=0){
  2481. $tbl_lp = Database::get_course_table('lp');
  2482. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  2483. $res = api_sql_query($sql);
  2484. return $res;
  2485. }else{
  2486. return false;
  2487. }
  2488. }
  2489. /**
  2490. * Sets the name of the LP maker (publisher) (and save)
  2491. * @param string Optional string giving the new content_maker of this learnpath
  2492. */
  2493. function set_maker($name=''){
  2494. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  2495. if(empty($name))return false;
  2496. $this->maker = $this->escape_string($name);
  2497. $lp_table = Database::get_course_table('lp');
  2498. $lp_id = $this->get_id();
  2499. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  2500. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  2501. //$res = Database::query($sql);
  2502. $res = api_sql_query($sql);
  2503. return true;
  2504. }
  2505. /**
  2506. * Sets the name of the current learnpath (and save)
  2507. * @param string Optional string giving the new name of this learnpath
  2508. */
  2509. function set_name($name=''){
  2510. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  2511. if(empty($name))return false;
  2512. $this->name = $this->escape_string($name);
  2513. $lp_table = Database::get_course_table('lp');
  2514. $lp_id = $this->get_id();
  2515. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  2516. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  2517. //$res = Database::query($sql);
  2518. $res = api_sql_query($sql);
  2519. return true;
  2520. }
  2521. /**
  2522. * Sets the location/proximity of the LP (local/remote) (and save)
  2523. * @param string Optional string giving the new location of this learnpath
  2524. */
  2525. function set_proximity($name=''){
  2526. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  2527. if(empty($name))return false;
  2528. $this->proximity = $this->escape_string($name);
  2529. $lp_table = Database::get_course_table('lp');
  2530. $lp_id = $this->get_id();
  2531. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  2532. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  2533. //$res = Database::query($sql);
  2534. $res = api_sql_query($sql);
  2535. return true;
  2536. }
  2537. /**
  2538. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  2539. * @param integer DB ID of the item
  2540. */
  2541. function set_previous_item($id)
  2542. {
  2543. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  2544. $this->last = $id;
  2545. }
  2546. /**
  2547. * Sets the object's error message
  2548. * @param string Error message. If empty, reinits the error string
  2549. * @return void
  2550. */
  2551. function set_error_msg($error='')
  2552. {
  2553. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  2554. if(empty($error)){
  2555. $this->error = '';
  2556. }else{
  2557. $this->error .= $error;
  2558. }
  2559. }
  2560. /**
  2561. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  2562. *
  2563. */
  2564. function start_current_item(){
  2565. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  2566. if($this->current != 0 AND
  2567. is_object($this->items[$this->current]))
  2568. {
  2569. $type = $this->get_type();
  2570. if(
  2571. ($type == 2 && $this->items[$this->current]->get_type()!='sco')
  2572. OR
  2573. ($type == 3 && $this->items[$this->current]->get_type()!='au')
  2574. OR
  2575. ($type==1)
  2576. )
  2577. {
  2578. $this->items[$this->current]->open();
  2579. $this->items[$this->current]->save(false);
  2580. $this->autocomplete_parents($this->current);
  2581. $this->prerequisites_match(); //launch the prerequisites check and set error if needed
  2582. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2583. }else{
  2584. //if sco, then it is supposed to have been updated by some other call
  2585. }
  2586. }
  2587. return true;
  2588. }
  2589. /**
  2590. * Stops the processing and counters for the old item (as held in $this->last)
  2591. * @param
  2592. */
  2593. function stop_previous_item(){
  2594. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  2595. if($this->last != 0 AND is_object($this->items[$this->last]))
  2596. {
  2597. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  2598. switch($this->get_type()){
  2599. case '3':
  2600. if($this->items[$this->last]->get_type()!='au')
  2601. {
  2602. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  2603. $this->items[$this->last]->close();
  2604. //$this->autocomplete_parents($this->last);
  2605. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2606. }else{
  2607. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  2608. }
  2609. case '2':
  2610. if($this->items[$this->last]->get_type()!='sco')
  2611. {
  2612. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  2613. $this->items[$this->last]->close();
  2614. //$this->autocomplete_parents($this->last);
  2615. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  2616. }else{
  2617. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  2618. }
  2619. break;
  2620. case '1':
  2621. default:
  2622. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  2623. $this->items[$this->last]->close();
  2624. break;
  2625. }
  2626. }else{
  2627. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  2628. return false;
  2629. }
  2630. return true;
  2631. }
  2632. /**
  2633. * Updates the default view mode from fullscreen to embedded and inversely
  2634. * @return string The current default view mode ('fullscreen' or 'embedded')
  2635. */
  2636. function update_default_view_mode()
  2637. {
  2638. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  2639. $lp_table = Database::get_course_table('lp');
  2640. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2641. $res = api_sql_query($sql);
  2642. if(Database::num_rows($res)>0){
  2643. $row = Database::fetch_array($res);
  2644. $view_mode = $row['default_view_mod'];
  2645. if($view_mode == 'fullscreen'){
  2646. $view_mode = 'embedded';
  2647. }elseif($view_mode == 'embedded'){
  2648. $view_mode = 'fullscreen';
  2649. }
  2650. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  2651. $res = api_sql_query($sql);
  2652. $this->mode = $view_mode;
  2653. return $view_mode;
  2654. }else{
  2655. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  2656. }
  2657. return -1;
  2658. }
  2659. /**
  2660. * Updates the default behaviour about auto-commiting SCORM updates
  2661. * @return boolean True if auto-commit has been set to 'on', false otherwise
  2662. */
  2663. function update_default_scorm_commit(){
  2664. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  2665. $lp_table = Database::get_course_table('lp');
  2666. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2667. $res = api_sql_query($sql);
  2668. if(Database::num_rows($res)>0){
  2669. $row = Database::fetch_array($res);
  2670. $force = $row['force_commit'];
  2671. if($force == 1){
  2672. $force = 0;
  2673. $force_return = false;
  2674. }elseif($force == 0){
  2675. $force = 1;
  2676. $force_return = true;
  2677. }
  2678. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  2679. $res = api_sql_query($sql);
  2680. $this->force_commit = $force_return;
  2681. return $force_return;
  2682. }else{
  2683. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  2684. }
  2685. return -1;
  2686. }
  2687. /**
  2688. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  2689. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  2690. */
  2691. function update_reinit(){
  2692. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  2693. $lp_table = Database::get_course_table('lp');
  2694. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2695. $res = api_sql_query($sql);
  2696. if(Database::num_rows($res)>0){
  2697. $row = Database::fetch_array($res);
  2698. $force = $row['prevent_reinit'];
  2699. if($force == 1){
  2700. $force = 0;
  2701. }elseif($force == 0){
  2702. $force = 1;
  2703. }
  2704. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  2705. $res = api_sql_query($sql,__FILE__,__LINE__);
  2706. $this->prevent_reinit = $force;
  2707. return $force;
  2708. }else{
  2709. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  2710. }
  2711. return -1;
  2712. }
  2713. /**
  2714. * Updates the "scorm_debug" value that shows or hide the debug window
  2715. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  2716. */
  2717. function update_scorm_debug(){
  2718. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  2719. $lp_table = Database::get_course_table('lp');
  2720. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  2721. $res = api_sql_query($sql);
  2722. if(Database::num_rows($res)>0){
  2723. $row = Database::fetch_array($res);
  2724. $force = $row['debug'];
  2725. if($force == 1){
  2726. $force = 0;
  2727. }elseif($force == 0){
  2728. $force = 1;
  2729. }
  2730. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  2731. $res = api_sql_query($sql,__FILE__,__LINE__);
  2732. $this->scorm_debug = $force;
  2733. return $force;
  2734. }else{
  2735. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  2736. }
  2737. return -1;
  2738. }
  2739. /**
  2740. * Function that makes a call to the function sort_tree_array and create_tree_array
  2741. *
  2742. * @author Kevin Van Den Haute
  2743. *
  2744. * @param unknown_type $array
  2745. */
  2746. function tree_array($array)
  2747. {
  2748. $array = $this->sort_tree_array($array);
  2749. $this->create_tree_array($array);
  2750. }
  2751. /**
  2752. * Creates an array with the elements of the learning path tree in it
  2753. *
  2754. * @author Kevin Van Den Haute
  2755. *
  2756. * @param array $array
  2757. * @param int $parent
  2758. * @param int $depth
  2759. * @param array $tmp
  2760. */
  2761. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  2762. {
  2763. if(is_array($array))
  2764. {
  2765. for($i = 0; $i < count($array); $i++)
  2766. {
  2767. if($array[$i]['parent_item_id'] == $parent)
  2768. {
  2769. if(!in_array($array[$i]['parent_item_id'], $tmp))
  2770. {
  2771. $tmp[] = $array[$i]['parent_item_id'];
  2772. $depth++;
  2773. }
  2774. $this->arrMenu[] = array(
  2775. 'id' => $array[$i]['id'],
  2776. 'item_type' => $array[$i]['item_type'],
  2777. 'title' => $array[$i]['title'],
  2778. 'path' => $array[$i]['path'],
  2779. 'description' => $array[$i]['description'],
  2780. 'parent_item_id' => $array[$i]['parent_item_id'],
  2781. 'previous_item_id' => $array[$i]['previous_item_id'],
  2782. 'next_item_id' => $array[$i]['next_item_id'],
  2783. 'display_order' => $array[$i]['display_order'],
  2784. 'depth' => $depth
  2785. );
  2786. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  2787. }
  2788. }
  2789. }
  2790. }
  2791. /**
  2792. * Sorts a multi dimensional array by parent id and display order
  2793. * @author Kevin Van Den Haute
  2794. *
  2795. * @param array $array (array with al the learning path items in it)
  2796. *
  2797. * @return array
  2798. */
  2799. function sort_tree_array($array)
  2800. {
  2801. foreach($array as $key => $row)
  2802. {
  2803. $parent[$key] = $row['parent_item_id'];
  2804. $position[$key] = $row['display_order'];
  2805. }
  2806. if(count($array) > 0)
  2807. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  2808. return $array;
  2809. }
  2810. /**
  2811. * Function that creates a table structure with a learning path his modules, chapters and documents.
  2812. * Also the actions for the modules, chapters and documents are in this table.
  2813. *
  2814. * @author Kevin Van Den Haute
  2815. *
  2816. * @param int $lp_id
  2817. *
  2818. * @return string
  2819. */
  2820. function overview()
  2821. {
  2822. $return = '';
  2823. $tbl_lp_item = Database::get_course_table('lp_item');
  2824. $sql = "
  2825. SELECT *
  2826. FROM " . $tbl_lp_item . "
  2827. WHERE
  2828. lp_id = " . $this->lp_id;
  2829. $result = api_sql_query($sql, __FILE__, __LINE__);
  2830. $arrLP = array();
  2831. while($row = Database::fetch_array($result))
  2832. {
  2833. $arrLP[] = array(
  2834. 'id' => $row['id'],
  2835. 'item_type' => $row['item_type'],
  2836. 'title' => $row['title'],
  2837. 'description' => $row['description'],
  2838. 'parent_item_id' => $row['parent_item_id'],
  2839. 'previous_item_id' => $row['previous_item_id'],
  2840. 'next_item_id' => $row['next_item_id'],
  2841. 'display_order' => $row['display_order']);
  2842. }
  2843. $this->tree_array($arrLP);
  2844. $arrLP = $this->arrMenu;
  2845. unset($this->arrMenu);
  2846. if(api_is_allowed_to_edit())
  2847. $return .= '<p><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">'.get_lang("Advanced").'</a>&nbsp;<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$this->lp_id.'">'.get_lang("Display").'</a></p>';
  2848. $return .= '<table cellpadding="0" cellspacing="2" class="lp_overview">' . "\n";
  2849. $return .= "\t" . '<tr class="header">' . "\n";
  2850. $return .= "\t" . '<th width="75%">'.get_lang("Title").'</th>' . "\n";
  2851. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  2852. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  2853. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  2854. $return .= "\t" . '</tr>' . "\n";
  2855. for($i = 0; $i < count($arrLP); $i++)
  2856. {
  2857. if($arrLP[$i]['description'] == '')
  2858. $arrLP[$i]['description'] = '&nbsp;';
  2859. $return .= "\t" . '<tr>' . "\n";
  2860. $return .= "\t\t" . '<td class="title" style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:3px;" />' . stripslashes($arrLP[$i]['title']) . '</td>' . "\n";
  2861. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  2862. if(api_is_allowed_to_edit())
  2863. {
  2864. $return .= "\t\t" . '<td class="move">' . "\n";
  2865. if($arrLP[$i]['previous_item_id'] != 0)
  2866. {
  2867. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  2868. $return .= '<img alt="" src="img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.png" />';
  2869. $return .= '</a>' . "\n";
  2870. }
  2871. else
  2872. $return .= "\t\t\t" . '<img alt="" src="img/blanco.png" title="" />' . "\n";
  2873. if($arrLP[$i]['next_item_id'] != 0)
  2874. {
  2875. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  2876. $return .= '<img src="img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.png" />';
  2877. $return .= '</a>' . "\n";
  2878. }
  2879. else
  2880. $return .= "\t\t\t" . '<img alt="" src="img/blanco.png" title="" />' . "\n";
  2881. $return .= "\t\t" . '</td>' . "\n";
  2882. $return .= "\t\t" . '<td class="actions">' . "\n";
  2883. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  2884. {
  2885. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  2886. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  2887. $return .= '</a>' . "\n";
  2888. }
  2889. else
  2890. {
  2891. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  2892. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  2893. $return .= '</a>' . "\n";
  2894. }
  2895. $return .= "\t\t\t" . '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . $arrLP[$i]['title'] . '\');">';
  2896. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  2897. $return .= '</a>' . "\n";
  2898. $return .= "\t\t" . '</td>' . "\n";
  2899. }
  2900. $return .= "\t" . '</tr>' . "\n";
  2901. }
  2902. if(count($arrLP) == 0)
  2903. {
  2904. $return .= "\t" . '<tr>' . "\n";
  2905. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  2906. $return .= "\t" . '</tr>' . "\n";
  2907. }
  2908. $return .= '</table>' . "\n";
  2909. return $return;
  2910. }
  2911. /**
  2912. * This functions builds the LP tree based on data from the database.
  2913. *
  2914. * @return string
  2915. * @uses dtree.js :: necessary javascript for building this tree
  2916. */
  2917. function build_tree()
  2918. {
  2919. $return = "<script type=\"text/javascript\">\n";
  2920. $return .= "\tm = new dTree('m');\n\n";
  2921. $return .= "\tm.config.folderLinks = true;\n";
  2922. $return .= "\tm.config.useCookies = true;\n";
  2923. $return .= "\tm.config.useIcons = true;\n";
  2924. $return .= "\tm.config.useLines = true;\n";
  2925. $return .= "\tm.config.useSelection = true;\n";
  2926. $return .= "\tm.config.useStatustext = false;\n\n";
  2927. $menu = 0;
  2928. $parent = '';
  2929. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  2930. $tbl_lp_item = Database::get_course_table('lp_item');
  2931. $sql = "
  2932. SELECT *
  2933. FROM " . $tbl_lp_item . "
  2934. WHERE
  2935. lp_id = " . $this->lp_id;
  2936. $result = api_sql_query($sql, __FILE__, __LINE__);
  2937. $arrLP = array();
  2938. while($row = Database::fetch_array($result))
  2939. {
  2940. $arrLP[] = array(
  2941. 'id' => $row['id'],
  2942. 'item_type' => $row['item_type'],
  2943. 'title' => $row['title'],
  2944. 'path' => $row['path'],
  2945. 'description' => $row['description'],
  2946. 'parent_item_id' => $row['parent_item_id'],
  2947. 'previous_item_id' => $row['previous_item_id'],
  2948. 'next_item_id' => $row['next_item_id'],
  2949. 'display_order' => $row['display_order']);
  2950. }
  2951. $this->tree_array($arrLP);
  2952. $arrLP = $this->arrMenu;
  2953. unset($this->arrMenu);
  2954. for($i = 0; $i < count($arrLP); $i++)
  2955. {
  2956. $menu_page = $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  2957. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $arrLP[$i]['title'] . "', '" . $menu_page . "', '', '', 'img/lp_" . $arrLP[$i]['item_type'] . ".png', 'img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
  2958. if($menu < $arrLP[$i]['id'])
  2959. $menu = $arrLP[$i]['id'];
  2960. }
  2961. $return .= "\n\tdocument.write(m);\n";
  2962. $return .= "\t if(!m.selectedNode) m.s(1);";
  2963. $return .= "</script>\n";
  2964. return $return;
  2965. }
  2966. /**
  2967. * Create a new document //still needs some finetuning
  2968. *
  2969. * @param array $_course
  2970. * @return string
  2971. */
  2972. function create_document($_course)
  2973. {
  2974. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  2975. if(strstr($dir, '..'))
  2976. $dir = '/';
  2977. if($dir[0] == '.')
  2978. $dir = substr($dir, 1);
  2979. if($dir[0] != '/')
  2980. $dir = '/'.$dir;
  2981. if($dir[strlen($dir) - 1] != '/')
  2982. $dir .= '/';
  2983. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  2984. if(!is_dir($filepath))
  2985. {
  2986. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  2987. $dir = '/';
  2988. }
  2989. $title = replace_dangerous_char($_POST['title']);
  2990. $filename = $title;
  2991. $content = $_POST['content_lp'];
  2992. $tmp_filename = $filename;
  2993. while(file_exists($filepath . $tmp_filename . '.html'))
  2994. $tmp_filename = $filename . '_' . ++$i;
  2995. $filename = $tmp_filename . '.html';
  2996. $content = stripslashes(text_filter($content));
  2997. $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  2998. $content = str_replace($path_to_remove, './', $content);
  2999. if(!file_exists($filepath . $filename))
  3000. {
  3001. if($fp = @fopen($filepath . $filename, 'w'))
  3002. {
  3003. fputs($fp, $content);
  3004. fclose($fp);
  3005. $file_size = filesize($filepath . $filename);
  3006. $save_file_path = $dir . $filename;
  3007. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  3008. if($document_id)
  3009. {
  3010. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id);
  3011. //update parent folders
  3012. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  3013. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  3014. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  3015. if($new_comment || $new_title)
  3016. {
  3017. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3018. $ct = '';
  3019. if($new_comment)
  3020. $ct .= ", comment='" . $new_comment . "'";
  3021. if($new_title)
  3022. $ct .= ", title='" . $new_title . ".html '";
  3023. $sql_update = "
  3024. UPDATE " . $tbl_doc . "
  3025. SET " . substr($ct, 1) . "
  3026. WHERE id = " . $document_id;
  3027. api_sql_query($sql_update, __FILE__, __LINE__);
  3028. }
  3029. }
  3030. return $document_id;
  3031. }
  3032. }
  3033. }
  3034. /**
  3035. * Enter description here...
  3036. *
  3037. * @param array $_course
  3038. */
  3039. function edit_document($_course)
  3040. {
  3041. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3042. if(strstr($dir, '..'))
  3043. $dir = '/';
  3044. if($dir[0] == '.')
  3045. $dir = substr($dir, 1);
  3046. if($dir[0] != '/')
  3047. $dir = '/'.$dir;
  3048. if($dir[strlen($dir) - 1] != '/')
  3049. $dir .= '/';
  3050. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  3051. if(!is_dir($filepath))
  3052. {
  3053. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3054. $dir = '/';
  3055. }
  3056. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  3057. $sql = "
  3058. SELECT path
  3059. FROM " . $table_doc . "
  3060. WHERE id = " . $_POST['path'];
  3061. $res = api_sql_query($sql, __FILE__, __LINE__);
  3062. $row = Database::fetch_array($res);
  3063. $content = stripslashes($_POST['content']);
  3064. $file = $filepath . $row['path'];
  3065. if($fp = @fopen($file, 'w'))
  3066. {
  3067. $content = text_filter($content);
  3068. $path_to_remove = api_get_path('WEB_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3069. $content = str_replace($path_to_remove, './', $content);
  3070. fputs($fp, $content);
  3071. fclose($fp);
  3072. }
  3073. }
  3074. /**
  3075. * Displays the selected item, with a panel for manipulating the item
  3076. *
  3077. * @param int $item_id
  3078. * @param string $msg
  3079. * @return string
  3080. */
  3081. function display_item($item_id, $iframe = true, $msg = '')
  3082. {
  3083. global $_course; //will disappear
  3084. $return = '';
  3085. if(is_numeric($item_id))
  3086. {
  3087. $tbl_lp_item = Database::get_course_table('lp_item');
  3088. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3089. $sql = "
  3090. SELECT
  3091. lp.*
  3092. FROM " . $tbl_lp_item . " as lp
  3093. WHERE
  3094. lp.id = " . $item_id;
  3095. $result = api_sql_query($sql, __FILE__, __LINE__);
  3096. while($row = Database::fetch_array($result))
  3097. {
  3098. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3099. $return .= '<div style="padding:10px;">';
  3100. if($msg != '')
  3101. $return .= $msg;
  3102. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  3103. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  3104. //$return .= '<hr />';
  3105. if($row['item_type'] == TOOL_DOCUMENT)
  3106. $return .= $this->display_document($row['path'], true, true);
  3107. $return .= '</div>';
  3108. }
  3109. }
  3110. return $return;
  3111. }
  3112. /**
  3113. * Shows the needed forms for editing a specific item
  3114. *
  3115. * @param int $item_id
  3116. * @return string
  3117. */
  3118. function display_edit_item($item_id)
  3119. {
  3120. global $_course; //will disappear
  3121. $return = '';
  3122. if(is_numeric($item_id))
  3123. {
  3124. $tbl_lp_item = Database::get_course_table('lp_item');
  3125. $sql = "
  3126. SELECT *
  3127. FROM " . $tbl_lp_item . "
  3128. WHERE id = " . $item_id;
  3129. $res = api_sql_query($sql, __FILE__, __LINE__);
  3130. $row = Database::fetch_array($res);
  3131. switch($row['item_type'])
  3132. {
  3133. case 'dokeos_chapter':
  3134. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3135. {
  3136. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3137. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  3138. }
  3139. else
  3140. {
  3141. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  3142. }
  3143. break;
  3144. case TOOL_DOCUMENT:
  3145. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3146. $sql_step = "
  3147. SELECT
  3148. lp.*,
  3149. doc.path as dir
  3150. FROM " . $tbl_lp_item . " as lp
  3151. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  3152. WHERE
  3153. lp.id = " . $item_id;
  3154. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  3155. $row_step = Database::fetch_array($res_step);
  3156. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3157. $return .= $this->display_document_form('edit', $item_id, $row_step);
  3158. break;
  3159. case TOOL_LINK:
  3160. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3161. $return .= $this->display_link_form('edit', $item_id, $row);
  3162. break;
  3163. case 'dokeos_module':
  3164. if(isset($_GET['view']) && $_GET['view'] == 'build')
  3165. {
  3166. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3167. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  3168. }
  3169. else
  3170. {
  3171. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  3172. }
  3173. break;
  3174. case TOOL_QUIZ:
  3175. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3176. $return .= $this->display_quiz_form('edit', $item_id, $row);
  3177. break;
  3178. case TOOL_STUDENTPUBLICATION:
  3179. $return .= $this->display_manipulate($item_id, $row['item_type']);
  3180. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  3181. break;
  3182. }
  3183. }
  3184. return $return;
  3185. }
  3186. /**
  3187. * Function that displays a list with al the resources that could be added to the learning path
  3188. *
  3189. * @return string
  3190. */
  3191. function display_resources()
  3192. {
  3193. global $_course; //TODO: don't use globals
  3194. $return = '<div style="margin:3px 10px;">' . "\n";
  3195. $return .= '<p class="lp_title" style="margin-top:0;">'.get_lang("CreateNewStep").'</p>';
  3196. $return .= '<div><a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.get_lang("NewDocument").'</a></div>';
  3197. $return .= '<p class="lp_title" style="margin-top:10px;">'.get_lang("UseAnExistingResource").'</p>';
  3198. /* get al the docs */
  3199. $return .= $this->get_documents();
  3200. /* get al the exercises */
  3201. $return .= $this->get_exercises();
  3202. /* get al links */
  3203. //$return .= $this->get_links();
  3204. /* get al the student publications */
  3205. //$return .= $this->get_student_publications();
  3206. $return .= '</div>' . "\n";
  3207. return $return;
  3208. }
  3209. /**
  3210. * Returns the extension of a document
  3211. *
  3212. * @param unknown_type $filename
  3213. * @return unknown
  3214. */
  3215. function get_extension($filename)
  3216. {
  3217. $explode = explode('.', $filename);
  3218. return $explode[count($explode) - 1];
  3219. }
  3220. /**
  3221. * Displays a document by id
  3222. *
  3223. * @param unknown_type $id
  3224. * @return unknown
  3225. */
  3226. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  3227. {
  3228. global $_course; //temporary
  3229. $return = '';
  3230. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3231. $sql_doc = "
  3232. SELECT *
  3233. FROM " . $tbl_doc . "
  3234. WHERE id = " . $id;
  3235. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  3236. $row_doc = Database::fetch_array($res_doc);
  3237. if($show_title)
  3238. //$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $_GET['file'] . '&amp;edit=true&amp;lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
  3239. //TODO: add a path filter
  3240. if($iframe)
  3241. $return .= '<iframe frameborder="0" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path'] . '" style="background:#FFFFFF; border:1px solid #CCCCCC; height:490px; width:100%;"></iframe>';
  3242. else
  3243. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  3244. return $return;
  3245. }
  3246. /**
  3247. * Enter description here...
  3248. *
  3249. * @param unknown_type $action
  3250. * @param unknown_type $id
  3251. * @param unknown_type $extra_info
  3252. * @return unknown
  3253. */
  3254. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  3255. {
  3256. $tbl_lp_item = Database::get_course_table('lp_item');
  3257. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  3258. if($id != 0 && is_array($extra_info))
  3259. {
  3260. $item_title = stripslashes($extra_info['title']);
  3261. $item_description = stripslashes($extra_info['description']);
  3262. }
  3263. elseif(is_numeric($extra_info))
  3264. {
  3265. $sql_quiz = "
  3266. SELECT
  3267. title,
  3268. description
  3269. FROM " . $tbl_quiz . "
  3270. WHERE id = " . $extra_info;
  3271. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  3272. $row = Database::fetch_array($result);
  3273. $item_title = $row['title'];
  3274. $item_description = $row['description'];
  3275. }
  3276. else
  3277. {
  3278. $item_title = '';
  3279. $item_description = '';
  3280. }
  3281. $return = '<div style="margin:3px 10px;">';
  3282. if($id != 0 && is_array($extra_info))
  3283. $parent = $extra_info['parent_item_id'];
  3284. else
  3285. $parent = 0;
  3286. $sql = "
  3287. SELECT *
  3288. FROM " . $tbl_lp_item . "
  3289. WHERE
  3290. lp_id = " . $this->lp_id;
  3291. $result = api_sql_query($sql, __FILE__, __LINE__);
  3292. $arrLP = array();
  3293. while($row = Database::fetch_array($result))
  3294. {
  3295. $arrLP[] = array(
  3296. 'id' => $row['id'],
  3297. 'item_type' => $row['item_type'],
  3298. 'title' => $row['title'],
  3299. 'path' => $row['path'],
  3300. 'description' => $row['description'],
  3301. 'parent_item_id' => $row['parent_item_id'],
  3302. 'previous_item_id' => $row['previous_item_id'],
  3303. 'next_item_id' => $row['next_item_id'],
  3304. 'display_order' => $row['display_order']);
  3305. }
  3306. $this->tree_array($arrLP);
  3307. $arrLP = $this->arrMenu;
  3308. unset($this->arrMenu);
  3309. if($action == 'add')
  3310. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").' :</p>' . "\n";
  3311. elseif($action == 'move')
  3312. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").' :</p>' . "\n";
  3313. else
  3314. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").' :</p>' . "\n";
  3315. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3316. {
  3317. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3318. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  3319. $return .= get_lang("WarningEditingDocument");
  3320. $return .= '</div>';
  3321. }
  3322. $return .= '<form method="POST">' . "\n";
  3323. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3324. $return .= "\t\t" . '<tr>' . "\n";
  3325. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3326. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3327. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3328. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3329. $arrHide = array($id);
  3330. for($i = 0; $i < count($arrLP); $i++)
  3331. {
  3332. if($action != 'add')
  3333. {
  3334. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3335. {
  3336. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3337. }
  3338. else
  3339. {
  3340. $arrHide[] = $arrLP[$i]['id'];
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3346. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3347. }
  3348. }
  3349. reset($arrLP);
  3350. $return .= "\t\t\t\t" . '</select>';
  3351. $return .= "\t\t\t" . '</td>' . "\n";
  3352. $return .= "\t\t" . '</tr>' . "\n";
  3353. $return .= "\t\t" . '<tr>' . "\n";
  3354. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3355. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3356. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3357. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3358. for($i = 0; $i < count($arrLP); $i++)
  3359. {
  3360. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3361. {
  3362. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3363. $selected = 'selected="selected" ';
  3364. elseif($action == 'add')
  3365. $selected = 'selected="selected" ';
  3366. else
  3367. $selected = '';
  3368. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3369. }
  3370. }
  3371. $return .= "\t\t\t\t" . '</select>';
  3372. $return .= "\t\t\t" . '</td>' . "\n";
  3373. $return .= "\t\t" . '</tr>' . "\n";
  3374. if($action != 'move')
  3375. {
  3376. $return .= "\t\t" . '<tr>' . "\n";
  3377. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3378. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3379. $return .= "\t\t" . '</tr>' . "\n";
  3380. $return .= "\t\t" . '<tr>' . "\n";
  3381. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3382. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3383. $return .= "\t\t" . '</tr>' . "\n";
  3384. }
  3385. $return .= "\t\t" . '<tr>' . "\n";
  3386. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3387. $return .= "\t\t" . '</tr>' . "\n";
  3388. $return .= "\t" . '</table>' . "\n";
  3389. if($action == 'move')
  3390. {
  3391. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3392. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3393. }
  3394. if(is_numeric($extra_info))
  3395. {
  3396. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3397. }
  3398. elseif(is_array($extra_info))
  3399. {
  3400. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3401. }
  3402. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  3403. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3404. $return .= '</form>' . "\n";
  3405. $return .= '</div>' . "\n";
  3406. return $return;
  3407. }
  3408. /**
  3409. * Enter description here...
  3410. *
  3411. * @param unknown_type $item_type
  3412. * @param unknown_type $title
  3413. * @param unknown_type $action
  3414. * @param unknown_type $id
  3415. * @param unknown_type $extra_info
  3416. * @return unknown
  3417. */
  3418. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  3419. {
  3420. $tbl_lp_item = Database::get_course_table('lp_item');
  3421. if($id != 0 && is_array($extra_info))
  3422. {
  3423. $item_title = stripslashes($extra_info['title']);
  3424. $item_description = stripslashes($extra_info['description']);
  3425. }
  3426. else
  3427. {
  3428. $item_title = '';
  3429. $item_description = '';
  3430. }
  3431. $return = '<div style="margin:3px 10px;">';
  3432. if($id != 0 && is_array($extra_info))
  3433. $parent = $extra_info['parent_item_id'];
  3434. else
  3435. $parent = 0;
  3436. $sql = "
  3437. SELECT *
  3438. FROM " . $tbl_lp_item . "
  3439. WHERE
  3440. lp_id = " . $this->lp_id;
  3441. if($item_type == 'module')
  3442. $sql .= " AND parent_item_id = 0";
  3443. $result = api_sql_query($sql, __FILE__, __LINE__);
  3444. $arrLP = array();
  3445. while($row = Database::fetch_array($result))
  3446. {
  3447. $arrLP[] = array(
  3448. 'id' => $row['id'],
  3449. 'item_type' => $row['item_type'],
  3450. 'title' => $row['title'],
  3451. 'path' => $row['path'],
  3452. 'description' => $row['description'],
  3453. 'parent_item_id' => $row['parent_item_id'],
  3454. 'previous_item_id' => $row['previous_item_id'],
  3455. 'next_item_id' => $row['next_item_id'],
  3456. 'display_order' => $row['display_order']);
  3457. }
  3458. $this->tree_array($arrLP);
  3459. $arrLP = $this->arrMenu;
  3460. unset($this->arrMenu);
  3461. $return .= '<p class="lp_title">' . $title . '</p>' . "\n";
  3462. $return .= '<form method="POST">' . "\n";
  3463. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3464. if($item_type != 'module' && $item_type != 'dokeos_module')
  3465. {
  3466. $return .= "\t\t" . '<tr>' . "\n";
  3467. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3468. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3469. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3470. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3471. $arrHide = array($id);
  3472. for($i = 0; $i < count($arrLP); $i++)
  3473. {
  3474. if($action != 'add')
  3475. {
  3476. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] != 'dokeos_chapter' && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3477. {
  3478. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3479. }
  3480. else
  3481. {
  3482. $arrHide[] = $arrLP[$i]['id'];
  3483. }
  3484. }
  3485. else
  3486. {
  3487. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3488. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3489. }
  3490. }
  3491. reset($arrLP);
  3492. $return .= "\t\t\t\t" . '</select>';
  3493. $return .= "\t\t\t" . '</td>' . "\n";
  3494. $return .= "\t\t" . '</tr>' . "\n";
  3495. }
  3496. $return .= "\t\t" . '<tr>' . "\n";
  3497. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3498. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3499. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3500. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3501. for($i = 0; $i < count($arrLP); $i++)
  3502. {
  3503. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3504. {
  3505. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3506. $selected = 'selected="selected" ';
  3507. elseif($action == 'add')
  3508. $selected = 'selected="selected" ';
  3509. else
  3510. $selected = '';
  3511. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3512. }
  3513. }
  3514. $return .= "\t\t\t\t" . '</select>';
  3515. $return .= "\t\t\t" . '</td>' . "\n";
  3516. $return .= "\t\t" . '</tr>' . "\n";
  3517. if($action != 'move')
  3518. {
  3519. $return .= "\t\t" . '<tr>' . "\n";
  3520. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3521. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3522. $return .= "\t\t" . '</tr>' . "\n";
  3523. $return .= "\t\t" . '<tr>' . "\n";
  3524. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3525. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3526. $return .= "\t\t" . '</tr>' . "\n";
  3527. }
  3528. $return .= "\t\t" . '<tr>' . "\n";
  3529. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3530. $return .= "\t\t" . '</tr>' . "\n";
  3531. $return .= "\t" . '</table>' . "\n";
  3532. if($item_type == 'module' || $item_type == 'dokeos_module')
  3533. $return .= "\t" . '<input name="parent" type="hidden" value="0" />' . "\n";
  3534. if($action == 'move')
  3535. {
  3536. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3537. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3538. }
  3539. /*if($id != 0 && is_array($extra_info))
  3540. {
  3541. $return .= "\t" . '<input name="old_previous" type="hidden" value="' . $extra_info['parent_item_id'] . '" />' . "\n";
  3542. $return .= "\t" . '<input name="old_next" type="hidden" value="' . $extra_info['previous_item_id'] . '" />' . "\n";
  3543. }*/
  3544. $return .= "\t" . '<input name="type" type="hidden" value="dokeos_' . $item_type . '" />' . "\n";
  3545. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3546. $return .= '</form>' . "\n";
  3547. $return .= '</div>' . "\n";
  3548. return $return;
  3549. }
  3550. /**
  3551. * Enter description here...
  3552. *
  3553. * @param unknown_type $action
  3554. * @param unknown_type $id
  3555. * @param unknown_type $extra_info
  3556. * @return unknown
  3557. */
  3558. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  3559. {
  3560. $tbl_lp_item = Database::get_course_table('lp_item');
  3561. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3562. $path_parts = pathinfo($extra_info[16]);
  3563. $no_display_edit_textarea=false;
  3564. //If action==edit document
  3565. //We don't display the document form if it's not an editable document (html or txt file)
  3566. if($action=="edit"){
  3567. if(is_array($extra_info)){
  3568. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  3569. $no_display_edit_textarea=true;
  3570. }
  3571. }
  3572. }
  3573. $no_display_add=false;
  3574. //If action==add an existing document
  3575. //We don't display the document form if it's not an editable document (html or txt file)
  3576. if($action=="add"){
  3577. if(is_numeric($extra_info)){
  3578. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  3579. $result=api_sql_query($sql_doc);
  3580. $path_file=mysql_result($result,0,0);
  3581. $path_parts = pathinfo($path_file);
  3582. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  3583. $no_display_add=true;
  3584. }
  3585. }
  3586. }
  3587. if($id != 0 && is_array($extra_info))
  3588. {
  3589. $item_title = stripslashes($extra_info['title']);
  3590. $item_description = stripslashes($extra_info['description']);
  3591. }
  3592. elseif(is_numeric($extra_info))
  3593. {
  3594. $sql_doc = "
  3595. SELECT title
  3596. FROM " . $tbl_doc . "
  3597. WHERE id = " . $extra_info;
  3598. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  3599. $row = Database::fetch_array($result);
  3600. $explode = explode('.', $row['title']);
  3601. for($i = 0; $i < count($explode) - 1; $i++)
  3602. $item_title .= $explode[$i];
  3603. $item_title = str_replace('_', ' ', $item_title);
  3604. }
  3605. else
  3606. {
  3607. $item_title = '';
  3608. $item_description = '';
  3609. }
  3610. $return = '<div style="margin:3px 10px;">';
  3611. if($id != 0 && is_array($extra_info))
  3612. $parent = $extra_info['parent_item_id'];
  3613. else
  3614. $parent = 0;
  3615. $sql = "
  3616. SELECT *
  3617. FROM " . $tbl_lp_item . "
  3618. WHERE
  3619. lp_id = " . $this->lp_id;
  3620. $result = api_sql_query($sql, __FILE__, __LINE__);
  3621. $arrLP = array();
  3622. while($row = Database::fetch_array($result))
  3623. {
  3624. $arrLP[] = array(
  3625. 'id' => $row['id'],
  3626. 'item_type' => $row['item_type'],
  3627. 'title' => $row['title'],
  3628. 'path' => $row['path'],
  3629. 'description' => $row['description'],
  3630. 'parent_item_id' => $row['parent_item_id'],
  3631. 'previous_item_id' => $row['previous_item_id'],
  3632. 'next_item_id' => $row['next_item_id'],
  3633. 'display_order' => $row['display_order']);
  3634. }
  3635. $this->tree_array($arrLP);
  3636. $arrLP = $this->arrMenu;
  3637. unset($this->arrMenu);
  3638. if($action == 'add')
  3639. $return .= '<p class="lp_title">'.get_lang("CreateTheDocument").' :</p>' . "\n";
  3640. elseif($action == 'move')
  3641. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentDocument").' :</p>' . "\n";
  3642. else
  3643. $return .= '<p class="lp_title">'.get_lang("EditTheCurrentDocument").' :</p>' . "\n";
  3644. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  3645. {
  3646. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3647. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  3648. $return .= get_lang("WarningEditingDocument");
  3649. $return .= '</div>';
  3650. }
  3651. if($no_display_add==true){
  3652. $return .= '<div class="lp_message" style="margin-bottom:15px;">';
  3653. $return .= get_lang("CantEditDocument");
  3654. $return .= '</div>';
  3655. return $return;
  3656. }
  3657. $return .= '<form method="POST">' . "\n";
  3658. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3659. $return .= "\t\t" . '<tr>' . "\n";
  3660. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  3661. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3662. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3663. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3664. $arrHide = array($id);
  3665. for($i = 0; $i < count($arrLP); $i++)
  3666. {
  3667. if($action != 'add')
  3668. {
  3669. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3670. {
  3671. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3672. }
  3673. else
  3674. {
  3675. $arrHide[] = $arrLP[$i]['id'];
  3676. }
  3677. }
  3678. else
  3679. {
  3680. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3681. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3682. }
  3683. }
  3684. reset($arrLP);
  3685. $return .= "\t\t\t\t" . '</select>';
  3686. $return .= "\t\t\t" . '</td>' . "\n";
  3687. $return .= "\t\t" . '</tr>' . "\n";
  3688. $return .= "\t\t" . '<tr>' . "\n";
  3689. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  3690. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3691. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3692. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3693. for($i = 0; $i < count($arrLP); $i++)
  3694. {
  3695. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3696. {
  3697. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3698. $selected = 'selected="selected" ';
  3699. elseif($action == 'add')
  3700. $selected = 'selected="selected" ';
  3701. else
  3702. $selected = '';
  3703. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3704. }
  3705. }
  3706. $return .= "\t\t\t\t" . '</select>';
  3707. $return .= "\t\t\t" . '</td>' . "\n";
  3708. $return .= "\t\t" . '</tr>' . "\n";
  3709. if($action != 'move')
  3710. {
  3711. $return .= "\t\t" . '<tr>' . "\n";
  3712. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  3713. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3714. $return .= "\t\t" . '</tr>' . "\n";
  3715. $return .= "\t\t" . '<tr>' . "\n";
  3716. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  3717. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3718. $return .= "\t\t" . '</tr>' . "\n";
  3719. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  3720. {
  3721. if($action == 'add' || $_GET['edit'] == 'true')
  3722. {
  3723. $return .= "\t\t" . '<tr>' . "\n";
  3724. $return .= "\t\t\t" . '<td class="label"><label for="idDir">'.get_lang("Directory").' :</label></td>' . "\n";
  3725. $return .= "\t\t\t" . '<td class="input">';
  3726. $sql_doc = "
  3727. SELECT *
  3728. FROM " . $tbl_doc . "
  3729. WHERE
  3730. filetype = 'folder'
  3731. ORDER BY path ASC";
  3732. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  3733. $return .= "\t\t\t\t" . '<select id="idDir" name="dir" size="1">' . "\n";
  3734. $return .= "\t\t\t\t\t" . '<option value="/">/ ( root )</option>' . "\n";
  3735. while($row_doc = Database::fetch_array($result))
  3736. {
  3737. $return .= "\t\t\t\t\t" . '<option value="' . $row_doc['path'] . '">' . $row_doc['path'] . '</option>' . "\n";
  3738. }
  3739. $return .= "\t\t\t\t" . '</select>' . "\n";
  3740. $return .= "\t\t\t" . '</td>' . "\n";
  3741. $return .= "\t\t" . '</tr>' . "\n";
  3742. }
  3743. $return .= "\t\t" . '<tr>' . "\n";
  3744. $return .= "\t\t\t" . '<td colspan="2">' . "\n";
  3745. if(isset($_POST['content']))
  3746. $content = stripslashes($_POST['content']);
  3747. elseif(is_array($extra_info))
  3748. $content = $this->display_document($extra_info['path'], false, false);
  3749. elseif(is_numeric($extra_info))
  3750. $content = $this->display_document($extra_info, false, false);
  3751. else
  3752. $content = '';
  3753. $oFCKeditor = new FCKeditor('content_lp') ;
  3754. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  3755. $oFCKeditor->Height = '400';
  3756. $oFCKeditor->Width = '100%';
  3757. $oFCKeditor->Value = $content;
  3758. $return .= $oFCKeditor->CreateHtml();
  3759. $return .= "\t\t\t" . '</td>' . "\n";
  3760. $return .= "\t\t" . '</tr>' . "\n";
  3761. }
  3762. elseif(is_numeric($extra_info))
  3763. {
  3764. $return .= "\t\t" . '<tr>' . "\n";
  3765. $return .= "\t\t\t" . '<td colspan="2" style="background:#F8F8F8; border:1px solid #999999;">' . "\n";
  3766. $return .= $this->display_document($extra_info, true, true, true);
  3767. $return .= "\t\t\t" . '</td>' . "\n";
  3768. $return .= "\t\t" . '</tr>' . "\n";
  3769. }
  3770. }
  3771. $return .= "\t\t" . '<tr>' . "\n";
  3772. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3773. $return .= "\t\t" . '</tr>' . "\n";
  3774. $return .= "\t" . '</table>' . "\n";
  3775. if($action == 'move')
  3776. {
  3777. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3778. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3779. }
  3780. if(is_numeric($extra_info))
  3781. {
  3782. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3783. }
  3784. elseif(is_array($extra_info))
  3785. {
  3786. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3787. }
  3788. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_DOCUMENT.'" />' . "\n";
  3789. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3790. $return .= '</form>' . "\n";
  3791. $return .= '</div>' . "\n";
  3792. return $return;
  3793. }
  3794. /**
  3795. * Enter description here...
  3796. *
  3797. * @param unknown_type $action
  3798. * @param unknown_type $id
  3799. * @param unknown_type $extra_info
  3800. */
  3801. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  3802. {
  3803. $tbl_lp_item = Database::get_course_table('lp_item');
  3804. $tbl_link = Database::get_course_table(TABLE_LINK);
  3805. if($id != 0 && is_array($extra_info))
  3806. {
  3807. $item_title = stripslashes($extra_info['title']);
  3808. $item_description = stripslashes($extra_info['description']);
  3809. }
  3810. elseif(is_numeric($extra_info))
  3811. {
  3812. $sql_link = "
  3813. SELECT
  3814. title,
  3815. description,
  3816. url
  3817. FROM " . $tbl_link . "
  3818. WHERE id = " . $extra_info;
  3819. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  3820. $row = Database::fetch_array($result);
  3821. $item_title = $row['title'];
  3822. $item_description = $row['description'];
  3823. $item_url = $row['url'];
  3824. }
  3825. else
  3826. {
  3827. $item_title = '';
  3828. $item_description = '';
  3829. }
  3830. $return = '<div style="margin:3px 10px;">';
  3831. if($id != 0 && is_array($extra_info))
  3832. $parent = $extra_info['parent_item_id'];
  3833. else
  3834. $parent = 0;
  3835. $sql = "
  3836. SELECT *
  3837. FROM " . $tbl_lp_item . "
  3838. WHERE
  3839. lp_id = " . $this->lp_id;
  3840. $result = api_sql_query($sql, __FILE__, __LINE__);
  3841. $arrLP = array();
  3842. while($row = Database::fetch_array($result))
  3843. {
  3844. $arrLP[] = array(
  3845. 'id' => $row['id'],
  3846. 'item_type' => $row['item_type'],
  3847. 'title' => $row['title'],
  3848. 'path' => $row['path'],
  3849. 'description' => $row['description'],
  3850. 'parent_item_id' => $row['parent_item_id'],
  3851. 'previous_item_id' => $row['previous_item_id'],
  3852. 'next_item_id' => $row['next_item_id'],
  3853. 'display_order' => $row['display_order']);
  3854. }
  3855. $this->tree_array($arrLP);
  3856. $arrLP = $this->arrMenu;
  3857. unset($this->arrMenu);
  3858. if($action == 'add')
  3859. $return .= '<p class="lp_title">Create the link:</p>' . "\n";
  3860. elseif($action == 'move')
  3861. $return .= '<p class="lp_title">Move the current link:</p>' . "\n";
  3862. else
  3863. $return .= '<p class="lp_title">Edit the current link:</p>' . "\n";
  3864. $return .= '<form method="POST">' . "\n";
  3865. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  3866. $return .= "\t\t" . '<tr>' . "\n";
  3867. $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
  3868. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3869. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  3870. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  3871. $arrHide = array($id);
  3872. for($i = 0; $i < count($arrLP); $i++)
  3873. {
  3874. if($action != 'add')
  3875. {
  3876. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  3877. {
  3878. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3879. }
  3880. else
  3881. {
  3882. $arrHide[] = $arrLP[$i]['id'];
  3883. }
  3884. }
  3885. else
  3886. {
  3887. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  3888. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  3889. }
  3890. }
  3891. reset($arrLP);
  3892. $return .= "\t\t\t\t" . '</select>';
  3893. $return .= "\t\t\t" . '</td>' . "\n";
  3894. $return .= "\t\t" . '</tr>' . "\n";
  3895. $return .= "\t\t" . '<tr>' . "\n";
  3896. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
  3897. $return .= "\t\t\t" . '<td class="input">' . "\n";
  3898. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  3899. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  3900. for($i = 0; $i < count($arrLP); $i++)
  3901. {
  3902. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  3903. {
  3904. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  3905. $selected = 'selected="selected" ';
  3906. elseif($action == 'add')
  3907. $selected = 'selected="selected" ';
  3908. else
  3909. $selected = '';
  3910. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  3911. }
  3912. }
  3913. $return .= "\t\t\t\t" . '</select>';
  3914. $return .= "\t\t\t" . '</td>' . "\n";
  3915. $return .= "\t\t" . '</tr>' . "\n";
  3916. if($action != 'move')
  3917. {
  3918. $return .= "\t\t" . '<tr>' . "\n";
  3919. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  3920. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  3921. $return .= "\t\t" . '</tr>' . "\n";
  3922. $return .= "\t\t" . '<tr>' . "\n";
  3923. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  3924. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  3925. $return .= "\t\t" . '</tr>' . "\n";
  3926. $return .= "\t\t" . '<tr>' . "\n";
  3927. $return .= "\t\t\t" . '<td class="label"><label for="idURL">URL:</label></td>' . "\n";
  3928. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" type="text" value="' . $item_url . '" /></td>' . "\n";
  3929. $return .= "\t\t" . '</tr>' . "\n";
  3930. }
  3931. $return .= "\t\t" . '<tr>' . "\n";
  3932. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  3933. $return .= "\t\t" . '</tr>' . "\n";
  3934. $return .= "\t" . '</table>' . "\n";
  3935. if($action == 'move')
  3936. {
  3937. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  3938. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  3939. }
  3940. if(is_numeric($extra_info))
  3941. {
  3942. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  3943. }
  3944. elseif(is_array($extra_info))
  3945. {
  3946. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  3947. }
  3948. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  3949. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  3950. $return .= '</form>' . "\n";
  3951. $return .= '</div>' . "\n";
  3952. return $return;
  3953. }
  3954. /**
  3955. * Enter description here...
  3956. *
  3957. * @param unknown_type $action
  3958. * @param unknown_type $id
  3959. * @param unknown_type $extra_info
  3960. * @return unknown
  3961. */
  3962. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  3963. {
  3964. $tbl_lp_item = Database::get_course_table('lp_item');
  3965. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  3966. if($id != 0 && is_array($extra_info))
  3967. {
  3968. $item_title = stripslashes($extra_info['title']);
  3969. $item_description = stripslashes($extra_info['description']);
  3970. }
  3971. elseif(is_numeric($extra_info))
  3972. {
  3973. $sql_publication = "
  3974. SELECT
  3975. title,
  3976. description
  3977. FROM " . $tbl_publication . "
  3978. WHERE id = " . $extra_info;
  3979. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  3980. $row = Database::fetch_array($result);
  3981. $item_title = $row['title'];
  3982. $item_description = $row['description'];
  3983. }
  3984. else
  3985. {
  3986. $item_title = '';
  3987. $item_description = '';
  3988. }
  3989. $return = '<div style="margin:3px 10px;">';
  3990. if($id != 0 && is_array($extra_info))
  3991. $parent = $extra_info['parent_item_id'];
  3992. else
  3993. $parent = 0;
  3994. $sql = "
  3995. SELECT *
  3996. FROM " . $tbl_lp_item . "
  3997. WHERE
  3998. lp_id = " . $this->lp_id;
  3999. $result = api_sql_query($sql, __FILE__, __LINE__);
  4000. $arrLP = array();
  4001. while($row = Database::fetch_array($result))
  4002. {
  4003. $arrLP[] = array(
  4004. 'id' => $row['id'],
  4005. 'item_type' => $row['item_type'],
  4006. 'title' => $row['title'],
  4007. 'path' => $row['path'],
  4008. 'description' => $row['description'],
  4009. 'parent_item_id' => $row['parent_item_id'],
  4010. 'previous_item_id' => $row['previous_item_id'],
  4011. 'next_item_id' => $row['next_item_id'],
  4012. 'display_order' => $row['display_order']);
  4013. }
  4014. $this->tree_array($arrLP);
  4015. $arrLP = $this->arrMenu;
  4016. unset($this->arrMenu);
  4017. if($action == 'add')
  4018. $return .= '<p class="lp_title">Create the student publication:</p>' . "\n";
  4019. elseif($action == 'move')
  4020. $return .= '<p class="lp_title">Move the current student publication:</p>' . "\n";
  4021. else
  4022. $return .= '<p class="lp_title">Edit the current student publication:</p>' . "\n";
  4023. $return .= '<form method="POST">' . "\n";
  4024. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4025. $return .= "\t\t" . '<tr>' . "\n";
  4026. $return .= "\t\t\t" . '<td class="label"><label for="idParent">Parent:</label></td>' . "\n";
  4027. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4028. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4029. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4030. $arrHide = array($id);
  4031. for($i = 0; $i < count($arrLP); $i++)
  4032. {
  4033. if($action != 'add')
  4034. {
  4035. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4036. {
  4037. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4038. }
  4039. else
  4040. {
  4041. $arrHide[] = $arrLP[$i]['id'];
  4042. }
  4043. }
  4044. else
  4045. {
  4046. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter')
  4047. $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'] . '">' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '</option>';
  4048. }
  4049. }
  4050. reset($arrLP);
  4051. $return .= "\t\t\t\t" . '</select>';
  4052. $return .= "\t\t\t" . '</td>' . "\n";
  4053. $return .= "\t\t" . '</tr>' . "\n";
  4054. $return .= "\t\t" . '<tr>' . "\n";
  4055. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">Position:</label></td>' . "\n";
  4056. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4057. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4058. $return .= "\t\t\t\t\t" . '<option class="top" value="0">First position</option>';
  4059. for($i = 0; $i < count($arrLP); $i++)
  4060. {
  4061. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4062. {
  4063. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4064. $selected = 'selected="selected" ';
  4065. elseif($action == 'add')
  4066. $selected = 'selected="selected" ';
  4067. else
  4068. $selected = '';
  4069. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">After "' . html_entity_decode(stripslashes($arrLP[$i]['title'])) . '"</option>';
  4070. }
  4071. }
  4072. $return .= "\t\t\t\t" . '</select>';
  4073. $return .= "\t\t\t" . '</td>' . "\n";
  4074. $return .= "\t\t" . '</tr>' . "\n";
  4075. if($action != 'move')
  4076. {
  4077. $return .= "\t\t" . '<tr>' . "\n";
  4078. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  4079. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4080. $return .= "\t\t" . '</tr>' . "\n";
  4081. $return .= "\t\t" . '<tr>' . "\n";
  4082. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  4083. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4084. $return .= "\t\t" . '</tr>' . "\n";
  4085. }
  4086. $return .= "\t\t" . '<tr>' . "\n";
  4087. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4088. $return .= "\t\t" . '</tr>' . "\n";
  4089. $return .= "\t" . '</table>' . "\n";
  4090. if($action == 'move')
  4091. {
  4092. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4093. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4094. }
  4095. if(is_numeric($extra_info))
  4096. {
  4097. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4098. }
  4099. elseif(is_array($extra_info))
  4100. {
  4101. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4102. }
  4103. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  4104. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4105. $return .= '</form>' . "\n";
  4106. $return .= '</div>' . "\n";
  4107. return $return;
  4108. }
  4109. /**
  4110. * Displays the menu for manipulating a step
  4111. *
  4112. * @return unknown
  4113. */
  4114. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  4115. {
  4116. $return = '<div class="lp_manipulate"><table border="0" width="100%"><tr><td valign="top" width="400">';
  4117. switch($item_type)
  4118. {
  4119. case 'dokeos_chapter':
  4120. case 'chapter':
  4121. $lang = get_lang('TitleManipulateChapter');
  4122. break;
  4123. case 'dokeos_module':
  4124. case 'module':
  4125. $lang = get_lang('TitleManipulateModule');
  4126. break;
  4127. case TOOL_DOCUMENT:
  4128. $lang = get_lang('TitleManipulateDocument');
  4129. break;
  4130. case TOOL_LINK:
  4131. case 'link':
  4132. $lang = get_lang('TitleManipulateLink');
  4133. break;
  4134. case TOOL_QUIZ:
  4135. $lang = get_lang('TitleManipulateQuiz');
  4136. break;
  4137. case TOOL_STUDENTPUBLICATION:
  4138. $lang = get_lang('TitleManipulateStudentPublication');
  4139. break;
  4140. }
  4141. $tbl_lp_item = Database::get_course_table('lp_item');
  4142. $sql = "
  4143. SELECT
  4144. description
  4145. FROM " . $tbl_lp_item . " as lp
  4146. WHERE
  4147. lp.id = " . $item_id;
  4148. $result = api_sql_query($sql, __FILE__, __LINE__);
  4149. $s_description=mysql_result($result,0,0);
  4150. $return .= '<p class="lp_title">' . $lang . '</p>';
  4151. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Edit the current item"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="Edit the current item" /> '.get_lang("Edit").'</a>';
  4152. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="Move the current item" /> '.get_lang("Move").'</a>';
  4153. if($item_type != 'chapter' && $item_type != 'dokeos_chapter' && $item_type != 'module' && $item_type != 'dokeos_module')
  4154. //$return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="'.get_lang("langEditPrerequisites").'"><img align="absbottom" alt="'.get_lang("langEditPrerequisites").'" src="../img/asterisk_prerequisites.gif" title="'.get_lang("langEditPrerequisites").'" /> '.get_lang("Prerequisites").'</a>';
  4155. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . $row['title'] . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="Delete the current item" /> '.get_lang("Delete").'</a>';
  4156. $return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  4157. $return.="</td><td valign='top'>";
  4158. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  4159. ob_start();
  4160. $audio_recorder_studentview = 'false';
  4161. $audio_recorder_item_id = $item_id;
  4162. if(api_get_setting('service_ppt2lp','active')=='true' && api_get_setting('service_ppt2lp','path_to_lzx')!=''){
  4163. include('audiorecorder.inc.php');
  4164. }
  4165. $return .= ob_get_contents();
  4166. ob_end_clean();
  4167. // end of audiorecorder include
  4168. $return.="</td></tr></table>";
  4169. $return .= '</div>';
  4170. return $return;
  4171. }
  4172. /**
  4173. * Creates the javascript needed for filling up the checkboxes without page reload
  4174. *
  4175. * @return string
  4176. */
  4177. function create_js()
  4178. {
  4179. $return = '<script language="javascript" type="text/javascript">' . "\n";
  4180. $return .= 'function load_cbo(id){' . "\n";
  4181. $return .= "var cbo = document.getElementById('idPosition');";
  4182. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  4183. $return .= 'cbo.options[i] = null;';
  4184. $return .= 'for(var i = 1; i <= child_name[id].length; i++)';
  4185. $return .= 'cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);';
  4186. $return .= '}' . "\n\n";
  4187. $return .= 'var child_name = new Array();' . "\n";
  4188. $return .= 'var child_value = new Array();' . "\n\n";
  4189. $return .= 'child_name[0] = new Array();' . "\n";
  4190. $return .= 'child_value[0] = new Array();' . "\n\n";
  4191. $tbl_lp_item = Database::get_course_table('lp_item');
  4192. $sql_zero = "
  4193. SELECT *
  4194. FROM " . $tbl_lp_item . "
  4195. WHERE
  4196. lp_id = " . $this->lp_id . " AND
  4197. parent_item_id = 0
  4198. ORDER BY display_order ASC";
  4199. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  4200. $i = 0;
  4201. while($row_zero = Database::fetch_array($res_zero))
  4202. {
  4203. $return .= 'child_name[0][' . $i . '] = "After \"' . $row_zero['title'] . '\"";' . "\n";
  4204. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  4205. }
  4206. $return .= "\n";
  4207. $sql = "
  4208. SELECT *
  4209. FROM " . $tbl_lp_item . "
  4210. WHERE
  4211. lp_id = " . $this->lp_id;
  4212. $res = api_sql_query($sql, __FILE__, __LINE__);
  4213. while($row = Database::fetch_array($res))
  4214. {
  4215. $sql_parent = "
  4216. SELECT *
  4217. FROM " . $tbl_lp_item . "
  4218. WHERE parent_item_id = " . $row['id'] . "
  4219. ORDER BY display_order ASC";
  4220. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  4221. $i = 0;
  4222. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  4223. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  4224. while($row_parent = Database::fetch_array($res_parent))
  4225. {
  4226. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "After \"' . $row_parent['title'] . '\"";' . "\n";
  4227. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  4228. }
  4229. $return .= "\n";
  4230. }
  4231. $return .= '</script>' . "\n";
  4232. return $return;
  4233. }
  4234. /**
  4235. * Enter description here...
  4236. *
  4237. * @param unknown_type $item_id
  4238. * @return unknown
  4239. */
  4240. function display_move_item($item_id)
  4241. {
  4242. global $_course; //will disappear
  4243. $return = '';
  4244. if(is_numeric($item_id))
  4245. {
  4246. $tbl_lp_item = Database::get_course_table('lp_item');
  4247. $sql = "
  4248. SELECT *
  4249. FROM " . $tbl_lp_item . "
  4250. WHERE id = " . $item_id;
  4251. $res = api_sql_query($sql, __FILE__, __LINE__);
  4252. $row = Database::fetch_array($res);
  4253. switch($row['item_type'])
  4254. {
  4255. case 'dokeos_chapter':
  4256. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4257. $return .= $this->display_item_form($row['item_type'], 'Move the current chapter:', 'move', $item_id, $row);
  4258. break;
  4259. case 'dokeos_module':
  4260. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4261. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  4262. break;
  4263. case TOOL_DOCUMENT:
  4264. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4265. $return .= $this->display_document_form('move', $item_id, $row);
  4266. break;
  4267. case TOOL_LINK:
  4268. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4269. $return .= $this->display_link_form('move', $item_id, $row);
  4270. break;
  4271. case TOOL_QUIZ:
  4272. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4273. $return .= $this->display_quiz_form('move', $item_id, $row);
  4274. break;
  4275. case TOOL_STUDENTPUBLICATION:
  4276. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4277. $return .= $this->display_student_publication_form('move', $item_id, $row);
  4278. break;
  4279. }
  4280. }
  4281. return $return;
  4282. }
  4283. /**
  4284. * Displays a basic form on the overview page for changing the item title and the item description.
  4285. *
  4286. * @param string $item_type
  4287. * @param string $title
  4288. * @param array $data
  4289. * @return string
  4290. */
  4291. function display_item_small_form($item_type, $title = '', $data)
  4292. {
  4293. $return .= '<div class="lp_small_form">' . "\n";
  4294. $return .= '<p class="lp_title">' . $title . '</p>';
  4295. $return .= '<form method="post">' . "\n";
  4296. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  4297. $return .= "\t\t" . '<tr>' . "\n";
  4298. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title:</label></td>' . "\n";
  4299. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  4300. $return .= "\t\t" . '</tr>' . "\n";
  4301. $return .= "\t\t" . '<tr>' . "\n";
  4302. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description:</label></td>' . "\n";
  4303. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  4304. $return .= "\t\t" . '</tr>' . "\n";
  4305. $return .= "\t\t" . '<tr>' . "\n";
  4306. $return .= "\t\t\t" . '<td colspan="2"><input class="button small_form" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4307. $return .= "\t\t" . '</tr>' . "\n";
  4308. $return .= "\t\t" . '</table>' . "\n";
  4309. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  4310. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  4311. $return .= '</form>';
  4312. $return .= '</div>';
  4313. return $return;
  4314. }
  4315. /**
  4316. * Enter description here...
  4317. *
  4318. * @param unknown_type $item_id
  4319. * @return unknown
  4320. */
  4321. function display_item_prerequisites_form($item_id)
  4322. {
  4323. $tbl_lp_item = Database::get_course_table('lp_item');
  4324. /* current prerequisite */
  4325. $sql = "
  4326. SELECT *
  4327. FROM " . $tbl_lp_item . "
  4328. WHERE id = " . $item_id;
  4329. $result = api_sql_query($sql, __FILE__, __LINE__);
  4330. $row = Database::fetch_array($result);
  4331. $preq_id = $row['prerequisite'];
  4332. $preq_min = $row['min_score'];
  4333. $preq_max = $row['max_score'];
  4334. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  4335. $return .= '<div style="margin:3px 10px;">';
  4336. $return .= '<p class="lp_title">'.get_lang("AddEditPrerequisites").'</p>';
  4337. $return .= '<form method="POST">';
  4338. $return .= '<table class="lp_form">';
  4339. $return .= '<tr>';
  4340. $return .= '<th></th>';
  4341. $return .= '<th class="exercise">'.get_lang("Minimum").'</th>';
  4342. $return .= '<th class="exercise">'.get_lang("Maximum").'</th>';
  4343. $return .= '</tr>';
  4344. $return .= '<tr>';
  4345. $return .= '<td class="radio" colspan="3">';
  4346. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  4347. $return .= '<label for="idNone">'.get_lang("None").'</label>';
  4348. $return .= '</td>';
  4349. $return .= '</tr>';
  4350. $sql = "
  4351. SELECT *
  4352. FROM " . $tbl_lp_item . "
  4353. WHERE
  4354. lp_id = " . $this->lp_id;
  4355. $result = api_sql_query($sql, __FILE__, __LINE__);
  4356. $arrLP = array();
  4357. while($row = Database::fetch_array($result))
  4358. {
  4359. $arrLP[] = array(
  4360. 'id' => $row['id'],
  4361. 'item_type' => $row['item_type'],
  4362. 'title' => $row['title'],
  4363. 'description' => $row['description'],
  4364. 'parent_item_id' => $row['parent_item_id'],
  4365. 'previous_item_id' => $row['previous_item_id'],
  4366. 'next_item_id' => $row['next_item_id'],
  4367. 'display_order' => $row['display_order']);
  4368. }
  4369. $this->tree_array($arrLP);
  4370. $arrLP = $this->arrMenu;
  4371. unset($this->arrMenu);
  4372. for($i = 0; $i < count($arrLP); $i++)
  4373. {
  4374. if($arrLP[$i]['id'] == $item_id)
  4375. break;
  4376. $return .= '<tr>';
  4377. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ) ? ' colspan="3"' : '') . '>';
  4378. $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'] . '" />';
  4379. $return .= '<img alt="" src="img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  4380. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . stripslashes($arrLP[$i]['title']) . '</label>';
  4381. $return .= '</td>';
  4382. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  4383. {
  4384. $return .= '<td class="exercise">';
  4385. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_min : 0) . '" />';
  4386. $return .= '</td>';
  4387. $return .= '<td class="exercise">';
  4388. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_max : 100) . '" />';
  4389. $return .= '</td>';
  4390. }
  4391. $return .= '</tr>';
  4392. }
  4393. $return .= '<tr>';
  4394. $return .= '<td colspan="3">';
  4395. $return .= '<input class="button" name="submit_button" type="submit" value="OK" /></td>' . "\n";
  4396. $return .= '</td>';
  4397. $return .= '</tr>';
  4398. $return .= '</table>';
  4399. $return .= '</form>';
  4400. $return .= '</div>';
  4401. return $return;
  4402. }
  4403. /**
  4404. * Creates a list with all the documents in it
  4405. *
  4406. * @return string
  4407. */
  4408. function get_documents()
  4409. {
  4410. global $_course;
  4411. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4412. $sql_doc = "
  4413. SELECT *
  4414. FROM " . $tbl_doc . "
  4415. WHERE
  4416. path NOT LIKE '%_DELETED_%'
  4417. ORDER BY path ASC";
  4418. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  4419. $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';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="img/lp_' . TOOL_DOCUMENT . '.png" style="margin-right:5px;" title="" />'.get_lang("Document").'</div>';
  4420. $return .= '<div class="lp_resource_elements" id="resDoc">';
  4421. while($row_doc = Database::fetch_array($res_doc))
  4422. {
  4423. $explode = explode('/', $row_doc['path']);
  4424. $num = count($explode) - 2;
  4425. $return .= '<div class="lp_resource_element">';
  4426. $return .= '<img align="left" alt="" src="img/lp_' . (($row_doc['filetype'] == 'file') ? TOOL_DOCUMENT : 'folder') . '.png" style="margin-left:' . ($num * 20) . 'px;margin-right:5px;" title="" />';
  4427. if($row_doc['filetype'] == 'file')
  4428. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $row_doc['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_doc['title'] . '</a>';
  4429. else
  4430. $return .= $row_doc['title'];
  4431. $return .= '</div>';
  4432. }
  4433. if(Database::num_rows($res_doc) == 0)
  4434. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  4435. $return .= '</div>';
  4436. return $return;
  4437. }
  4438. /**
  4439. * Creates a list with all the exercises (quiz) in it
  4440. *
  4441. * @return string
  4442. */
  4443. function get_exercises()
  4444. {
  4445. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  4446. $sql_quiz = "
  4447. SELECT *
  4448. FROM " . $tbl_quiz . "
  4449. ORDER BY title ASC";
  4450. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  4451. $return .= '<div class="lp_resource_header_end"' . " onclick=\"if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="img/lp_' . TOOL_QUIZ . '.png" style="margin-right:5px;" title="" />'.get_lang("Exercise").'</div>';
  4452. $return .= '<div class="lp_resource_elements_end" id="resExercise">';
  4453. while($row_quiz = Database::fetch_array($res_quiz))
  4454. {
  4455. $return .= '<div class="lp_resource_element">';
  4456. $return .= '<img align="left" alt="" src="img/lp_' . TOOL_QUIZ . '.png" style="margin-right:5px;" title="" />';
  4457. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_quiz['title'] . '</a>';
  4458. //$return .= $row_quiz['title'];
  4459. $return .= '</div>';
  4460. }
  4461. if(Database::num_rows($res_quiz) == 0)
  4462. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  4463. $return .= '</div>';
  4464. return $return;
  4465. }
  4466. /**
  4467. * Creates a list with all the links in it
  4468. *
  4469. * @return string
  4470. */
  4471. function get_links()
  4472. {
  4473. $tbl_link = Database::get_course_table(TABLE_LINK);
  4474. $sql_link = "
  4475. SELECT *
  4476. FROM " . $tbl_link . "
  4477. ORDER BY title ASC";
  4478. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  4479. $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';}\"" . ' style="cursor:pointer;"><img align="left" alt="" src="img/lp_' . TOOL_LINK . '.png" style="margin-right:5px;" title="" />Links</div>';
  4480. $return .= '<div class="lp_resource_elements" id="resLink">';
  4481. while($row_link = Database::fetch_array($res_link))
  4482. {
  4483. $return .= '<div class="lp_resource_element">';
  4484. $return .= '<img align="left" alt="" src="img/lp_' . TOOL_LINK . '.png" style="margin-right:5px;" title="" />';
  4485. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_LINK . '&amp;file=' . $row_link['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_link['title'] . '</a>';
  4486. $return .= '</div>';
  4487. }
  4488. if(Database::num_rows($res_link) == 0)
  4489. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  4490. $return .= '</div>';
  4491. return $return;
  4492. }
  4493. /**
  4494. * Creates a list with all the student publications in it
  4495. *
  4496. * @return unknown
  4497. */
  4498. function get_student_publications()
  4499. {
  4500. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  4501. $sql_student = "
  4502. SELECT *
  4503. FROM " . $tbl_student . "
  4504. ORDER BY title ASC";
  4505. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  4506. $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';}\"" . ' style="border-bottom:1px solid #999999; cursor:pointer;"><img align="left" alt="" src="img/lp_' . TOOL_STUDENTPUBLICATION . '.png" style="margin-right:5px;" title="" />Student Publications</div>';
  4507. $return .= '<div class="lp_resource_elements" id="resStudent" style="border-bottom:1px solid #999999; border-top:0;">';
  4508. while($row_student = Database::fetch_array($res_student))
  4509. {
  4510. $return .= '<div class="lp_resource_element">';
  4511. $return .= '<img align="left" alt="" src="img/lp_' . TOOL_STUDENTPUBLICATION . '.png" style="margin-right:5px;" title="" />';
  4512. $return .= '<a href="' . $_SERVER['PHP_SELF'] . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;file=' . $row_student['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_student['title'] . '</a>';
  4513. $return .= '</div>';
  4514. }
  4515. if(Database::num_rows($res_student) == 0)
  4516. $return .= '<div class="lp_resource_element">No student publications available</div>';
  4517. $return .= '</div>';
  4518. return $return;
  4519. }
  4520. }
  4521. ?>