learnpath.class.php 331 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026
  1. <?php // $Id: index.php 16620 2008-10-25 20:03:54Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue Notre Dame, 152, B-1140 Evere, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
  19. * learnpaths. It is used by the scorm class as well as the dokeos_lp class.
  20. * @package dokeos.learnpath
  21. * @author Yannick Warnier <ywarnier@beeznest.org>
  22. * @license GNU/GPL - See Dokeos license directory for details
  23. */
  24. /**
  25. * Defines the learnpath parent class
  26. * @package dokeos.learnpath
  27. */
  28. class learnpath {
  29. var $attempt = 0; //the number for the current ID view
  30. var $cc; //course (code) this learnpath is located in
  31. var $current; //id of the current item the user is viewing
  32. var $current_score; //the score of the current item
  33. var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
  34. var $current_time_stop; //the time the user closed this resource
  35. var $default_status = 'not attempted';
  36. var $encoding = 'ISO-8859-1';
  37. var $error = '';
  38. var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
  39. var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
  40. var $index; //the index of the active learnpath_item in $ordered_items array
  41. var $items = array();
  42. var $last; //item_id of last item viewed in the learning path
  43. var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
  44. var $license; //which license this course has been given - not used yet on 20060522
  45. var $lp_id; //DB ID for this learnpath
  46. var $lp_view_id; //DB ID for lp_view
  47. var $log_file; //file where to log learnpath API msg
  48. var $maker; //which maker has conceived the content (ENI, Articulate, ...)
  49. var $message = '';
  50. var $mode='embedded'; //holds the video display mode (fullscreen or embedded)
  51. var $name; //learnpath name (they generally have one)
  52. var $ordered_items = array(); //list of the learnpath items in the order they are to be read
  53. var $path = ''; //path inside the scorm directory (if scorm)
  54. var $theme; // the current theme of the learning path
  55. var $preview_image; // the current image of the learning path
  56. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
  57. var $prevent_reinit = 1;
  58. // Describes the mode of progress bar display
  59. var $progress_bar_mode = '%';
  60. // Percentage progress as saved in the db
  61. var $progress_db = '0';
  62. var $proximity; //wether the content is distant or local or unknown
  63. var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
  64. //!!!This array (refs_list) is built differently depending on the nature of the LP.
  65. //If SCORM, uses ref, if Dokeos, uses id to keep a unique value
  66. var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  67. //TODO check if this type variable is useful here (instead of just in the controller script)
  68. var $user_id; //ID of the user that is viewing/using the course
  69. var $update_queue = array();
  70. var $scorm_debug = 0;
  71. var $arrMenu = array(); //array for the menu items
  72. var $debug = 1; //logging level
  73. /**
  74. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  75. * Also builds the list of items into $this->items.
  76. * @param string Course code
  77. * @param integer Learnpath ID
  78. * @param integer User ID
  79. * @return boolean True on success, false on error
  80. */
  81. function learnpath($course, $lp_id, $user_id) {
  82. //check params
  83. //check course code
  84. if($this->debug>0){error_log('New LP - In learnpath::learnpath('.$course.','.$lp_id.','.$user_id.')',0);}
  85. if(empty($course)){
  86. $this->error = 'Course code is empty';
  87. return false;
  88. }
  89. else
  90. {
  91. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  92. //$course = Database::escape_string($course);
  93. $course = $this->escape_string($course);
  94. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  95. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying course: '.$sql,0);}
  96. //$res = Database::query($sql);
  97. $res = api_sql_query($sql, __FILE__, __LINE__);
  98. if(Database::num_rows($res)>0)
  99. {
  100. $this->cc = $course;
  101. }
  102. else
  103. {
  104. $this->error = 'Course code does not exist in database ('.$sql.')';
  105. return false;
  106. }
  107. }
  108. //check learnpath ID
  109. if(empty($lp_id))
  110. {
  111. $this->error = 'Learnpath ID is empty';
  112. return false;
  113. }
  114. else
  115. {
  116. //TODO make it flexible to use any course_code (still using env course code here)
  117. $lp_table = Database::get_course_table('lp');
  118. //$id = Database::escape_integer($id);
  119. $lp_id = $this->escape_string($lp_id);
  120. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  121. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying lp: '.$sql,0);}
  122. //$res = Database::query($sql);
  123. $res = api_sql_query($sql, __FILE__, __LINE__);
  124. if(Database::num_rows($res)>0)
  125. {
  126. $this->lp_id = $lp_id;
  127. $row = Database::fetch_array($res);
  128. $this->type = $row['lp_type'];
  129. $this->name = stripslashes($row['name']);
  130. $this->encoding = $row['default_encoding'];
  131. $this->proximity = $row['content_local'];
  132. $this->theme = $row['theme'];
  133. $this->maker = $row['content_maker'];
  134. $this->prevent_reinit = $row['prevent_reinit'];
  135. $this->license = $row['content_license'];
  136. $this->scorm_debug = $row['debug'];
  137. $this->js_lib = $row['js_lib'];
  138. $this->path = $row['path'];
  139. $this->preview_image= $row['preview_image'];
  140. $this->author= $row['author'];
  141. if($this->type == 2){
  142. if($row['force_commit'] == 1){
  143. $this->force_commit = true;
  144. }
  145. }
  146. $this->mode = $row['default_view_mod'];
  147. }
  148. else
  149. {
  150. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  151. return false;
  152. }
  153. }
  154. //check user ID
  155. if(empty($user_id)){
  156. $this->error = 'User ID is empty';
  157. return false;
  158. }
  159. else
  160. {
  161. //$main_table = Database::get_main_user_table();
  162. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  163. //$user_id = Database::escape_integer($user_id);
  164. $user_id = $this->escape_string($user_id);
  165. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  166. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Querying user: '.$sql,0);}
  167. //$res = Database::query($sql);
  168. $res = api_sql_query($sql, __FILE__, __LINE__);
  169. if(Database::num_rows($res)>0)
  170. {
  171. $this->user_id = $user_id;
  172. }
  173. else
  174. {
  175. $this->error = 'User ID does not exist in database ('.$sql.')';
  176. return false;
  177. }
  178. }
  179. //end of variables checking
  180. //now get the latest attempt from this user on this LP, if available, otherwise create a new one
  181. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  182. //selecting by view_count descending allows to get the highest view_count first
  183. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
  184. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - querying lp_view: '.$sql,0);}
  185. //$res = Database::query($sql);
  186. $res = api_sql_query($sql, __FILE__, __LINE__);
  187. $view_id = 0; //used later to query lp_item_view
  188. if(Database::num_rows($res)>0)
  189. {
  190. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Found previous view',0);}
  191. $row = Database::fetch_array($res);
  192. $this->attempt = $row['view_count'];
  193. $this->lp_view_id = $row['id'];
  194. $this->last_item_seen = $row['last_item'];
  195. $this->progress_db = $row['progress'];
  196. }
  197. else
  198. {
  199. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - NOT Found previous view',0);}
  200. $this->attempt = 1;
  201. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
  202. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  203. $this->lp_view_id = Database::get_last_insert_id();
  204. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - inserting new lp_view: '.$sql_ins,0);}
  205. }
  206. //initialise items
  207. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  208. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  209. $res = api_sql_query($sql, __FILE__, __LINE__);
  210. while($row = Database::fetch_array($res))
  211. {
  212. $oItem = '';
  213. //$this->ordered_items[] = $row['id'];
  214. switch($this->type){
  215. case 3: //aicc
  216. $oItem = new aiccItem('db',$row['id']);
  217. if(is_object($oItem)){
  218. $my_item_id = $oItem->get_id();
  219. $oItem->set_lp_view($this->lp_view_id);
  220. $oItem->set_prevent_reinit($this->prevent_reinit);
  221. // Don't use reference here as the next loop will make the pointed object change
  222. $this->items[$my_item_id] = $oItem;
  223. $this->refs_list[$oItem->ref]=$my_item_id;
  224. if($this->debug>2){error_log('New LP - learnpath::learnpath() - aicc object with id '.$my_item_id.' set in items[]',0);}
  225. }
  226. break;
  227. case 2:
  228. require_once('scorm.class.php');
  229. require_once('scormItem.class.php');
  230. $oItem = new scormItem('db',$row['id']);
  231. if(is_object($oItem)){
  232. $my_item_id = $oItem->get_id();
  233. $oItem->set_lp_view($this->lp_view_id);
  234. $oItem->set_prevent_reinit($this->prevent_reinit);
  235. // Don't use reference here as the next loop will make the pointed object change
  236. $this->items[$my_item_id] = $oItem;
  237. $this->refs_list[$oItem->ref]=$my_item_id;
  238. if($this->debug>2){error_log('New LP - object with id '.$my_item_id.' set in items[]',0);}
  239. }
  240. break;
  241. case 1:
  242. default:
  243. require_once('learnpathItem.class.php');
  244. $oItem = new learnpathItem($row['id'],$user_id);
  245. if(is_object($oItem)){
  246. $my_item_id = $oItem->get_id();
  247. //$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
  248. $oItem->set_prevent_reinit($this->prevent_reinit);
  249. // Don't use reference here as the next loop will make the pointed object change
  250. $this->items[$my_item_id] = $oItem;
  251. $this->refs_list[$my_item_id]=$my_item_id;
  252. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - object with id '.$my_item_id.' set in items[]',0);}
  253. }
  254. break;
  255. }
  256. //items is a list of pointers to all items, classified by DB ID, not SCO id
  257. if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
  258. $this->items[$row['id']]->set_level(0);
  259. }else{
  260. $level = $this->items[$row['parent_item_id']]->get_level()+1;
  261. $this->items[$row['id']]->set_level($level);
  262. if(is_object($this->items[$row['parent_item_id']])){
  263. //items is a list of pointers from item DB ids to item objects
  264. $this->items[$row['parent_item_id']]->add_child($row['id']);
  265. }else{
  266. 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);}
  267. }
  268. }
  269. //get last viewing vars
  270. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  271. //this query should only return one or zero result
  272. $sql = "SELECT * " .
  273. "FROM $lp_item_view_table " .
  274. "WHERE lp_view_id = ".$this->lp_view_id." " .
  275. "AND lp_item_id = ".$row['id']." ORDER BY view_count DESC ";
  276. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '.$sql,0);}
  277. //get the item status
  278. $res2 = api_sql_query($sql, __FILE__, __LINE__);
  279. if(Database::num_rows($res2)>0)
  280. {
  281. //if this learnpath has already been used by this user, get his last attempt count and
  282. //the last item seen back into this object
  283. //$max = 0;
  284. $row2 = Database::fetch_array($res2);
  285. if($this->debug>2){error_log('New LP - learnpath::learnpath() - Got item_view: '.print_r($row2,true),0);}
  286. $this->items[$row['id']]->set_status($row2['status']);
  287. if(empty($row2['status'])){
  288. $this->items[$row['id']]->set_status($this->default_status);
  289. }
  290. //$this->attempt = $row['view_count'];
  291. //$this->last_item = $row['id'];
  292. }
  293. else //no item found in lp_item_view for this view
  294. {
  295. //first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
  296. //TODO if the learnpath has not got attempts activated, always use attempt '1'
  297. //$this->attempt = 1;
  298. //$this->last_item = 0;
  299. $this->items[$row['id']]->set_status($this->default_status);
  300. //Add that row to the lp_item_view table so that we have something to show in the stats page
  301. $sql_ins = "INSERT INTO $lp_item_view_table " .
  302. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  303. "(".$row['id'].",".$this->lp_view_id.",1,'not attempted')";
  304. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - Inserting blank item_view : '.$sql_ins,0);}
  305. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  306. }
  307. //setting the view in the item object
  308. $this->items[$row['id']]->set_lp_view($this->lp_view_id);
  309. }
  310. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(),0);
  311. $this->max_ordered_items = 0;
  312. foreach($this->ordered_items as $index=>$dummy){
  313. if($index > $this->max_ordered_items AND !empty($dummy)){
  314. $this->max_ordered_items = $index;
  315. }
  316. }
  317. //TODO define the current item better
  318. $this->first();
  319. if($this->debug>2){error_log('New LP - learnpath::learnpath() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(),0);}
  320. }
  321. /**
  322. * 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
  323. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  324. *
  325. * @param int $parent
  326. * @param int $previous
  327. * @param string $type
  328. * @param int $id
  329. * @param string $title
  330. * @param string $description
  331. * @return int
  332. */
  333. function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0, $max_time_allowed=0)
  334. {
  335. global $charset;
  336. if($this->debug>0){error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')',0);}
  337. $tbl_lp_item = Database::get_course_table('lp_item');
  338. $parent = intval($parent);
  339. $previous = intval($previous);
  340. $type = $this->escape_string($type);
  341. $id = intval($id);
  342. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  343. if (empty($max_time_allowed)) { $max_time_allowed = 0; }
  344. $title = $this->escape_string(mb_convert_encoding($title,$this->encoding,$charset));
  345. $description = $this->escape_string(mb_convert_encoding($description,$this->encoding,$charset));
  346. $sql_count = "
  347. SELECT COUNT(id) AS num
  348. FROM " . $tbl_lp_item . "
  349. WHERE
  350. lp_id = " . $this->get_id() . " AND
  351. parent_item_id = " . $parent;
  352. $res_count = api_sql_query($sql_count, __FILE__, __LINE__);
  353. $row = Database::fetch_array($res_count);
  354. $num = $row['num'];
  355. if($num > 0) {
  356. if($previous == 0) {
  357. $sql = "
  358. SELECT
  359. id,
  360. next_item_id,
  361. display_order
  362. FROM " . $tbl_lp_item . "
  363. WHERE
  364. lp_id = " . $this->get_id() . " AND
  365. parent_item_id = " . $parent . " AND
  366. previous_item_id = 0 OR previous_item_id=".$parent;
  367. $result = api_sql_query($sql, __FILE__, __LINE__);
  368. $row = Database::fetch_array($result);
  369. $tmp_previous = 0;
  370. $next = $row['id'];
  371. $display_order = 0;
  372. } else {
  373. $previous = (int) $previous;
  374. $sql = "
  375. SELECT
  376. id,
  377. previous_item_id,
  378. next_item_id,
  379. display_order
  380. FROM " . $tbl_lp_item . "
  381. WHERE
  382. lp_id = " . $this->get_id() . " AND
  383. id = " . $previous;
  384. $result = api_sql_query($sql, __FILE__, __LINE__);
  385. $row = Database::fetch_array($result);
  386. $tmp_previous = $row['id'];
  387. $next = $row['next_item_id'];
  388. $display_order = $row['display_order'];
  389. }
  390. } else {
  391. $tmp_previous = 0;
  392. $next = 0;
  393. $display_order = 0;
  394. }
  395. $new_item_id = -1;
  396. $id = $this->escape_string($id);
  397. if($type == 'quiz') {
  398. $sql = 'SELECT SUM(ponderation)
  399. FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
  400. INNER JOIN '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
  401. ON quiz_question.id = quiz_rel_question.question_id
  402. AND quiz_rel_question.exercice_id = '.$id;
  403. $rsQuiz = api_sql_query($sql, __FILE__, __LINE__);
  404. $max_score = Database::result($rsQuiz, 0, 0);
  405. } else {
  406. $max_score = 100;
  407. }
  408. if($prerequisites!=0) {
  409. $sql_ins = "
  410. INSERT INTO " . $tbl_lp_item . " (
  411. lp_id,
  412. item_type,
  413. ref,
  414. title,
  415. description,
  416. path,
  417. max_score,
  418. parent_item_id,
  419. previous_item_id,
  420. next_item_id,
  421. display_order,
  422. prerequisite,
  423. max_time_allowed
  424. ) VALUES (
  425. " . $this->get_id() . ",
  426. '" . $type . "',
  427. '',
  428. '" . $title . "',
  429. '" . $description . "',
  430. '" . $id . "',
  431. '" . $max_score. "',
  432. " . $parent . ",
  433. " . $previous . ",
  434. " . $next . ",
  435. " . ($display_order + 1) . ",
  436. " . $prerequisites . ",
  437. " . $max_time_allowed . "
  438. )";
  439. } else {
  440. //insert new item
  441. $sql_ins = "
  442. INSERT INTO " . $tbl_lp_item . " (
  443. lp_id,
  444. item_type,
  445. ref,
  446. title,
  447. description,
  448. path,
  449. max_score,
  450. parent_item_id,
  451. previous_item_id,
  452. next_item_id,
  453. display_order,
  454. max_time_allowed
  455. ) VALUES (
  456. " . $this->get_id() . ",
  457. '" . $type . "',
  458. '',
  459. '" . $title . "',
  460. '" . $description . "',
  461. '" . $id . "',
  462. '" . $max_score. "',
  463. " . $parent . ",
  464. " . $previous . ",
  465. " . $next . ",
  466. " . ($display_order + 1) . ",
  467. " . $max_time_allowed . "
  468. )";
  469. }
  470. if($this->debug>2){error_log('New LP - Inserting dokeos_chapter: '.$sql_ins,0);}
  471. $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__);
  472. if($res_ins > 0)
  473. {
  474. $new_item_id = Database::get_last_insert_id($res_ins);
  475. //update the item that should come after the new item
  476. $sql_update_next = "
  477. UPDATE " . $tbl_lp_item . "
  478. SET previous_item_id = " . $new_item_id . "
  479. WHERE id = " . $next;
  480. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  481. //update the item that should be before the new item
  482. $sql_update_previous = "
  483. UPDATE " . $tbl_lp_item . "
  484. SET next_item_id = " . $new_item_id . "
  485. WHERE id = " . $tmp_previous;
  486. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  487. //update all the items after the new item
  488. $sql_update_order = "
  489. UPDATE " . $tbl_lp_item . "
  490. SET display_order = display_order + 1
  491. WHERE
  492. lp_id = " . $this->get_id() . " AND
  493. id <> " . $new_item_id . " AND
  494. parent_item_id = " . $parent . " AND
  495. display_order > " . $display_order;
  496. $res_update_previous = api_sql_query($sql_update_order, __FILE__, __LINE__);
  497. //update the item that should come after the new item
  498. $sql_update_ref = "
  499. UPDATE " . $tbl_lp_item . "
  500. SET ref = " . $new_item_id . "
  501. WHERE id = " . $new_item_id;
  502. api_sql_query($sql_update_ref, __FILE__, __LINE__);
  503. }
  504. // upload audio
  505. if (!empty($_FILES['mp3']['name'])) {
  506. // create the audio folder if it does not exist yet
  507. global $_course;
  508. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  509. if(!is_dir($filepath.'audio')) {
  510. $perm = api_get_setting('permissions_for_new_directories');
  511. $perm = octdec(!empty($perm)?$perm:'0770');
  512. mkdir($filepath.'audio',$perm);
  513. $audio_id=add_document($_course,'/audio','folder',0,'audio');
  514. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  515. }
  516. // upload the file in the documents tool
  517. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  518. $file_path = handle_uploaded_document($_course, $_FILES['mp3'],api_get_path('SYS_COURSE_PATH').$_course['path'].'/document','/audio',api_get_user_id(),'','','','','',false);
  519. // getting the filename only
  520. $file_components = explode('/',$file_path);
  521. $file = $file_components[count($file_components)-1];
  522. // store the mp3 file in the lp_item table
  523. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($new_item_id)."'";
  524. api_sql_query($sql_insert_audio, __FILE__, __LINE__);
  525. }
  526. return $new_item_id;
  527. }
  528. /**
  529. * Static admin function allowing addition of a learnpath to a course.
  530. * @param string Course code
  531. * @param string Learnpath name
  532. * @param string Learnpath description string, if provided
  533. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  534. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  535. * @param string Zip file containing the learnpath or directory containing the learnpath
  536. * @return integer The new learnpath ID on success, 0 on failure
  537. */
  538. function add_lp($course,$name,$description='',$learnpath='guess',$origin='zip',$zipname='')
  539. {
  540. //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
  541. //TODO
  542. $tbl_lp = Database::get_course_table('lp');
  543. //check course code exists
  544. //check lp_name doesn't exist, otherwise append something
  545. $i = 0;
  546. $name = learnpath::escape_string(htmlentities($name)); //Kevin Van Den Haute: added htmlentities()
  547. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  548. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  549. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  550. while(Database::num_rows($res_name)){
  551. //there is already one such name, update the current one a bit
  552. $i++;
  553. $name = $name.' - '.$i;
  554. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  555. //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
  556. $res_name = api_sql_query($check_name, __FILE__, __LINE__);
  557. }
  558. //new name does not exist yet; keep it
  559. //escape description
  560. $description = learnpath::escape_string(htmlentities($description)); //Kevin: added htmlentities()
  561. $type = 1;
  562. switch($learnpath){
  563. case 'guess':
  564. break;
  565. case 'dokeos':
  566. $type = 1;
  567. break;
  568. case 'aicc':
  569. break;
  570. }
  571. switch($origin){
  572. case 'zip':
  573. //check zipname string. If empty, we are currently creating a new Dokeos learnpath
  574. break;
  575. case 'manual':
  576. default:
  577. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  578. $res_max = api_sql_query($get_max, __FILE__, __LINE__);
  579. if(Database::num_rows($res_max)<1){
  580. $dsp = 1;
  581. }else{
  582. $row = Database::fetch_array($res_max);
  583. $dsp = $row[0]+1;
  584. }
  585. $sql_insert = "INSERT INTO $tbl_lp " .
  586. "(lp_type,name,description,path,default_view_mod," .
  587. "default_encoding,display_order,content_maker," .
  588. "content_local,js_lib) " .
  589. "VALUES ($type,'$name','$description','','embedded'," .
  590. "'UTF-8','$dsp','Dokeos'," .
  591. "'local','')";
  592. //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
  593. $res_insert = api_sql_query($sql_insert, __FILE__, __LINE__);
  594. $id = Database::get_last_insert_id();
  595. if($id>0){
  596. //insert into item_property
  597. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$id,'LearnpathAdded',api_get_user_id());
  598. return $id;
  599. }
  600. break;
  601. }
  602. }
  603. /**
  604. * Appends a message to the message attribute
  605. * @param string Message to append.
  606. */
  607. function append_message($string)
  608. {
  609. if($this->debug>0){error_log('New LP - In learnpath::append_message()',0);}
  610. $this->message .= $string;
  611. }
  612. /**
  613. * Autocompletes the parents of an item in case it's been completed or passed
  614. * @param integer Optional ID of the item from which to look for parents
  615. */
  616. function autocomplete_parents($item)
  617. {
  618. if($this->debug>0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
  619. if(empty($item)){
  620. $item = $this->current;
  621. }
  622. $parent_id = $this->items[$item]->get_parent();
  623. if($this->debug>2){error_log('New LP - autocompleting parent of item '.$item.' (item '.$parent_id.')',0);}
  624. if(is_object($this->items[$item]) and !empty($parent_id))
  625. {//if $item points to an object and there is a parent
  626. if($this->debug>2){error_log('New LP - '.$item.' is an item, proceed',0);}
  627. $current_item =& $this->items[$item];
  628. $parent =& $this->items[$parent_id]; //get the parent
  629. //new experiment including failed and browsed in completed status
  630. $current_status = $current_item->get_status();
  631. if($current_item->is_done() || $current_status=='browsed' || $current_status=='failed')
  632. {
  633. //if the current item is completed or passes or succeeded
  634. $completed = true;
  635. if($this->debug>2){error_log('New LP - Status of current item is alright',0);}
  636. foreach($parent->get_children() as $child)
  637. {
  638. //check all his brothers (his parent's children) for completion status
  639. if($child!= $item)
  640. {
  641. if($this->debug>2){error_log('New LP - Looking at brother with ID '.$child.', status is '.$this->items[$child]->get_status(),0);}
  642. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  643. //Trying completing parents of failed and browsed items as well
  644. if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
  645. {
  646. //keep completion status to true
  647. }else{
  648. if($this->debug>2){error_log('New LP - Found one incomplete child of '.$parent_id.': '.$child.' is '.$this->items[$child]->get_status(),0);}
  649. $completed = false;
  650. }
  651. }
  652. }
  653. if($completed == true)
  654. { //if all the children were completed
  655. $parent->set_status('completed');
  656. $parent->save(false,$this->prerequisites_match($parent->get_id()));
  657. $this->update_queue[$parent->get_id()] = $parent->get_status();
  658. if($this->debug>2){error_log('New LP - Added parent to update queue '.print_r($this->update_queue,true),0);}
  659. $this->autocomplete_parents($parent->get_id()); //recursive call
  660. }
  661. }else{
  662. //error_log('New LP - status of current item is not enough to get bothered with it',0);
  663. }
  664. }
  665. }
  666. /**
  667. * Autosaves the current results into the database for the whole learnpath
  668. */
  669. function autosave()
  670. {
  671. if($this->debug>0){error_log('New LP - In learnpath::autosave()',0);}
  672. //TODO add aditionnal save operations for the learnpath itself
  673. }
  674. /**
  675. * Clears the message attribute
  676. */
  677. function clear_message()
  678. {
  679. if($this->debug>0){error_log('New LP - In learnpath::clear_message()',0);}
  680. $this->message = '';
  681. }
  682. /**
  683. * Closes the current resource
  684. *
  685. * Stops the timer
  686. * Saves into the database if required
  687. * Clears the current resource data from this object
  688. * @return boolean True on success, false on failure
  689. */
  690. function close()
  691. {
  692. if($this->debug>0){error_log('New LP - In learnpath::close()',0);}
  693. if(empty($this->lp_id))
  694. {
  695. $this->error = 'Trying to close this learnpath but no ID is set';
  696. return false;
  697. }
  698. $this->current_time_stop = time();
  699. if($this->save)
  700. {
  701. $learnpath_view_table = Database::get_course_table(TABLE_LP_VIEW);
  702. /*
  703. $sql = "UPDATE $learnpath_view_table " .
  704. "SET " .
  705. "stop_time = ".$this->current_time_stop.", " .
  706. "score = ".$this->current_score.", ".
  707. "WHERE learnpath_id = '".$this->lp_id."'";
  708. //$res = Database::query($sql);
  709. $res = api_sql_query($res);
  710. if(mysql_affected_rows($res)<1)
  711. {
  712. $this->error = 'Could not update learnpath_view table while closing learnpath';
  713. return false;
  714. }
  715. */
  716. }
  717. $this->ordered_items = array();
  718. $this->index=0;
  719. unset($this->lp_id);
  720. //unset other stuff
  721. return true;
  722. }
  723. /**
  724. * Static admin function allowing removal of a learnpath
  725. * @param string Course code
  726. * @param integer Learnpath ID
  727. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  728. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  729. */
  730. function delete($course=null,$id=null,$delete='keep')
  731. {
  732. //TODO implement a way of getting this to work when the current object is not set
  733. //In clear: implement this in the item class as well (abstract class) and use the given ID in queries
  734. //if(empty($course)){$course = api_get_course_id();}
  735. //if(empty($id)){$id = $this->get_id();}
  736. //If an ID is specifically given and the current LP is not the same,
  737. //prevent delete
  738. if(!empty($id) && ($id != $this->lp_id)){return false;}
  739. $lp = Database::get_course_table('lp');
  740. $lp_view = Database::get_course_table('lp_view');
  741. $lp_item_view = Database::get_course_table('lp_item_view');
  742. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  743. //delete lp item id
  744. foreach($this->items as $id => $dummy) {
  745. //$this->items[$id]->delete();
  746. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '".$id."'";
  747. $res_del_item_view=api_sql_query($sql_del_view,__FILE__,__LINE__);
  748. }
  749. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  750. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  751. $res_del_view = api_sql_query($sql_del_view, __FILE__, __LINE__);
  752. $this->toggle_publish($this->lp_id,'i');
  753. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  754. if($this->type == 2 OR $this->type==3){
  755. //this is a scorm learning path, delete the files as well
  756. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  757. $res = api_sql_query($sql, __FILE__, __LINE__);
  758. if(Database::num_rows($res)>0){
  759. $row = Database::fetch_array($res);
  760. $path = $row['path'];
  761. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  762. $res = api_sql_query($sql, __FILE__, __LINE__);
  763. if(Database::num_rows($res)>0)
  764. { //another learning path uses this directory, so don't delete it
  765. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  766. }else{
  767. //no other LP uses that directory, delete it
  768. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  769. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  770. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  771. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  772. exec('rm -rf '.$course_scorm_dir.$path);
  773. }
  774. }
  775. }
  776. }
  777. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  778. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  779. $res_del_lp = api_sql_query($sql_del_lp, __FILE__, __LINE__);
  780. $this->update_display_order();//updates the display order of all lps
  781. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$this->lp_id,'delete',api_get_user_id());
  782. require_once '../gradebook/lib/be.inc.php';
  783. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  784. //delete link of gradebook tool
  785. $sql='SELECT gl.id FROM '.$tbl_grade_link.' gl WHERE gl.type="4" AND gl.ref_id="'.$id.'";';
  786. $result=api_sql_query($sql,__FILE__,__LINE__);
  787. $row=Database::fetch_array($result,'ASSOC');
  788. $link= LinkFactory :: load($row['id']);
  789. if ($link[0] != null) {
  790. $link[0]->delete();
  791. }
  792. //TODO: also delete items and item-views
  793. if (api_get_setting('search_enabled') == 'true') {
  794. require_once(api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php');
  795. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  796. }
  797. }
  798. /**
  799. * Removes all the children of one item - dangerous!
  800. * @param integer Element ID of which children have to be removed
  801. * @return integer Total number of children removed
  802. */
  803. function delete_children_items($id){
  804. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  805. $num = 0;
  806. if(empty($id) || $id != strval(intval($id))){return false;}
  807. $lp_item = Database::get_course_table('lp_item');
  808. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  809. $res = api_sql_query($sql, __FILE__, __LINE__);
  810. while($row = Database::fetch_array($res)){
  811. $num += $this->delete_children_items($row['id']);
  812. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  813. $res_del = api_sql_query($sql_del, __FILE__, __LINE__);
  814. $num++;
  815. }
  816. return $num;
  817. }
  818. /**
  819. * Removes an item from the current learnpath
  820. * @param integer Elem ID (0 if first)
  821. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  822. * @return integer Number of elements moved
  823. * @todo implement resource removal
  824. */
  825. function delete_item($id, $remove='keep')
  826. {
  827. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  828. //TODO - implement the resource removal
  829. if(empty($id) || $id != strval(intval($id))){return false;}
  830. //first select item to get previous, next, and display order
  831. $lp_item = Database::get_course_table('lp_item');
  832. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  833. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  834. if(Database::num_rows($res_sel)<1){return false;}
  835. $row = Database::fetch_array($res_sel);
  836. $previous = $row['previous_item_id'];
  837. $next = $row['next_item_id'];
  838. $display = $row['display_order'];
  839. $parent = $row['parent_item_id'];
  840. $lp = $row['lp_id'];
  841. //delete children items
  842. $num = $this->delete_children_items($id);
  843. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  844. //now delete the item
  845. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  846. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  847. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  848. //now update surrounding items
  849. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  850. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  851. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  852. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  853. //now update all following items with new display order
  854. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  855. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  856. // remove from search engine if enabled
  857. if (api_get_setting('search_enabled') == 'true') {
  858. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  859. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  860. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  861. $res = api_sql_query($sql, __FILE__, __LINE__);
  862. if (Database::num_rows($res) > 0) {
  863. $row2 = Database::fetch_array($res);
  864. require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php');
  865. $di = new DokeosIndexer();
  866. $di->remove_document((int)$row2['search_did']);
  867. }
  868. $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  869. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  870. api_sql_query($sql, __FILE__, __LINE__);
  871. }
  872. }
  873. /**
  874. * Updates an item's content in place
  875. * @param integer Element ID
  876. * @param integer Parent item ID
  877. * @param integer Previous item ID
  878. * @param string Item title
  879. * @param string Item description
  880. * @param string Prerequisites (optional)
  881. * @param string Indexing terms (optional)
  882. * @param array The array resulting of the $_FILES[mp3] element
  883. * @return boolean True on success, false on error
  884. */
  885. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $audio=NULL, $max_time_allowed=0) {
  886. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  887. if(empty($max_time_allowed)) { $max_time_allowed = 0;}
  888. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  889. $tbl_lp_item = Database::get_course_table('lp_item');
  890. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  891. $res_select = api_sql_query($sql_select, __FILE__, __LINE__);
  892. $row_select = Database::fetch_array($res_select);
  893. $audio_update_sql = '';
  894. if (is_array($audio) && !empty($audio['tmp_name']) && $audio['error']===0) {
  895. // create the audio folder if it does not exist yet
  896. global $_course;
  897. $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
  898. if(!is_dir($filepath.'audio')) {
  899. $perm = api_get_setting('permissions_for_new_directories');
  900. $perm = octdec(!empty($perm)?$perm:'0770');
  901. mkdir($filepath.'audio',$perm);
  902. $audio_id=add_document($_course,'/audio','folder',0,'audio');
  903. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id());
  904. }
  905. //upload file in documents
  906. $pi = pathinfo($audio['name']);
  907. if ($pi['extension'] == 'mp3') {
  908. $c_det = api_get_course_info($this->cc);
  909. $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document';
  910. $path = handle_uploaded_document($c_det,$audio,$bp,'/audio',api_get_user_id(),0,null,'',0,'rename',false,0);
  911. $path = substr($path,7);
  912. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  913. $audio_update_sql = ", audio = '".Database::escape_string($path)."' ";
  914. }
  915. }
  916. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  917. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  918. if($same_parent && $same_previous) {
  919. //only update title and description
  920. $sql_update = "
  921. UPDATE " . $tbl_lp_item . "
  922. SET
  923. title = '" . $this->escape_string(htmlentities($title)) . "',
  924. prerequisite = '".$prerequisites."',
  925. description = '" . $this->escape_string(htmlentities($description)) . "'
  926. ". $audio_update_sql . ",
  927. max_time_allowed = '" . $this->escape_string(htmlentities($max_time_allowed)) . "'
  928. WHERE id = " . $id;
  929. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  930. }
  931. else
  932. {
  933. $old_parent = $row_select['parent_item_id'];
  934. $old_previous = $row_select['previous_item_id'];
  935. $old_next = $row_select['next_item_id'];
  936. $old_order = $row_select['display_order'];
  937. $old_prerequisite = $row_select['prerequisite'];
  938. $old_max_time_allowed = $row_select['max_time_allowed'];
  939. /* BEGIN -- virtually remove the current item id */
  940. /* for the next and previous item it is like the current item doesn't exist anymore */
  941. if($old_previous != 0)
  942. {
  943. $sql_update_next = "
  944. UPDATE " . $tbl_lp_item . "
  945. SET next_item_id = " . $old_next . "
  946. WHERE id = " . $old_previous;
  947. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  948. //echo '<p>' . $sql_update_next . '</p>';
  949. }
  950. if($old_next != 0)
  951. {
  952. $sql_update_previous = "
  953. UPDATE " . $tbl_lp_item . "
  954. SET previous_item_id = " . $old_previous . "
  955. WHERE id = " . $old_next;
  956. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  957. //echo '<p>' . $sql_update_previous . '</p>';
  958. }
  959. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  960. $sql_update_order = "
  961. UPDATE " . $tbl_lp_item . "
  962. SET display_order = display_order - 1
  963. WHERE
  964. display_order > " . $old_order . " AND
  965. parent_item_id = " . $old_parent;
  966. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  967. //echo '<p>' . $sql_update_order . '</p>';
  968. /* END -- virtually remove the current item id */
  969. /* BEGIN -- update the current item id to his new location */
  970. if($previous == 0)
  971. {
  972. //select the data of the item that should come after the current item
  973. $sql_select_old = "
  974. SELECT
  975. id,
  976. display_order
  977. FROM " . $tbl_lp_item . "
  978. WHERE
  979. lp_id = " . $this->lp_id . " AND
  980. parent_item_id = " . $parent . " AND
  981. previous_item_id = " . $previous;
  982. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  983. $row_select_old = Database::fetch_array($res_select_old);
  984. //echo '<p>' . $sql_select_old . '</p>';
  985. //if the new parent didn't have children before
  986. if(Database::num_rows($res_select_old) == 0)
  987. {
  988. $new_next = 0;
  989. $new_order = 1;
  990. }
  991. else
  992. {
  993. $new_next = $row_select_old['id'];
  994. $new_order = $row_select_old['display_order'];
  995. }
  996. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  997. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  998. //echo 'New display_order of current item: ' . $new_order . '<br />';
  999. }
  1000. else
  1001. {
  1002. //select the data of the item that should come before the current item
  1003. $sql_select_old = "
  1004. SELECT
  1005. next_item_id,
  1006. display_order
  1007. FROM " . $tbl_lp_item . "
  1008. WHERE id = " . $previous;
  1009. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  1010. $row_select_old = Database::fetch_array($res_select_old);
  1011. //echo '<p>' . $sql_select_old . '</p>';
  1012. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1013. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1014. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1015. $new_next = $row_select_old['next_item_id'];
  1016. $new_order = $row_select_old['display_order'] + 1;
  1017. }
  1018. //update the current item with the new data
  1019. $sql_update = "
  1020. UPDATE " . $tbl_lp_item . "
  1021. SET
  1022. title = '" . $this->escape_string(htmlentities($title)) . "',
  1023. description = '" . $this->escape_string(htmlentities($description)) . "',
  1024. parent_item_id = " . $parent . ",
  1025. previous_item_id = " . $previous . ",
  1026. next_item_id = " . $new_next . ",
  1027. display_order = " . $new_order . "
  1028. ". $audio_update_sql . "
  1029. WHERE id = " . $id;
  1030. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  1031. //echo '<p>' . $sql_update . '</p>';
  1032. if($previous != 0)
  1033. {
  1034. //update the previous item's next_item_id
  1035. $sql_update_previous = "
  1036. UPDATE " . $tbl_lp_item . "
  1037. SET next_item_id = " . $id . "
  1038. WHERE id = " . $previous;
  1039. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  1040. //echo '<p>' . $sql_update_previous . '</p>';
  1041. }
  1042. if($new_next != 0)
  1043. {
  1044. //update the next item's previous_item_id
  1045. $sql_update_next = "
  1046. UPDATE " . $tbl_lp_item . "
  1047. SET previous_item_id = " . $id . "
  1048. WHERE id = " . $new_next;
  1049. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1050. //echo '<p>' . $sql_update_next . '</p>';
  1051. }
  1052. if($old_prerequisite!=$prerequisites){
  1053. $sql_update_next = "
  1054. UPDATE " . $tbl_lp_item . "
  1055. SET prerequisite = " . $prerequisites . "
  1056. WHERE id = " . $id;
  1057. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1058. }
  1059. if($old_max_time_allowed!=$max_time_allowed){
  1060. $sql_update_max_time_allowed = "
  1061. UPDATE " . $tbl_lp_item . "
  1062. SET max_time_allowed = " . $max_time_allowed . "
  1063. WHERE id = " . $id;
  1064. $res_update_max_time_allowed = api_sql_query($sql_update_max_time_allowed, __FILE__, __LINE__);
  1065. }
  1066. //update all the items with the same or a bigger display_order than
  1067. //the current item
  1068. $sql_update_order = "
  1069. UPDATE " . $tbl_lp_item . "
  1070. SET display_order = display_order + 1
  1071. WHERE
  1072. lp_id = " . $this->get_id() . " AND
  1073. id <> " . $id . " AND
  1074. parent_item_id = " . $parent . " AND
  1075. display_order >= " . $new_order;
  1076. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  1077. //echo '<p>' . $sql_update_order . '</p>';
  1078. /* END -- update the current item id to his new location */
  1079. }
  1080. }
  1081. /**
  1082. * Updates an item's prereq in place
  1083. * @param integer Element ID
  1084. * @param string Prerequisite Element ID
  1085. *
  1086. * @param string Prerequisite item type
  1087. *
  1088. * @param string Prerequisite min score
  1089. *
  1090. * @param string Prerequisite max score
  1091. * @return boolean True on success, false on error
  1092. */
  1093. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
  1094. {
  1095. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')',0);}
  1096. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  1097. $prerequisite_id = $this->escape_string($prerequisite_id);
  1098. $tbl_lp_item = Database::get_course_table('lp_item');
  1099. if(!is_numeric($mastery_score) || $mastery_score < 0)
  1100. $mastery_score = 0;
  1101. if(!is_numeric($max_score) || $max_score < 0)
  1102. $max_score = 100;
  1103. if($mastery_score > $max_score)
  1104. $max_score = $mastery_score;
  1105. if(!is_numeric($prerequisite_id))
  1106. $prerequisite_id = 'NULL';
  1107. $sql_upd = "
  1108. UPDATE " . $tbl_lp_item . "
  1109. SET prerequisite = ".$prerequisite_id." WHERE id = ".$id;
  1110. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1111. if($prerequisite_id!='NULL' && $prerequisite_id!='')
  1112. {
  1113. $sql_upd = " UPDATE ".$tbl_lp_item." SET
  1114. mastery_score = " . $mastery_score .
  1115. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1116. " WHERE ref = '" . $prerequisite_id."'" ; //will this be enough to ensure unicity?
  1117. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1118. }
  1119. //TODO update the item object (can be ignored for now because refreshed)
  1120. return true;
  1121. }
  1122. /**
  1123. * Escapes a string with the available database escape function
  1124. * @param string String to escape
  1125. * @return string String escaped
  1126. */
  1127. function escape_string($string){
  1128. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1129. return Database::escape_string($string);
  1130. }
  1131. /**
  1132. * Static admin function exporting a learnpath into a zip file
  1133. * @param string Export type (scorm, zip, cd)
  1134. * @param string Course code
  1135. * @param integer Learnpath ID
  1136. * @param string Zip file name
  1137. * @return string Zip file path (or false on error)
  1138. */
  1139. function export_lp($type, $course, $id, $zipname)
  1140. {
  1141. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1142. //TODO
  1143. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1144. $url = '';
  1145. switch($type){
  1146. case 'scorm':
  1147. break;
  1148. case 'zip':
  1149. break;
  1150. case 'cdrom':
  1151. break;
  1152. }
  1153. return $url;
  1154. }
  1155. /**
  1156. * Gets all the chapters belonging to the same parent as the item/chapter given
  1157. * Can also be called as abstract method
  1158. * @param integer Item ID
  1159. * @return array A list of all the "brother items" (or an empty array on failure)
  1160. */
  1161. function get_brother_chapters($id){
  1162. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1163. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1164. $lp_item = Database::get_course_table('lp_item');
  1165. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1166. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1167. if(Database::num_rows($res_parent)>0){
  1168. $row_parent = Database::fetch_array($res_parent);
  1169. $parent = $row_parent['parent_item_id'];
  1170. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1171. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1172. $list = array();
  1173. while ($row_bro = Database::fetch_array($res_bros)){
  1174. $list[] = $row_bro;
  1175. }
  1176. return $list;
  1177. }
  1178. return array();
  1179. }
  1180. /**
  1181. * Gets all the items belonging to the same parent as the item given
  1182. * Can also be called as abstract method
  1183. * @param integer Item ID
  1184. * @return array A list of all the "brother items" (or an empty array on failure)
  1185. */
  1186. function get_brother_items($id){
  1187. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1188. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1189. $lp_item = Database::get_course_table('lp_item');
  1190. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1191. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1192. if(Database::num_rows($res_parent)>0){
  1193. $row_parent = Database::fetch_array($res_parent);
  1194. $parent = $row_parent['parent_item_id'];
  1195. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1196. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1197. $list = array();
  1198. while ($row_bro = Database::fetch_array($res_bros)){
  1199. $list[] = $row_bro;
  1200. }
  1201. return $list;
  1202. }
  1203. return array();
  1204. }
  1205. /**
  1206. * Get the specific prefix index terms of this learning path
  1207. * @return array Array of terms
  1208. */
  1209. function get_common_index_terms_by_prefix($prefix)
  1210. {
  1211. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  1212. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1213. $prefix_terms = array();
  1214. foreach($terms as $term)
  1215. {
  1216. $prefix_terms[] = $term['value'];
  1217. }
  1218. return $prefix_terms;
  1219. }
  1220. /**
  1221. * Gets the number of items currently completed
  1222. * @return integer The number of items currently completed
  1223. */
  1224. function get_complete_items_count()
  1225. {
  1226. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1227. $i = 0;
  1228. foreach($this->items as $id => $dummy){
  1229. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1230. //Trying failed and browsed considered "progressed" as well
  1231. if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))&&$this->items[$id]->get_type()!='dokeos_chapter'&&$this->items[$id]->get_type()!='dir'){
  1232. $i++;
  1233. }
  1234. }
  1235. return $i;
  1236. }
  1237. /**
  1238. * Gets the current item ID
  1239. * @return integer The current learnpath item id
  1240. */
  1241. function get_current_item_id()
  1242. {
  1243. $current = 0;
  1244. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1245. if(!empty($this->current))
  1246. {
  1247. $current = $this->current;
  1248. }
  1249. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1250. return $current;
  1251. }
  1252. /** Force to get the first learnpath item id
  1253. * @return integer The current learnpath item id
  1254. */
  1255. function get_first_item_id()
  1256. {
  1257. $current = 0;
  1258. if (is_array($this->ordered_items)) {
  1259. $current = $this->ordered_items[0];
  1260. }
  1261. return $current;
  1262. }
  1263. /**
  1264. * Gets the total number of items available for viewing in this SCORM
  1265. * @return integer The total number of items
  1266. */
  1267. function get_total_items_count()
  1268. {
  1269. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1270. return count($this->items);
  1271. }
  1272. /**
  1273. * Gets the total number of items available for viewing in this SCORM but without chapters
  1274. * @return integer The total no-chapters number of items
  1275. */
  1276. function get_total_items_count_without_chapters()
  1277. {
  1278. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1279. $total=0;
  1280. foreach($this->items as $temp=>$temp2){
  1281. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1282. }
  1283. return $total;
  1284. }
  1285. /**
  1286. * Gets the first element URL.
  1287. * @return string URL to load into the viewer
  1288. */
  1289. function first()
  1290. {
  1291. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1292. //test if the last_item_seen exists and is not a dir
  1293. if ( count($this->ordered_items) == 0 ) {
  1294. $this->index = 0;
  1295. }
  1296. if(!empty($this->last_item_seen)
  1297. && !empty($this->items[$this->last_item_seen])
  1298. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1299. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1300. && $this->items[$this->last_item_seen]->is_done() != true
  1301. ){
  1302. 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);}
  1303. $index = -1;
  1304. foreach($this->ordered_items as $myindex => $item_id){
  1305. if($item_id == $this->last_item_seen){
  1306. $index = $myindex;
  1307. break;
  1308. }
  1309. }
  1310. if($index==-1){
  1311. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1312. 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);}
  1313. return false;
  1314. }else{
  1315. $this->last = $this->last_item_seen;
  1316. $this->current = $this->last_item_seen;
  1317. $this->index = $index;
  1318. }
  1319. }else{
  1320. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1321. $index = 0;
  1322. //loop through all ordered items and stop at the first item that is
  1323. //not a directory *and* that has not been completed yet
  1324. while (!empty($this->ordered_items[$index])
  1325. AND
  1326. is_a($this->items[$this->ordered_items[$index]],'learnpathItem')
  1327. AND
  1328. (
  1329. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1330. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1331. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1332. )
  1333. AND $index < $this->max_ordered_items)
  1334. {
  1335. $index ++;
  1336. }
  1337. $this->last = $this->current;
  1338. //current is
  1339. $this->current = $this->ordered_items[$index];
  1340. $this->index = $index;
  1341. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1342. }
  1343. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1344. }
  1345. /**
  1346. * Gets the information about an item in a format usable as JavaScript to update
  1347. * the JS API by just printing this content into the <head> section of the message frame
  1348. * @param integer Item ID
  1349. * @return string
  1350. */
  1351. function get_js_info($item_id=''){
  1352. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1353. $info = '';
  1354. $item_id = $this->escape_string($item_id);
  1355. if(!empty($item_id) && is_object($this->items[$item_id])){
  1356. //if item is defined, return values from DB
  1357. $oItem = $this->items[$item_id];
  1358. $info .= '<script language="javascript">';
  1359. $info .= "top.set_score(".$oItem->get_score().");\n";
  1360. $info .= "top.set_max(".$oItem->get_max().");\n";
  1361. $info .= "top.set_min(".$oItem->get_min().");\n";
  1362. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1363. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1364. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1365. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1366. $info .= "top.set_flag_synchronized();";
  1367. $info .= '</script>';
  1368. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1369. return $info;
  1370. }else{
  1371. //if item_id is empty, just update to default SCORM data
  1372. $info .= '<script language="javascript">';
  1373. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1374. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1375. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1376. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1377. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1378. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1379. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1380. $info .= "top.set_flag_synchronized();";
  1381. $info .= '</script>';
  1382. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1383. return $info;
  1384. }
  1385. }
  1386. /**
  1387. * Gets the js library from the database
  1388. * @return string The name of the javascript library to be used
  1389. */
  1390. function get_js_lib(){
  1391. $lib = '';
  1392. if(!empty($this->js_lib)){
  1393. $lib = $this->js_lib;
  1394. }
  1395. return $lib;
  1396. }
  1397. /**
  1398. * Gets the learnpath database ID
  1399. * @return integer Learnpath ID in the lp table
  1400. */
  1401. function get_id()
  1402. {
  1403. //if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1404. if(!empty($this->lp_id))
  1405. {
  1406. return $this->lp_id;
  1407. }else{
  1408. return 0;
  1409. }
  1410. }
  1411. /**
  1412. * Gets the last element URL.
  1413. * @return string URL to load into the viewer
  1414. */
  1415. function get_last()
  1416. {
  1417. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1418. $this->index = count($this->ordered_items)-1;
  1419. return $this->ordered_items[$this->index];
  1420. }
  1421. /**
  1422. * Gets the navigation bar for the learnpath display screen
  1423. * @return string The HTML string to use as a navigation bar
  1424. */
  1425. function get_navigation_bar()
  1426. {
  1427. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1428. //TODO find a good value for the following variables
  1429. $file = '';
  1430. $openDir = '';
  1431. $edoceo = '';
  1432. $time = 0;
  1433. $navbar = '';
  1434. $RequestUri = '';
  1435. $mycurrentitemid = $this->get_current_item_id();
  1436. if($this->mode == 'fullscreen')
  1437. {
  1438. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1439. ' <tr> '."\n" .
  1440. ' <td>'."\n" .
  1441. ' <div class="buttons">'."\n" .
  1442. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('Reporting').'"></a>'."\n" .
  1443. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>'."\n" .
  1444. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>'."\n" .
  1445. //' <a href="lp_controller.php?action=mode&mode=embedded" target="_top" title="embedded mode"><img border="0" src="../img/view_choose.gif" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1446. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1447. ' </div>'."\n" .
  1448. ' </td>'."\n" .
  1449. ' </tr>'."\n" .
  1450. '</table>'."\n" ;
  1451. }else{
  1452. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1453. ' <tr> '."\n" .
  1454. ' <td>'."\n" .
  1455. ' <div class="buttons">'."\n" .
  1456. ' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'.get_lang('Reporting').'"></a>'."\n" .
  1457. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'.get_lang('ScormPrevious').'"></a>'."\n" .
  1458. ' <a href="" onclick="dokeos_xajax_handler.switch_item('.$mycurrentitemid.',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'.get_lang('ScormNext').'"></a>'."\n" .
  1459. // ' <a href="lp_controller.php?action=mode&mode=fullscreen" target="_top" title="fullscreen"><img border="0" src="../img/view_fullscreen.gif" width="18" height="18" title="'.get_lang('ScormFullScreen').'"></a>'."\n" .
  1460. ' </div>'."\n" .
  1461. ' </td>'."\n" .
  1462. ' </tr>'."\n" .
  1463. '</table>'."\n" ;
  1464. }
  1465. return $navbar;
  1466. }
  1467. /**
  1468. * Gets the next resource in queue (url).
  1469. * @return string URL to load into the viewer
  1470. */
  1471. function get_next_index()
  1472. {
  1473. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1474. //TODO
  1475. $index = $this->index;
  1476. $index ++;
  1477. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type,0);}
  1478. while(!empty($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') AND $index < $this->max_ordered_items)
  1479. {
  1480. $index ++;
  1481. if($index == $this->max_ordered_items)
  1482. {
  1483. return $this->index;
  1484. }
  1485. }
  1486. if(empty($this->ordered_items[$index])){
  1487. return $this->index;
  1488. }
  1489. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1490. return $index;
  1491. }
  1492. /**
  1493. * Gets item_id for the next element
  1494. * @return integer Next item (DB) ID
  1495. */
  1496. function get_next_item_id()
  1497. {
  1498. if($this->debug>0){error_log('New LP - In learnpath::get_next_item_id()',0);}
  1499. $new_index = $this->get_next_index();
  1500. if(!empty($new_index))
  1501. {
  1502. if(isset($this->ordered_items[$new_index]))
  1503. {
  1504. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index],0);}
  1505. return $this->ordered_items[$new_index];
  1506. }
  1507. }
  1508. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
  1509. return 0;
  1510. }
  1511. /**
  1512. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1513. *
  1514. * Generally, the package provided is in the form of a zip file, so the function
  1515. * has been written to test a zip file. If not a zip, the function will return the
  1516. * default return value: ''
  1517. * @param string the path to the file
  1518. * @param string the original name of the file
  1519. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1520. */
  1521. function get_package_type($file_path,$file_name){
  1522. //get name of the zip file without the extension
  1523. $file_info = pathinfo($file_name);
  1524. $filename = $file_info['basename'];//name including extension
  1525. $extension = $file_info['extension'];//extension only
  1526. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1527. {
  1528. return 'oogie';
  1529. }
  1530. if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
  1531. {
  1532. return 'woogie';
  1533. }
  1534. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1535. $zipFile = new pclZip($file_path);
  1536. // Check the zip content (real size and file extension)
  1537. $zipContentArray = $zipFile->listContent();
  1538. $package_type='';
  1539. $at_root = false;
  1540. $manifest = '';
  1541. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1542. if (is_array($zipContentArray) && count($zipContentArray)>0) {
  1543. foreach($zipContentArray as $thisContent)
  1544. {
  1545. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1546. {
  1547. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1548. }
  1549. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1550. {
  1551. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1552. $package_type = 'scorm';
  1553. break;//exit the foreach loop
  1554. }
  1555. elseif(preg_match('/aicc\//i',$thisContent['filename'])!=false)
  1556. {//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1557. $package_type='aicc';
  1558. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1559. }
  1560. else
  1561. {
  1562. $package_type = '';
  1563. }
  1564. }
  1565. }
  1566. return $package_type;
  1567. }
  1568. /**
  1569. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1570. * @return string URL to load into the viewer
  1571. */
  1572. function get_previous_index()
  1573. {
  1574. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1575. $index = $this->index;
  1576. if(isset($this->ordered_items[$index-1])){
  1577. $index --;
  1578. while(isset($this->ordered_items[$index]) AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'))
  1579. {
  1580. $index --;
  1581. if($index < 0){
  1582. return $this->index;
  1583. }
  1584. }
  1585. }else{
  1586. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1587. //no previous item
  1588. }
  1589. return $index;
  1590. }
  1591. /**
  1592. * Gets item_id for the next element
  1593. * @return integer Previous item (DB) ID
  1594. */
  1595. function get_previous_item_id()
  1596. {
  1597. if($this->debug>0){error_log('New LP - In learnpath::get_previous_item_id()',0);}
  1598. $new_index = $this->get_previous_index();
  1599. return $this->ordered_items[$new_index];
  1600. }
  1601. /**
  1602. * Gets the progress value from the progress_db attribute
  1603. * @return integer Current progress value
  1604. */
  1605. function get_progress()
  1606. {
  1607. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1608. if(!empty($this->progress_db))
  1609. {
  1610. return $this->progress_db;
  1611. }
  1612. return 0;
  1613. }
  1614. /**
  1615. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1616. * @param integer Learnpath ID
  1617. * @param integer User ID
  1618. * @param string Mode of display ('%','abs' or 'both')
  1619. * @param string Course database name (optional, defaults to '')
  1620. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1621. * @return integer Current progress value as found in the database
  1622. */
  1623. function get_db_progress($lp_id,$user_id,$mode='%', $course_db='', $sincere=false)
  1624. {
  1625. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1626. $table = Database::get_course_table('lp_view', $course_db);
  1627. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1628. $res = api_sql_query($sql,__FILE__,__LINE__);
  1629. $view_id = 0;
  1630. if(Database::num_rows($res)>0)
  1631. {
  1632. $row = Database::fetch_array($res);
  1633. $progress = $row['progress'];
  1634. $view_id = $row['id'];
  1635. }
  1636. else
  1637. {
  1638. if($sincere)
  1639. {
  1640. return null;
  1641. }
  1642. }
  1643. if(empty($progress))
  1644. {
  1645. $progress = '0';
  1646. }
  1647. if($mode == '%')
  1648. {
  1649. return $progress.'%';
  1650. }
  1651. else
  1652. {
  1653. //get the number of items completed and the number of items total
  1654. $tbl = Database::get_course_table('lp_item', $course_db);
  1655. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1656. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1657. $res = api_sql_query($sql, __FILE__, __LINE__);
  1658. $row = Database::fetch_array($res);
  1659. $total = $row[0];
  1660. $tbl_item_view = Database::get_course_table('lp_item_view', $course_db);
  1661. $tbl_item = Database::get_course_table('lp_item', $course_db);
  1662. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1663. //trying as also counting browsed and failed items
  1664. $sql = "SELECT count(distinct(lp_item_id))
  1665. FROM $tbl_item_view as item_view
  1666. INNER JOIN $tbl_item as item
  1667. ON item.id = item_view.lp_item_id
  1668. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1669. WHERE lp_view_id = ".$view_id."
  1670. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1671. $res = api_sql_query($sql, __FILE__, __LINE__);
  1672. $row = Database::fetch_array($res);
  1673. $completed = $row[0];
  1674. if($mode == 'abs')
  1675. {
  1676. return $completed.'/'.$total;
  1677. }
  1678. elseif($mode == 'both')
  1679. {
  1680. if($progress<($completed/($total?$total:1)))
  1681. {
  1682. $progress = number_format(($completed/($total?$total:1))*100,0);
  1683. }
  1684. return $progress.'% ('.$completed.'/'.$total.')';
  1685. }
  1686. }
  1687. return $progress;
  1688. }
  1689. function get_mediaplayer()
  1690. {
  1691. global $_course;
  1692. // Database table definition
  1693. $tbl_lp_item = Database::get_course_table('lp_item');
  1694. // getting all the information about the item
  1695. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = '" . $_SESSION['oLP']->current."'";
  1696. $result = api_sql_query($sql, __FILE__, __LINE__);
  1697. $row= mysql_fetch_assoc($result);
  1698. $output='';
  1699. if (!empty($row['audio']))
  1700. {
  1701. // the mp3 player
  1702. $output = '<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
  1703. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1704. $output .= '<script type="text/javascript">
  1705. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1706. s1.addParam("allowscriptaccess","always");
  1707. s1.addParam("flashvars","file='.api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  1708. s1.write("container");
  1709. </script>';
  1710. }
  1711. return $output;
  1712. }
  1713. /**
  1714. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1715. * completed so far.
  1716. * @param string Mode in which we want the values
  1717. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1718. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1719. * @param boolean true if it comes from a Diplay LP view
  1720. * @return string HTML string containing the progress bar
  1721. */
  1722. function get_progress_bar($mode='',$percentage=-1,$text_add='',$from_lp=false)
  1723. {
  1724. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1725. global $lp_theme_css;
  1726. // Setting up the CSS path of the current style if exists
  1727. if (!empty($lp_theme_css))
  1728. {
  1729. $css_path=api_get_path(WEB_CODE_PATH).'css/'.$lp_theme_css.'/images/';
  1730. }
  1731. else
  1732. {
  1733. $css_path='../img/';
  1734. }
  1735. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1736. if(isset($this) && is_object($this) && ($percentage=='-1' OR $text_add==''))
  1737. {
  1738. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1739. }
  1740. $text = $percentage.$text_add;
  1741. //Default progress bar config
  1742. // times that will be greater or shorter
  1743. $factor=1.2;
  1744. if ($from_lp)
  1745. $progress_height='26';
  1746. else
  1747. $progress_height='16';
  1748. $size = str_replace('%','',$percentage);
  1749. $output = ''
  1750. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1751. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1752. .'<img id="progress_img_limit_left" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'">'
  1753. .'<img id="progress_img_full" src="'.$css_path.'bar_1u.gif" width="'.$size*$factor.'px" height="'.$progress_height.'" id="full_portion">'
  1754. .'<img id="progress_img_limit_middle" src="'.$css_path.'bar_1m.gif" width="1" height="'.$progress_height.'">';
  1755. if($percentage <= 98)
  1756. {
  1757. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="'.(100-$size)*$factor.'px" height="'.$progress_height.'" id="empty_portion">';
  1758. }
  1759. else
  1760. {
  1761. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="0" height="'.$progress_height.'" id="empty_portion">';
  1762. }
  1763. $output .= '<img id="progress_bar_img_limit_right" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'"></td></tr></table>'
  1764. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1765. return $output;
  1766. }
  1767. /**
  1768. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1769. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1770. * //@param integer Additional steps to fake as completed
  1771. * @return list Percentage or number and symbol (% or /xx)
  1772. */
  1773. function get_progress_bar_text($mode='',$add=0)
  1774. {
  1775. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1776. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1777. $total_items = $this->get_total_items_count_without_chapters();
  1778. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1779. $i = $this->get_complete_items_count();
  1780. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1781. if($add != 0){
  1782. $i += $add;
  1783. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1784. }
  1785. $text = '';
  1786. if($i>$total_items){
  1787. $i = $total_items;
  1788. }
  1789. if($mode == '%'){
  1790. if($total_items>0){
  1791. $percentage = ((float)$i/(float)$total_items)*100;
  1792. }
  1793. else
  1794. {
  1795. $percentage = 0;
  1796. }
  1797. $percentage = number_format($percentage,0);
  1798. $text = '%';
  1799. }elseif($mode == 'abs'){
  1800. $percentage = $i;
  1801. $text = '/'.$total_items;
  1802. }
  1803. return array($percentage,$text);
  1804. }
  1805. /**
  1806. * Gets the progress bar mode
  1807. * @return string The progress bar mode attribute
  1808. */
  1809. function get_progress_bar_mode()
  1810. {
  1811. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1812. if(!empty($this->progress_bar_mode))
  1813. {
  1814. return $this->progress_bar_mode;
  1815. }else{
  1816. return '%';
  1817. }
  1818. }
  1819. /**
  1820. * Gets the learnpath proximity (remote or local)
  1821. * @return string Learnpath proximity
  1822. */
  1823. function get_proximity()
  1824. {
  1825. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1826. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1827. }
  1828. /**
  1829. * Gets the learnpath theme (remote or local)
  1830. * @return string Learnpath theme
  1831. */
  1832. function get_theme()
  1833. {
  1834. if($this->debug>0){error_log('New LP - In learnpath::get_theme()',0);}
  1835. if(!empty($this->theme)){return $this->theme;}else{return '';}
  1836. }
  1837. /**
  1838. * Gets the learnpath image
  1839. * @return string Web URL of the LP image
  1840. */
  1841. function get_preview_image()
  1842. {
  1843. if($this->debug>0){error_log('New LP - In learnpath::get_preview_image()',0);}
  1844. if(!empty($this->preview_image)){return $this->preview_image;}else{return '';}
  1845. }
  1846. /**
  1847. * Gets the learnpath author
  1848. * @return string LP's author
  1849. */
  1850. function get_author()
  1851. {
  1852. if($this->debug>0){error_log('New LP - In learnpath::get_author()',0);}
  1853. if(!empty($this->author)){return $this->author;}else{return '';}
  1854. }
  1855. /**
  1856. * Generate a new prerequisites string for a given item. If this item was a sco and
  1857. * its prerequisites were strings (instead of IDs), then transform those strings into
  1858. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1859. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1860. * same rule as the scorm_export() method
  1861. * @param integer Item ID
  1862. * @return string Prerequisites string ready for the export as SCORM
  1863. */
  1864. function get_scorm_prereq_string($item_id)
  1865. {
  1866. if($this->debug>0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
  1867. if(!is_object($this->items[$item_id])){return false;}
  1868. $oItem = $this->items[$item_id];
  1869. $prereq = $oItem->get_prereq_string();
  1870. if(empty($prereq))
  1871. {
  1872. return '';
  1873. }
  1874. if(preg_match('/^\d+$/',$prereq) && is_object($this->items[$prereq]))
  1875. { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  1876. //then simply return it (with the ITEM_ prefix)
  1877. return 'ITEM_'.$prereq;
  1878. }
  1879. else
  1880. {
  1881. if(isset($this->refs_list[$prereq]))
  1882. {
  1883. //it's a simple string item from which the ID can be found in the refs list
  1884. //so we can transform it directly to an ID for export
  1885. return 'ITEM_'.$this->refs_list[$prereq];
  1886. }
  1887. else
  1888. {
  1889. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  1890. //and replace them, one by one, by the internal IDs (dokeos db)
  1891. //TODO modify the '*' replacement to replace the multiplier in front of it
  1892. //by a space as well
  1893. $find = array('&','|','~','=','<>','{','}','*','(',')');
  1894. $replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
  1895. $prereq_mod = str_replace($find,$replace,$prereq);
  1896. $ids = split(' ',$prereq_mod);
  1897. foreach($ids as $id)
  1898. {
  1899. $id = trim($id);
  1900. if(isset($this->refs_list[$id]))
  1901. {
  1902. $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/','ITEM_'.$this->refs_list[$id],$prereq);
  1903. }
  1904. }
  1905. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '.$prereq,0);
  1906. return $prereq;
  1907. }
  1908. }
  1909. }
  1910. /**
  1911. * Returns the XML DOM document's node
  1912. * @param resource Reference to a list of objects to search for the given ITEM_*
  1913. * @param string The identifier to look for
  1914. * @return mixed The reference to the element found with that identifier. False if not found
  1915. */
  1916. function get_scorm_xml_node(&$children,$id)
  1917. {
  1918. for($i=0;$i<$children->length;$i++){
  1919. $item_temp = $children->item($i);
  1920. if ($item_temp -> nodeName == 'item')
  1921. {
  1922. if($item_temp->getAttribute('identifier') == $id)
  1923. {
  1924. return $item_temp;
  1925. }
  1926. }
  1927. $subchildren = $item_temp->childNodes;
  1928. if($subchildren->length>0)
  1929. {
  1930. $val = $this->get_scorm_xml_node($subchildren,$id);
  1931. if(is_object($val))
  1932. {
  1933. return $val;
  1934. }
  1935. }
  1936. }
  1937. return false;
  1938. }
  1939. /**
  1940. * Returns a usable array of stats related to the current learnpath and user
  1941. * @return array Well-formatted array containing status for the current learnpath
  1942. */
  1943. function get_stats()
  1944. {
  1945. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1946. //TODO
  1947. }
  1948. /**
  1949. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1950. * the given course (for all learnpaths and all users)
  1951. * @param string Course code
  1952. * @return array Well-formatted array containing status for the course's learnpaths
  1953. */
  1954. function get_stats_course($course)
  1955. {
  1956. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1957. //TODO
  1958. }
  1959. /**
  1960. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1961. * the given course and learnpath (for all users)
  1962. * @param string Course code
  1963. * @param integer Learnpath ID
  1964. * @return array Well-formatted array containing status for the specified learnpath
  1965. */
  1966. function get_stats_lp($course,$lp)
  1967. {
  1968. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1969. //TODO
  1970. }
  1971. /**
  1972. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1973. * the given course, learnpath and user.
  1974. * @param string Course code
  1975. * @param integer Learnpath ID
  1976. * @param integer User ID
  1977. * @return array Well-formatted array containing status for the specified learnpath and user
  1978. */
  1979. function get_stats_lp_user($course,$lp,$user)
  1980. {
  1981. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1982. //TODO
  1983. }
  1984. /**
  1985. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1986. * the given course and learnpath (for all users)
  1987. * @param string Course code
  1988. * @param integer User ID
  1989. * @return array Well-formatted array containing status for the user's learnpaths
  1990. */
  1991. function get_stats_user($course,$user)
  1992. {
  1993. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1994. //TODO
  1995. }
  1996. /**
  1997. * Gets the status list for all LP's items
  1998. * @return array Array of [index] => [item ID => current status]
  1999. */
  2000. function get_items_status_list(){
  2001. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  2002. $list = array();
  2003. foreach($this->ordered_items as $item_id)
  2004. {
  2005. $list[]= array($item_id => $this->items[$item_id]->get_status());
  2006. }
  2007. return $list;
  2008. }
  2009. /**
  2010. * Return the number of interactions for the given learnpath Item View ID.
  2011. * This method can be used as static.
  2012. * @param integer Item View ID
  2013. * @return integer Number of interactions
  2014. */
  2015. function get_interactions_count_from_db($lp_iv_id=0){
  2016. if(empty($lp_iv_id)){return -1;}
  2017. $table = Database::get_course_table('lp_iv_interaction');
  2018. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2019. $res = api_sql_query($sql,__FILE__,__LINE__);
  2020. $row = Database::fetch_array($res);
  2021. $num = $row[0];
  2022. return $num;
  2023. }
  2024. /**
  2025. * Return the interactions as an array for the given lp_iv_id.
  2026. * This method can be used as static.
  2027. * @param integer Learnpath Item View ID
  2028. * @return array
  2029. * @todo Translate labels
  2030. */
  2031. function get_iv_interactions_array($lp_iv_id=0){
  2032. $list = array();
  2033. $table = Database::get_course_table('lp_iv_interaction');
  2034. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2035. $res = api_sql_query($sql,__FILE__,__LINE__);
  2036. $num = Database::num_rows($res);
  2037. if($num>0){
  2038. $list[] = array(
  2039. "order_id"=>htmlentities(get_lang('Order')),
  2040. "id"=>htmlentities(get_lang('InteractionID')),
  2041. "type"=>htmlentities(get_lang('Type')),
  2042. "time"=>htmlentities(get_lang('TimeFinished')),
  2043. "correct_responses"=>htmlentities(get_lang('CorrectAnswers')),
  2044. "student_response"=>htmlentities(get_lang('StudentResponse')),
  2045. "result"=>htmlentities(get_lang('Result')),
  2046. "latency"=>htmlentities(get_lang('LatencyTimeSpent')));
  2047. while ($row = Database::fetch_array($res)){
  2048. $list[] = array(
  2049. "order_id"=>($row['order_id']+1),
  2050. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  2051. "type"=>$row['interaction_type'],
  2052. "time"=>$row['completion_time'],
  2053. //"correct_responses"=>$row['correct_responses'],
  2054. //hide correct responses from students
  2055. "correct_responses"=>'',
  2056. "student_response"=>$row['student_response'],
  2057. "result"=>$row['result'],
  2058. "latency"=>$row['latency']);
  2059. }
  2060. }
  2061. return $list;
  2062. }
  2063. /**
  2064. * Return the number of objectives for the given learnpath Item View ID.
  2065. * This method can be used as static.
  2066. * @param integer Item View ID
  2067. * @return integer Number of objectives
  2068. */
  2069. function get_objectives_count_from_db($lp_iv_id=0){
  2070. if(empty($lp_iv_id)){return -1;}
  2071. $table = Database::get_course_table('lp_iv_objective');
  2072. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2073. $res = api_sql_query($sql,__FILE__,__LINE__);
  2074. $row = Database::fetch_array($res);
  2075. $num = $row[0];
  2076. return $num;
  2077. }
  2078. /**
  2079. * Return the objectives as an array for the given lp_iv_id.
  2080. * This method can be used as static.
  2081. * @param integer Learnpath Item View ID
  2082. * @return array
  2083. * @todo Translate labels
  2084. */
  2085. function get_iv_objectives_array($lp_iv_id=0){
  2086. $list = array();
  2087. $table = Database::get_course_table('lp_iv_objective');
  2088. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2089. $res = api_sql_query($sql,__FILE__,__LINE__);
  2090. $num = Database::num_rows($res);
  2091. if($num>0){
  2092. $list[] = array(
  2093. "order_id"=>htmlentities(get_lang('Order')),
  2094. "objective_id"=>htmlentities(get_lang('ObjectiveID')),
  2095. "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')),
  2096. "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')),
  2097. "score_min"=>htmlentities(get_lang('ObjectiveMinScore')),
  2098. "status"=>htmlentities(get_lang('ObjectiveStatus')));
  2099. while ($row = Database::fetch_array($res)){
  2100. $list[] = array(
  2101. "order_id"=>($row['order_id']+1),
  2102. "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
  2103. "score_raw"=>$row['score_raw'],
  2104. "score_max"=>$row['score_max'],
  2105. "score_min"=>$row['score_min'],
  2106. "status"=>$row['status']);
  2107. }
  2108. }
  2109. return $list;
  2110. }
  2111. /**
  2112. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2113. * used by get_html_toc() to be ready to display
  2114. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2115. */
  2116. function get_toc()
  2117. {
  2118. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  2119. $toc = array();
  2120. //echo "<pre>".print_r($this->items,true)."</pre>";
  2121. foreach($this->ordered_items as $item_id)
  2122. {
  2123. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  2124. //TODO change this link generation and use new function instead
  2125. $toc[] = array(
  2126. 'id'=>$item_id,
  2127. 'title'=>$this->items[$item_id]->get_title(),
  2128. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2129. 'status'=>$this->items[$item_id]->get_status(),
  2130. 'level'=>$this->items[$item_id]->get_level(),
  2131. 'type' =>$this->items[$item_id]->get_type(),
  2132. 'description'=>$this->items[$item_id]->get_description(),
  2133. 'path'=>$this->items[$item_id]->get_path(),
  2134. );
  2135. }
  2136. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  2137. return $toc;
  2138. }
  2139. /**
  2140. * Gets the learning path type
  2141. * @param boolean Return the name? If false, return the ID. Default is false.
  2142. * @return mixed Type ID or name, depending on the parameter
  2143. */
  2144. function get_type($get_name = false)
  2145. {
  2146. $res = false;
  2147. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  2148. if(!empty($this->type))
  2149. {
  2150. if($get_name)
  2151. {
  2152. //get it from the lp_type table in main db
  2153. }else{
  2154. $res = $this->type;
  2155. }
  2156. }
  2157. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  2158. return $res;
  2159. }
  2160. /**
  2161. * Gets the learning path type as static method
  2162. * @param boolean Return the name? If false, return the ID. Default is false.
  2163. * @return mixed Type ID or name, depending on the parameter
  2164. */
  2165. function get_type_static($lp_id=0)
  2166. {
  2167. $tbl_lp = Database::get_course_table('lp');
  2168. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '".$lp_id."'";
  2169. $res = api_sql_query($sql, __FILE__, __LINE__);
  2170. if($res===false){ return null;}
  2171. if(Database::num_rows($res)<=0){return null;}
  2172. $row = Database::fetch_array($res);
  2173. return $row['lp_type'];
  2174. }
  2175. /**
  2176. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2177. * This method can be used as abstract and is recursive
  2178. * @param integer Learnpath ID
  2179. * @param integer Parent ID of the items to look for
  2180. * @return mixed Ordered list of item IDs or false on error
  2181. */
  2182. function get_flat_ordered_items_list($lp,$parent=0)
  2183. {
  2184. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2185. $list = array();
  2186. if(empty($lp)){return false;}
  2187. $tbl_lp_item = Database::get_course_table('lp_item');
  2188. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2189. $res = api_sql_query($sql,__FILE__,__LINE__);
  2190. while($row = Database::fetch_array($res)){
  2191. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  2192. $list[] = $row['id'];
  2193. foreach($sublist as $item){
  2194. $list[] = $item;
  2195. }
  2196. }
  2197. return $list;
  2198. }
  2199. /**
  2200. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2201. * @return string HTML TOC ready to display
  2202. */
  2203. /*function get_html_toc()
  2204. {
  2205. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2206. $list = $this->get_toc();
  2207. //echo $this->current;
  2208. //$parent = $this->items[$this->current]->get_parent();
  2209. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2210. $html = '<div class="inner_lp_toc">'."\n" ;
  2211. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2212. require_once('resourcelinker.inc.php');
  2213. //temp variables
  2214. $mycurrentitemid = $this->get_current_item_id();
  2215. foreach($list as $item)
  2216. {
  2217. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2218. //TODO complete this
  2219. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2220. 'incomplete' => '../img/incomplete.gif',
  2221. 'failed' => '../img/failed.gif',
  2222. 'completed' => '../img/completed.gif',
  2223. 'passed' => '../img/passed.gif',
  2224. 'succeeded' => '../img/succeeded.gif',
  2225. 'browsed' => '../img/completed.gif');
  2226. $style = 'scorm_item';
  2227. if($item['id'] == $this->current){
  2228. $style = 'scorm_item_highlight';
  2229. }
  2230. //the anchor will let us center the TOC on the currently viewed item &^D
  2231. $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'].'" >' .
  2232. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2233. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2234. $title = $item['title'];
  2235. if(empty($title)){
  2236. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2237. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2238. }
  2239. if(empty($title))$title = '-';
  2240. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2241. //$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>" ;
  2242. $url = $this->get_link('http',$item['id']);
  2243. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2244. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2245. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2246. $mycurrentitemid.',' .
  2247. $item['id'].');' .
  2248. 'return false;" >'.$title.'</a>' ;
  2249. }else{
  2250. $html .= $title;
  2251. }
  2252. $html .= "</div>\n";
  2253. }
  2254. $html .= "</div>\n";
  2255. return $html;
  2256. }*/
  2257. /**
  2258. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2259. * @return string HTML TOC ready to display
  2260. */
  2261. function get_html_toc()
  2262. {
  2263. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2264. $list = $this->get_toc();
  2265. $mych = api_get_setting('platform_charset');
  2266. //echo $this->current;
  2267. //$parent = $this->items[$this->current]->get_parent();
  2268. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2269. $html= '<div class="scorm_title"><div class="scorm_title_text">'.mb_convert_encoding($this->get_name(),$this->encoding,$mych).'</div></div>';
  2270. // build, display
  2271. if(api_is_allowed_to_edit())
  2272. {
  2273. $html .='<div class="actions_lp">';
  2274. //the icon it was removed in display (build)
  2275. //$html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;action=build&amp;lp_id=".$this->lp_id."' target='_parent'>".Display::return_icon('learnpath_build.gif', get_lang('Build')).' '.mb_convert_encoding(get_lang('Build'),$this->encoding,$mych)."</a>";
  2276. $html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;action=build&amp;lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang('Build'),$this->encoding,$mych)."</a>";
  2277. //the icon it was removed in display (organize)
  2278. //$html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;action=admin_view&amp;lp_id=".$this->lp_id."' target='_parent'>".Display::return_icon('learnpath_organize.gif', get_lang('BasicOverview')).' '.mb_convert_encoding(get_lang('BasicOverview'),$this->encoding,$mych)."</a>";
  2279. $html .= "<a href='lp_controller.php?".api_get_cidreq()."&amp;action=admin_view&amp;lp_id=".$this->lp_id."' target='_parent'>".mb_convert_encoding(get_lang('BasicOverview'),$this->encoding,$mych)."</a>";
  2280. //the icon it was removed in display (display)
  2281. //$html .= '<span>'.Display::return_icon('learnpath_view.gif', get_lang("Display")).' '.mb_convert_encoding(get_lang("Display"),$this->encoding,$mych).'</span>';
  2282. $html .= '<span>'.mb_convert_encoding(get_lang("Display"),$this->encoding,$mych).'</span>';
  2283. $html .= '</div>';
  2284. unset($mych);
  2285. }
  2286. $html.= '<div id="inner_lp_toc" class="inner_lp_toc">'."\n" ;
  2287. //$html.= '<div class="scorm_title"><div class="scorm_title_text">'.mb_convert_encoding($this->get_name(),$this->encoding,$mych).'</div></div>';
  2288. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2289. require_once('resourcelinker.inc.php');
  2290. //temp variables
  2291. $mycurrentitemid = $this->get_current_item_id();
  2292. $color_counter=0;
  2293. $i=0;
  2294. foreach($list as $item)
  2295. {
  2296. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2297. //TODO complete this
  2298. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2299. 'incomplete' => '../img/incomplete.gif',
  2300. 'failed' => '../img/failed.gif',
  2301. 'completed' => '../img/completed.gif',
  2302. 'passed' => '../img/passed.gif',
  2303. 'succeeded' => '../img/succeeded.gif',
  2304. 'browsed' => '../img/completed.gif');
  2305. $style = 'scorm_item';
  2306. $scorm_color_background='scorm_item';
  2307. $style_item ='scorm_item';
  2308. $current=false;
  2309. if($item['id'] == $this->current)
  2310. {
  2311. $style = 'scorm_item_highlight';
  2312. $scorm_color_background ='scorm_item_highlight';
  2313. }
  2314. else
  2315. if ($color_counter%2==0)
  2316. {
  2317. $scorm_color_background='scorm_item_1';
  2318. }
  2319. else
  2320. {
  2321. $scorm_color_background='scorm_item_2';
  2322. }
  2323. if ($scorm_color_background!='')
  2324. {
  2325. $html .= '<div id="toc_'.$item['id'].'" class="'.$scorm_color_background.'">';
  2326. }
  2327. //the anchor will let us center the TOC on the currently viewed item &^D
  2328. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter')
  2329. {
  2330. $html .= '<a name="atoc_'.$item['id'].'" />';
  2331. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" title="'.$item['description'].'" >';
  2332. }
  2333. else
  2334. {
  2335. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" title="'.$item['description'].'" >';
  2336. }
  2337. $title=$item['title'];
  2338. if(empty($title))
  2339. {
  2340. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2341. }
  2342. $title = utf8_decode(html_entity_decode($title,ENT_QUOTES,$this->encoding));
  2343. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module')
  2344. {
  2345. //$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>" ;
  2346. $url = $this->get_link('http',$item['id']);
  2347. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2348. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2349. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2350. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2351. $mycurrentitemid.',' .
  2352. $item['id'].');' .
  2353. 'return false;" >'.stripslashes($title).'</a>' ;
  2354. }
  2355. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter')
  2356. {
  2357. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  2358. }
  2359. elseif($item['type']=='dir')
  2360. {
  2361. $html .= stripslashes($title);
  2362. }
  2363. $tbl_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2364. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  2365. $user_id = api_get_user_id();
  2366. $course_id = api_get_course_id();
  2367. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2368. WHERE path = '".$item['path']."' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2369. $result = api_sql_query($sql,__FILE__,__LINE__);
  2370. $count = Database::num_rows($result);
  2371. if ($item['type']=='quiz') {
  2372. if ($item['status']=='completed') {
  2373. $html .= "&nbsp;<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' width='12' height='12' />";
  2374. }
  2375. } else {
  2376. if ($item['type']!='dokeos_chapter' && $item['type']!='dokeos_module' && $item['type']!='dir') {
  2377. $html .= "&nbsp;<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' width='12' height='12' />";
  2378. }
  2379. }
  2380. $html .= "</div>";
  2381. if ($scorm_color_background!='')
  2382. {
  2383. $html .= '</div>';
  2384. }
  2385. $color_counter++;
  2386. }
  2387. $html .= "</div>\n";
  2388. return $html;
  2389. }
  2390. /**
  2391. * Gets the learnpath maker name - generally the editor's name
  2392. * @return string Learnpath maker name
  2393. */
  2394. function get_maker()
  2395. {
  2396. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  2397. if(!empty($this->maker)){return $this->maker;}else{return '';}
  2398. }
  2399. /**
  2400. * Gets the user-friendly message stored in $this->message
  2401. * @return string Message
  2402. */
  2403. function get_message(){
  2404. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  2405. return $this->message;
  2406. }
  2407. /**
  2408. * Gets the learnpath name/title
  2409. * @return string Learnpath name/title
  2410. */
  2411. function get_name()
  2412. {
  2413. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2414. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2415. }
  2416. /**
  2417. * Gets a link to the resource from the present location, depending on item ID.
  2418. * @param string Type of link expected
  2419. * @param integer Learnpath item ID
  2420. * @return string Link to the lp_item resource
  2421. */
  2422. function get_link($type='http',$item_id=null)
  2423. {
  2424. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2425. if(empty($item_id))
  2426. {
  2427. 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);}
  2428. $item_id = $this->get_current_item_id();
  2429. }
  2430. if(empty($item_id)){
  2431. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2432. //still empty, this means there was no item_id given and we are not in an object context or
  2433. //the object property is empty, return empty link
  2434. $item_id = $this->first();
  2435. return '';
  2436. }
  2437. $file = '';
  2438. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2439. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2440. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  2441. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2442. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2443. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2444. $res = api_sql_query($sel, __FILE__, __LINE__);
  2445. if(Database::num_rows($res)>0)
  2446. {
  2447. $row = Database::fetch_array($res);
  2448. //var_dump($row);
  2449. $lp_type = $row['ltype'];
  2450. $lp_path = $row['lpath'];
  2451. $lp_item_type = $row['litype'];
  2452. $lp_item_path = $row['lipath'];
  2453. $lp_item_params = $row['liparams'];
  2454. if(empty($lp_item_params) && strpos($lp_item_path,'?')!==false)
  2455. {
  2456. list($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
  2457. }
  2458. //$lp_item_params = '?'.$lp_item_params;
  2459. //add ? if none - left commented to give freedom to scorm implementation
  2460. //if(substr($lp_item_params,0,1)!='?'){
  2461. // $lp_item_params = '?'.$lp_item_params;
  2462. //}
  2463. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2464. if($type == 'http'){
  2465. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2466. }else{
  2467. $course_path = $sys_course_path; //system path
  2468. }
  2469. //now go through the specific cases to get the end of the path
  2470. switch($lp_type){
  2471. case 1:
  2472. if($lp_item_type == 'dokeos_chapter'){
  2473. $file = 'lp_content.php?type=dir';
  2474. }else{
  2475. require_once('resourcelinker.inc.php');
  2476. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2477. // check how much attempts of a exercise exits in lp
  2478. $lp_item_id = $this->get_current_item_id();
  2479. $lp_view_id = $this->get_view_id();
  2480. $prevent_reinit = $this->items[$this->current]->prevent_reinit;
  2481. $list = $this->get_toc();
  2482. $type_quiz = false;
  2483. foreach($list as $toc) {
  2484. if ($toc['id'] == $lp_item_id && ($toc['type']=='quiz') ) {
  2485. $type_quiz = true;
  2486. }
  2487. }
  2488. if ($type_quiz) {
  2489. $lp_item_id = Database::escape_string($lp_item_id);
  2490. $lp_view_id = Database::escape_string($lp_view_id);
  2491. $sql = "SELECT count(*) FROM $lp_item_view_table WHERE lp_item_id='".(int)$lp_item_id."' AND lp_view_id ='".(int)$lp_view_id."' AND status='completed'";
  2492. $result = api_sql_query($sql,__FILE__,__LINE__);
  2493. $row_count = Database::fetch_row($result);
  2494. $count_item_view = (int)$row_count[0];
  2495. $not_multiple_attempt = 0;
  2496. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2497. $not_multiple_attempt = 1;
  2498. }
  2499. $file .= '&not_multiple_attempt='.$not_multiple_attempt;
  2500. }
  2501. $tmp_array=explode("/",$file);
  2502. $document_name=$tmp_array[count($tmp_array)-1];
  2503. if(strpos($document_name,'_DELETED_')){
  2504. $file = 'blank.php?error=document_deleted';
  2505. }
  2506. }
  2507. break;
  2508. case 2:
  2509. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2510. if($lp_item_type!='dir'){
  2511. //Quite complex here:
  2512. //we want to make sure 'http://' (and similar) links can
  2513. //be loaded as is (withouth the Dokeos path in front) but
  2514. //some contents use this form: resource.htm?resource=http://blablabla
  2515. //which means we have to find a protocol at the path's start, otherwise
  2516. //it should not be considered as an external URL
  2517. //if($this->prerequisites_match($item_id)){
  2518. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2519. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2520. //distant url, return as is
  2521. $file = $lp_item_path;
  2522. }else{
  2523. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2524. //prevent getting untranslatable urls
  2525. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2526. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2527. //prepare the path
  2528. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2529. //TODO fix this for urls with protocol header
  2530. $file = str_replace('//','/',$file);
  2531. $file = str_replace(':/','://',$file);
  2532. if(substr($lp_path,-1)=='/')
  2533. {
  2534. $lp_path = substr($lp_path,0,-1);
  2535. }
  2536. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path)))
  2537. {//if file not found
  2538. $decoded = html_entity_decode($lp_item_path);
  2539. list($decoded) = explode('?',$decoded);
  2540. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded)))
  2541. {
  2542. require_once('resourcelinker.inc.php');
  2543. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2544. $tmp_array=explode("/",$file);
  2545. $document_name=$tmp_array[count($tmp_array)-1];
  2546. if(strpos($document_name,'_DELETED_')){
  2547. $file = 'blank.php?error=document_deleted';
  2548. }
  2549. }
  2550. else
  2551. {
  2552. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2553. }
  2554. }
  2555. }
  2556. //}else{
  2557. //prerequisites did not match
  2558. //$file = 'blank.php';
  2559. //}
  2560. //We want to use parameters if they were defined in the imsmanifest
  2561. if($file!='blank.php')
  2562. {
  2563. $file.= (strstr($file,'?')===false?'?':'').$lp_item_params;
  2564. }
  2565. }else{
  2566. $file = 'lp_content.php?type=dir';
  2567. }
  2568. break;
  2569. case 3:
  2570. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2571. //formatting AICC HACP append URL
  2572. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2573. if($lp_item_type!='dir'){
  2574. //Quite complex here:
  2575. //we want to make sure 'http://' (and similar) links can
  2576. //be loaded as is (withouth the Dokeos path in front) but
  2577. //some contents use this form: resource.htm?resource=http://blablabla
  2578. //which means we have to find a protocol at the path's start, otherwise
  2579. //it should not be considered as an external URL
  2580. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2581. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2582. //distant url, return as is
  2583. $file = $lp_item_path;
  2584. /*
  2585. if(stristr($file,'<servername>')!==false){
  2586. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2587. }
  2588. */
  2589. $file .= $aicc_append;
  2590. }else{
  2591. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2592. //prevent getting untranslatable urls
  2593. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2594. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2595. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2596. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2597. //TODO fix this for urls with protocol header
  2598. $file = str_replace('//','/',$file);
  2599. $file = str_replace(':/','://',$file);
  2600. $file .= $aicc_append;
  2601. }
  2602. }else{
  2603. $file = 'lp_content.php?type=dir';
  2604. }
  2605. break;
  2606. case 4:
  2607. break;
  2608. default:
  2609. break;
  2610. }
  2611. }
  2612. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2613. return $file;
  2614. }
  2615. /**
  2616. * Gets the latest usable view or generate a new one
  2617. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2618. * @return integer DB lp_view id
  2619. */
  2620. function get_view($attempt_num=0)
  2621. {
  2622. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2623. $search = '';
  2624. //use $attempt_num to enable multi-views management (disabled so far)
  2625. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2626. {
  2627. $search = 'AND view_count = '.$attempt_num;
  2628. }
  2629. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2630. $lp_view_table = Database::get_course_table('lp_view');
  2631. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2632. "WHERE lp_id = ".$this->get_id()." " .
  2633. "AND user_id = ".$this->get_user_id()." " .
  2634. $search .
  2635. " ORDER BY view_count DESC";
  2636. $res = api_sql_query($sql, __FILE__, __LINE__);
  2637. if(Database::num_rows($res)>0)
  2638. {
  2639. $row = Database::fetch_array($res);
  2640. $this->lp_view_id = $row['id'];
  2641. }else{
  2642. //no database record, create one
  2643. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2644. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2645. $res = api_sql_query($sql, __FILE__, __LINE__);
  2646. $id = Database::get_last_insert_id();
  2647. $this->lp_view_id = $id;
  2648. }
  2649. return $this->lp_view_id;
  2650. }
  2651. /**
  2652. * Gets the current view id
  2653. * @return integer View ID (from lp_view)
  2654. */
  2655. function get_view_id()
  2656. {
  2657. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2658. if(!empty($this->lp_view_id))
  2659. {
  2660. return $this->lp_view_id;
  2661. }else{
  2662. return 0;
  2663. }
  2664. }
  2665. /**
  2666. * Gets the update queue
  2667. * @return array Array containing IDs of items to be updated by JavaScript
  2668. */
  2669. function get_update_queue()
  2670. {
  2671. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2672. return $this->update_queue;
  2673. }
  2674. /**
  2675. * Gets the user ID
  2676. * @return integer User ID
  2677. */
  2678. function get_user_id()
  2679. {
  2680. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2681. if(!empty($this->user_id))
  2682. {
  2683. return $this->user_id;
  2684. }else{
  2685. return false;
  2686. }
  2687. }
  2688. /**
  2689. * Checks if any of the items has an audio element attached
  2690. * @return bool True or false
  2691. */
  2692. function has_audio() {
  2693. if($this->debug>1){error_log('New LP - In learnpath::has_audio()',0);}
  2694. $has = false;
  2695. foreach ($this->items as $i=>$item) {
  2696. if (!empty($this->items[$i]->audio)) {
  2697. $has = true;
  2698. break;
  2699. }
  2700. }
  2701. return $has;
  2702. }
  2703. /**
  2704. * Logs a message into a file
  2705. * @param string Message to log
  2706. * @return boolean True on success, false on error or if msg empty
  2707. */
  2708. function log($msg)
  2709. {
  2710. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2711. //TODO
  2712. $this->error .= $msg."\n";
  2713. return true;
  2714. }
  2715. /**
  2716. * Moves an item up and down at its level
  2717. * @param integer Item to move up and down
  2718. * @param string Direction 'up' or 'down'
  2719. * @return integer New display order, or false on error
  2720. */
  2721. function move_item($id, $direction){
  2722. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2723. if(empty($id) or empty($direction)){return false;}
  2724. $tbl_lp_item = Database::get_course_table('lp_item');
  2725. $sql_sel = "
  2726. SELECT *
  2727. FROM " . $tbl_lp_item . "
  2728. WHERE id = " . $id;
  2729. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2730. //check if elem exists
  2731. if(Database::num_rows($res_sel)<1){return false;}
  2732. //gather data
  2733. $row = Database::fetch_array($res_sel);
  2734. $previous = $row['previous_item_id'];
  2735. $next = $row['next_item_id'];
  2736. $display = $row['display_order'];
  2737. $parent = $row['parent_item_id'];
  2738. $lp = $row['lp_id'];
  2739. //update the item (switch with previous/next one)
  2740. switch($direction)
  2741. {
  2742. case 'up':
  2743. if($this->debug>2){error_log('Movement up detected',0);}
  2744. if($display <= 1){/*do nothing*/}
  2745. else{
  2746. $sql_sel2 = "SELECT *
  2747. FROM $tbl_lp_item
  2748. WHERE id = $previous";
  2749. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2750. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2751. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2752. //gather data
  2753. $row2 = Database::fetch_array($res_sel2);
  2754. $previous_previous = $row2['previous_item_id'];
  2755. //update previous_previous item (switch "next" with current)
  2756. if($previous_previous != 0)
  2757. {
  2758. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2759. if($this->debug>2){error_log($sql_upd2,0);}
  2760. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2761. }
  2762. //update previous item (switch with current)
  2763. if($previous != 0)
  2764. {
  2765. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2766. if($this->debug>2){error_log($sql_upd2,0);}
  2767. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2768. }
  2769. //update current item (switch with previous)
  2770. if($id != 0){
  2771. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2772. if($this->debug>2){error_log($sql_upd2,0);}
  2773. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2774. }
  2775. //update next item (new previous item)
  2776. if($next != 0){
  2777. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2778. if($this->debug>2){error_log($sql_upd2,0);}
  2779. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2780. }
  2781. $display = $display-1;
  2782. }
  2783. break;
  2784. case 'down':
  2785. if($this->debug>2){error_log('Movement down detected',0);}
  2786. if($next == 0){/*do nothing*/}
  2787. else{
  2788. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2789. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2790. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2791. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2792. //gather data
  2793. $row2 = Database::fetch_array($res_sel2);
  2794. $next_next = $row2['next_item_id'];
  2795. //update previous item (switch with current)
  2796. if($previous != 0)
  2797. {
  2798. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2799. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2800. }
  2801. //update current item (switch with previous)
  2802. if($id != 0)
  2803. {
  2804. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2805. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2806. }
  2807. //update next item (new previous item)
  2808. if($next != 0)
  2809. {
  2810. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2811. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2812. }
  2813. //update next_next item (switch "previous" with current)
  2814. if($next_next != 0)
  2815. {
  2816. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2817. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2818. }
  2819. $display = $display+1;
  2820. }
  2821. break;
  2822. default:
  2823. return false;
  2824. }
  2825. return $display;
  2826. }
  2827. /**
  2828. * Move a learnpath up (display_order)
  2829. * @param integer Learnpath ID
  2830. */
  2831. function move_up($lp_id)
  2832. {
  2833. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2834. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2835. $res = api_sql_query($sql, __FILE__, __LINE__);
  2836. if($res === false) return false;
  2837. $lps = array();
  2838. $lp_order = array();
  2839. $num = Database::num_rows($res);
  2840. //first check the order is correct, globally (might be wrong because
  2841. //of versions < 1.8.4)
  2842. if($num>0)
  2843. {
  2844. $i = 1;
  2845. while($row = Database::fetch_array($res))
  2846. {
  2847. if($row['display_order'] != $i)
  2848. { //if we find a gap in the order, we need to fix it
  2849. $need_fix = true;
  2850. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2851. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2852. }
  2853. $row['display_order'] = $i;
  2854. $lps[$row['id']] = $row;
  2855. $lp_order[$i] = $row['id'];
  2856. $i++;
  2857. }
  2858. }
  2859. if($num>1) //if there's only one element, no need to sort
  2860. {
  2861. $order = $lps[$lp_id]['display_order'];
  2862. if($order>1) //if it's the first element, no need to move up
  2863. {
  2864. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
  2865. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2866. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
  2867. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2868. }
  2869. }
  2870. }
  2871. /**
  2872. * Move a learnpath down (display_order)
  2873. * @param integer Learnpath ID
  2874. */
  2875. function move_down($lp_id)
  2876. {
  2877. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2878. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2879. $res = api_sql_query($sql, __FILE__, __LINE__);
  2880. if($res === false) return false;
  2881. $lps = array();
  2882. $lp_order = array();
  2883. $num = Database::num_rows($res);
  2884. $max = 0;
  2885. //first check the order is correct, globally (might be wrong because
  2886. //of versions < 1.8.4)
  2887. if($num>0)
  2888. {
  2889. $i = 1;
  2890. while($row = Database::fetch_array($res))
  2891. {
  2892. $max = $i;
  2893. if($row['display_order'] != $i)
  2894. { //if we find a gap in the order, we need to fix it
  2895. $need_fix = true;
  2896. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2897. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2898. }
  2899. $row['display_order'] = $i;
  2900. $lps[$row['id']] = $row;
  2901. $lp_order[$i] = $row['id'];
  2902. $i++;
  2903. }
  2904. }
  2905. if($num>1) //if there's only one element, no need to sort
  2906. {
  2907. $order = $lps[$lp_id]['display_order'];
  2908. if($order<$max) //if it's the first element, no need to move up
  2909. {
  2910. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
  2911. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2912. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
  2913. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2914. }
  2915. }
  2916. }
  2917. /**
  2918. * Updates learnpath attributes to point to the next element
  2919. * The last part is similar to set_current_item but processing the other way around
  2920. */
  2921. function next()
  2922. {
  2923. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2924. $this->last = $this->get_current_item_id();
  2925. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2926. $this->autocomplete_parents($this->last);
  2927. $new_index = $this->get_next_index();
  2928. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2929. $this->index = $new_index;
  2930. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2931. $this->current = $this->ordered_items[$new_index];
  2932. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2933. }
  2934. /**
  2935. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2936. * class, this might be redefined to allow several behaviours depending on the document type.
  2937. * @param integer Resource ID
  2938. * @return boolean True on success, false otherwise
  2939. */
  2940. function open($id)
  2941. {
  2942. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2943. //TODO
  2944. //set the current resource attribute to this resource
  2945. //switch on element type (redefine in child class?)
  2946. //set status for this item to "opened"
  2947. //start timer
  2948. //initialise score
  2949. $this->index = 0; //or = the last item seen (see $this->last)
  2950. }
  2951. /**
  2952. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2953. * and the prerequisite string on error.
  2954. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2955. * @param integer Optional item ID. If none given, uses the current open item.
  2956. * @return boolean True if prerequisites are matched, false otherwise
  2957. * @return string Empty string if true returned, prerequisites string otherwise.
  2958. */
  2959. function prerequisites_match($item = null)
  2960. {
  2961. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2962. if(empty($item)){$item = $this->current;}
  2963. if(is_object($this->items[$item]))
  2964. {
  2965. $prereq_string = $this->items[$item]->get_prereq_string();
  2966. if(empty($prereq_string)){return true;}
  2967. //clean spaces
  2968. $prereq_string = str_replace(' ','',$prereq_string);
  2969. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2970. //now send to the parse_prereq() function that will check this component's prerequisites
  2971. $result = $this->items[$item]->parse_prereq($prereq_string,$this->items,$this->refs_list,$this->get_user_id());
  2972. if($result === false)
  2973. {
  2974. $this->set_error_msg($this->items[$item]->prereq_alert);
  2975. }
  2976. }else{
  2977. $result = true;
  2978. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2979. }
  2980. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2981. return $result;
  2982. }
  2983. /**
  2984. * Updates learnpath attributes to point to the previous element
  2985. * The last part is similar to set_current_item but processing the other way around
  2986. */
  2987. function previous()
  2988. {
  2989. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2990. $this->last = $this->get_current_item_id();
  2991. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2992. $this->autocomplete_parents($this->last);
  2993. $new_index = $this->get_previous_index();
  2994. $this->index = $new_index;
  2995. $this->current = $this->ordered_items[$new_index];
  2996. }
  2997. /**
  2998. * Publishes a learnpath. This basically means show or hide the learnpath
  2999. * to normal users.
  3000. * Can be used as abstract
  3001. * @param integer Learnpath ID
  3002. * @param string New visibility
  3003. */
  3004. function toggle_visibility($lp_id,$set_visibility=1)
  3005. {
  3006. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  3007. $action = 'visible';
  3008. if($set_visibility != 1)
  3009. {
  3010. $action = 'invisible';
  3011. }
  3012. return api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$lp_id,$action,api_get_user_id());
  3013. }
  3014. /**
  3015. * Publishes a learnpath. This basically means show or hide the learnpath
  3016. * on the course homepage
  3017. * Can be used as abstract
  3018. * @param integer Learnpath ID
  3019. * @param string New visibility
  3020. */
  3021. function toggle_publish($lp_id,$set_visibility='v')
  3022. {
  3023. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  3024. $tbl_lp = Database::get_course_table('lp');
  3025. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  3026. $result=api_sql_query($sql,__FILE__,__LINE__);
  3027. $row=Database::fetch_array($result);
  3028. $name=domesticate($row['name']);
  3029. if($set_visibility == 'i') {
  3030. $s=$name." ".get_lang('_no_published');
  3031. $dialogBox=$s;
  3032. $v=0;
  3033. }
  3034. if($set_visibility == 'v')
  3035. {
  3036. $s=$name." ".get_lang('_published');
  3037. $dialogBox=$s;
  3038. $v=1;
  3039. }
  3040. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  3041. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  3042. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  3043. $result=api_sql_query($sql,__FILE__,__LINE__);
  3044. $num=Database::num_rows($result);
  3045. $row2=Database::fetch_array($result);
  3046. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  3047. if(($set_visibility == 'i') && ($num>0))
  3048. {
  3049. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  3050. }
  3051. elseif(($set_visibility == 'v') && ($num==0))
  3052. {
  3053. $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)";
  3054. }
  3055. else
  3056. {
  3057. //parameter and database incompatible, do nothing
  3058. }
  3059. $result=api_sql_query($sql,__FILE__,__LINE__);
  3060. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3061. }
  3062. /**
  3063. * Restart the whole learnpath. Return the URL of the first element.
  3064. * Make sure the results are saved with anoter method. This method should probably be
  3065. * redefined in children classes.
  3066. * To use a similar method statically, use the create_new_attempt() method
  3067. * @return string URL to load in the viewer
  3068. */
  3069. function restart()
  3070. {
  3071. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  3072. //TODO
  3073. //call autosave method to save the current progress
  3074. //$this->index = 0;
  3075. $lp_view_table = Database::get_course_table('lp_view');
  3076. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  3077. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  3078. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  3079. $res = api_sql_query($sql, __FILE__, __LINE__);
  3080. if($view_id = Database::get_last_insert_id($res))
  3081. {
  3082. $this->lp_view_id = $view_id;
  3083. $this->attempt = $this->attempt+1;
  3084. }else{
  3085. $this->error = 'Could not insert into item_view table...';
  3086. return false;
  3087. }
  3088. $this->autocomplete_parents($this->current);
  3089. foreach($this->items as $index=>$dummy){
  3090. $this->items[$index]->restart();
  3091. $this->items[$index]->set_lp_view($this->lp_view_id);
  3092. }
  3093. $this->first();
  3094. return true;
  3095. }
  3096. /**
  3097. * Saves the current item
  3098. * @return boolean
  3099. */
  3100. function save_current(){
  3101. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  3102. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3103. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3104. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  3105. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  3106. if(is_object($this->items[$this->current])){
  3107. //$res = $this->items[$this->current]->save(false);
  3108. $res = $this->items[$this->current]->save(false,$this->prerequisites_match($this->current));
  3109. $this->autocomplete_parents($this->current);
  3110. $status = $this->items[$this->current]->get_status();
  3111. $this->append_message('new_item_status: '.$status);
  3112. $this->update_queue[$this->current] = $status;
  3113. return $res;
  3114. }
  3115. return false;
  3116. }
  3117. /**
  3118. * Saves the given item
  3119. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3120. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3121. * @return boolean
  3122. */
  3123. function save_item($item_id=null,$from_outside=true){
  3124. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  3125. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3126. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3127. if(empty($item_id)){
  3128. $item_id = $this->escape_string($_REQUEST['id']);
  3129. }
  3130. if(empty($item_id))
  3131. {
  3132. $item_id = $this->get_current_item_id();
  3133. }
  3134. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  3135. if(is_object($this->items[$item_id])){
  3136. $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id));
  3137. //$res = $this->items[$item_id]->save($from_outside);
  3138. $this->autocomplete_parents($item_id);
  3139. $status = $this->items[$item_id]->get_status();
  3140. $this->append_message('new_item_status: '.$status);
  3141. $this->update_queue[$item_id] = $status;
  3142. return $res;
  3143. }
  3144. return false;
  3145. }
  3146. /**
  3147. * Saves the last item seen's ID only in case
  3148. */
  3149. function save_last(){
  3150. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  3151. $table = Database::get_course_table('lp_view');
  3152. if(isset($this->current)){
  3153. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  3154. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  3155. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  3156. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  3157. $res = api_sql_query($sql,__FILE__,__LINE__);
  3158. }
  3159. //save progress
  3160. list($progress,$text) = $this->get_progress_bar_text('%');
  3161. if($progress>=0 AND $progress<=100){
  3162. $progress= (int)$progress;
  3163. $sql = "UPDATE $table SET progress = $progress " .
  3164. "WHERE lp_id = ".$this->get_id()." AND " .
  3165. "user_id = ".$this->get_user_id();
  3166. $res = api_sql_query($sql,__FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  3167. $this->progress_db = $progress;
  3168. }
  3169. }
  3170. /**
  3171. * Sets the current item ID (checks if valid and authorized first)
  3172. * @param integer New item ID. If not given or not authorized, defaults to current
  3173. */
  3174. function set_current_item($item_id=null)
  3175. {
  3176. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  3177. if(empty($item_id)){
  3178. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  3179. //do nothing
  3180. }else{
  3181. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  3182. $item_id = $this->escape_string($item_id);
  3183. //TODO check in database here
  3184. $this->last = $this->current;
  3185. $this->current = $item_id;
  3186. //TODO update $this->index as well
  3187. foreach($this->ordered_items as $index => $item)
  3188. {
  3189. if($item == $this->current)
  3190. {
  3191. $this->index = $index;
  3192. break;
  3193. }
  3194. }
  3195. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  3196. }
  3197. }
  3198. /**
  3199. * Sets the encoding
  3200. * @param string New encoding
  3201. */
  3202. function set_encoding($enc='ISO-8859-1'){
  3203. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  3204. $enc = strtoupper($enc);
  3205. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','cp1251','cp1252','KOI8-R','BIG5','GB2312','Shift_JIS','EUC-JP','');
  3206. if(in_array($enc,$encodings)){
  3207. $lp = $this->get_id();
  3208. if($lp!=0){
  3209. $tbl_lp = Database::get_course_table('lp');
  3210. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  3211. $res = api_sql_query($sql, __FILE__, __LINE__);
  3212. return $res;
  3213. }
  3214. }
  3215. return false;
  3216. }
  3217. /**
  3218. * Sets the JS lib setting in the database directly.
  3219. * This is the JavaScript library file this lp needs to load on startup
  3220. * @param string Proximity setting
  3221. */
  3222. function set_jslib($lib=''){
  3223. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  3224. $lp = $this->get_id();
  3225. if($lp!=0){
  3226. $tbl_lp = Database::get_course_table('lp');
  3227. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  3228. $res = api_sql_query($sql, __FILE__, __LINE__);
  3229. return $res;
  3230. }else{
  3231. return false;
  3232. }
  3233. }
  3234. /**
  3235. * Sets the name of the LP maker (publisher) (and save)
  3236. * @param string Optional string giving the new content_maker of this learnpath
  3237. */
  3238. function set_maker($name=''){
  3239. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  3240. if(empty($name))return false;
  3241. $this->maker = $this->escape_string($name);
  3242. $lp_table = Database::get_course_table('lp');
  3243. $lp_id = $this->get_id();
  3244. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  3245. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  3246. //$res = Database::query($sql);
  3247. $res = api_sql_query($sql, __FILE__, __LINE__);
  3248. return true;
  3249. }
  3250. /**
  3251. * Sets the name of the current learnpath (and save)
  3252. * @param string Optional string giving the new name of this learnpath
  3253. */
  3254. function set_name($name=''){
  3255. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  3256. if(empty($name))return false;
  3257. $this->name = $this->escape_string($name);
  3258. $lp_table = Database::get_course_table('lp');
  3259. $lp_id = $this->get_id();
  3260. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  3261. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  3262. //$res = Database::query($sql);
  3263. $res = api_sql_query($sql, __FILE__, __LINE__);
  3264. // if the lp is visible on the homepage, change his name there
  3265. if(mysql_affected_rows())
  3266. {
  3267. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3268. $sql = 'UPDATE '.$table.' SET
  3269. name = "'.$this->name.'"
  3270. WHERE link = "newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'"';
  3271. api_sql_query($sql, __FILE__, __LINE__);
  3272. }
  3273. return true;
  3274. }
  3275. /**
  3276. * Set index specified prefix terms for all items in this path
  3277. * @param string Comma-separated list of terms
  3278. * @param char Xapian term prefix
  3279. * @return boolean False on error, true otherwise
  3280. */
  3281. function set_terms_by_prefix($terms_string, $prefix) {
  3282. if (api_get_setting('search_enabled') !== 'true')
  3283. return FALSE;
  3284. $terms_string = trim($terms_string);
  3285. $terms = explode(',', $terms_string);
  3286. array_walk($terms, 'trim_value');
  3287. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3288. //var_dump($stored_terms);
  3289. //var_dump($terms);
  3290. // don't do anything if no change, verify only at DB, not the search engine
  3291. if ( (count(array_diff($terms, $stored_terms))==0) && (count(array_diff($stored_terms, $terms))==0) )
  3292. return FALSE;
  3293. require_once('xapian.php'); //TODO try catch every xapian use or make wrappers on api
  3294. require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php');
  3295. require_once(api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php');
  3296. require_once(api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php');
  3297. $items_table = Database::get_course_table('lp_item');
  3298. //TODO: make query secure agains XSS : use member attr instead of post var
  3299. $lp_id = $_POST['lp_id'];
  3300. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3301. $result = api_sql_query($sql);
  3302. $di = new DokeosIndexer();
  3303. while($lp_item = Database::fetch_array($result))
  3304. {
  3305. // get search_did
  3306. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3307. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
  3308. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3309. $res = api_sql_query($sql, __FILE__, __LINE__);
  3310. $se_ref = Database::fetch_array($res);
  3311. // compare terms
  3312. $doc = $di->get_document($se_ref['search_did']);
  3313. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3314. //var_dump($xapian_terms);
  3315. $xterms = array();
  3316. foreach ($xapian_terms as $xapian_term) $xterms[] = substr($xapian_term['name'],1);
  3317. $dterms = $terms;
  3318. //var_dump($xterms);
  3319. //var_dump($dterms);
  3320. $missing_terms = array_diff($dterms, $xterms);
  3321. $deprecated_terms = array_diff($xterms, $dterms);
  3322. // save it to search engine
  3323. foreach ($missing_terms as $term)
  3324. {
  3325. $doc->add_term($prefix. $term, 1);
  3326. }
  3327. foreach ($deprecated_terms as $term)
  3328. {
  3329. $doc->remove_term($prefix.$term);
  3330. }
  3331. $di->getDb()->replace_document((int)$se_ref['search_did'], $doc);
  3332. $di->getDb()->flush();
  3333. }
  3334. return true;
  3335. }
  3336. /**
  3337. * Sets the theme of the LP (local/remote) (and save)
  3338. * @param string Optional string giving the new theme of this learnpath
  3339. * @return bool returns true if theme name is not empty
  3340. */
  3341. function set_theme($name=''){
  3342. if($this->debug>0){error_log('New LP - In learnpath::set_theme()',0);}
  3343. $this->theme = $this->escape_string($name);
  3344. $lp_table = Database::get_course_table('lp');
  3345. $lp_id = $this->get_id();
  3346. $sql = "UPDATE $lp_table SET theme = '".$this->theme."' WHERE id = '$lp_id'";
  3347. if($this->debug>2){error_log('New LP - lp updated with new theme : '.$this->theme,0);}
  3348. //$res = Database::query($sql);
  3349. $res = api_sql_query($sql, __FILE__, __LINE__);
  3350. return true;
  3351. }
  3352. /**
  3353. * Sets the image of an LP (and save)
  3354. * @param string Optional string giving the new image of this learnpath
  3355. * @return bool returns true if theme name is not empty
  3356. */
  3357. function set_preview_image($name=''){
  3358. if($this->debug>0){error_log('New LP - In learnpath::set_preview_image()',0);}
  3359. $this->preview_image = $this->escape_string($name);
  3360. $lp_table = Database::get_course_table('lp');
  3361. $lp_id = $this->get_id();
  3362. $sql = "UPDATE $lp_table SET preview_image = '".$this->preview_image."' WHERE id = '$lp_id'";
  3363. if($this->debug>2){error_log('New LP - lp updated with new preview image : '.$this->preview_image,0);}
  3364. $res = api_sql_query($sql, __FILE__, __LINE__);
  3365. return true;
  3366. }
  3367. /**
  3368. * Sets the author of a LP (and save)
  3369. * @param string Optional string giving the new author of this learnpath
  3370. * @return bool returns true if author's name is not empty
  3371. */
  3372. function set_author($name=''){
  3373. if($this->debug>0){error_log('New LP - In learnpath::set_author()',0);}
  3374. $this->author = $this->escape_string($name);
  3375. $lp_table = Database::get_course_table('lp');
  3376. $lp_id = $this->get_id();
  3377. $sql = "UPDATE $lp_table SET author = '".$this->author."' WHERE id = '$lp_id'";
  3378. if($this->debug>2){error_log('New LP - lp updated with new preview author : '.$this->author,0);}
  3379. $res = api_sql_query($sql, __FILE__, __LINE__);
  3380. return true;
  3381. }
  3382. /**
  3383. * Sets the location/proximity of the LP (local/remote) (and save)
  3384. * @param string Optional string giving the new location of this learnpath
  3385. */
  3386. function set_proximity($name=''){
  3387. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  3388. if(empty($name))return false;
  3389. $this->proximity = $this->escape_string($name);
  3390. $lp_table = Database::get_course_table('lp');
  3391. $lp_id = $this->get_id();
  3392. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  3393. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  3394. //$res = Database::query($sql);
  3395. $res = api_sql_query($sql, __FILE__, __LINE__);
  3396. return true;
  3397. }
  3398. /**
  3399. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3400. * @param integer DB ID of the item
  3401. */
  3402. function set_previous_item($id)
  3403. {
  3404. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  3405. $this->last = $id;
  3406. }
  3407. /**
  3408. * Sets the object's error message
  3409. * @param string Error message. If empty, reinits the error string
  3410. * @return void
  3411. */
  3412. function set_error_msg($error='')
  3413. {
  3414. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  3415. if(empty($error)){
  3416. $this->error = '';
  3417. }else{
  3418. $this->error .= $error;
  3419. }
  3420. }
  3421. /**
  3422. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3423. *
  3424. */
  3425. function start_current_item($allow_new_attempt=false){
  3426. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  3427. if($this->current != 0 AND
  3428. is_object($this->items[$this->current]))
  3429. {
  3430. $type = $this->get_type();
  3431. $item_type = $this->items[$this->current]->get_type();
  3432. if(
  3433. ($type == 2 && $item_type!='sco')
  3434. OR
  3435. ($type == 3 && $item_type!='au')
  3436. OR
  3437. ($type == 1 && $item_type!=TOOL_QUIZ && $item_type!=TOOL_HOTPOTATOES)
  3438. )
  3439. {
  3440. $this->items[$this->current]->open($allow_new_attempt);
  3441. $this->autocomplete_parents($this->current);
  3442. $prereq_check = $this->prerequisites_match($this->current);
  3443. $this->items[$this->current]->save(false,$prereq_check);
  3444. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3445. }else{
  3446. //if sco, then it is supposed to have been updated by some other call
  3447. }
  3448. if ($item_type=='sco') {
  3449. $this->items[$this->current]->restart();
  3450. }
  3451. }
  3452. if($this->debug>0){error_log('New LP - End of learnpath::start_current_item()',0);}
  3453. return true;
  3454. }
  3455. /**
  3456. * Stops the processing and counters for the old item (as held in $this->last)
  3457. * @param
  3458. */
  3459. function stop_previous_item(){
  3460. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  3461. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  3462. {
  3463. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  3464. switch($this->get_type()){
  3465. case '3':
  3466. if($this->items[$this->last]->get_type()!='au')
  3467. {
  3468. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  3469. $this->items[$this->last]->close();
  3470. //$this->autocomplete_parents($this->last);
  3471. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3472. }else{
  3473. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  3474. }
  3475. case '2':
  3476. if($this->items[$this->last]->get_type()!='sco')
  3477. {
  3478. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  3479. $this->items[$this->last]->close();
  3480. //$this->autocomplete_parents($this->last);
  3481. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3482. }else{
  3483. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  3484. }
  3485. break;
  3486. case '1':
  3487. default:
  3488. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  3489. $this->items[$this->last]->close();
  3490. break;
  3491. }
  3492. }else{
  3493. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  3494. return false;
  3495. }
  3496. return true;
  3497. }
  3498. /**
  3499. * Updates the default view mode from fullscreen to embedded and inversely
  3500. * @return string The current default view mode ('fullscreen' or 'embedded')
  3501. */
  3502. function update_default_view_mode()
  3503. {
  3504. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  3505. $lp_table = Database::get_course_table('lp');
  3506. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3507. $res = api_sql_query($sql, __FILE__, __LINE__);
  3508. if(Database::num_rows($res)>0){
  3509. $row = Database::fetch_array($res);
  3510. $view_mode = $row['default_view_mod'];
  3511. if($view_mode == 'fullscreen'){
  3512. $view_mode = 'embedded';
  3513. }elseif($view_mode == 'embedded'){
  3514. $view_mode = 'fullscreen';
  3515. }
  3516. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  3517. $res = api_sql_query($sql, __FILE__, __LINE__);
  3518. $this->mode = $view_mode;
  3519. return $view_mode;
  3520. }else{
  3521. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  3522. }
  3523. return -1;
  3524. }
  3525. /**
  3526. * Updates the default behaviour about auto-commiting SCORM updates
  3527. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3528. */
  3529. function update_default_scorm_commit(){
  3530. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  3531. $lp_table = Database::get_course_table('lp');
  3532. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3533. $res = api_sql_query($sql, __FILE__, __LINE__);
  3534. if(Database::num_rows($res)>0){
  3535. $row = Database::fetch_array($res);
  3536. $force = $row['force_commit'];
  3537. if($force == 1){
  3538. $force = 0;
  3539. $force_return = false;
  3540. }elseif($force == 0){
  3541. $force = 1;
  3542. $force_return = true;
  3543. }
  3544. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  3545. $res = api_sql_query($sql, __FILE__, __LINE__);
  3546. $this->force_commit = $force_return;
  3547. return $force_return;
  3548. }else{
  3549. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  3550. }
  3551. return -1;
  3552. }
  3553. /**
  3554. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3555. * @return bool True on success, false on failure
  3556. */
  3557. function update_display_order()
  3558. {
  3559. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  3560. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3561. $res = api_sql_query($sql, __FILE__, __LINE__);
  3562. if($res === false) return false;
  3563. $lps = array();
  3564. $lp_order = array();
  3565. $num = Database::num_rows($res);
  3566. //first check the order is correct, globally (might be wrong because
  3567. //of versions < 1.8.4)
  3568. if($num>0)
  3569. {
  3570. $i = 1;
  3571. while($row = Database::fetch_array($res))
  3572. {
  3573. if($row['display_order'] != $i)
  3574. { //if we find a gap in the order, we need to fix it
  3575. $need_fix = true;
  3576. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  3577. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  3578. }
  3579. $i++;
  3580. }
  3581. }
  3582. return true;
  3583. }
  3584. /**
  3585. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3586. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3587. */
  3588. function update_reinit(){
  3589. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  3590. $lp_table = Database::get_course_table('lp');
  3591. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3592. $res = api_sql_query($sql, __FILE__, __LINE__);
  3593. if(Database::num_rows($res)>0){
  3594. $row = Database::fetch_array($res);
  3595. $force = $row['prevent_reinit'];
  3596. if($force == 1){
  3597. $force = 0;
  3598. }elseif($force == 0){
  3599. $force = 1;
  3600. }
  3601. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  3602. $res = api_sql_query($sql,__FILE__,__LINE__);
  3603. $this->prevent_reinit = $force;
  3604. return $force;
  3605. }else{
  3606. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  3607. }
  3608. return -1;
  3609. }
  3610. /**
  3611. * Updates the "scorm_debug" value that shows or hide the debug window
  3612. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3613. */
  3614. function update_scorm_debug(){
  3615. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  3616. $lp_table = Database::get_course_table('lp');
  3617. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3618. $res = api_sql_query($sql, __FILE__, __LINE__);
  3619. if(Database::num_rows($res)>0){
  3620. $row = Database::fetch_array($res);
  3621. $force = $row['debug'];
  3622. if($force == 1){
  3623. $force = 0;
  3624. }elseif($force == 0){
  3625. $force = 1;
  3626. }
  3627. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  3628. $res = api_sql_query($sql,__FILE__,__LINE__);
  3629. $this->scorm_debug = $force;
  3630. return $force;
  3631. }else{
  3632. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  3633. }
  3634. return -1;
  3635. }
  3636. /**
  3637. * Function that makes a call to the function sort_tree_array and create_tree_array
  3638. *
  3639. * @author Kevin Van Den Haute
  3640. *
  3641. * @param unknown_type $array
  3642. */
  3643. function tree_array($array)
  3644. {
  3645. if($this->debug>1){error_log('New LP - In learnpath::tree_array()',0);}
  3646. $array = $this->sort_tree_array($array);
  3647. $this->create_tree_array($array);
  3648. }
  3649. /**
  3650. * Creates an array with the elements of the learning path tree in it
  3651. *
  3652. * @author Kevin Van Den Haute
  3653. *
  3654. * @param array $array
  3655. * @param int $parent
  3656. * @param int $depth
  3657. * @param array $tmp
  3658. */
  3659. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  3660. {
  3661. if($this->debug>1){error_log('New LP - In learnpath::create_tree_array())',0);}
  3662. if(is_array($array))
  3663. {
  3664. for($i = 0; $i < count($array); $i++)
  3665. {
  3666. if($array[$i]['parent_item_id'] == $parent)
  3667. {
  3668. if(!in_array($array[$i]['parent_item_id'], $tmp))
  3669. {
  3670. $tmp[] = $array[$i]['parent_item_id'];
  3671. $depth++;
  3672. }
  3673. $preq = (empty($array[$i]['prerequisite'])?'':$array[$i]['prerequisite']);
  3674. $this->arrMenu[] = array(
  3675. 'id' => $array[$i]['id'],
  3676. 'item_type' => $array[$i]['item_type'],
  3677. 'title' => $array[$i]['title'],
  3678. 'path' => $array[$i]['path'],
  3679. 'description' => $array[$i]['description'],
  3680. 'parent_item_id' => $array[$i]['parent_item_id'],
  3681. 'previous_item_id' => $array[$i]['previous_item_id'],
  3682. 'next_item_id' => $array[$i]['next_item_id'],
  3683. 'min_score' => $array[$i]['min_score'],
  3684. 'max_score' => $array[$i]['max_score'],
  3685. 'mastery_score' => $array[$i]['mastery_score'],
  3686. 'display_order' => $array[$i]['display_order'],
  3687. 'prerequisite' => $preq,
  3688. 'depth' => $depth,
  3689. 'audio' => $array[$i]['audio']
  3690. );
  3691. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3692. }
  3693. }
  3694. }
  3695. }
  3696. /**
  3697. * Sorts a multi dimensional array by parent id and display order
  3698. * @author Kevin Van Den Haute
  3699. *
  3700. * @param array $array (array with al the learning path items in it)
  3701. *
  3702. * @return array
  3703. */
  3704. function sort_tree_array($array)
  3705. {
  3706. foreach($array as $key => $row)
  3707. {
  3708. $parent[$key] = $row['parent_item_id'];
  3709. $position[$key] = $row['display_order'];
  3710. }
  3711. if(count($array) > 0)
  3712. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3713. return $array;
  3714. }
  3715. /**
  3716. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3717. * Also the actions for the modules, chapters and documents are in this table.
  3718. *
  3719. * @author Kevin Van Den Haute
  3720. *
  3721. * @param int $lp_id
  3722. *
  3723. * @return string
  3724. */
  3725. function overview()
  3726. {
  3727. if($this->debug>0){error_log('New LP - In learnpath::overview()',0);}
  3728. global $charset, $_course;
  3729. $return = '';
  3730. $tbl_lp_item = Database::get_course_table('lp_item');
  3731. $sql = "
  3732. SELECT *
  3733. FROM " . $tbl_lp_item . "
  3734. WHERE
  3735. lp_id = " . $this->lp_id;
  3736. $result = api_sql_query($sql, __FILE__, __LINE__);
  3737. $arrLP = array();
  3738. $mycharset=api_get_setting('platform_charset');
  3739. while($row = Database::fetch_array($result))
  3740. {
  3741. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3742. $arrLP[] = array(
  3743. 'id' => $row['id'],
  3744. 'item_type' => $row['item_type'],
  3745. 'title' => $row['title'],
  3746. 'path' => $row['path'],
  3747. 'description' => $row['description'],
  3748. 'parent_item_id' => $row['parent_item_id'],
  3749. 'previous_item_id' => $row['previous_item_id'],
  3750. 'next_item_id' => $row['next_item_id'],
  3751. 'max_score' => $row['max_score'],
  3752. 'min_score' => $row['min_score'],
  3753. 'mastery_score' => $row['mastery_score'],
  3754. 'prerequisite' => $row['prerequisite'],
  3755. 'display_order' => $row['display_order'],
  3756. 'audio' => $row['audio']
  3757. );
  3758. }
  3759. $this->tree_array($arrLP);
  3760. $arrLP = $this->arrMenu;
  3761. unset($this->arrMenu);
  3762. if(api_is_allowed_to_edit())
  3763. {
  3764. $return .= '<div class="actions">';
  3765. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=build&amp;lp_id=' . $this->lp_id . '">'.Display::return_icon('learnpath_build.gif', get_lang('Build')).' '.get_lang('Build').'</a>';
  3766. $return .= '<span>'.Display::return_icon('learnpath_organize.gif', get_lang("BasicOverview")).' '.get_lang("BasicOverview").'</span>';
  3767. $return .= '<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$this->lp_id.'">'.Display::return_icon('learnpath_view.gif', get_lang("Display")).' '.get_lang("Display").'</a>';
  3768. $return .= '<a href="'.api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&amp;action='.Security::remove_XSS($_GET['action']).'&amp;lp_id='.Security::remove_XSS($_GET['lp_id']).'&amp;updateaudio=true">'.Display::return_icon('audio.gif', get_lang('UpdateAllAudioFragments')).' '.get_lang('UpdateAllAudioFragments').'</a>';
  3769. $return .= '</div>';
  3770. }
  3771. // we need to start a form when we want to update all the mp3 files
  3772. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0)
  3773. {
  3774. $return .= '<form action="'.api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&amp;action='.Security::remove_XSS($_GET['action']).'&amp;lp_id='.Security::remove_XSS($_GET['lp_id']).'" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  3775. $return .= Display::display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  3776. }
  3777. $return .= '<table class="data_table">' . "\n";
  3778. $return .= "\t" . '<tr>' . "\n";
  3779. $return .= "\t" . '<th width="60%">'.get_lang("Title").'</th>' . "\n";
  3780. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3781. $return .= "\t" . '<th>'.get_lang("Audio").'</th>' . "\n";
  3782. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3783. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3784. $return .= "\t" . '</tr>' . "\n";
  3785. for($i = 0; $i < count($arrLP); $i++)
  3786. {
  3787. $title=$arrLP[$i]['title'];
  3788. if($arrLP[$i]['description'] == '')
  3789. $arrLP[$i]['description'] = '&nbsp;';
  3790. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3791. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3792. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  3793. if (file_exists("../img/lp_" . $icon_name . ".png"))
  3794. {
  3795. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3796. }
  3797. else if(file_exists("../img/lp_" . $icon_name . ".gif"))
  3798. {
  3799. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3800. }
  3801. else
  3802. {
  3803. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_document.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3804. }
  3805. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3806. // The audio column
  3807. $return .= "\t\t" . '<td align="center">';
  3808. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true')
  3809. {
  3810. if (!empty($arrLP[$i]['audio']))
  3811. {
  3812. $return .= '<span id="container'.$i.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  3813. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  3814. $return .= '<script type="text/javascript">
  3815. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  3816. s1.addParam("allowscriptaccess","always");
  3817. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$arrLP[$i]['audio'].'&image=preview.jpg");
  3818. s1.write("container'.$i.'");
  3819. </script>';
  3820. }
  3821. else
  3822. {
  3823. $return .= ' - ';
  3824. }
  3825. }
  3826. else
  3827. {
  3828. if ($arrLP[$i]['item_type']!='dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  3829. $return .= ' <input type="file" name="mp3file'.$arrLP[$i]['id'].'" id="mp3file" />';
  3830. if (!empty($arrLP[$i]['audio']))
  3831. {
  3832. $return .= '<br /><input type="checkbox" name="removemp3'.$arrLP[$i]['id'].'" id="checkbox'.$arrLP[$i]['id'].'" />'.get_lang('RemoveAudio');
  3833. }
  3834. }
  3835. }
  3836. $return .= '</td>' . "\n";
  3837. if(api_is_allowed_to_edit())
  3838. {
  3839. $return .= "\t\t" . '<td align="center">' . "\n";
  3840. if($arrLP[$i]['previous_item_id'] != 0)
  3841. {
  3842. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3843. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3). '.gif" title="' . get_lang('MoveUp') .'"/>';
  3844. $return .= '</a>' . "\n";
  3845. }
  3846. else
  3847. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3848. if($arrLP[$i]['next_item_id'] != 0)
  3849. {
  3850. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '">';
  3851. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  3852. $return .= '</a>' . "\n";
  3853. }
  3854. else
  3855. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3856. $return .= "\t\t" . '</td>' . "\n";
  3857. $return .= "\t\t" . '<td align="center">' . "\n";
  3858. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3859. {
  3860. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item='.$arrLP[$i]['path'].'">';
  3861. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3862. $return .= '</a>' . "\n";
  3863. }
  3864. else
  3865. {
  3866. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item='.$arrLP[$i]['path'].'">';
  3867. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3868. $return .= '</a>' . "\n";
  3869. }
  3870. $return .= "\t\t\t" . '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($title). '\');">';
  3871. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3872. $return .= '</a>' . "\n";
  3873. $return .= "\t\t" . '</td>' . "\n";
  3874. }
  3875. $return .= "\t" . '</tr>' . "\n";
  3876. }
  3877. if(count($arrLP) == 0)
  3878. {
  3879. $return .= "\t" . '<tr>' . "\n";
  3880. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3881. $return .= "\t" . '</tr>' . "\n";
  3882. }
  3883. $return .= '</table>' . "\n";
  3884. // we need to close the form when we are updating the mp3 files
  3885. if ($_GET['updateaudio'] == 'true')
  3886. {
  3887. $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">'.get_lang('Save audio and organization').'</button></div>';
  3888. }
  3889. // we need to close the form when we are updating the mp3 files
  3890. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0)
  3891. {
  3892. $return .= '</form>';
  3893. }
  3894. return $return;
  3895. }
  3896. /**
  3897. * This function builds the action menu
  3898. *
  3899. * */
  3900. function build_action_menu()
  3901. {
  3902. echo '<div class="actions">';
  3903. echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  3904. echo '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.Display::return_icon('learnpath_organize.gif').' '.get_lang("BasicOverview").'</a>';
  3905. echo '<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']).'&action=view&lp_id='.$_SESSION['oLP']->lp_id.'">'.Display::return_icon('learnpath_view.gif').' '.get_lang('Display').'</a>';
  3906. echo '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang("NewChapter").'"><img alt="'.get_lang("NewChapter").'" src="../img/lp_dokeos_chapter_add.png" title="'.get_lang("NewChapter").'" />'.get_lang("NewChapter").'</a>';
  3907. echo '<a href="' .api_get_self(). '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang("NewStep").'"><img alt="'.get_lang("NewStep").'" src="../img/lp_dokeos_step_add.png" title="'.get_lang("NewStep").'" />'.get_lang("NewStep").'</a>';
  3908. echo '</div>';
  3909. }
  3910. /**
  3911. * This functions builds the LP tree based on data from the database.
  3912. *
  3913. * @return string
  3914. * @uses dtree.js :: necessary javascript for building this tree
  3915. */
  3916. function build_tree()
  3917. {
  3918. $return = "<script type=\"text/javascript\">\n";
  3919. $return .= "\tm = new dTree('m');\n\n";
  3920. $return .= "\tm.config.folderLinks = true;\n";
  3921. $return .= "\tm.config.useCookies = true;\n";
  3922. $return .= "\tm.config.useIcons = true;\n";
  3923. $return .= "\tm.config.useLines = true;\n";
  3924. $return .= "\tm.config.useSelection = true;\n";
  3925. $return .= "\tm.config.useStatustext = false;\n\n";
  3926. $menu = 0;
  3927. $parent = '';
  3928. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3929. $tbl_lp_item = Database::get_course_table('lp_item');
  3930. $sql = "
  3931. SELECT *
  3932. FROM " . $tbl_lp_item . "
  3933. WHERE
  3934. lp_id = " . $this->lp_id;
  3935. $result = api_sql_query($sql, __FILE__, __LINE__);
  3936. $arrLP = array();
  3937. $mycharset=api_get_setting('platform_charset');
  3938. while($row = Database::fetch_array($result))
  3939. {
  3940. if($this->encoding!=$mycharset)
  3941. {
  3942. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3943. }
  3944. $arrLP[] = array(
  3945. 'id' => $row['id'],
  3946. 'item_type' => $row['item_type'],
  3947. 'title' => $row['title'],
  3948. 'path' => $row['path'],
  3949. 'description' => $row['description'],
  3950. 'parent_item_id' => $row['parent_item_id'],
  3951. 'previous_item_id' => $row['previous_item_id'],
  3952. 'next_item_id' => $row['next_item_id'],
  3953. 'max_score' => $row['max_score'],
  3954. 'min_score' => $row['min_score'],
  3955. 'mastery_score' => $row['mastery_score'],
  3956. 'display_order' => $row['display_order']);
  3957. }
  3958. $this->tree_array($arrLP);
  3959. $arrLP = $this->arrMenu;
  3960. unset($this->arrMenu);
  3961. $title='';
  3962. for($i = 0; $i < count($arrLP); $i++)
  3963. {
  3964. $title = addslashes($arrLP[$i]['title']);
  3965. $menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3966. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  3967. if (file_exists("../img/lp_" . $icon_name . ".png"))
  3968. {
  3969. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".png', '../img/lp_" . $icon_name . ".png');\n";
  3970. }
  3971. else if(file_exists("../img/lp_" . $icon_name . ".gif"))
  3972. {
  3973. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".gif', '../img/lp_" . $icon_name . ".gif');\n";
  3974. }
  3975. else
  3976. {
  3977. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3978. }
  3979. if($menu < $arrLP[$i]['id'])
  3980. $menu = $arrLP[$i]['id'];
  3981. }
  3982. $return .= "\n\tdocument.write(m);\n";
  3983. $return .= "\t if(!m.selectedNode) m.s(1);";
  3984. $return .= "</script>\n";
  3985. return $return;
  3986. }
  3987. /**
  3988. * Create a new document //still needs some finetuning
  3989. *
  3990. * @param array $_course
  3991. * @return string
  3992. */
  3993. function create_document($_course)
  3994. {
  3995. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3996. if(strstr($dir, '..'))
  3997. $dir = '/';
  3998. if($dir[0] == '.')
  3999. $dir = substr($dir, 1);
  4000. if($dir[0] != '/')
  4001. $dir = '/'.$dir;
  4002. if($dir[strlen($dir) - 1] != '/')
  4003. $dir .= '/';
  4004. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  4005. if(!is_dir($filepath))
  4006. {
  4007. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4008. $dir = '/';
  4009. }
  4010. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  4011. //is already escaped twice when it gets here
  4012. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4013. $title = disable_dangerous_file($title);
  4014. $title = replace_accents($title);
  4015. $filename = $title;
  4016. $content = $_POST['content_lp'];
  4017. $tmp_filename = $filename;
  4018. $i=0;
  4019. while(file_exists($filepath . $tmp_filename . '.html'))
  4020. $tmp_filename = $filename . '_' . ++$i;
  4021. $filename = $tmp_filename . '.html';
  4022. $content = stripslashes(text_filter($content));
  4023. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH).'courses/', $content);
  4024. // change the path of mp3 to absolute
  4025. // first regexp deals with ../../../ urls
  4026. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  4027. //second regexp deals with audio/ urls
  4028. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  4029. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  4030. $content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
  4031. if(!file_exists($filepath . $filename))
  4032. {
  4033. if($fp = @fopen($filepath . $filename, 'w'))
  4034. {
  4035. fputs($fp, $content);
  4036. fclose($fp);
  4037. $file_size = filesize($filepath . $filename);
  4038. $save_file_path = $dir . $filename;
  4039. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4040. if($document_id)
  4041. {
  4042. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  4043. //update parent folders
  4044. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4045. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4046. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4047. if($new_comment || $new_title)
  4048. {
  4049. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4050. $ct = '';
  4051. if($new_comment)
  4052. $ct .= ", comment='" . $new_comment . "'";
  4053. if($new_title)
  4054. $ct .= ", title='" . $new_title . ".html '";
  4055. $sql_update = "
  4056. UPDATE " . $tbl_doc . "
  4057. SET " . substr($ct, 1) . "
  4058. WHERE id = " . $document_id;
  4059. api_sql_query($sql_update, __FILE__, __LINE__);
  4060. }
  4061. }
  4062. return $document_id;
  4063. }
  4064. }
  4065. }
  4066. /**
  4067. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4068. *
  4069. * @param array $_course array
  4070. * @return void
  4071. */
  4072. function edit_document($_course)
  4073. {
  4074. global $_configuration;
  4075. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  4076. if(strstr($dir, '..'))
  4077. $dir = '/';
  4078. if($dir[0] == '.')
  4079. $dir = substr($dir, 1);
  4080. if($dir[0] != '/')
  4081. $dir = '/'.$dir;
  4082. if($dir[strlen($dir) - 1] != '/')
  4083. $dir .= '/';
  4084. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  4085. if(!is_dir($filepath))
  4086. {
  4087. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4088. $dir = '/';
  4089. }
  4090. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  4091. $sql = "
  4092. SELECT path
  4093. FROM " . $table_doc . "
  4094. WHERE id = " . $_POST['path'];
  4095. $res = api_sql_query($sql, __FILE__, __LINE__);
  4096. $row = Database::fetch_array($res);
  4097. $content = stripslashes($_POST['content_lp']);
  4098. $file = $filepath . $row['path'];
  4099. if($fp = @fopen($file, 'w'))
  4100. {
  4101. $content = text_filter($content);
  4102. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  4103. // change the path of mp3 to absolute
  4104. // first regexp deals with ../../../ urls
  4105. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  4106. //second regexp deals with audio/ urls
  4107. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  4108. fputs($fp, $content);
  4109. fclose($fp);
  4110. }
  4111. }
  4112. /**
  4113. * Displays the selected item, with a panel for manipulating the item
  4114. *
  4115. * @param int $item_id
  4116. * @param string $msg
  4117. * @return string
  4118. */
  4119. function display_item($item_id, $iframe = true, $msg = '')
  4120. {
  4121. global $_course; //will disappear
  4122. $return = '';
  4123. if(is_numeric($item_id))
  4124. {
  4125. $tbl_lp_item = Database::get_course_table('lp_item');
  4126. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4127. $sql = "
  4128. SELECT
  4129. lp.*
  4130. FROM " . $tbl_lp_item . " as lp
  4131. WHERE
  4132. lp.id = " . $item_id;
  4133. $result = api_sql_query($sql, __FILE__, __LINE__);
  4134. while($row = Database::fetch_array($result))
  4135. {
  4136. $_SESSION['parent_item_id'] = ($row['item_type']=='dokeos_chapter' || $row['item_type']=='dokeos_module' || $row['item_type']=='dir')?$item_id:0;
  4137. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4138. $return .= '<div style="padding:10px;">';
  4139. if($msg != '')
  4140. $return .= $msg;
  4141. if($this->encoding=='UTF-8')
  4142. {
  4143. $row['title'] = utf8_decode($row['title']);
  4144. }
  4145. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  4146. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4147. //$return .= '<hr />';
  4148. if($row['item_type'] == TOOL_DOCUMENT)
  4149. {
  4150. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4151. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  4152. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  4153. $path_file=Database::result($result,0,0);
  4154. $path_parts = pathinfo($path_file);
  4155. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  4156. {
  4157. $return .= $this->display_document($row['path'], true, true);
  4158. }
  4159. }
  4160. $return .= '</div>';
  4161. }
  4162. }
  4163. return $return;
  4164. }
  4165. /**
  4166. * Shows the needed forms for editing a specific item
  4167. *
  4168. * @param int $item_id
  4169. * @return string
  4170. */
  4171. function display_edit_item($item_id)
  4172. {
  4173. global $_course; //will disappear
  4174. $return = '';
  4175. if(is_numeric($item_id))
  4176. {
  4177. $tbl_lp_item = Database::get_course_table('lp_item');
  4178. $sql = "
  4179. SELECT *
  4180. FROM " . $tbl_lp_item . "
  4181. WHERE id = " . $item_id;
  4182. $res = api_sql_query($sql, __FILE__, __LINE__);
  4183. $row = Database::fetch_array($res);
  4184. switch($row['item_type'])
  4185. {
  4186. case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
  4187. if(isset($_GET['view']) && $_GET['view'] == 'build')
  4188. {
  4189. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4190. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  4191. }
  4192. else
  4193. {
  4194. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  4195. }
  4196. break;
  4197. case TOOL_DOCUMENT:
  4198. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4199. $sql_step = "
  4200. SELECT
  4201. lp.*,
  4202. doc.path as dir
  4203. FROM " . $tbl_lp_item . " as lp
  4204. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4205. WHERE
  4206. lp.id = " . $item_id;
  4207. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  4208. $row_step = Database::fetch_array($res_step);
  4209. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4210. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4211. break;
  4212. case TOOL_LINK:
  4213. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4214. $return .= $this->display_link_form('edit', $item_id, $row);
  4215. break;
  4216. case 'dokeos_module':
  4217. if(isset($_GET['view']) && $_GET['view'] == 'build')
  4218. {
  4219. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4220. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  4221. }
  4222. else
  4223. {
  4224. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  4225. }
  4226. break;
  4227. case TOOL_QUIZ:
  4228. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4229. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4230. break;
  4231. case TOOL_HOTPOTATOES:
  4232. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4233. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4234. break;
  4235. case TOOL_STUDENTPUBLICATION:
  4236. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4237. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4238. break;
  4239. case TOOL_FORUM:
  4240. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4241. $return .= $this->display_forum_form('edit', $item_id, $row);
  4242. break;
  4243. case TOOL_THREAD:
  4244. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4245. $return .= $this->display_thread_form('edit', $item_id, $row);
  4246. break;
  4247. }
  4248. }
  4249. return $return;
  4250. }
  4251. /**
  4252. * Function that displays a list with al the resources that could be added to the learning path
  4253. *
  4254. * @return string
  4255. */
  4256. function display_resources()
  4257. {
  4258. global $_course; //TODO: don't use globals
  4259. $return .= '<div class="sectiontitle">'.get_lang('CreateNewStep').'</div>';
  4260. $return .= '<div class="sectioncomment"><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.'<img title="Nuevo documento" src="../img/new_doc.gif" alt="Nuevo documento"/> '.get_lang("NewDocument").'</a></div>';
  4261. $return .= '<div class="sectiontitle">'.get_lang('UseAnExistingResource').'</div>';
  4262. $return .= '<div class="sectioncomment">';
  4263. /* get all the docs */
  4264. $return .= $this->get_documents();
  4265. /* get all the exercises */
  4266. $return .= $this->get_exercises();
  4267. /* get all the links */
  4268. $return .= $this->get_links();
  4269. /* get al the student publications */
  4270. $return .= $this->get_student_publications();
  4271. /* get al the forums */
  4272. $return .= $this->get_forums();
  4273. $return .= '</div>';
  4274. return $return;
  4275. }
  4276. /**
  4277. * Returns the extension of a document
  4278. *
  4279. * @param unknown_type $filename
  4280. * @return unknown
  4281. */
  4282. function get_extension($filename)
  4283. {
  4284. $explode = explode('.', $filename);
  4285. return $explode[count($explode) - 1];
  4286. }
  4287. /**
  4288. * Displays a document by id
  4289. *
  4290. * @param unknown_type $id
  4291. * @return unknown
  4292. */
  4293. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  4294. {
  4295. global $_course; //temporary
  4296. $return = '';
  4297. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4298. $sql_doc = "
  4299. SELECT *
  4300. FROM " . $tbl_doc . "
  4301. WHERE id = " . $id;
  4302. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  4303. $row_doc = Database::fetch_array($res_doc);
  4304. //if($show_title)
  4305. //$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $_GET['file'] . '&amp;edit=true&amp;lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
  4306. //TODO: add a path filter
  4307. if($iframe){
  4308. $return .= '<iframe id="learnpath_preview_frame" frameborder="0" height="400" width="100%" scrolling="auto" src="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . str_replace('%2F','/',urlencode($row_doc['path'])) . '?'.api_get_cidreq().'"></iframe>';
  4309. }
  4310. else{
  4311. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4312. }
  4313. return $return;
  4314. }
  4315. /**
  4316. * Return HTML form to add/edit a quiz
  4317. *
  4318. * @param string Action (add/edit)
  4319. * @param integer Item ID if already exists
  4320. * @param mixed Extra information (quiz ID if integer)
  4321. * @return string HTML form
  4322. */
  4323. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  4324. {
  4325. global $charset;
  4326. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  4327. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  4328. if($id != 0 && is_array($extra_info)) {
  4329. $item_title = stripslashes($extra_info['title']);
  4330. $item_description = stripslashes($extra_info['description']);
  4331. } elseif(is_numeric($extra_info)) {
  4332. $sql_quiz = "
  4333. SELECT
  4334. title,
  4335. description
  4336. FROM " . $tbl_quiz . "
  4337. WHERE id = " . $extra_info;
  4338. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  4339. $row = Database::fetch_array($result);
  4340. $item_title = $row['title'];
  4341. $item_description = $row['description'];
  4342. } else {
  4343. $item_title = '';
  4344. $item_description = '';
  4345. }
  4346. $item_title = mb_convert_encoding($item_title,$charset,$this->encoding);
  4347. $return = '<div class="sectiontitle">';
  4348. if($id != 0 && is_array($extra_info))
  4349. $parent = $extra_info['parent_item_id'];
  4350. else
  4351. $parent = 0;
  4352. $sql = "
  4353. SELECT *
  4354. FROM " . $tbl_lp_item . "
  4355. WHERE
  4356. lp_id = " . $this->lp_id;
  4357. $result = api_sql_query($sql, __FILE__, __LINE__);
  4358. $arrLP = array();
  4359. while($row = Database::fetch_array($result)) {
  4360. $arrLP[] = array(
  4361. 'id' => $row['id'],
  4362. 'item_type' => $row['item_type'],
  4363. 'title' => $row['title'],
  4364. 'path' => $row['path'],
  4365. 'description' => $row['description'],
  4366. 'parent_item_id' => $row['parent_item_id'],
  4367. 'previous_item_id' => $row['previous_item_id'],
  4368. 'next_item_id' => $row['next_item_id'],
  4369. 'display_order' => $row['display_order'],
  4370. 'max_score' => $row['max_score'],
  4371. 'min_score' => $row['min_score'],
  4372. 'mastery_score' => $row['mastery_score'],
  4373. 'prerequisite' => $row['prerequisite'],
  4374. 'max_time_allowed' => $row['max_time_allowed']);
  4375. }
  4376. $this->tree_array($arrLP);
  4377. $arrLP = $this->arrMenu;
  4378. unset($this->arrMenu);
  4379. if($action == 'add')
  4380. $return .= get_lang("CreateTheExercise").'&nbsp;:' . "\n";
  4381. elseif($action == 'move')
  4382. $return .= get_lang("MoveTheCurrentExercise").'&nbsp;:' . "\n";
  4383. else
  4384. $return .= get_lang("EditCurrentExecice").'&nbsp;:' . "\n";
  4385. if(isset($_GET['edit']) && $_GET['edit'] == 'true') {
  4386. $return .= '<div class="warning-message">';
  4387. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4388. $return .= get_lang("WarningEditingDocument");
  4389. $return .= '</div>';
  4390. }
  4391. $return .= '</div>';
  4392. $return .= '<div class="sectioncomment">';
  4393. $return .= '<form method="POST">' . "\n";
  4394. $return .= "\t" . '<table>' . "\n";
  4395. if($action != 'move') {
  4396. $return .= "\t\t" . '<tr>' . "\n";
  4397. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  4398. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
  4399. $return .= "\t\t" . '</tr>' . "\n";
  4400. }
  4401. $return .= "\t\t" . '<tr>' . "\n";
  4402. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  4403. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4404. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4405. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4406. $arrHide = array($id);
  4407. $parent_item_id = $_SESSION['parent_item_id'];
  4408. for($i = 0; $i < count($arrLP); $i++) {
  4409. if($action != 'add') {
  4410. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
  4411. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4412. } else {
  4413. $arrHide[] = $arrLP[$i]['id'];
  4414. }
  4415. } else {
  4416. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4417. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4418. }
  4419. }
  4420. if (is_array($arrLP)) {
  4421. reset($arrLP);
  4422. }
  4423. $return .= "\t\t\t\t" . '</select>';
  4424. $return .= "\t\t\t" . '</td>' . "\n";
  4425. $return .= "\t\t" . '</tr>' . "\n";
  4426. $return .= "\t\t" . '<tr>' . "\n";
  4427. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  4428. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4429. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4430. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4431. for($i = 0; $i < count($arrLP); $i++) {
  4432. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4433. {
  4434. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4435. $selected = 'selected="selected" ';
  4436. elseif($action == 'add')
  4437. $selected = 'selected="selected" ';
  4438. else
  4439. $selected = '';
  4440. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  4441. }
  4442. }
  4443. $return .= "\t\t\t\t" . '</select>';
  4444. $return .= "\t\t\t" . '</td>' . "\n";
  4445. $return .= "\t\t" . '</tr>' . "\n";
  4446. if($action != 'move') {
  4447. $id_prerequisite=0;
  4448. if (is_array($arrLP )) {
  4449. foreach($arrLP as $key=>$value){
  4450. if($value['id']==$id){
  4451. $id_prerequisite=$value['prerequisite'];
  4452. break;
  4453. }
  4454. }
  4455. }
  4456. $arrHide=array();
  4457. for($i = 0; $i < count($arrLP); $i++) {
  4458. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4459. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4460. $s_selected_position=$arrLP[$i]['id'];
  4461. elseif($action == 'add')
  4462. $s_selected_position=0;
  4463. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4464. }
  4465. }
  4466. /*//comented the prerequisites, only visible in edit (exercise)
  4467. $return .= "\t\t" . '<tr>' . "\n";
  4468. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4469. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4470. foreach($arrHide as $key => $value){
  4471. if($key==$s_selected_position && $action == 'add'){
  4472. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4473. }
  4474. elseif($key==$id_prerequisite && $action == 'edit'){
  4475. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4476. }
  4477. else{
  4478. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4479. }
  4480. }
  4481. $return .= "</select></td>";
  4482. */
  4483. $return .= "\t\t" . '</tr>' . "\n";
  4484. $return .= "\t\t" . '<tr>' . "\n";
  4485. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">'.get_lang('MaxTimeAllowed').'</label></td>' . "\n";
  4486. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4487. //Remove temporaly the test description
  4488. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4489. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4490. $return .= "\t\t" . '</tr>' . "\n";
  4491. }
  4492. $return .= "\t\t" . '<tr>' . "\n";
  4493. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">'.get_lang('AddExercise').'</button></td>' . "\n";
  4494. $return .= "\t\t" . '</tr>' . "\n";
  4495. $return .= "\t" . '</table>' . "\n";
  4496. if($action == 'move') {
  4497. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4498. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4499. }
  4500. if(is_numeric($extra_info)) {
  4501. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4502. } elseif(is_array($extra_info)) {
  4503. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4504. }
  4505. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  4506. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4507. $return .= '</form>' . "\n";
  4508. $return .= '</div>' . "\n";
  4509. return $return;
  4510. }
  4511. /**
  4512. * Addition of Hotpotatoes tests
  4513. * @param string Action
  4514. * @param integer Internal ID of the item
  4515. * @param mixed Extra information - can be an array with title and description indexes
  4516. * @return string HTML structure to display the hotpotatoes addition formular
  4517. */
  4518. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
  4519. {
  4520. global $charset;
  4521. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4522. $tbl_lp_item = Database::get_course_table('lp_item');
  4523. if($id != 0 && is_array($extra_info))
  4524. {
  4525. $item_title = stripslashes($extra_info['title']);
  4526. $item_description = stripslashes($extra_info['description']);
  4527. }
  4528. elseif(is_numeric($extra_info))
  4529. {
  4530. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  4531. $sql_hot = "SELECT * FROM ".$TBL_DOCUMENT."
  4532. WHERE path LIKE '".$uploadPath."/%/%htm%'
  4533. ORDER BY id ASC";
  4534. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  4535. $row = Database::fetch_array($res_hot);
  4536. $item_title = $row['title'];
  4537. $item_description = $row['description'];
  4538. }
  4539. else
  4540. {
  4541. $item_title = '';
  4542. $item_description = '';
  4543. }
  4544. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4545. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4546. $return = '<div style="margin:3px 12px;">';
  4547. if($id != 0 && is_array($extra_info))
  4548. $parent = $extra_info['parent_item_id'];
  4549. else
  4550. $parent = 0;
  4551. $sql = "
  4552. SELECT *
  4553. FROM " . $tbl_lp_item . "
  4554. WHERE
  4555. lp_id = " . $this->lp_id;
  4556. $result = api_sql_query($sql, __FILE__, __LINE__);
  4557. $arrLP = array();
  4558. while($row = Database::fetch_array($result))
  4559. {
  4560. $arrLP[] = array(
  4561. 'id' => $row['id'],
  4562. 'item_type' => $row['item_type'],
  4563. 'title' => $row['title'],
  4564. 'path' => $row['path'],
  4565. 'description' => $row['description'],
  4566. 'parent_item_id' => $row['parent_item_id'],
  4567. 'previous_item_id' => $row['previous_item_id'],
  4568. 'next_item_id' => $row['next_item_id'],
  4569. 'display_order' => $row['display_order'],
  4570. 'max_score' => $row['max_score'],
  4571. 'min_score' => $row['min_score'],
  4572. 'mastery_score' => $row['mastery_score'],
  4573. 'prerequisite' => $row['prerequisite'],
  4574. 'max_time_allowed' => $row['max_time_allowed']);
  4575. }
  4576. $this->tree_array($arrLP);
  4577. $arrLP = $this->arrMenu;
  4578. unset($this->arrMenu);
  4579. if($action == 'add')
  4580. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").'&nbsp;:</p>' . "\n";
  4581. elseif($action == 'move')
  4582. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").'&nbsp;:</p>' . "\n";
  4583. else
  4584. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").'&nbsp;:</p>' . "\n";
  4585. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4586. {
  4587. $return .= '<div class="warning-message">';
  4588. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4589. $return .= get_lang("WarningEditingDocument");
  4590. $return .= '</div>';
  4591. }
  4592. $return .= '<form method="POST">' . "\n";
  4593. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4594. $return .= "\t\t" . '<tr>' . "\n";
  4595. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4596. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4597. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4598. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4599. $arrHide = array($id);
  4600. for($i = 0; $i < count($arrLP); $i++)
  4601. {
  4602. if($action != 'add')
  4603. {
  4604. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4605. {
  4606. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4607. }
  4608. else
  4609. {
  4610. $arrHide[] = $arrLP[$i]['id'];
  4611. }
  4612. }
  4613. else
  4614. {
  4615. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4616. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4617. }
  4618. }
  4619. reset($arrLP);
  4620. $return .= "\t\t\t\t" . '</select>';
  4621. $return .= "\t\t\t" . '</td>' . "\n";
  4622. $return .= "\t\t" . '</tr>' . "\n";
  4623. $return .= "\t\t" . '<tr>' . "\n";
  4624. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4625. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4626. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4627. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4628. for($i = 0; $i < count($arrLP); $i++)
  4629. {
  4630. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4631. {
  4632. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4633. $selected = 'selected="selected" ';
  4634. elseif($action == 'add')
  4635. $selected = 'selected="selected" ';
  4636. else
  4637. $selected = '';
  4638. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  4639. }
  4640. }
  4641. $return .= "\t\t\t\t" . '</select>';
  4642. $return .= "\t\t\t" . '</td>' . "\n";
  4643. $return .= "\t\t" . '</tr>' . "\n";
  4644. if($action != 'move')
  4645. {
  4646. $return .= "\t\t" . '<tr>' . "\n";
  4647. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4648. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4649. $return .= "\t\t" . '</tr>' . "\n";
  4650. $id_prerequisite=0;
  4651. foreach($arrLP as $key=>$value){
  4652. if($value['id']==$id){
  4653. $id_prerequisite=$value['prerequisite'];
  4654. break;
  4655. }
  4656. }
  4657. $arrHide=array();
  4658. for($i = 0; $i < count($arrLP); $i++)
  4659. {
  4660. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4661. {
  4662. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4663. $s_selected_position=$arrLP[$i]['id'];
  4664. elseif($action == 'add')
  4665. $s_selected_position=0;
  4666. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4667. }
  4668. }
  4669. $return .= "\t\t" . '<tr>' . "\n";
  4670. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4671. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4672. foreach($arrHide as $key => $value){
  4673. if($key==$s_selected_position && $action == 'add'){
  4674. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4675. }
  4676. elseif($key==$id_prerequisite && $action == 'edit'){
  4677. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4678. }
  4679. else{
  4680. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4681. }
  4682. }
  4683. $return .= "</select></td>";
  4684. $return .= "\t\t" . '</tr>' . "\n";
  4685. $return .= "\t\t" . '<tr>' . "\n";
  4686. //Remove temporaly the test description
  4687. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4688. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4689. $return .= "\t\t" . '</tr>' . "\n";
  4690. }
  4691. $return .= "\t\t" . '<tr>' . "\n";
  4692. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  4693. $return .= "\t\t" . '</tr>' . "\n";
  4694. $return .= "\t" . '</table>' . "\n";
  4695. if($action == 'move')
  4696. {
  4697. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4698. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4699. }
  4700. if(is_numeric($extra_info))
  4701. {
  4702. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4703. }
  4704. elseif(is_array($extra_info))
  4705. {
  4706. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4707. }
  4708. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />' . "\n";
  4709. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4710. $return .= '</form>' . "\n";
  4711. $return .= '</div>' . "\n";
  4712. return $return;
  4713. }
  4714. //fin du hotpot form
  4715. /**
  4716. * Return the form to display the forum edit/add option
  4717. *
  4718. * @param string Action (add/edit)
  4719. * @param integer ID of the lp_item if already exists
  4720. * @param mixed Forum ID or title
  4721. * @return string HTML form
  4722. */
  4723. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  4724. {
  4725. global $charset;
  4726. $tbl_lp_item = Database::get_course_table('lp_item');
  4727. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  4728. if($id != 0 && is_array($extra_info)) {
  4729. $item_title = stripslashes($extra_info['title']);
  4730. } elseif(is_numeric($extra_info)) {
  4731. $sql_forum = "
  4732. SELECT
  4733. forum_title as title, forum_comment as comment
  4734. FROM " . $tbl_forum . "
  4735. WHERE forum_id = " . $extra_info;
  4736. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4737. $row = Database::fetch_array($result);
  4738. $item_title = $row['title'];
  4739. $item_description = $row['comment'];
  4740. } else {
  4741. $item_title = '';
  4742. $item_description = '';
  4743. }
  4744. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4745. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4746. $return = '<div class="sectiontitle">';
  4747. if($id != 0 && is_array($extra_info))
  4748. $parent = $extra_info['parent_item_id'];
  4749. else
  4750. $parent = 0;
  4751. $sql = "
  4752. SELECT *
  4753. FROM " . $tbl_lp_item . "
  4754. WHERE
  4755. lp_id = " . $this->lp_id;
  4756. $result = api_sql_query($sql, __FILE__, __LINE__);
  4757. $arrLP = array();
  4758. while($row = Database::fetch_array($result)) {
  4759. $arrLP[] = array(
  4760. 'id' => $row['id'],
  4761. 'item_type' => $row['item_type'],
  4762. 'title' => $row['title'],
  4763. 'path' => $row['path'],
  4764. 'description' => $row['description'],
  4765. 'parent_item_id' => $row['parent_item_id'],
  4766. 'previous_item_id' => $row['previous_item_id'],
  4767. 'next_item_id' => $row['next_item_id'],
  4768. 'display_order' => $row['display_order'],
  4769. 'max_score' => $row['max_score'],
  4770. 'min_score' => $row['min_score'],
  4771. 'mastery_score' => $row['mastery_score'],
  4772. 'prerequisite' => $row['prerequisite']);
  4773. }
  4774. $this->tree_array($arrLP);
  4775. $arrLP = $this->arrMenu;
  4776. unset($this->arrMenu);
  4777. if($action == 'add')
  4778. $return .= get_lang("CreateTheForum").'&nbsp;:' . "\n";
  4779. elseif($action == 'move')
  4780. $return .= get_lang("MoveTheCurrentForum").'&nbsp;:' . "\n";
  4781. else
  4782. $return .= get_lang("EditCurrentForum").'&nbsp;:' . "\n";
  4783. $return .= '</div>';
  4784. $return .= '<div class="sectioncomment">';
  4785. $return .= '<form method="POST">' . "\n";
  4786. $return .= "\t" . '<table>' . "\n";
  4787. if($action != 'move') {
  4788. $return .= "\t\t" . '<tr>' . "\n";
  4789. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  4790. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  4791. $return .= "\t\t" . '</tr>' . "\n";
  4792. }
  4793. $return .= "\t\t" . '<tr>' . "\n";
  4794. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  4795. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4796. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4797. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4798. $arrHide = array($id);
  4799. $parent_item_id = $_SESSION['parent_item_id'];
  4800. for($i = 0; $i < count($arrLP); $i++)
  4801. {
  4802. if($action != 'add')
  4803. {
  4804. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  4805. {
  4806. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4807. }
  4808. else
  4809. {
  4810. $arrHide[] = $arrLP[$i]['id'];
  4811. }
  4812. }
  4813. else
  4814. {
  4815. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4816. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  4817. }
  4818. }
  4819. if (is_array($arrLP)) {
  4820. reset($arrLP);
  4821. }
  4822. $return .= "\t\t\t\t" . '</select>';
  4823. $return .= "\t\t\t" . '</td>' . "\n";
  4824. $return .= "\t\t" . '</tr>' . "\n";
  4825. $return .= "\t\t" . '<tr>' . "\n";
  4826. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  4827. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4828. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  4829. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4830. for($i = 0; $i < count($arrLP); $i++)
  4831. {
  4832. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4833. {
  4834. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4835. $selected = 'selected="selected" ';
  4836. elseif($action == 'add')
  4837. $selected = 'selected="selected" ';
  4838. else
  4839. $selected = '';
  4840. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  4841. }
  4842. }
  4843. $return .= "\t\t\t\t" . '</select>';
  4844. $return .= "\t\t\t" . '</td>' . "\n";
  4845. $return .= "\t\t" . '</tr>' . "\n";
  4846. if($action != 'move')
  4847. {
  4848. $return .= "\t\t" . '<tr>' . "\n";
  4849. //Remove temporaly the test description
  4850. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4851. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4852. $return .= "\t\t" . '</tr>' . "\n";
  4853. $id_prerequisite=0;
  4854. if (is_array($arrLP)) {
  4855. foreach($arrLP as $key=>$value){
  4856. if($value['id']==$id){
  4857. $id_prerequisite=$value['prerequisite'];
  4858. break;
  4859. }
  4860. }
  4861. }
  4862. $arrHide=array();
  4863. for($i = 0; $i < count($arrLP); $i++) {
  4864. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4865. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4866. $s_selected_position=$arrLP[$i]['id'];
  4867. elseif($action == 'add')
  4868. $s_selected_position=0;
  4869. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4870. }
  4871. }
  4872. /* //comented the prerequisites, only visible in edit (forum)
  4873. $return .= "\t\t" . '<tr>' . "\n";
  4874. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4875. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4876. foreach($arrHide as $key => $value) {
  4877. if($key==$s_selected_position && $action == 'add') {
  4878. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4879. }elseif($key==$id_prerequisite && $action == 'edit') {
  4880. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4881. } else {
  4882. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4883. }
  4884. }
  4885. $return .= "</select></td>";
  4886. */
  4887. $return .= "\t\t" . '</tr>' . "\n";
  4888. }
  4889. $return .= "\t\t" . '<tr>' . "\n";
  4890. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> '.get_lang('Ok').' </button></td>' . "\n";
  4891. $return .= "\t\t" . '</tr>' . "\n";
  4892. $return .= "\t" . '</table>' . "\n";
  4893. if($action == 'move') {
  4894. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4895. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4896. }
  4897. if(is_numeric($extra_info)) {
  4898. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4899. } elseif(is_array($extra_info)) {
  4900. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4901. }
  4902. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  4903. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4904. $return .= '</form>' . "\n";
  4905. $return .= '</div>' . "\n";
  4906. return $return;
  4907. }
  4908. /**
  4909. * Return HTML form to add/edit forum threads
  4910. * @param string Action (add/edit)
  4911. * @param integer Item ID if already exists in learning path
  4912. * @param mixed Extra information (thread ID if integer)
  4913. * @return string HTML form
  4914. */
  4915. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  4916. {
  4917. global $charset;
  4918. echo '
  4919. <style>
  4920. div.row div.label {
  4921. width:110px;
  4922. }
  4923. div.row div.formw {
  4924. width: 82%;
  4925. }
  4926. </style>';
  4927. $tbl_lp_item = Database::get_course_table('lp_item');
  4928. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  4929. if($id != 0 && is_array($extra_info))
  4930. {
  4931. $item_title = stripslashes($extra_info['title']);
  4932. }
  4933. elseif(is_numeric($extra_info))
  4934. {
  4935. $sql_forum = "
  4936. SELECT
  4937. thread_title as title
  4938. FROM " . $tbl_forum . "
  4939. WHERE thread_id = " . $extra_info;
  4940. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4941. $row = Database::fetch_array($result);
  4942. $item_title = $row['title'];
  4943. $item_description = '';
  4944. }
  4945. else
  4946. {
  4947. $item_title = '';
  4948. $item_description = '';
  4949. }
  4950. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4951. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4952. $return = '<div style="margin:3px 12px;">';
  4953. if($id != 0 && is_array($extra_info))
  4954. $parent = $extra_info['parent_item_id'];
  4955. else
  4956. $parent = 0;
  4957. $sql = "
  4958. SELECT *
  4959. FROM " . $tbl_lp_item . "
  4960. WHERE
  4961. lp_id = " . $this->lp_id;
  4962. $result = api_sql_query($sql, __FILE__, __LINE__);
  4963. $arrLP = array();
  4964. while($row = Database::fetch_array($result))
  4965. {
  4966. $arrLP[] = array(
  4967. 'id' => $row['id'],
  4968. 'item_type' => $row['item_type'],
  4969. 'title' => $row['title'],
  4970. 'path' => $row['path'],
  4971. 'description' => $row['description'],
  4972. 'parent_item_id' => $row['parent_item_id'],
  4973. 'previous_item_id' => $row['previous_item_id'],
  4974. 'next_item_id' => $row['next_item_id'],
  4975. 'display_order' => $row['display_order'],
  4976. 'max_score' => $row['max_score'],
  4977. 'min_score' => $row['min_score'],
  4978. 'mastery_score' => $row['mastery_score'],
  4979. 'prerequisite' => $row['prerequisite']);
  4980. }
  4981. $this->tree_array($arrLP);
  4982. $arrLP = $this->arrMenu;
  4983. unset($this->arrMenu);
  4984. if($action == 'add')
  4985. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").'&nbsp;:</p>' . "\n";
  4986. elseif($action == 'move')
  4987. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").'&nbsp;:</p>' . "\n";
  4988. else
  4989. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").'&nbsp;:</p>' . "\n";
  4990. $return .= '<form method="POST">' . "\n";
  4991. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4992. $return .= "\t\t" . '<tr>' . "\n";
  4993. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").'&nbsp;:</label></td>' . "\n";
  4994. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4995. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4996. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4997. $arrHide = array($id);
  4998. for($i = 0; $i < count($arrLP); $i++)
  4999. {
  5000. if($action != 'add')
  5001. {
  5002. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  5003. {
  5004. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5005. }
  5006. else
  5007. {
  5008. $arrHide[] = $arrLP[$i]['id'];
  5009. }
  5010. }
  5011. else
  5012. {
  5013. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5014. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5015. }
  5016. }
  5017. if ($arrLP!=null) {
  5018. reset($arrLP);
  5019. }
  5020. $return .= "\t\t\t\t" . '</select>';
  5021. $return .= "\t\t\t" . '</td>' . "\n";
  5022. $return .= "\t\t" . '</tr>' . "\n";
  5023. $return .= "\t\t" . '<tr>' . "\n";
  5024. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").'&nbsp;:</label></td>' . "\n";
  5025. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5026. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5027. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  5028. for($i = 0; $i < count($arrLP); $i++)
  5029. {
  5030. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5031. {
  5032. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5033. $selected = 'selected="selected" ';
  5034. elseif($action == 'add')
  5035. $selected = 'selected="selected" ';
  5036. else
  5037. $selected = '';
  5038. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  5039. }
  5040. }
  5041. $return .= "\t\t\t\t" . '</select>';
  5042. $return .= "\t\t\t" . '</td>' . "\n";
  5043. $return .= "\t\t" . '</tr>' . "\n";
  5044. if($action != 'move')
  5045. {
  5046. $return .= "\t\t" . '<tr>' . "\n";
  5047. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").'&nbsp;:</label></td>' . "\n";
  5048. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5049. $return .= "\t\t" . '</tr>' . "\n";
  5050. $return .= "\t\t" . '<tr>' . "\n";
  5051. //Remove temporaly the test description
  5052. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  5053. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5054. $return .= "\t\t" . '</tr>' . "\n";
  5055. $id_prerequisite=0;
  5056. if ($arrLP!=null) {
  5057. foreach($arrLP as $key=>$value){
  5058. if($value['id']==$id){
  5059. $id_prerequisite=$value['prerequisite'];
  5060. break;
  5061. }
  5062. }
  5063. }
  5064. $arrHide=array();
  5065. for($i = 0; $i < count($arrLP); $i++)
  5066. {
  5067. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5068. {
  5069. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5070. $s_selected_position=$arrLP[$i]['id'];
  5071. elseif($action == 'add')
  5072. $s_selected_position=0;
  5073. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5074. }
  5075. }
  5076. $return .= "\t\t" . '<tr>' . "\n";
  5077. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").'&nbsp;:</label></td>' . "\n";
  5078. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5079. foreach($arrHide as $key => $value){
  5080. if($key==$s_selected_position && $action == 'add'){
  5081. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5082. }
  5083. elseif($key==$id_prerequisite && $action == 'edit'){
  5084. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5085. }
  5086. else{
  5087. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5088. }
  5089. }
  5090. $return .= "</select></td>";
  5091. $return .= "\t\t" . '</tr>' . "\n";
  5092. }
  5093. $return .= "\t\t" . '<tr>' . "\n";
  5094. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  5095. $return .= "\t\t" . '</tr>' . "\n";
  5096. $return .= "\t" . '</table>' . "\n";
  5097. if($action == 'move')
  5098. {
  5099. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5100. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5101. }
  5102. if(is_numeric($extra_info))
  5103. {
  5104. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5105. }
  5106. elseif(is_array($extra_info))
  5107. {
  5108. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5109. }
  5110. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  5111. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5112. $return .= '</form>' . "\n";
  5113. $return .= '</div>' . "\n";
  5114. return $return;
  5115. }
  5116. /**
  5117. * Return the HTML form to display an item (generally a section/module item)
  5118. *
  5119. * @param string Item type (module/dokeos_module)
  5120. * @param string Title (optional, only when creating)
  5121. * @param string Action ('add'/'edit')
  5122. * @param integer lp_item ID
  5123. * @param mixed Extra info
  5124. * @return string HTML form
  5125. */
  5126. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  5127. {
  5128. global $_course;
  5129. global $charset;
  5130. $tbl_lp_item = Database::get_course_table('lp_item');
  5131. if($id != 0 && is_array($extra_info))
  5132. {
  5133. $item_title = $extra_info['title'];
  5134. $item_description = $extra_info['description'];
  5135. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
  5136. }
  5137. else
  5138. {
  5139. $item_title = '';
  5140. $item_description = '';
  5141. }
  5142. $return = '<div class="sectiontitle">';
  5143. if($id != 0 && is_array($extra_info))
  5144. $parent = $extra_info['parent_item_id'];
  5145. else
  5146. $parent = 0;
  5147. $sql = "
  5148. SELECT *
  5149. FROM " . $tbl_lp_item . "
  5150. WHERE lp_id = " . $this->lp_id. " AND id != " . $id. " ";
  5151. if($item_type == 'module')
  5152. $sql .= " AND parent_item_id = 0";
  5153. $result = api_sql_query($sql, __FILE__, __LINE__);
  5154. $arrLP = array();
  5155. while($row = Database::fetch_array($result))
  5156. {
  5157. $arrLP[] = array(
  5158. 'id' => $row['id'],
  5159. 'item_type' => $row['item_type'],
  5160. 'title' => $row['title'],
  5161. 'path' => $row['path'],
  5162. 'description' => $row['description'],
  5163. 'parent_item_id' => $row['parent_item_id'],
  5164. 'previous_item_id' => $row['previous_item_id'],
  5165. 'next_item_id' => $row['next_item_id'],
  5166. 'max_score' => $row['max_score'],
  5167. 'min_score' => $row['min_score'],
  5168. 'mastery_score' => $row['mastery_score'],
  5169. 'prerequisite' => $row['prerequisite'],
  5170. 'display_order' => $row['display_order']);
  5171. }
  5172. $this->tree_array($arrLP);
  5173. $arrLP = $this->arrMenu;
  5174. unset($this->arrMenu);
  5175. $return .= $title . "\n";
  5176. $return .= '</div>';
  5177. $return .= '<div class="sectioncomment">';
  5178. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5179. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  5180. $defaults["title"]=mb_convert_encoding($item_title,$charset,$this->encoding);
  5181. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5182. $form->addElement('html',$return);
  5183. //$arrHide = array($id);
  5184. $arrHide[0]['value']=$this->name;
  5185. $arrHide[0]['padding']=3;
  5186. if($item_type != 'module' && $item_type != 'dokeos_module')
  5187. {
  5188. for($i = 0; $i < count($arrLP); $i++)
  5189. {
  5190. if($action != 'add')
  5191. {
  5192. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  5193. {
  5194. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5195. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5196. if($parent == $arrLP[$i]['id'])
  5197. {
  5198. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5199. }
  5200. }
  5201. }
  5202. else
  5203. {
  5204. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5205. {
  5206. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5207. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5208. if($parent == $arrLP[$i]['id'])
  5209. {
  5210. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5211. }
  5212. }
  5213. }
  5214. }
  5215. if($action != 'move')
  5216. {
  5217. $form->addElement('text','title', get_lang('Title'),'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5218. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5219. }
  5220. else
  5221. {
  5222. $form->addElement('hidden','title');
  5223. }
  5224. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" style="width:37%;" id="Parent" onchange="load_cbo(this.value);"');
  5225. foreach($arrHide as $key => $value)
  5226. {
  5227. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5228. }
  5229. $parent_select -> setSelected($s_selected_parent);
  5230. }
  5231. if(is_array($arrLP)) { reset($arrLP); }
  5232. $arrHide=array();
  5233. //POSITION
  5234. for($i = 0; $i < count($arrLP); $i++)
  5235. {
  5236. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5237. {
  5238. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5239. $s_selected_position=$arrLP[$i]['id'];
  5240. elseif($action == 'add')
  5241. $s_selected_position=$arrLP[$i]['id'];
  5242. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5243. }
  5244. }
  5245. $position = &$form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5246. $position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'.$value['padding'].'px;"');
  5247. foreach($arrHide as $key => $value)
  5248. {
  5249. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5250. }
  5251. if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
  5252. if(is_array($arrLP)) { reset($arrLP); }
  5253. $form->addElement('style_submit_button', 'submit_button', get_lang('Save'),'class="save"');
  5254. if($item_type == 'module' || $item_type == 'dokeos_module')
  5255. {
  5256. $form->addElement('hidden', 'parent', '0');
  5257. }
  5258. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5259. if(($item_type=='asset' || $item_type=='sco') && ($extension == 'html' || $extension == 'htm'))
  5260. {
  5261. if($item_type=='sco')
  5262. {
  5263. $form->addElement('html','<script type="text/javascript">alert("'.get_lang('WarningWhenEditingScorm').'")</script>');
  5264. }
  5265. $renderer = $form->defaultRenderer();
  5266. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5267. $form->addElement('html_editor','content_lp','');
  5268. //$form->addElement('html_editor','content_lp','');
  5269. $defaults["content_lp"]=file_get_contents($item_path);
  5270. }
  5271. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  5272. $form->addElement('hidden', 'post_time', time());
  5273. $form->setDefaults($defaults);
  5274. $form->addElement('html','</div>');
  5275. return $form->return_form();
  5276. }
  5277. /**
  5278. * Returns the form to update or create a document
  5279. *
  5280. * @param string Action (add/edit)
  5281. * @param integer ID of the lp_item (if already exists)
  5282. * @param mixed Integer if document ID, string if info ('new')
  5283. * @return string HTML form
  5284. */
  5285. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  5286. {
  5287. global $charset;
  5288. $tbl_lp_item = Database::get_course_table('lp_item');
  5289. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5290. $path_parts = pathinfo($extra_info['dir']);
  5291. $no_display_edit_textarea=false;
  5292. //If action==edit document
  5293. //We don't display the document form if it's not an editable document (html or txt file)
  5294. if($action=="edit"){
  5295. if(is_array($extra_info)){
  5296. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5297. $no_display_edit_textarea=true;
  5298. }
  5299. }
  5300. }
  5301. $no_display_add=false;
  5302. //If action==add an existing document
  5303. //We don't display the document form if it's not an editable document (html or txt file)
  5304. if($action=="add"){
  5305. if(is_numeric($extra_info)){
  5306. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  5307. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  5308. $path_file=Database::result($result,0,0);
  5309. $path_parts = pathinfo($path_file);
  5310. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5311. $no_display_add=true;
  5312. }
  5313. }
  5314. }
  5315. if($id != 0 && is_array($extra_info))
  5316. {
  5317. $item_title = stripslashes($extra_info['title']);
  5318. $item_description = stripslashes($extra_info['description']);
  5319. $item_terms = stripslashes($extra_info['terms']);
  5320. if(empty($item_title))
  5321. {
  5322. $path_parts = pathinfo($extra_info['path']);
  5323. $item_title = stripslashes($path_parts['filename']);
  5324. }
  5325. }
  5326. elseif(is_numeric($extra_info))
  5327. {
  5328. $sql_doc = "
  5329. SELECT path, title
  5330. FROM " . $tbl_doc . "
  5331. WHERE id = " . $extra_info;
  5332. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  5333. $row = Database::fetch_array($result);
  5334. $explode = explode('.', $row['title']);
  5335. if(count($explode)>1){
  5336. for($i = 0; $i < count($explode) - 1; $i++)
  5337. $item_title .= $explode[$i];
  5338. }
  5339. else{
  5340. $item_title=$row['title'];
  5341. }
  5342. $item_title = str_replace('_', ' ', $item_title);
  5343. if(empty($item_title))
  5344. {
  5345. $path_parts = pathinfo($row['path']);
  5346. $item_title = stripslashes($path_parts['filename']);
  5347. }
  5348. }
  5349. else
  5350. {
  5351. $item_title = '';
  5352. $item_description = '';
  5353. }
  5354. $return = '<div class="sectiontitle">';
  5355. if($id != 0 && is_array($extra_info))
  5356. $parent = $extra_info['parent_item_id'];
  5357. else
  5358. $parent = 0;
  5359. $sql = "
  5360. SELECT *
  5361. FROM " . $tbl_lp_item . "
  5362. WHERE
  5363. lp_id = " . $this->lp_id;
  5364. $result = api_sql_query($sql, __FILE__, __LINE__);
  5365. $arrLP = array();
  5366. while($row = Database::fetch_array($result))
  5367. {
  5368. $arrLP[] = array(
  5369. 'id' => $row['id'],
  5370. 'item_type' => $row['item_type'],
  5371. 'title' => $row['title'],
  5372. 'path' => $row['path'],
  5373. 'description' => $row['description'],
  5374. 'parent_item_id' => $row['parent_item_id'],
  5375. 'previous_item_id' => $row['previous_item_id'],
  5376. 'next_item_id' => $row['next_item_id'],
  5377. 'display_order' => $row['display_order'],
  5378. 'max_score' => $row['max_score'],
  5379. 'min_score' => $row['min_score'],
  5380. 'mastery_score' => $row['mastery_score'],
  5381. 'prerequisite' => $row['prerequisite']);
  5382. }
  5383. $this->tree_array($arrLP);
  5384. $arrLP = $this->arrMenu;
  5385. unset($this->arrMenu);
  5386. if($action == 'add')
  5387. {
  5388. $return .= get_lang("CreateTheDocument") . "\n";
  5389. }
  5390. elseif($action == 'move')
  5391. {
  5392. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5393. }
  5394. else
  5395. {
  5396. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5397. }
  5398. $return .= '</div>';
  5399. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  5400. {
  5401. $return .= '<div class="warning-message">';
  5402. $return .= '<strong>'.get_lang("Warning").' !</strong><br />';
  5403. $return .= get_lang("WarningEditingDocument");
  5404. $return .= '</div>';
  5405. }
  5406. /*
  5407. if($no_display_add==true){
  5408. $return .= '<div class="warning-message">';
  5409. $return .= get_lang("CantEditDocument");
  5410. $return .= '</div>';
  5411. return $return;
  5412. }
  5413. */
  5414. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5415. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"],'','enctype="multipart/form-data"');
  5416. $defaults["title"] = html_entity_decode($item_title);
  5417. $defaults["title"]=mb_convert_encoding($defaults["title"],$charset,$this->encoding);
  5418. if(empty($defaults["title"]))
  5419. {
  5420. $defaults["title"] = html_entity_decode($item_title);
  5421. }
  5422. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5423. $form->addElement('html',$return);
  5424. if($action != 'move')
  5425. {
  5426. $form->addElement('text','title', get_lang('Title'),'id="idTitle" class="learnpath_item_form" size=44%');
  5427. }
  5428. //$arrHide = array($id);
  5429. $arrHide[0]['value']=$this->name;
  5430. $arrHide[0]['padding']=3;
  5431. for($i = 0; $i < count($arrLP); $i++)
  5432. {
  5433. if($action != 'add'){
  5434. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)){
  5435. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5436. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5437. if($parent == $arrLP[$i]['id']){
  5438. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5439. }
  5440. }
  5441. }
  5442. else{
  5443. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  5444. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5445. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5446. if($parent == $arrLP[$i]['id']){
  5447. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5448. }
  5449. }
  5450. }
  5451. }
  5452. $parent_select = &$form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
  5453. foreach($arrHide as $key => $value) {
  5454. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5455. }
  5456. if (!empty($id)) {
  5457. $parent_select -> setSelected($parent);
  5458. } else {
  5459. $parent_item_id = $_SESSION['parent_item_id'];
  5460. $parent_select -> setSelected($parent_item_id);
  5461. }
  5462. if(is_array($arrLP)) {
  5463. reset($arrLP);
  5464. }
  5465. $arrHide=array();
  5466. //POSITION
  5467. for($i = 0; $i < count($arrLP); $i++) {
  5468. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5469. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5470. $s_selected_position=$arrLP[$i]['id'];
  5471. elseif($action == 'add')
  5472. $s_selected_position=$arrLP[$i]['id'];
  5473. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding).'"';
  5474. }
  5475. }
  5476. $position = &$form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5477. $position->addOption(get_lang("FirstPosition"),0);
  5478. foreach($arrHide as $key => $value) {
  5479. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5480. }
  5481. $position -> setSelected($s_selected_position);
  5482. if(is_array($arrLP)) {
  5483. reset($arrLP);
  5484. }
  5485. if($action != 'move') {
  5486. $id_prerequisite=0;
  5487. if(is_array($arrLP)) {
  5488. foreach($arrLP as $key=>$value){
  5489. if($value['id']==$id){
  5490. $id_prerequisite=$value['prerequisite'];
  5491. break;
  5492. }
  5493. }
  5494. }
  5495. //comented the prerequisites, only visible in edit (new document)
  5496. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5497. //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5498. // form element for uploading an mp3 file
  5499. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5500. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5501. /* Code deprecated - moved to lp level (not lp-item)
  5502. if ( api_get_setting('search_enabled') === 'true' )
  5503. {
  5504. //add terms field
  5505. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5506. $terms->setValue($item_terms);
  5507. }
  5508. */
  5509. $arrHide=array();
  5510. for($i = 0; $i < count($arrLP); $i++)
  5511. {
  5512. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5513. {
  5514. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5515. $s_selected_position=$arrLP[$i]['id'];
  5516. elseif($action == 'add')
  5517. $s_selected_position=$arrLP[$i]['id'];
  5518. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5519. }
  5520. }
  5521. /* foreach($arrHide as $key => $value){
  5522. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5523. if($key==$s_selected_position && $action == 'add'){
  5524. $select_prerequisites -> setSelected(0);
  5525. }
  5526. elseif($key==$id_prerequisite && $action == 'edit'){
  5527. $select_prerequisites -> setSelected($id_prerequisite);
  5528. }
  5529. }
  5530. */
  5531. if(!$no_display_add)
  5532. {
  5533. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  5534. {
  5535. if(isset($_POST['content']))
  5536. $content = stripslashes($_POST['content']);
  5537. elseif(is_array($extra_info)){
  5538. //If it's an html document or a text file
  5539. if(!$no_display_edit_textarea){
  5540. $content = $this->display_document($extra_info['path'], false, false);
  5541. }
  5542. }
  5543. elseif(is_numeric($extra_info))
  5544. $content = $this->display_document($extra_info, false, false);
  5545. else
  5546. $content = '';
  5547. if(!$no_display_edit_textarea)
  5548. {
  5549. // We need to claculate here some specific settings for the online editor.
  5550. // The calculated settings work for documents in the Documents tool
  5551. // (on the root or in subfolders).
  5552. // For documents in native scorm packages it is unclear whether the
  5553. // online editor should be activated or not.
  5554. global $fck_attribute;
  5555. $fck_attribute['Width'] = '100%';
  5556. $fck_attribute['Height'] = '700';
  5557. $fck_attribute['ToolbarSet'] = 'LearnPath';
  5558. $fck_attribute['Config']['FullPage'] = true;
  5559. $relative_path = $extra_info['dir'];
  5560. if ($relative_path == 'n/')
  5561. {
  5562. // A new document, it is in the root of the repository.
  5563. $relative_path = '';
  5564. $relative_prefix = '';
  5565. }
  5566. else
  5567. {
  5568. // The document already exists. Whe have to determine its relative path towards the repository root.
  5569. $relative_path = explode('/', $relative_path);
  5570. $cnt = count($relative_path) - 2;
  5571. if ($cnt < 0) { $cnt = 0; }
  5572. $relative_prefix = str_repeat('../', $cnt);
  5573. $relative_path = array_slice($relative_path, 1, $cnt);
  5574. $relative_path = implode('/', $relative_path);
  5575. if (strlen($relative_path) > 0)
  5576. {
  5577. $relative_path = $relative_path.'/';
  5578. }
  5579. }
  5580. $fck_attribute['Config']['CreateDocumentDir'] = $relative_prefix;
  5581. $fck_attribute['Config']['CreateDocumentWebDir'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/';
  5582. $fck_attribute['Config']['BaseHref'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/'.$relative_path;
  5583. if ($_GET['action']=='add_item'){
  5584. $class='add';
  5585. $text=get_lang('LPCreateDocument');
  5586. } else if ($_GET['action']=='edit_item'){
  5587. $class='save';
  5588. $text=get_lang('LPModifyDocument');
  5589. }
  5590. $form->addElement('style_submit_button', 'submit_button', $text,'class="'.$class.'"');
  5591. $renderer = $form->defaultRenderer();
  5592. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5593. $form->addElement('html','<div style="margin:3px 12px">');
  5594. $form->addElement('html_editor','content_lp','');
  5595. $form->addElement('html','</div>');
  5596. $defaults["content_lp"]=$content;
  5597. }
  5598. }
  5599. elseif(is_numeric($extra_info))
  5600. {
  5601. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5602. $return = $this->display_document($extra_info, true, true, true);
  5603. $form->addElement('html',$return);
  5604. }
  5605. }
  5606. }
  5607. if($action == 'move')
  5608. {
  5609. $form->addElement('hidden', 'title', $item_title);
  5610. $form->addElement('hidden', 'description', $item_description);
  5611. }
  5612. if(is_numeric($extra_info))
  5613. {
  5614. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5615. $form->addElement('hidden', 'path', $extra_info);
  5616. }
  5617. elseif(is_array($extra_info))
  5618. {
  5619. $form->addElement('style_submit_button', 'submit_button', get_lang('TitleManipulateDocument'), 'class="save"');
  5620. $form->addElement('hidden', 'path', $extra_info['path']);
  5621. }
  5622. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5623. $form->addElement('hidden', 'post_time', time());
  5624. $form->setDefaults($defaults);
  5625. return $form->return_form();
  5626. }
  5627. /**
  5628. * Return HTML form to add/edit a link item
  5629. *
  5630. * @param string Action (add/edit)
  5631. * @param integer Item ID if exists
  5632. * @param mixed Extra info
  5633. * @return string HTML form
  5634. */
  5635. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  5636. {
  5637. global $charset;
  5638. $tbl_lp_item = Database::get_course_table('lp_item');
  5639. $tbl_link = Database::get_course_table(TABLE_LINK);
  5640. if($id != 0 && is_array($extra_info)) {
  5641. $item_title = stripslashes($extra_info['title']);
  5642. $item_description = stripslashes($extra_info['description']);
  5643. } elseif(is_numeric($extra_info)) {
  5644. $sql_link = "
  5645. SELECT
  5646. title,
  5647. description,
  5648. url
  5649. FROM " . $tbl_link . "
  5650. WHERE id = " . $extra_info;
  5651. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  5652. $row = Database::fetch_array($result);
  5653. $item_title = $row['title'];
  5654. $item_description = $row['description'];
  5655. $item_url = $row['url'];
  5656. } else {
  5657. $item_title = '';
  5658. $item_description = '';
  5659. }
  5660. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5661. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  5662. $return = '<div class="sectiontitle">';
  5663. if($id != 0 && is_array($extra_info))
  5664. $parent = $extra_info['parent_item_id'];
  5665. else
  5666. $parent = 0;
  5667. $sql = "
  5668. SELECT *
  5669. FROM " . $tbl_lp_item . "
  5670. WHERE
  5671. lp_id = " . $this->lp_id;
  5672. $result = api_sql_query($sql, __FILE__, __LINE__);
  5673. $arrLP = array();
  5674. while($row = Database::fetch_array($result)) {
  5675. $arrLP[] = array(
  5676. 'id' => $row['id'],
  5677. 'item_type' => $row['item_type'],
  5678. 'title' => $row['title'],
  5679. 'path' => $row['path'],
  5680. 'description' => $row['description'],
  5681. 'parent_item_id' => $row['parent_item_id'],
  5682. 'previous_item_id' => $row['previous_item_id'],
  5683. 'next_item_id' => $row['next_item_id'],
  5684. 'display_order' => $row['display_order'],
  5685. 'max_score' => $row['max_score'],
  5686. 'min_score' => $row['min_score'],
  5687. 'mastery_score' => $row['mastery_score'],
  5688. 'prerequisite' => $row['prerequisite']);
  5689. }
  5690. $this->tree_array($arrLP);
  5691. $arrLP = $this->arrMenu;
  5692. unset($this->arrMenu);
  5693. if($action == 'add')
  5694. $return .= get_lang("CreateTheLink").'&nbsp;:' . "\n";
  5695. elseif($action == 'move')
  5696. $return .= get_lang("MoveCurrentLink").'&nbsp;:' . "\n";
  5697. else
  5698. $return .= get_lang("EditCurrentLink").'&nbsp;:' . "\n";
  5699. $return .= '</div>';
  5700. $return .= '<div class="sectioncomment">';
  5701. $return .= '<form method="POST">' . "\n";
  5702. $return .= "\t" . '<table>' . "\n";
  5703. if($action != 'move') {
  5704. $return .= "\t\t" . '<tr>' . "\n";
  5705. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  5706. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
  5707. $return .= "\t\t" . '</tr>' . "\n";
  5708. }
  5709. $return .= "\t\t" . '<tr>' . "\n";
  5710. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  5711. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5712. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5713. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5714. $arrHide = array($id);
  5715. $parent_item_id = $_SESSION['parent_item_id'];
  5716. for($i = 0; $i < count($arrLP); $i++) {
  5717. if($action != 'add') {
  5718. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  5719. {
  5720. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5721. } else {
  5722. $arrHide[] = $arrLP[$i]['id'];
  5723. }
  5724. } else {
  5725. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5726. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5727. }
  5728. }
  5729. if(is_array($arrLP)) {
  5730. reset($arrLP);
  5731. }
  5732. $return .= "\t\t\t\t" . '</select>';
  5733. $return .= "\t\t\t" . '</td>' . "\n";
  5734. $return .= "\t\t" . '</tr>' . "\n";
  5735. $return .= "\t\t" . '<tr>' . "\n";
  5736. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  5737. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5738. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5739. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5740. for($i = 0; $i < count($arrLP); $i++)
  5741. {
  5742. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5743. {
  5744. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5745. $selected = 'selected="selected" ';
  5746. elseif($action == 'add')
  5747. $selected = 'selected="selected" ';
  5748. else
  5749. $selected = '';
  5750. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  5751. }
  5752. }
  5753. $return .= "\t\t\t\t" . '</select>';
  5754. $return .= "\t\t\t" . '</td>' . "\n";
  5755. $return .= "\t\t" . '</tr>' . "\n";
  5756. if($action != 'move') {
  5757. $return .= "\t\t" . '<tr>' . "\n";
  5758. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
  5759. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" style="width:100%;" name="description" class="learnpath_item_form" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5760. $return .= "\t\t" . '</tr>' . "\n";
  5761. $return .= "\t\t" . '<tr>' . "\n";
  5762. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang('Url').'</label></td>' . "\n";
  5763. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>' . "\n";
  5764. $return .= "\t\t" . '</tr>' . "\n";
  5765. $id_prerequisite=0;
  5766. if (is_array($arrLP)){
  5767. foreach($arrLP as $key=>$value){
  5768. if($value['id']==$id){
  5769. $id_prerequisite=$value['prerequisite'];
  5770. break;
  5771. }
  5772. }
  5773. }
  5774. $arrHide=array();
  5775. for($i = 0; $i < count($arrLP); $i++) {
  5776. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5777. {
  5778. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5779. $s_selected_position=$arrLP[$i]['id'];
  5780. elseif($action == 'add')
  5781. $s_selected_position=0;
  5782. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5783. }
  5784. }
  5785. /*//comented the prerequisites, only visible in edit (link)
  5786. $return .= "\t\t" . '<tr>' . "\n";
  5787. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5788. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5789. foreach($arrHide as $key => $value)
  5790. {
  5791. if($key==$s_selected_position && $action == 'add')
  5792. {
  5793. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5794. }
  5795. elseif($key==$id_prerequisite && $action == 'edit'){
  5796. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5797. }
  5798. else{
  5799. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5800. }
  5801. }
  5802. $return .= "</select></td>";
  5803. */
  5804. $return .= "\t\t" . '</tr>' . "\n";
  5805. }
  5806. $return .= "\t\t" . '<tr>' . "\n";
  5807. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">'.get_lang("Ok").'</button></td>' . "\n";
  5808. $return .= "\t\t" . '</tr>' . "\n";
  5809. $return .= "\t" . '</table>' . "\n";
  5810. if($action == 'move')
  5811. {
  5812. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5813. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5814. }
  5815. if(is_numeric($extra_info))
  5816. {
  5817. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5818. }
  5819. elseif(is_array($extra_info))
  5820. {
  5821. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5822. }
  5823. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  5824. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5825. $return .= '</form>' . "\n";
  5826. $return .= '</div>' . "\n";
  5827. return $return;
  5828. }
  5829. /**
  5830. * Return HTML form to add/edit a student publication (work)
  5831. *
  5832. * @param string Action (add/edit)
  5833. * @param integer Item ID if already exists
  5834. * @param mixed Extra info (work ID if integer)
  5835. * @return string HTML form
  5836. */
  5837. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  5838. {
  5839. global $charset;
  5840. $tbl_lp_item = Database::get_course_table('lp_item');
  5841. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5842. if($id != 0 && is_array($extra_info)) {
  5843. $item_title = stripslashes($extra_info['title']);
  5844. $item_description = stripslashes($extra_info['description']);
  5845. } elseif(is_numeric($extra_info)) {
  5846. $sql_publication = "
  5847. SELECT
  5848. title,
  5849. description
  5850. FROM " . $tbl_publication . "
  5851. WHERE id = " . $extra_info;
  5852. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  5853. $row = Database::fetch_array($result);
  5854. $item_title = $row['title'];
  5855. } else {
  5856. $item_title = '';
  5857. }
  5858. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5859. $return = '<div class="sectiontitle">';
  5860. if($id != 0 && is_array($extra_info))
  5861. $parent = $extra_info['parent_item_id'];
  5862. else
  5863. $parent = 0;
  5864. $sql = "
  5865. SELECT *
  5866. FROM " . $tbl_lp_item . "
  5867. WHERE
  5868. lp_id = " . $this->lp_id;
  5869. $result = api_sql_query($sql, __FILE__, __LINE__);
  5870. $arrLP = array();
  5871. while($row = Database::fetch_array($result)) {
  5872. $arrLP[] = array(
  5873. 'id' => $row['id'],
  5874. 'item_type' => $row['item_type'],
  5875. 'title' => $row['title'],
  5876. 'path' => $row['path'],
  5877. 'description' => $row['description'],
  5878. 'parent_item_id' => $row['parent_item_id'],
  5879. 'previous_item_id' => $row['previous_item_id'],
  5880. 'next_item_id' => $row['next_item_id'],
  5881. 'display_order' => $row['display_order'],
  5882. 'max_score' => $row['max_score'],
  5883. 'min_score' => $row['min_score'],
  5884. 'mastery_score' => $row['mastery_score'],
  5885. 'prerequisite' => $row['prerequisite']);
  5886. }
  5887. $this->tree_array($arrLP);
  5888. $arrLP = $this->arrMenu;
  5889. unset($this->arrMenu);
  5890. if($action == 'add')
  5891. $return .= get_lang("Student_publication").'&nbsp;:' . "\n";
  5892. elseif($action == 'move')
  5893. $return .= get_lang("MoveCurrentStudentPublication").'&nbsp;:' . "\n";
  5894. else
  5895. $return .= get_lang("EditCurrentStudentPublication").'&nbsp;:' . "\n";
  5896. $return .= '</div>';
  5897. $return .= '<div class="sectioncomment">';
  5898. $return .= '<form method="POST">' . "\n";
  5899. $return .= "\t" . '<table>' . "\n";
  5900. if($action != 'move')
  5901. {
  5902. $return .= "\t\t" . '<tr>' . "\n";
  5903. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  5904. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  5905. $return .= "\t\t" . '</tr>' . "\n";
  5906. }
  5907. $return .= "\t\t" . '<tr>' . "\n";
  5908. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  5909. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5910. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5911. $parent_item_id = $_SESSION['parent_item_id'];
  5912. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5913. $arrHide = array($id);
  5914. for($i = 0; $i < count($arrLP); $i++)
  5915. {
  5916. if($action != 'add')
  5917. {
  5918. if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
  5919. {
  5920. $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'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
  5921. }
  5922. else
  5923. {
  5924. $arrHide[] = $arrLP[$i]['id'];
  5925. }
  5926. }
  5927. else
  5928. {
  5929. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5930. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding). '</option>';
  5931. }
  5932. }
  5933. if(is_array($arrLP))
  5934. {
  5935. reset($arrLP);
  5936. }
  5937. $return .= "\t\t\t\t" . '</select>';
  5938. $return .= "\t\t\t" . '</td>' . "\n";
  5939. $return .= "\t\t" . '</tr>' . "\n";
  5940. $return .= "\t\t" . '<tr>' . "\n";
  5941. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  5942. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5943. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5944. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5945. for($i = 0; $i < count($arrLP); $i++)
  5946. {
  5947. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5948. {
  5949. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5950. $selected = 'selected="selected" ';
  5951. elseif($action == 'add')
  5952. $selected = 'selected="selected" ';
  5953. else
  5954. $selected = '';
  5955. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'.get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
  5956. }
  5957. }
  5958. $return .= "\t\t\t\t" . '</select>';
  5959. $return .= "\t\t\t" . '</td>' . "\n";
  5960. $return .= "\t\t" . '</tr>' . "\n";
  5961. if($action != 'move')
  5962. {
  5963. $id_prerequisite=0;
  5964. if(is_array($arrLP))
  5965. {
  5966. foreach($arrLP as $key=>$value){
  5967. if($value['id']==$id){
  5968. $id_prerequisite=$value['prerequisite'];
  5969. break;
  5970. }
  5971. }
  5972. }
  5973. $arrHide=array();
  5974. for($i = 0; $i < count($arrLP); $i++)
  5975. {
  5976. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5977. {
  5978. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5979. $s_selected_position=$arrLP[$i]['id'];
  5980. elseif($action == 'add')
  5981. $s_selected_position=0;
  5982. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5983. }
  5984. }
  5985. //comented the prerequisites, only visible in edit (work)
  5986. /*
  5987. $return .= "\t\t" . '<tr>' . "\n";
  5988. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5989. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5990. foreach($arrHide as $key => $value){
  5991. if($key==$s_selected_position && $action == 'add'){
  5992. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5993. }
  5994. elseif($key==$id_prerequisite && $action == 'edit'){
  5995. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5996. }
  5997. else{
  5998. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5999. }
  6000. }
  6001. $return .= "</select></td>";
  6002. */
  6003. $return .= "\t\t" . '</tr>' . "\n";
  6004. }
  6005. $return .= "\t\t" . '<tr>' . "\n";
  6006. $return .= "\t\t\t" . '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">'.get_lang("Ok").'</button></td>' . "\n";
  6007. $return .= "\t\t" . '</tr>' . "\n";
  6008. $return .= "\t" . '</table>' . "\n";
  6009. if($action == 'move')
  6010. {
  6011. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6012. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6013. }
  6014. if(is_numeric($extra_info))
  6015. {
  6016. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6017. }
  6018. elseif(is_array($extra_info))
  6019. {
  6020. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6021. }
  6022. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  6023. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6024. $return .= '</form>' . "\n";
  6025. $return .= '</div>' . "\n";
  6026. return $return;
  6027. }
  6028. /**
  6029. * Displays the menu for manipulating a step
  6030. *
  6031. * @return unknown
  6032. */
  6033. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  6034. {
  6035. global $charset, $_course;
  6036. $return = '<div class="actions">';
  6037. switch($item_type)
  6038. {
  6039. case 'dokeos_chapter':
  6040. case 'chapter':
  6041. //comented the message cause should not show it
  6042. //$lang = get_lang('TitleManipulateChapter');
  6043. break;
  6044. case 'dokeos_module':
  6045. case 'module':
  6046. //comented the message cause should not show it
  6047. //$lang = get_lang('TitleManipulateModule');
  6048. break;
  6049. case TOOL_DOCUMENT:
  6050. //comented the message cause should not show it
  6051. //$lang = get_lang('TitleManipulateDocument');
  6052. break;
  6053. case TOOL_LINK:
  6054. case 'link':
  6055. //comented the message cause should not show it
  6056. //$lang = get_lang('TitleManipulateLink');
  6057. break;
  6058. case TOOL_QUIZ:
  6059. //comented the message cause should not show it
  6060. //$lang = get_lang('TitleManipulateQuiz');
  6061. break;
  6062. case TOOL_STUDENTPUBLICATION:
  6063. //comented the message cause should not show it
  6064. //$lang = get_lang('TitleManipulateStudentPublication');
  6065. break;
  6066. }
  6067. $tbl_lp_item = Database::get_course_table('lp_item');
  6068. $sql = "
  6069. SELECT
  6070. *
  6071. FROM " . $tbl_lp_item . " as lp
  6072. WHERE
  6073. lp.id = " . $item_id;
  6074. $result = api_sql_query($sql, __FILE__, __LINE__);
  6075. $row= mysql_fetch_assoc($result);
  6076. $s_title = $row['title'];
  6077. $s_title=mb_convert_encoding($s_title,$charset,$this->encoding);
  6078. // we display an audio player if needed
  6079. if (!empty($row['audio']))
  6080. {
  6081. $return .= '<div class="lp_mediaplayer" id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
  6082. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6083. $return .= '<script type="text/javascript">
  6084. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6085. s1.addParam("allowscriptaccess","always");
  6086. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  6087. s1.write("container");
  6088. </script>';
  6089. }
  6090. //commented ":" for message in step
  6091. //$return .= $lang.': ';
  6092. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '&path_item='.$row['path'].'" title="'.get_lang('Edit').'"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="'.get_lang("Edit").'" /> '.get_lang("Edit").'</a>';
  6093. $return .= '<a href="' .api_get_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="'.get_lang("Move").'" /> '.get_lang("Move").'</a>';
  6094. // commented for now as prerequisites cannot be added to chapters
  6095. if($item_type != 'dokeos_chapter' && $item_type != 'chapter')
  6096. {
  6097. $return .= '<a href="' .api_get_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('Prerequisites').'"><img align="absbottom" alt="'.get_lang('Prerequisites').'" src="../img/right.gif" title="'.get_lang('Prerequisites').'" /> '.get_lang('Prerequisites').'</a>';
  6098. }
  6099. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' .addslashes($s_title). '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="'.get_lang("Delete").'" /> '.get_lang("Delete").'</a>';
  6100. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  6101. //$return.="</td><td valign='top'>";
  6102. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  6103. ob_start();
  6104. $audio_recorder_studentview = 'false';
  6105. $audio_recorder_item_id = $item_id;
  6106. if(api_get_setting('service_visio','active')=='true'){
  6107. include('audiorecorder.inc.php');
  6108. }
  6109. $return .= ob_get_contents();
  6110. ob_end_clean();
  6111. // end of audiorecorder include
  6112. $return .= '</div>';
  6113. return $return;
  6114. }
  6115. /**
  6116. * Creates the javascript needed for filling up the checkboxes without page reload
  6117. *
  6118. * @return string
  6119. */
  6120. function create_js()
  6121. {
  6122. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6123. $return .= 'function load_cbo(id){' . "\n";
  6124. $return .= "var cbo = document.getElementById('idPosition');\n";
  6125. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6126. $return .= 'cbo.options[i] = null;'."\n";
  6127. $return .= 'var k=0;'."\n";
  6128. $return .= 'for(var i = 1; i <= child_name[id].length; i++){'."\n";
  6129. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);'."\n";
  6130. $return .= 'k=i;';
  6131. $return .= '}' . "\n\n";
  6132. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6133. $return .='}';
  6134. $return .= 'var child_name = new Array();' . "\n";
  6135. $return .= 'var child_value = new Array();' . "\n\n";
  6136. $return .= 'child_name[0] = new Array();' . "\n";
  6137. $return .= 'child_value[0] = new Array();' . "\n\n";
  6138. $tbl_lp_item = Database::get_course_table('lp_item');
  6139. $sql_zero = "
  6140. SELECT *
  6141. FROM " . $tbl_lp_item . "
  6142. WHERE
  6143. lp_id = " . $this->lp_id . " AND
  6144. parent_item_id = 0
  6145. ORDER BY display_order ASC";
  6146. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  6147. global $charset;
  6148. $i = 0;
  6149. while($row_zero = Database::fetch_array($res_zero))
  6150. {
  6151. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_zero['title'],$charset,$this->encoding) . '\"";' . "\n";
  6152. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6153. }
  6154. $return .= "\n";
  6155. $sql = "
  6156. SELECT *
  6157. FROM " . $tbl_lp_item . "
  6158. WHERE
  6159. lp_id = " . $this->lp_id;
  6160. $res = api_sql_query($sql, __FILE__, __LINE__);
  6161. while($row = Database::fetch_array($res))
  6162. {
  6163. $sql_parent = "
  6164. SELECT *
  6165. FROM " . $tbl_lp_item . "
  6166. WHERE parent_item_id = " . $row['id'] . "
  6167. ORDER BY display_order ASC";
  6168. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  6169. $i = 0;
  6170. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6171. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6172. while($row_parent = Database::fetch_array($res_parent))
  6173. {
  6174. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_parent['title'],$charset,$this->encoding) . '\"";' . "\n";
  6175. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6176. }
  6177. $return .= "\n";
  6178. }
  6179. $return .= '</script>' . "\n";
  6180. return $return;
  6181. }
  6182. /**
  6183. * Display the form to allow moving an item
  6184. *
  6185. * @param integer Item ID
  6186. * @return string HTML form
  6187. */
  6188. function display_move_item($item_id)
  6189. {
  6190. global $_course; //will disappear
  6191. global $charset;
  6192. $return = '';
  6193. if(is_numeric($item_id))
  6194. {
  6195. $tbl_lp_item = Database::get_course_table('lp_item');
  6196. $sql = "
  6197. SELECT *
  6198. FROM " . $tbl_lp_item . "
  6199. WHERE id = " . $item_id;
  6200. $res = api_sql_query($sql, __FILE__, __LINE__);
  6201. $row = Database::fetch_array($res);
  6202. switch($row['item_type'])
  6203. {
  6204. case 'dokeos_chapter': case 'dir' : case 'asset' :
  6205. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6206. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6207. break;
  6208. case 'dokeos_module':
  6209. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6210. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6211. break;
  6212. case TOOL_DOCUMENT:
  6213. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6214. $return .= $this->display_document_form('move', $item_id, $row);
  6215. break;
  6216. case TOOL_LINK:
  6217. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6218. $return .= $this->display_link_form('move', $item_id, $row);
  6219. break;
  6220. case TOOL_HOTPOTATOES:
  6221. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6222. $return .= $this->display_link_form('move', $item_id, $row);
  6223. break;
  6224. case TOOL_QUIZ:
  6225. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6226. $return .= $this->display_quiz_form('move', $item_id, $row);
  6227. break;
  6228. case TOOL_STUDENTPUBLICATION:
  6229. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6230. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6231. break;
  6232. case TOOL_FORUM :
  6233. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6234. $return .= $this->display_forum_form('move', $item_id, $row);
  6235. }
  6236. }
  6237. return $return;
  6238. }
  6239. /**
  6240. * Displays a basic form on the overview page for changing the item title and the item description.
  6241. *
  6242. * @param string $item_type
  6243. * @param string $title
  6244. * @param array $data
  6245. * @return string
  6246. */
  6247. function display_item_small_form($item_type, $title = '', $data)
  6248. {
  6249. $return .= '<div class="lp_small_form">' . "\n";
  6250. $return .= '<p class="lp_title">' . $title . '</p>';
  6251. $return .= '<form method="post">' . "\n";
  6252. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6253. $return .= "\t\t" . '<tr>' . "\n";
  6254. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6255. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  6256. $return .= "\t\t" . '</tr>' . "\n";
  6257. $return .= "\t\t" . '<tr>' . "\n";
  6258. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6259. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6260. $return .= "\t\t" . '</tr>' . "\n";
  6261. $return .= "\t\t" . '<tr>' . "\n";
  6262. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">'.get_lang('Save').'</button></td>' . "\n";
  6263. $return .= "\t\t" . '</tr>' . "\n";
  6264. $return .= "\t\t" . '</table>' . "\n";
  6265. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6266. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6267. $return .= '</form>';
  6268. $return .= '</div>';
  6269. return $return;
  6270. }
  6271. /**
  6272. * Return HTML form to allow prerequisites selection
  6273. *
  6274. * @param integer Item ID
  6275. * @return string HTML form
  6276. */
  6277. function display_item_prerequisites_form($item_id)
  6278. {
  6279. global $charset;
  6280. $tbl_lp_item = Database::get_course_table('lp_item');
  6281. /* current prerequisite */
  6282. $sql = "
  6283. SELECT *
  6284. FROM " . $tbl_lp_item . "
  6285. WHERE id = " . $item_id;
  6286. $result = api_sql_query($sql, __FILE__, __LINE__);
  6287. $row = Database::fetch_array($result);
  6288. $preq_id = $row['prerequisite'];
  6289. //$preq_mastery = $row['mastery_score'];
  6290. //$preq_max = $row['max_score'];
  6291. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6292. $return .= '<div class="sectiontitle">';
  6293. $return .= get_lang('AddEditPrerequisites');
  6294. $return .= '</div>';
  6295. $return .= '<div class="sectioncomment">';
  6296. $return .= '<form method="POST">';
  6297. $return .= '<table class="lp_prerequisites">';
  6298. $return .= '<tr>';
  6299. $return .= '<th></th>';
  6300. $return .= '<th >'.get_lang('Minimum').'</th>';
  6301. $return .= '<th>'.get_lang('Maximum').'</th>';
  6302. $return .= '</tr>';
  6303. $return .= '<tr>';
  6304. $return .= '<td class="radio">';
  6305. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6306. $return .= '<label for="idNone">'.get_lang('None').'</label>';
  6307. $return .= '</td><td colspan="2" />';
  6308. $return .= '</tr>';
  6309. $sql = "
  6310. SELECT *
  6311. FROM " . $tbl_lp_item . "
  6312. WHERE
  6313. lp_id = " . $this->lp_id;
  6314. $result = api_sql_query($sql, __FILE__, __LINE__);
  6315. $arrLP = array();
  6316. while($row = Database::fetch_array($result))
  6317. {
  6318. $arrLP[] = array(
  6319. 'id' => $row['id'],
  6320. 'item_type' => $row['item_type'],
  6321. 'title' => mb_convert_encoding($row['title'],$charset,$this->encoding),
  6322. 'ref' => $row['ref'],
  6323. 'description' => $row['description'],
  6324. 'parent_item_id' => $row['parent_item_id'],
  6325. 'previous_item_id' => $row['previous_item_id'],
  6326. 'next_item_id' => $row['next_item_id'],
  6327. 'max_score' => $row['max_score'],
  6328. 'min_score' => $row['min_score'],
  6329. 'mastery_score' => $row['mastery_score'],
  6330. 'prerequisite' => $row['prerequisite'],
  6331. 'next_item_id' => $row['next_item_id'],
  6332. 'display_order' => $row['display_order']);
  6333. if($row['ref'] == $preq_id)
  6334. {
  6335. $preq_mastery = $row['mastery_score'];
  6336. $preq_max = $row['max_score'];
  6337. }
  6338. }
  6339. $this->tree_array($arrLP);
  6340. $arrLP = $this->arrMenu;
  6341. unset($this->arrMenu);
  6342. for($i = 0; $i < count($arrLP); $i++)
  6343. {
  6344. if($arrLP[$i]['id'] == $item_id)
  6345. break;
  6346. $return .= '<tr>';
  6347. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6348. $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'] . '" />';
  6349. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6350. if (file_exists("../img/lp_" . $icon_name . ".png"))
  6351. {
  6352. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6353. }
  6354. else if(file_exists("../img/lp_" . $icon_name . ".gif"))
  6355. {
  6356. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6357. }
  6358. else
  6359. {
  6360. $return .= '<img alt="" src="../img/lp_document.png" style="margin-right:5px;" title="" />';
  6361. }
  6362. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6363. $return .= '</td>';
  6364. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6365. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  6366. {
  6367. $return .= '<td class="exercise">';
  6368. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6369. $return .= '</td>';
  6370. $return .= '<td class="exercise">';
  6371. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6372. $return .= '</td>';
  6373. }
  6374. if($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES)
  6375. {
  6376. $return .= '<td class="exercise">';
  6377. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6378. $return .= '</td>';
  6379. $return .= '<td class="exercise">';
  6380. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6381. $return .= '</td>';
  6382. }
  6383. $return .='</tr>';
  6384. }
  6385. $return .= '<tr>';
  6386. $return .= '<td colspan="3">';
  6387. $return .= '<button class="save" name="submit_button" type="submit">'.get_lang("ModifyPrerequisites").' </button></td>' . "\n";
  6388. $return .= '</td>';
  6389. $return .= '</tr>';
  6390. $return .= '</table>';
  6391. $return .= '</form>';
  6392. $return .= '</div>';
  6393. return $return;
  6394. }
  6395. /**
  6396. * Creates a list with all the documents in it
  6397. *
  6398. * @return string
  6399. */
  6400. function get_documents()
  6401. {
  6402. global $_course;
  6403. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6404. $sql_doc = "
  6405. SELECT *
  6406. FROM " . $tbl_doc . "
  6407. WHERE
  6408. path NOT LIKE '%_DELETED_%'
  6409. ORDER BY path ASC";
  6410. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  6411. $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';}\"" . '><img alt="" src="../img/lp_' . TOOL_DOCUMENT . '.gif" style="margin-right:5px;" title="" />'.get_lang("Documents").'</div>';
  6412. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6413. $resources=api_store_result($res_doc);
  6414. $resources_sorted = array();
  6415. // if you want to debug it, I advise you to do "echo" on the eval statements
  6416. foreach($resources as $resource)
  6417. {
  6418. $resource_paths = explode('/',$resource['path']);
  6419. array_shift($resource_paths);
  6420. $path_to_eval = $last_path = '';
  6421. $is_file = false;
  6422. foreach($resource_paths as $key => $resource_path)
  6423. {
  6424. if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1)
  6425. { // it's a folder
  6426. $path_to_eval .= '["'.$resource_path.'"]["files"]';
  6427. }
  6428. else if(strpos($resource_path,'.')!==false)
  6429. $is_file = true;
  6430. $last_path = $resource_path;
  6431. }
  6432. if($is_file)
  6433. {
  6434. eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";');
  6435. }
  6436. else
  6437. {
  6438. eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';');
  6439. }
  6440. }
  6441. $return .=$this->write_resources_tree($resources_sorted);
  6442. $return .='</div>';
  6443. if(Database::num_rows($res_doc) == 0)
  6444. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  6445. return $return;
  6446. }
  6447. /**
  6448. * Generate and return an HTML list of resources based on a given array.
  6449. *
  6450. * This list is used to show the course creator a list of available resources to choose from
  6451. * when creating a learning path.
  6452. * @param array Array of elements to add to the list
  6453. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6454. * @return string The HTML list
  6455. */
  6456. function write_resources_tree($resources_sorted, $num=0){
  6457. include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
  6458. if(count($resources_sorted)>0)
  6459. {
  6460. foreach($resources_sorted as $key=>$resource)
  6461. {
  6462. if(is_int($resource['id']))
  6463. { // it's a folder
  6464. $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_'.$resource["id"].'" onclick="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onclick="testResources(\''.$resource["id"].'\',\'img_'.$resource["id"].'\')" style="cursor: pointer;" >'.$key.'</span></div><div style="display: none;" id="'.$resource['id'].'">';
  6465. $return .= $this->write_resources_tree($resource['files'], $num+1);
  6466. $return .= "</div></div>\r\n";
  6467. }
  6468. else
  6469. {
  6470. // it's a file
  6471. $icon = choose_image($resource);
  6472. $position = strrpos($icon,'.');
  6473. $icon=substr($icon,0,$position).'_small.gif';
  6474. $return .= '<div><div style="margin-left:' . (($num+1) * 15) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' . $this->lp_id . '"><img alt="" src="../img/'.$icon.'" title="" />&nbsp;'.$resource."</a></div></div>\r\n";
  6475. }
  6476. }
  6477. }
  6478. return $return;
  6479. }
  6480. /**
  6481. * Creates a list with all the exercises (quiz) in it
  6482. *
  6483. * @return string
  6484. */
  6485. function get_exercises()
  6486. {
  6487. // new for hotpotatoes
  6488. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6489. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6490. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  6491. $sql_quiz = "
  6492. SELECT *
  6493. FROM " . $tbl_quiz . "
  6494. WHERE active<>'-1'
  6495. ORDER BY title ASC";
  6496. $sql_hot = "SELECT * FROM ".$tbl_doc." " .
  6497. " WHERE path LIKE '".$uploadPath."/%/%htm%'" .
  6498. " ORDER BY id ASC";
  6499. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  6500. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  6501. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resExercise').style.display == 'block') {document.getElementById('resExercise').style.display = 'none';} else {document.getElementById('resExercise').style.display = 'block';}\"" . ' ><img align="left" alt="" src="../img/lp_' . TOOL_QUIZ . '.gif" style="margin-right:5px;" title="" />'.get_lang('Quiz').'</div>';
  6502. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6503. while ($row_hot = Database::fetch_array($res_hot)) {
  6504. $return .= '<div class="lp_resource_element">';
  6505. //display quizhotpotatoes
  6506. $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
  6507. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . $row_hot['title'] . '</a>';
  6508. //$return .= $row_quiz['title'];
  6509. $return .= '</div>';
  6510. }
  6511. while($row_quiz = Database::fetch_array($res_quiz)) {
  6512. $return .= '<div class="lp_resource_element">';
  6513. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6514. $return .= '<a href="' .api_get_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>';
  6515. //$return .= $row_quiz['title'];
  6516. $return .= '</div>';
  6517. }
  6518. if(Database::num_rows($res_quiz) == 0)
  6519. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  6520. $return .= '<div class="lp_resource_element">';
  6521. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6522. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6523. $return .= '</div>';
  6524. $return .= '</div>';
  6525. return $return;
  6526. }
  6527. /**
  6528. * Creates a list with all the links in it
  6529. *
  6530. * @return string
  6531. */
  6532. function get_links()
  6533. {
  6534. $tbl_link = Database::get_course_table(TABLE_LINK);
  6535. $sql_link = "
  6536. SELECT *
  6537. FROM " . $tbl_link . "
  6538. ORDER BY title ASC";
  6539. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  6540. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resLink').style.display == 'block') {document.getElementById('resLink').style.display = 'none';} else {document.getElementById('resLink').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_LINK . '.gif" style="margin-right:5px;" title="" />'.get_lang("Links").'</div>';
  6541. $return .= '<div class="lp_resource_elements" id="resLink">';
  6542. while($row_link = Database::fetch_array($res_link))
  6543. {
  6544. $return .= '<div class="lp_resource_element">';
  6545. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6546. $return .= '<a href="' .api_get_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>';
  6547. $return .= '</div>';
  6548. }
  6549. $return .= '<div class="lp_resource_element">';
  6550. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6551. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'link/link.php?'.api_get_cidreq().'&action=addlink" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  6552. $return .= '</div>';
  6553. if(Database::num_rows($res_link) == 0)
  6554. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  6555. $return .= '</div>';
  6556. return $return;
  6557. }
  6558. /**
  6559. * Creates a list with all the student publications in it
  6560. *
  6561. * @return unknown
  6562. */
  6563. function get_student_publications()
  6564. {
  6565. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  6566. $sql_student = "
  6567. SELECT *
  6568. FROM " . $tbl_student . "
  6569. ORDER BY title ASC";
  6570. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  6571. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('resStudent').style.display == 'block') {document.getElementById('resStudent').style.display = 'none';} else {document.getElementById('resStudent').style.display = 'block';}\"" . '><img alt="" src="../img/lp_' . TOOL_STUDENTPUBLICATION . '.gif" style="margin-right:5px;" title="" />'.get_lang('Student_publication').'</div>';
  6572. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6573. $return .= '<div class="lp_resource_element">';
  6574. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6575. $return .= '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  6576. $return .= '</div>';
  6577. $return .= '</div>';
  6578. return $return;
  6579. }
  6580. /**
  6581. * Creates a list with all the forums in it
  6582. *
  6583. * @return string
  6584. */
  6585. function get_forums()
  6586. {
  6587. include ('../forum/forumfunction.inc.php');
  6588. include ('../forum/forumconfig.inc.php');
  6589. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  6590. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6591. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6592. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6593. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6594. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6595. $a_forums = get_forums();
  6596. $return .= '<div class="lp_resource_header"' . " onclick=\"if(document.getElementById('forums').style.display == 'block') {document.getElementById('forums').style.display = 'none';} else {document.getElementById('forums').style.display = 'block';}\"" . '><img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />'.get_lang('Forums').'</div>';
  6597. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6598. foreach($a_forums as $forum)
  6599. {
  6600. $return .= '<div class="lp_resource_element">';
  6601. $return .= '<script type="text/javascript">
  6602. function toggle_forum(forum_id){
  6603. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6604. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6605. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  6606. }
  6607. else {
  6608. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6609. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  6610. }
  6611. }
  6612. </script>
  6613. ';
  6614. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6615. $return .= '<a style="cursor:hand" onclick="toggle_forum('.$forum['forum_id'].')" style="vertical-align:middle"><img src="'.api_get_path(WEB_IMG_PATH).'add.gif" id="forum_'.$forum['forum_id'].'_opener" align="absbottom" /></a>
  6616. <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_FORUM . '&amp;forum_id=' . $forum['forum_id'] . '&amp;lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . $forum['forum_title'] . '</a><ul style="display:none" id="forum_'.$forum['forum_id'].'_content">';
  6617. $a_threads = get_threads($forum['forum_id']);
  6618. if(is_array($a_threads)){
  6619. foreach($a_threads as $thread)
  6620. {
  6621. $return .= '<li><a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . $thread['thread_title'] . '</a></li>';
  6622. }
  6623. }
  6624. $return .= '</ul></div>';
  6625. }
  6626. $return .= '<div class="lp_resource_element">';
  6627. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6628. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&action=add&amp;content=forum" title="'.get_lang('CreateANewForum').'">'.get_lang('CreateANewForum').'</a>';
  6629. $return .= '</div>';
  6630. return $return;
  6631. }
  6632. /**
  6633. * Exports the learning path as a SCORM package. This is the main function that
  6634. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6635. * whole thing and returns the zip.
  6636. *
  6637. * This method needs to be called in PHP5, as it will fail with non-adequate
  6638. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6639. * you need to call it on a learnpath object.
  6640. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6641. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6642. * path has been modified, it should use the generic method here below.
  6643. * @TODO link this function with the export_lp() function in the same class
  6644. * @param string Optional name of zip file. If none, title of learnpath is
  6645. * domesticated and trailed with ".zip"
  6646. * @return string Returns the zip package string, or null if error
  6647. */
  6648. function scorm_export()
  6649. {
  6650. global $_course;
  6651. if (!class_exists('DomDocument'))
  6652. {
  6653. error_log('DOM functions not supported for PHP version below 5.0',0);
  6654. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6655. return null;
  6656. }
  6657. //remove memory and time limits as much as possible as this might be a long process...
  6658. if(function_exists('ini_set'))
  6659. {
  6660. $mem = ini_get('memory_limit');
  6661. if(substr($mem,-1,1)=='M')
  6662. {
  6663. $mem_num = substr($mem,0,-1);
  6664. if($mem_num<128)
  6665. {
  6666. ini_set('memory_limit','128M');
  6667. }
  6668. }
  6669. else
  6670. {
  6671. ini_set('memory_limit','128M');
  6672. }
  6673. ini_set('max_execution_time',600);
  6674. //}else{
  6675. //error_log('Scorm export: could not change memory and time limits',0);
  6676. }
  6677. //Create the zip handler (this will remain available throughout the method)
  6678. $garbage_path = api_get_path(GARBAGE_PATH);
  6679. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6680. $temp_dir_short = uniqid();
  6681. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  6682. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6683. $zip_folder=new PclZip($temp_zip_file);
  6684. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6685. $root_path = $main_path = api_get_path(SYS_PATH);
  6686. $files_cleanup = array();
  6687. //place to temporarily stash the zipfiles
  6688. //create the temp dir if it doesn't exist
  6689. //or do a cleanup befor creating the zipfile
  6690. if(!is_dir($temp_zip_dir))
  6691. {
  6692. mkdir($temp_zip_dir);
  6693. }
  6694. else
  6695. {//cleanup: check the temp dir for old files and delete them
  6696. $handle=opendir($temp_zip_dir);
  6697. while (false!==($file = readdir($handle)))
  6698. {
  6699. if ($file != "." && $file != "..")
  6700. {
  6701. unlink("$temp_zip_dir/$file");
  6702. }
  6703. }
  6704. closedir($handle);
  6705. }
  6706. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6707. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6708. {
  6709. // remove the possible . at the end of the path
  6710. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6711. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6712. $perm = api_get_setting('permissions_for_new_directories');
  6713. $perm = octdec(!empty($perm)?$perm:'0770');
  6714. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6715. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6716. }
  6717. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6718. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6719. //Aggregation Model official document, secion "2.3 Content Packaging"
  6720. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6721. $root = $xmldoc->createElement('manifest');
  6722. $root->setAttribute('identifier','SingleCourseManifest');
  6723. $root->setAttribute('version','1.1');
  6724. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6725. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6726. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6727. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  6728. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  6729. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6730. //Build mandatory sub-root container elements
  6731. $metadata = $xmldoc->createElement('metadata');
  6732. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6733. $metadata->appendChild($md_schema);
  6734. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6735. $metadata->appendChild($md_schemaversion);
  6736. $root->appendChild($metadata);
  6737. $organizations = $xmldoc->createElement('organizations');
  6738. $resources = $xmldoc->createElement('resources');
  6739. //Build the only organization we will use in building our learnpaths
  6740. $organizations->setAttribute('default','dokeos_scorm_export');
  6741. $organization = $xmldoc->createElement('organization');
  6742. $organization->setAttribute('identifier','dokeos_scorm_export');
  6743. //to set the title of the SCORM entity (=organization), we take the name given
  6744. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6745. //learning path charset) as it is the encoding that defines how it is stored
  6746. //in the database. Then we convert it to HTML entities again as the "&" character
  6747. //alone is not authorized in XML (must be &amp;)
  6748. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6749. global $charset;
  6750. $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6751. $organization->appendChild($org_title);
  6752. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6753. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6754. //format
  6755. $link_updates = array();
  6756. foreach($this->items as $index => $item){
  6757. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6758. {
  6759. //get included documents from this item
  6760. if($item->type=='sco')
  6761. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6762. else
  6763. $inc_docs = $item->get_resources_from_source();
  6764. //give a child element <item> to the <organization> element
  6765. $my_item_id = $item->get_id();
  6766. $my_item = $xmldoc->createElement('item');
  6767. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6768. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6769. $my_item->setAttribute('isvisible','true');
  6770. //give a child element <title> to the <item> element
  6771. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6772. $my_item->appendChild($my_title);
  6773. //give a child element <adlcp:prerequisites> to the <item> element
  6774. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6775. $my_prereqs->setAttribute('type','aicc_script');
  6776. $my_item->appendChild($my_prereqs);
  6777. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6778. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6779. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6780. //$xmldoc->createElement('adlcp:timelimitaction','');
  6781. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6782. //$xmldoc->createElement('adlcp:datafromlms','');
  6783. //give a child element <adlcp:masteryscore> to the <item> element
  6784. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6785. $my_item->appendChild($my_masteryscore);
  6786. //attach this item to the organization element or hits parent if there is one
  6787. if(!empty($item->parent) && $item->parent!=0)
  6788. {
  6789. $children = $organization->childNodes;
  6790. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6791. if(is_object($possible_parent))
  6792. {
  6793. $possible_parent->appendChild($my_item);
  6794. }
  6795. else
  6796. {
  6797. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6798. }
  6799. }
  6800. else
  6801. {
  6802. if($this->debug>0){error_log('No parent');}
  6803. $organization->appendChild($my_item);
  6804. }
  6805. //get the path of the file(s) from the course directory root
  6806. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6807. $my_xml_file_path = htmlentities($my_file_path);
  6808. $my_sub_dir = dirname($my_file_path);
  6809. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6810. //give a <resource> child to the <resources> element
  6811. $my_resource = $xmldoc->createElement('resource');
  6812. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6813. $my_resource->setAttribute('type','webcontent');
  6814. $my_resource->setAttribute('href',$my_xml_file_path);
  6815. //adlcp:scormtype can be either 'sco' or 'asset'
  6816. if($item->type=='sco')
  6817. {
  6818. $my_resource->setAttribute('adlcp:scormtype','sco');
  6819. }
  6820. else
  6821. {
  6822. $my_resource->setAttribute('adlcp:scormtype','asset');
  6823. }
  6824. //xml:base is the base directory to find the files declared in this resource
  6825. $my_resource->setAttribute('xml:base','');
  6826. //give a <file> child to the <resource> element
  6827. $my_file = $xmldoc->createElement('file');
  6828. $my_file->setAttribute('href',$my_xml_file_path);
  6829. $my_resource->appendChild($my_file);
  6830. //dependency to other files - not yet supported
  6831. $i = 1;
  6832. foreach($inc_docs as $doc_info)
  6833. {
  6834. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6835. $my_dep = $xmldoc->createElement('resource');
  6836. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6837. $my_dep->setAttribute('identifier',$res_id);
  6838. $my_dep->setAttribute('type','webcontent');
  6839. $my_dep->setAttribute('adlcp:scormtype','asset');
  6840. $my_dep_file = $xmldoc->createElement('file');
  6841. //check type of URL
  6842. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6843. if($doc_info[1] == 'remote')
  6844. { //remote file. Save url as is
  6845. $my_dep_file->setAttribute('href',$doc_info[0]);
  6846. $my_dep->setAttribute('xml:base','');
  6847. }elseif($doc_info[1] == 'local'){
  6848. switch($doc_info[2])
  6849. {
  6850. case 'url': //local URL - save path as url for now, don't zip file
  6851. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6852. $current_dir = dirname($abs_path);
  6853. $file_path = realpath($abs_path);
  6854. $my_dep_file->setAttribute('href',$file_path);
  6855. $my_dep->setAttribute('xml:base','');
  6856. if(strstr($file_path,$main_path) !== false)
  6857. {//the calculated real path is really inside the dokeos root path
  6858. //reduce file path to what's under the DocumentRoot
  6859. $file_path = substr($file_path,strlen($root_path)-1);
  6860. //echo $file_path;echo '<br><br>';
  6861. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6862. $zip_files_abs[] = $file_path;
  6863. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6864. $my_dep_file->setAttribute('href',$file_path);
  6865. $my_dep->setAttribute('xml:base','');
  6866. }
  6867. else if (empty($file_path))
  6868. {
  6869. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6870. if(strpos($document_root,-1)=='/')
  6871. {
  6872. $document_root = substr(0, -1, $document_root);
  6873. }*/
  6874. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6875. $file_path = str_replace('//','/',$file_path);
  6876. if(file_exists($file_path))
  6877. {
  6878. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6879. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6880. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6881. $my_dep_file->setAttribute('href',$file_path);
  6882. $my_dep->setAttribute('xml:base','');
  6883. }
  6884. }
  6885. break;
  6886. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6887. $my_dep_file->setAttribute('href',$doc_info[0]);
  6888. $my_dep->setAttribute('xml:base','');
  6889. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6890. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  6891. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  6892. $abs_img_path_without_subdir = $doc_info[0];
  6893. $relp = api_get_path(REL_PATH); //the url-append config param
  6894. $pos = strpos($abs_img_path_without_subdir,$relp);
  6895. if($pos===0)
  6896. {
  6897. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  6898. }
  6899. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6900. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  6901. $file_path = str_replace('\\','/',$file_path);
  6902. $file_path = str_replace('//','/',$file_path);
  6903. //error_log(__LINE__.'Abs path: '.$file_path,0);
  6904. //prepare the current directory path (until just under 'document') with a trailing slash
  6905. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6906. //check if the current document is in that path
  6907. if(strstr($file_path,$cur_path) !== false)
  6908. {
  6909. //the document is in that path, now get the relative path
  6910. //to the containing document
  6911. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  6912. $relative_path ='';
  6913. if(strstr($file_path,$cur_path)!==false)
  6914. {
  6915. $relative_path = substr($file_path,strlen($orig_file_path));
  6916. $file_path = substr($file_path,strlen($cur_path));
  6917. }
  6918. else
  6919. {
  6920. //this case is still a problem as it's difficult to calculate a relative path easily
  6921. //might still generate wrong links
  6922. //$file_path = substr($file_path,strlen($cur_path));
  6923. //calculate the directory path to the current file (without trailing slash)
  6924. $my_relative_path = dirname($file_path);
  6925. $my_relative_file = basename($file_path);
  6926. //calculate the directory path to the containing file (without trailing slash)
  6927. $my_orig_file_path = substr($orig_file_path,0,-1);
  6928. $dotdot = '';
  6929. $subdir = '';
  6930. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  6931. {
  6932. $my_relative_path2 = dirname($my_relative_path);
  6933. $my_orig_file_path = dirname($my_orig_file_path);
  6934. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  6935. $dotdot += '../';
  6936. $my_relative_path = $my_relative_path2;
  6937. }
  6938. $relative_path = $dotdot.$subdir.$my_relative_file;
  6939. }
  6940. //put the current document in the zip (this array is the array
  6941. //that will manage documents already in the course folder - relative)
  6942. $zip_files[] = $file_path;
  6943. //update the links to the current document in the containing document (make them relative)
  6944. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  6945. $my_dep_file->setAttribute('href',$file_path);
  6946. $my_dep->setAttribute('xml:base','');
  6947. }
  6948. elseif(strstr($file_path,$main_path) !== false)
  6949. {//the calculated real path is really inside the dokeos root path
  6950. //reduce file path to what's under the DocumentRoot
  6951. $file_path = substr($file_path,strlen($root_path));
  6952. //echo $file_path;echo '<br><br>';
  6953. //error_log('Reduced path: '.$file_path,0);
  6954. $zip_files_abs[] = $file_path;
  6955. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6956. $my_dep_file->setAttribute('href','document/'.$file_path);
  6957. $my_dep->setAttribute('xml:base','');
  6958. }
  6959. else if (empty($file_path))
  6960. {
  6961. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6962. if(strpos($document_root,-1)=='/')
  6963. {
  6964. $document_root = substr(0, -1, $document_root);
  6965. }*/
  6966. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6967. $file_path = str_replace('//','/',$file_path);
  6968. if(file_exists($file_path))
  6969. {
  6970. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6971. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6972. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6973. $my_dep_file->setAttribute('href','document/'.$file_path);
  6974. $my_dep->setAttribute('xml:base','');
  6975. }
  6976. }
  6977. break;
  6978. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  6979. if(substr($doc_info[0],0,2)=='..')
  6980. { //relative path going up
  6981. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6982. $file_path = realpath($current_dir.$doc_info[0]);
  6983. //error_log($file_path.' <-> '.$main_path,0);
  6984. if(strstr($file_path,$main_path) !== false)
  6985. {//the calculated real path is really inside the dokeos root path
  6986. //reduce file path to what's under the DocumentRoot
  6987. $file_path = substr($file_path,strlen($root_path));
  6988. //error_log('Reduced path: '.$file_path,0);
  6989. $zip_files_abs[] = $file_path;
  6990. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6991. $my_dep_file->setAttribute('href','document/'.$file_path);
  6992. $my_dep->setAttribute('xml:base','');
  6993. }
  6994. }else{
  6995. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6996. $my_dep_file->setAttribute('href',$doc_info[0]);
  6997. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6998. }
  6999. break;
  7000. default:
  7001. $my_dep_file->setAttribute('href',$doc_info[0]);
  7002. $my_dep->setAttribute('xml:base','');
  7003. break;
  7004. }
  7005. }
  7006. $my_dep->appendChild($my_dep_file);
  7007. $resources->appendChild($my_dep);
  7008. $dependency = $xmldoc->createElement('dependency');
  7009. $dependency->setAttribute('identifierref',$res_id);
  7010. $my_resource->appendChild($dependency);
  7011. $i++;
  7012. }
  7013. //$my_dependency = $xmldoc->createElement('dependency');
  7014. //$my_dependency->setAttribute('identifierref','');
  7015. $resources->appendChild($my_resource);
  7016. $zip_files[] = $my_file_path;
  7017. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  7018. }
  7019. else
  7020. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  7021. if($item->type == TOOL_LINK)
  7022. {
  7023. $my_item = $xmldoc->createElement('item');
  7024. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7025. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7026. $my_item->setAttribute('isvisible','true');
  7027. //give a child element <title> to the <item> element
  7028. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7029. $my_item->appendChild($my_title);
  7030. //give a child element <adlcp:prerequisites> to the <item> element
  7031. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7032. $my_prereqs->setAttribute('type','aicc_script');
  7033. $my_item->appendChild($my_prereqs);
  7034. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  7035. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7036. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  7037. //$xmldoc->createElement('adlcp:timelimitaction','');
  7038. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  7039. //$xmldoc->createElement('adlcp:datafromlms','');
  7040. //give a child element <adlcp:masteryscore> to the <item> element
  7041. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  7042. $my_item->appendChild($my_masteryscore);
  7043. //attach this item to the organization element or its parent if there is one
  7044. if(!empty($item->parent) && $item->parent!=0)
  7045. {
  7046. $children = $organization->childNodes;
  7047. for($i=0;$i<$children->length;$i++){
  7048. $item_temp = $children->item($i);
  7049. if ($item_temp -> nodeName == 'item')
  7050. {
  7051. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7052. {
  7053. $item_temp -> appendChild($my_item);
  7054. }
  7055. }
  7056. }
  7057. }
  7058. else
  7059. {
  7060. $organization->appendChild($my_item);
  7061. }
  7062. $my_file_path = 'link_'.$item->get_id().'.html';
  7063. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7064. $rs = api_sql_query($sql, __FILE__, __LINE__);
  7065. if($link = Database :: fetch_array($rs))
  7066. {
  7067. $url = $link['url'];
  7068. $title = stripslashes($link['title']);
  7069. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  7070. $my_xml_file_path = htmlentities($my_file_path);
  7071. $my_sub_dir = dirname($my_file_path);
  7072. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7073. //give a <resource> child to the <resources> element
  7074. $my_resource = $xmldoc->createElement('resource');
  7075. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7076. $my_resource->setAttribute('type','webcontent');
  7077. $my_resource->setAttribute('href',$my_xml_file_path);
  7078. //adlcp:scormtype can be either 'sco' or 'asset'
  7079. $my_resource->setAttribute('adlcp:scormtype','asset');
  7080. //xml:base is the base directory to find the files declared in this resource
  7081. $my_resource->setAttribute('xml:base','');
  7082. //give a <file> child to the <resource> element
  7083. $my_file = $xmldoc->createElement('file');
  7084. $my_file->setAttribute('href',$my_xml_file_path);
  7085. $my_resource->appendChild($my_file);
  7086. $resources->appendChild($my_resource);
  7087. }
  7088. }
  7089. elseif($item->type == TOOL_QUIZ)
  7090. {
  7091. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  7092. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  7093. $exe = new Exercise();
  7094. $exe->read($exe_id);
  7095. $my_item = $xmldoc->createElement('item');
  7096. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  7097. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  7098. $my_item->setAttribute('isvisible','true');
  7099. //give a child element <title> to the <item> element
  7100. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  7101. $my_item->appendChild($my_title);
  7102. //give a child element <adlcp:prerequisites> to the <item> element
  7103. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  7104. $my_prereqs->setAttribute('type','aicc_script');
  7105. $my_item->appendChild($my_prereqs);
  7106. //give a child element <adlcp:masteryscore> to the <item> element
  7107. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  7108. $my_item->appendChild($my_masteryscore);
  7109. //attach this item to the organization element or hits parent if there is one
  7110. if(!empty($item->parent) && $item->parent!=0)
  7111. {
  7112. $children = $organization->childNodes;
  7113. for($i=0;$i<$children->length;$i++){
  7114. $item_temp = $children->item($i);
  7115. if ($item_temp -> nodeName == 'item')
  7116. {
  7117. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  7118. {
  7119. $item_temp -> appendChild($my_item);
  7120. }
  7121. }
  7122. }
  7123. }
  7124. else
  7125. {
  7126. $organization->appendChild($my_item);
  7127. }
  7128. //include export scripts
  7129. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  7130. //get the path of the file(s) from the course directory root
  7131. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7132. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7133. //write the contents of the exported exercise into a (big) html file
  7134. //to later pack it into the exported SCORM. The file will be removed afterwards
  7135. $contents = export_exercise($exe_id,true);
  7136. $tmp_file_path = $garbage_path.$temp_dir_short.'/'.$my_file_path;
  7137. $res = file_put_contents($tmp_file_path,$contents);
  7138. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7139. $files_cleanup[] = $tmp_file_path;
  7140. //error_log($tmp_path);die();
  7141. $my_xml_file_path = htmlentities($my_file_path);
  7142. $my_sub_dir = dirname($my_file_path);
  7143. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7144. //give a <resource> child to the <resources> element
  7145. $my_resource = $xmldoc->createElement('resource');
  7146. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7147. $my_resource->setAttribute('type','webcontent');
  7148. $my_resource->setAttribute('href',$my_xml_file_path);
  7149. //adlcp:scormtype can be either 'sco' or 'asset'
  7150. $my_resource->setAttribute('adlcp:scormtype','sco');
  7151. //xml:base is the base directory to find the files declared in this resource
  7152. $my_resource->setAttribute('xml:base','');
  7153. //give a <file> child to the <resource> element
  7154. $my_file = $xmldoc->createElement('file');
  7155. $my_file->setAttribute('href',$my_xml_file_path);
  7156. $my_resource->appendChild($my_file);
  7157. //get included docs
  7158. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7159. //dependency to other files - not yet supported
  7160. $i = 1;
  7161. foreach($inc_docs as $doc_info)
  7162. {
  7163. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7164. $my_dep = $xmldoc->createElement('resource');
  7165. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7166. $my_dep->setAttribute('identifier',$res_id);
  7167. $my_dep->setAttribute('type','webcontent');
  7168. $my_dep->setAttribute('adlcp:scormtype','asset');
  7169. $my_dep_file = $xmldoc->createElement('file');
  7170. //check type of URL
  7171. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7172. if($doc_info[1] == 'remote')
  7173. { //remote file. Save url as is
  7174. $my_dep_file->setAttribute('href',$doc_info[0]);
  7175. $my_dep->setAttribute('xml:base','');
  7176. }elseif($doc_info[1] == 'local'){
  7177. switch($doc_info[2])
  7178. {
  7179. case 'url': //local URL - save path as url for now, don't zip file
  7180. //save file but as local file (retrieve from URL)
  7181. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7182. $current_dir = dirname($abs_path);
  7183. $file_path = realpath($abs_path);
  7184. $my_dep_file->setAttribute('href','document/'.$file_path);
  7185. $my_dep->setAttribute('xml:base','');
  7186. if(strstr($file_path,$main_path) !== false)
  7187. {//the calculated real path is really inside the dokeos root path
  7188. //reduce file path to what's under the DocumentRoot
  7189. $file_path = substr($file_path,strlen($root_path));
  7190. //echo $file_path;echo '<br><br>';
  7191. //error_log('Reduced path: '.$file_path,0);
  7192. $zip_files_abs[] = $file_path;
  7193. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7194. $my_dep_file->setAttribute('href','document/'.$file_path);
  7195. $my_dep->setAttribute('xml:base','');
  7196. }
  7197. else if (empty($file_path))
  7198. {
  7199. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7200. if(strpos($document_root,-1)=='/')
  7201. {
  7202. $document_root = substr(0, -1, $document_root);
  7203. }*/
  7204. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7205. $file_path = str_replace('//','/',$file_path);
  7206. if(file_exists($file_path))
  7207. {
  7208. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7209. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7210. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7211. $my_dep_file->setAttribute('href','document/'.$file_path);
  7212. $my_dep->setAttribute('xml:base','');
  7213. }
  7214. }
  7215. break;
  7216. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7217. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7218. $file_path = realpath($doc_info[0]);
  7219. $my_dep_file->setAttribute('href',$file_path);
  7220. $my_dep->setAttribute('xml:base','');
  7221. if(strstr($file_path,$main_path) !== false)
  7222. {//the calculated real path is really inside the dokeos root path
  7223. //reduce file path to what's under the DocumentRoot
  7224. $file_path = substr($file_path,strlen($root_path));
  7225. //echo $file_path;echo '<br><br>';
  7226. //error_log('Reduced path: '.$file_path,0);
  7227. $zip_files_abs[] = $file_path;
  7228. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7229. $my_dep_file->setAttribute('href','document/'.$file_path);
  7230. $my_dep->setAttribute('xml:base','');
  7231. }
  7232. else if (empty($file_path))
  7233. {
  7234. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7235. if(strpos($document_root,-1)=='/')
  7236. {
  7237. $document_root = substr(0, -1, $document_root);
  7238. }*/
  7239. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7240. $file_path = str_replace('//','/',$file_path);
  7241. if(file_exists($file_path))
  7242. {
  7243. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7244. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7245. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7246. $my_dep_file->setAttribute('href','document/'.$file_path);
  7247. $my_dep->setAttribute('xml:base','');
  7248. }
  7249. }
  7250. break;
  7251. case 'rel': //path relative to the current document. Save xml:base as current document's directory and save file in zip as subdir.file_path
  7252. if(substr($doc_info[0],0,2)=='..')
  7253. { //relative path going up
  7254. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7255. $file_path = realpath($current_dir.$doc_info[0]);
  7256. //error_log($file_path.' <-> '.$main_path,0);
  7257. if(strstr($file_path,$main_path) !== false)
  7258. {//the calculated real path is really inside the dokeos root path
  7259. //reduce file path to what's under the DocumentRoot
  7260. $file_path = substr($file_path,strlen($root_path));
  7261. //error_log('Reduced path: '.$file_path,0);
  7262. $zip_files_abs[] = $file_path;
  7263. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7264. $my_dep_file->setAttribute('href','document/'.$file_path);
  7265. $my_dep->setAttribute('xml:base','');
  7266. }
  7267. }else{
  7268. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7269. $my_dep_file->setAttribute('href',$doc_info[0]);
  7270. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7271. }
  7272. break;
  7273. default:
  7274. $my_dep_file->setAttribute('href',$doc_info[0]);
  7275. $my_dep->setAttribute('xml:base','');
  7276. break;
  7277. }
  7278. }
  7279. $my_dep->appendChild($my_dep_file);
  7280. $resources->appendChild($my_dep);
  7281. $dependency = $xmldoc->createElement('dependency');
  7282. $dependency->setAttribute('identifierref',$res_id);
  7283. $my_resource->appendChild($dependency);
  7284. $i++;
  7285. }
  7286. $resources->appendChild($my_resource);
  7287. $zip_files[] = $my_file_path;
  7288. }
  7289. else
  7290. {
  7291. //get the path of the file(s) from the course directory root
  7292. $my_file_path = 'non_exportable.html';
  7293. $my_xml_file_path = htmlentities($my_file_path);
  7294. $my_sub_dir = dirname($my_file_path);
  7295. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7296. //give a <resource> child to the <resources> element
  7297. $my_resource = $xmldoc->createElement('resource');
  7298. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7299. $my_resource->setAttribute('type','webcontent');
  7300. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7301. //adlcp:scormtype can be either 'sco' or 'asset'
  7302. $my_resource->setAttribute('adlcp:scormtype','asset');
  7303. //xml:base is the base directory to find the files declared in this resource
  7304. $my_resource->setAttribute('xml:base','');
  7305. //give a <file> child to the <resource> element
  7306. $my_file = $xmldoc->createElement('file');
  7307. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7308. $my_resource->appendChild($my_file);
  7309. $resources->appendChild($my_resource);
  7310. }
  7311. }
  7312. }
  7313. $organizations->appendChild($organization);
  7314. $root->appendChild($organizations);
  7315. $root->appendChild($resources);
  7316. $xmldoc->appendChild($root);
  7317. //todo: add a readme file here, with a short description and a link to the Reload player
  7318. //then add the file to the zip, then destroy the file (this is done automatically)
  7319. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7320. //error_log(print_r($zip_files,true),0);
  7321. foreach($zip_files as $file_path)
  7322. {
  7323. if(empty($file_path)){continue;}
  7324. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7325. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  7326. $this->create_path($dest_file);
  7327. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  7328. //echo $main_path.$file_path.'<br>';
  7329. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7330. //check if the file needs a link update
  7331. if(in_array($file_path,array_keys($link_updates))){
  7332. $string = file_get_contents($dest_file);
  7333. unlink($dest_file);
  7334. foreach($link_updates[$file_path] as $old_new)
  7335. {
  7336. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7337. //this is an ugly hack that allows .flv files to be found by the flv player that
  7338. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7339. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7340. // ../../.. to return from inc/lib/flv_player to the document/main path
  7341. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7342. {
  7343. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7344. }
  7345. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7346. {
  7347. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7348. }
  7349. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7350. }
  7351. file_put_contents($dest_file,$string);
  7352. }
  7353. }
  7354. foreach($zip_files_abs as $file_path)
  7355. {
  7356. if(empty($file_path)){continue;}
  7357. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7358. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7359. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7360. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  7361. $this->create_path($dest_file);
  7362. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  7363. //error_log('copy '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/'.$file_path.' to '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/'.$file_path,0);
  7364. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7365. copy($main_path.$file_path,$dest_file);
  7366. //check if the file needs a link update
  7367. if(in_array($file_path,array_keys($link_updates)))
  7368. {
  7369. $string = file_get_contents($dest_file);
  7370. unlink($dest_file);
  7371. foreach($link_updates[$file_path] as $old_new)
  7372. {
  7373. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7374. //this is an ugly hack that allows .flv files to be found by the flv player that
  7375. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7376. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7377. // ../../.. to return from inc/lib/flv_player to the document/main path
  7378. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7379. {
  7380. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7381. }
  7382. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7383. }
  7384. file_put_contents($dest_file,$string);
  7385. }
  7386. }
  7387. if(is_array($links_to_create))
  7388. {
  7389. foreach($links_to_create as $file=>$link)
  7390. {
  7391. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7392. file_put_contents($garbage_path.$temp_dir_short.'/'.$file, $file_content);
  7393. }
  7394. }
  7395. // add non exportable message explanation
  7396. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7397. $file_content =
  7398. <<<EOD
  7399. <html>
  7400. <head>
  7401. <style>
  7402. .error-message {
  7403. font-family: arial, verdana, helvetica, sans-serif;
  7404. border-width: 1px;
  7405. border-style: solid;
  7406. left: 50%;
  7407. margin: 10px auto;
  7408. min-height: 30px;
  7409. padding: 5px;
  7410. right: 50%;
  7411. width: 500px;
  7412. background-color: #FFD1D1;
  7413. border-color: #FF0000;
  7414. color: #000;
  7415. }
  7416. </style>
  7417. <body>
  7418. <div class="error-message">
  7419. $lang_not_exportable
  7420. </div>
  7421. </body>
  7422. </html>
  7423. EOD;
  7424. if(!is_dir($garbage_path.$temp_dir_short.'/document'))
  7425. {
  7426. @mkdir($garbage_path.$temp_dir_short.'/document');
  7427. }
  7428. file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7429. //Add the extra files that go along with a SCORM package
  7430. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7431. $extra_files = scandir($main_code_path);
  7432. foreach($extra_files as $extra_file)
  7433. {
  7434. if(strpos($extra_file,'.')===0) continue;
  7435. else
  7436. {
  7437. $dest_file = $garbage_path.$temp_dir_short.'/'.$extra_file;
  7438. $this->create_path($dest_file);
  7439. copy($main_code_path.$extra_file,$dest_file);
  7440. }
  7441. }
  7442. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7443. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7444. $zip_folder->add($garbage_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/'.$temp_dir_short.'/');
  7445. //clean possible temporary files
  7446. foreach($files_cleanup as $file)
  7447. {
  7448. $res = unlink($file);
  7449. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7450. }
  7451. //Send file to client
  7452. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7453. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7454. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7455. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7456. }
  7457. /**
  7458. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7459. * if it doesn't exist
  7460. */
  7461. function create_path($path){
  7462. $path_bits = split('/',dirname($path));
  7463. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7464. $path_built = IS_WINDOWS_OS ? '' : '/';
  7465. foreach($path_bits as $bit){
  7466. if(!empty($bit)){
  7467. $new_path = $path_built.$bit;
  7468. if(is_dir($new_path)){
  7469. $path_built = $new_path.'/';
  7470. }
  7471. else
  7472. {
  7473. mkdir($new_path);
  7474. $path_built = $new_path.'/';
  7475. }
  7476. }
  7477. }
  7478. }
  7479. /**
  7480. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7481. * @return boolean The results of the unlink function, or false if there was no image to start with
  7482. */
  7483. function delete_lp_image()
  7484. {
  7485. $img = $this->get_preview_image();
  7486. if ($img!='')
  7487. {
  7488. $del_file = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$img;
  7489. $this->set_preview_image('');
  7490. return @unlink($del_file);
  7491. }
  7492. else
  7493. {
  7494. return false;
  7495. }
  7496. }
  7497. /**
  7498. * Uploads an author image to the upload/learning_path/images directory
  7499. * @param array The image array, coming from the $_FILES superglobal
  7500. * @return boolean True on success, false on error
  7501. */
  7502. function upload_image($image_array)
  7503. {
  7504. $image_moved=false;
  7505. if(!empty($image_array['name']))
  7506. {
  7507. $upload_ok = process_uploaded_file($image_array);
  7508. $has_attachment=true;
  7509. }
  7510. else
  7511. {
  7512. $image_moved=true;
  7513. }
  7514. if($upload_ok)
  7515. {
  7516. if ($has_attachment)
  7517. {
  7518. $courseDir = api_get_course_path().'/upload/learning_path/images';
  7519. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7520. $updir = $sys_course_path.$courseDir;
  7521. // Try to add an extension to the file if it hasn't one
  7522. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7523. if (!filter_extension($new_file_name))
  7524. {
  7525. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7526. $image_moved=false;
  7527. }
  7528. else
  7529. {
  7530. $file_extension = explode('.', $image_array['name']);
  7531. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7532. $new_file_name = uniqid('').'.'.$file_extension;
  7533. $new_path=$updir.'/'.$new_file_name;
  7534. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7535. // resize the image
  7536. include_once (api_get_path(LIBRARY_PATH).'image.lib.php');
  7537. $temp = new image($image_array['tmp_name']);
  7538. $picture_infos=getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7539. if ($picture_infos[0]>240)
  7540. $thumbwidth=240;
  7541. else
  7542. $thumbwidth=$picture_infos[0];
  7543. if ($picture_infos[1]>100)
  7544. $new_height=100;
  7545. else
  7546. $new_height = $picture_infos[1];
  7547. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7548. $temp->resize($thumbwidth,$new_height,0);
  7549. $type=$picture_infos[2];
  7550. $result=false;
  7551. switch ($type)
  7552. {
  7553. case 2 :
  7554. $result=$temp->send_image('JPG',$new_path);
  7555. break;
  7556. case 3 :
  7557. $result=$temp->send_image('PNG',$new_path);
  7558. break;
  7559. case 1 :
  7560. $result=$temp->send_image('GIF',$new_path);
  7561. break;
  7562. }
  7563. // Storing the image filename
  7564. if ($result)
  7565. {
  7566. $image_moved=true;
  7567. $this->set_preview_image($new_file_name);
  7568. return true;
  7569. }
  7570. }
  7571. }
  7572. }
  7573. return false;
  7574. }
  7575. }
  7576. if (!function_exists('trim_value')) {
  7577. function trim_value(&$value) {
  7578. $value = trim($value);
  7579. }
  7580. }