learnpath.class.php 199 KB

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