learnpath.class.php 214 KB

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