learnpath.class.php 332 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897
  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 = 0; //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. //if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
  740. foreach($this->items as $id => $dummy)
  741. {
  742. $this->items[$id]->delete();
  743. }
  744. $lp = Database::get_course_table('lp');
  745. $lp_view = Database::get_course_table('lp_view');
  746. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ".$this->lp_id;
  747. //if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
  748. $res_del_view = api_sql_query($sql_del_view, __FILE__, __LINE__);
  749. $this->toggle_publish($this->lp_id,'i');
  750. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
  751. if($this->type == 2 OR $this->type==3){
  752. //this is a scorm learning path, delete the files as well
  753. $sql = "SELECT path FROM $lp WHERE id = ".$this->lp_id;
  754. $res = api_sql_query($sql, __FILE__, __LINE__);
  755. if(Database::num_rows($res)>0){
  756. $row = Database::fetch_array($res);
  757. $path = $row['path'];
  758. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ".$this->lp_id;
  759. $res = api_sql_query($sql, __FILE__, __LINE__);
  760. if(Database::num_rows($res)>0)
  761. { //another learning path uses this directory, so don't delete it
  762. if($this->debug>2){error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory',0);}
  763. }else{
  764. //no other LP uses that directory, delete it
  765. $course_rel_dir = api_get_course_path().'/scorm/'; //scorm dir web path starting from /courses
  766. $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
  767. if($delete == 'remove' && is_dir($course_scorm_dir.$path) and !empty($course_scorm_dir)){
  768. if($this->debug>2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path,0);}
  769. exec('rm -rf '.$course_scorm_dir.$path);
  770. }
  771. }
  772. }
  773. }
  774. $sql_del_lp = "DELETE FROM $lp WHERE id = ".$this->lp_id;
  775. //if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
  776. $res_del_lp = api_sql_query($sql_del_lp, __FILE__, __LINE__);
  777. $this->update_display_order();//updates the display order of all lps
  778. api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$this->lp_id,'delete',api_get_user_id());
  779. require_once '../gradebook/lib/be.inc.php';
  780. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  781. //delete link of gradebook tool
  782. $sql='SELECT gl.id FROM '.$tbl_grade_link.' gl WHERE gl.type="4" AND gl.ref_id="'.$id.'";';
  783. $result=api_sql_query($sql,__FILE__,__LINE__);
  784. $row=Database::fetch_array($result,'ASSOC');
  785. $link= LinkFactory :: load($row['id']);
  786. if ($link[0] != null) {
  787. $link[0]->delete();
  788. }
  789. //TODO: also delete items and item-views
  790. if (api_get_setting('search_enabled') == 'true') {
  791. require_once(api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php');
  792. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  793. }
  794. }
  795. /**
  796. * Removes all the children of one item - dangerous!
  797. * @param integer Element ID of which children have to be removed
  798. * @return integer Total number of children removed
  799. */
  800. function delete_children_items($id){
  801. if($this->debug>0){error_log('New LP - In learnpath::delete_children_items('.$id.')',0);}
  802. $num = 0;
  803. if(empty($id) || $id != strval(intval($id))){return false;}
  804. $lp_item = Database::get_course_table('lp_item');
  805. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  806. $res = api_sql_query($sql, __FILE__, __LINE__);
  807. while($row = Database::fetch_array($res)){
  808. $num += $this->delete_children_items($row['id']);
  809. $sql_del = "DELETE FROM $lp_item WHERE id = ".$row['id'];
  810. $res_del = api_sql_query($sql_del, __FILE__, __LINE__);
  811. $num++;
  812. }
  813. return $num;
  814. }
  815. /**
  816. * Removes an item from the current learnpath
  817. * @param integer Elem ID (0 if first)
  818. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  819. * @return integer Number of elements moved
  820. * @todo implement resource removal
  821. */
  822. function delete_item($id, $remove='keep')
  823. {
  824. if($this->debug>0){error_log('New LP - In learnpath::delete_item()',0);}
  825. //TODO - implement the resource removal
  826. if(empty($id) || $id != strval(intval($id))){return false;}
  827. //first select item to get previous, next, and display order
  828. $lp_item = Database::get_course_table('lp_item');
  829. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  830. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  831. if(Database::num_rows($res_sel)<1){return false;}
  832. $row = Database::fetch_array($res_sel);
  833. $previous = $row['previous_item_id'];
  834. $next = $row['next_item_id'];
  835. $display = $row['display_order'];
  836. $parent = $row['parent_item_id'];
  837. $lp = $row['lp_id'];
  838. //delete children items
  839. $num = $this->delete_children_items($id);
  840. if($this->debug>2){error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id,0);}
  841. //now delete the item
  842. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  843. if($this->debug>2){error_log('New LP - Deleting item: '.$sql_del,0);}
  844. $res_del = api_sql_query($sql_del,__FILE__,__LINE__);
  845. //now update surrounding items
  846. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  847. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  848. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  849. $res_upd = api_sql_query($sql_upd,__FILE__,__LINE__);
  850. //now update all following items with new display order
  851. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  852. $res_all = api_sql_query($sql_all,__FILE__,__LINE__);
  853. // remove from search engine if enabled
  854. if (api_get_setting('search_enabled') == 'true') {
  855. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  856. $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';
  857. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  858. $res = api_sql_query($sql, __FILE__, __LINE__);
  859. if (Database::num_rows($res) > 0) {
  860. $row2 = Database::fetch_array($res);
  861. require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php');
  862. $di = new DokeosIndexer();
  863. $di->remove_document((int)$row2['search_did']);
  864. }
  865. $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';
  866. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  867. api_sql_query($sql, __FILE__, __LINE__);
  868. }
  869. }
  870. /**
  871. * Updates an item's content in place
  872. * @param integer Element ID
  873. * @param integer Parent item ID
  874. * @param integer Previous item ID
  875. * @param string Item title
  876. * @param string Item description
  877. * @param string Prerequisites (optional)
  878. * @param string Indexing terms (optional)
  879. * @param array The array resulting of the $_FILES[mp3] element
  880. * @return boolean True on success, false on error
  881. */
  882. function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $audio=NULL, $max_time_allowed=0) {
  883. if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
  884. if(empty($max_time_allowed)) { $max_time_allowed = 0;}
  885. if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
  886. $tbl_lp_item = Database::get_course_table('lp_item');
  887. $sql_select = "
  888. SELECT *
  889. FROM " . $tbl_lp_item . "
  890. 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. //upload file in documents
  896. $pi = pathinfo($audio['name']);
  897. if ($pi['extension'] == 'mp3') {
  898. $c_det = api_get_course_info($this->cc);
  899. $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document';
  900. $path = handle_uploaded_document($c_det,$audio,$bp,'/audio',api_get_user_id(),0,null,'',0,'rename',false,0);
  901. $path = substr($path,7);
  902. //update reference in lp_item - audio path is the path from inside de document/audio/ dir
  903. $audio_update_sql = ", audio = '".Database::escape_string($path)."' ";
  904. }
  905. }
  906. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  907. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  908. if($same_parent && $same_previous)
  909. {
  910. //only update title and description
  911. $sql_update = "
  912. UPDATE " . $tbl_lp_item . "
  913. SET
  914. title = '" . $this->escape_string(htmlentities($title)) . "',
  915. prerequisite = '".$prerequisites."',
  916. description = '" . $this->escape_string(htmlentities($description)) . "'
  917. ". $audio_update_sql . ",
  918. max_time_allowed = '" . $this->escape_string(htmlentities($max_time_allowed)) . "'
  919. WHERE id = " . $id;
  920. $res_update = api_sql_query($sql_update, __FILE__, __LINE__);
  921. }
  922. else
  923. {
  924. $old_parent = $row_select['parent_item_id'];
  925. $old_previous = $row_select['previous_item_id'];
  926. $old_next = $row_select['next_item_id'];
  927. $old_order = $row_select['display_order'];
  928. $old_prerequisite = $row_select['prerequisite'];
  929. $old_max_time_allowed = $row_select['max_time_allowed'];
  930. /* BEGIN -- virtually remove the current item id */
  931. /* for the next and previous item it is like the current item doesn't exist anymore */
  932. if($old_previous != 0)
  933. {
  934. $sql_update_next = "
  935. UPDATE " . $tbl_lp_item . "
  936. SET next_item_id = " . $old_next . "
  937. WHERE id = " . $old_previous;
  938. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  939. //echo '<p>' . $sql_update_next . '</p>';
  940. }
  941. if($old_next != 0)
  942. {
  943. $sql_update_previous = "
  944. UPDATE " . $tbl_lp_item . "
  945. SET previous_item_id = " . $old_previous . "
  946. WHERE id = " . $old_next;
  947. $res_update_previous = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  948. //echo '<p>' . $sql_update_previous . '</p>';
  949. }
  950. //display_order - 1 for every item with a display_order bigger then the display_order of the current item
  951. $sql_update_order = "
  952. UPDATE " . $tbl_lp_item . "
  953. SET display_order = display_order - 1
  954. WHERE
  955. display_order > " . $old_order . " AND
  956. parent_item_id = " . $old_parent;
  957. $res_update_order = api_sql_query($sql_update_order, __FILE__, __LINE__);
  958. //echo '<p>' . $sql_update_order . '</p>';
  959. /* END -- virtually remove the current item id */
  960. /* BEGIN -- update the current item id to his new location */
  961. if($previous == 0)
  962. {
  963. //select the data of the item that should come after the current item
  964. $sql_select_old = "
  965. SELECT
  966. id,
  967. display_order
  968. FROM " . $tbl_lp_item . "
  969. WHERE
  970. lp_id = " . $this->lp_id . " AND
  971. parent_item_id = " . $parent . " AND
  972. previous_item_id = " . $previous;
  973. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  974. $row_select_old = Database::fetch_array($res_select_old);
  975. //echo '<p>' . $sql_select_old . '</p>';
  976. //if the new parent didn't have children before
  977. if(Database::num_rows($res_select_old) == 0)
  978. {
  979. $new_next = 0;
  980. $new_order = 1;
  981. }
  982. else
  983. {
  984. $new_next = $row_select_old['id'];
  985. $new_order = $row_select_old['display_order'];
  986. }
  987. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  988. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  989. //echo 'New display_order of current item: ' . $new_order . '<br />';
  990. }
  991. else
  992. {
  993. //select the data of the item that should come before the current item
  994. $sql_select_old = "
  995. SELECT
  996. next_item_id,
  997. display_order
  998. FROM " . $tbl_lp_item . "
  999. WHERE id = " . $previous;
  1000. $res_select_old = api_sql_query($sql_select_old, __FILE__, __LINE__);
  1001. $row_select_old = Database::fetch_array($res_select_old);
  1002. //echo '<p>' . $sql_select_old . '</p>';
  1003. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1004. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1005. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1006. $new_next = $row_select_old['next_item_id'];
  1007. $new_order = $row_select_old['display_order'] + 1;
  1008. }
  1009. //update the current item with the new data
  1010. $sql_update = "
  1011. UPDATE " . $tbl_lp_item . "
  1012. SET
  1013. title = '" . $this->escape_string(htmlentities($title)) . "',
  1014. description = '" . $this->escape_string(htmlentities($description)) . "',
  1015. parent_item_id = " . $parent . ",
  1016. previous_item_id = " . $previous . ",
  1017. next_item_id = " . $new_next . ",
  1018. display_order = " . $new_order . "
  1019. ". $audio_update_sql . "
  1020. WHERE id = " . $id;
  1021. $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__);
  1022. //echo '<p>' . $sql_update . '</p>';
  1023. if($previous != 0)
  1024. {
  1025. //update the previous item's next_item_id
  1026. $sql_update_previous = "
  1027. UPDATE " . $tbl_lp_item . "
  1028. SET next_item_id = " . $id . "
  1029. WHERE id = " . $previous;
  1030. $res_update_next = api_sql_query($sql_update_previous, __FILE__, __LINE__);
  1031. //echo '<p>' . $sql_update_previous . '</p>';
  1032. }
  1033. if($new_next != 0)
  1034. {
  1035. //update the next item's previous_item_id
  1036. $sql_update_next = "
  1037. UPDATE " . $tbl_lp_item . "
  1038. SET previous_item_id = " . $id . "
  1039. WHERE id = " . $new_next;
  1040. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1041. //echo '<p>' . $sql_update_next . '</p>';
  1042. }
  1043. if($old_prerequisite!=$prerequisites){
  1044. $sql_update_next = "
  1045. UPDATE " . $tbl_lp_item . "
  1046. SET prerequisite = " . $prerequisites . "
  1047. WHERE id = " . $id;
  1048. $res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
  1049. }
  1050. if($old_max_time_allowed!=$max_time_allowed){
  1051. $sql_update_max_time_allowed = "
  1052. UPDATE " . $tbl_lp_item . "
  1053. SET max_time_allowed = " . $max_time_allowed . "
  1054. WHERE id = " . $id;
  1055. $res_update_max_time_allowed = api_sql_query($sql_update_max_time_allowed, __FILE__, __LINE__);
  1056. }
  1057. //update all the items with the same or a bigger display_order than
  1058. //the current item
  1059. $sql_update_order = "
  1060. UPDATE " . $tbl_lp_item . "
  1061. SET display_order = display_order + 1
  1062. WHERE
  1063. lp_id = " . $this->get_id() . " AND
  1064. id <> " . $id . " AND
  1065. parent_item_id = " . $parent . " AND
  1066. display_order >= " . $new_order;
  1067. $res_update_next = api_sql_query($sql_update_order, __FILE__, __LINE__);
  1068. //echo '<p>' . $sql_update_order . '</p>';
  1069. /* END -- update the current item id to his new location */
  1070. }
  1071. }
  1072. /**
  1073. * Updates an item's prereq in place
  1074. * @param integer Element ID
  1075. * @param string Prerequisite Element ID
  1076. *
  1077. * @param string Prerequisite item type
  1078. *
  1079. * @param string Prerequisite min score
  1080. *
  1081. * @param string Prerequisite max score
  1082. * @return boolean True on success, false on error
  1083. */
  1084. function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
  1085. {
  1086. if($this->debug>0){error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')',0);}
  1087. if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
  1088. $prerequisite_id = $this->escape_string($prerequisite_id);
  1089. $tbl_lp_item = Database::get_course_table('lp_item');
  1090. if(!is_numeric($mastery_score) || $mastery_score < 0)
  1091. $mastery_score = 0;
  1092. if(!is_numeric($max_score) || $max_score < 0)
  1093. $max_score = 100;
  1094. if($mastery_score > $max_score)
  1095. $max_score = $mastery_score;
  1096. if(!is_numeric($prerequisite_id))
  1097. $prerequisite_id = 'NULL';
  1098. $sql_upd = "
  1099. UPDATE " . $tbl_lp_item . "
  1100. SET prerequisite = ".$prerequisite_id." WHERE id = ".$id;
  1101. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1102. if($prerequisite_id!='NULL' && $prerequisite_id!='')
  1103. {
  1104. $sql_upd = " UPDATE ".$tbl_lp_item." SET
  1105. mastery_score = " . $mastery_score .
  1106. //", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
  1107. " WHERE ref = '" . $prerequisite_id."'" ; //will this be enough to ensure unicity?
  1108. $res_upd = api_sql_query($sql_upd ,__FILE__, __LINE__);
  1109. }
  1110. //TODO update the item object (can be ignored for now because refreshed)
  1111. return true;
  1112. }
  1113. /**
  1114. * Escapes a string with the available database escape function
  1115. * @param string String to escape
  1116. * @return string String escaped
  1117. */
  1118. function escape_string($string){
  1119. //if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
  1120. return Database::escape_string($string);
  1121. }
  1122. /**
  1123. * Static admin function exporting a learnpath into a zip file
  1124. * @param string Export type (scorm, zip, cd)
  1125. * @param string Course code
  1126. * @param integer Learnpath ID
  1127. * @param string Zip file name
  1128. * @return string Zip file path (or false on error)
  1129. */
  1130. function export_lp($type, $course, $id, $zipname)
  1131. {
  1132. //if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
  1133. //TODO
  1134. if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
  1135. $url = '';
  1136. switch($type){
  1137. case 'scorm':
  1138. break;
  1139. case 'zip':
  1140. break;
  1141. case 'cdrom':
  1142. break;
  1143. }
  1144. return $url;
  1145. }
  1146. /**
  1147. * Gets all the chapters belonging to the same parent as the item/chapter given
  1148. * Can also be called as abstract method
  1149. * @param integer Item ID
  1150. * @return array A list of all the "brother items" (or an empty array on failure)
  1151. */
  1152. function get_brother_chapters($id){
  1153. if($this->debug>0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
  1154. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1155. $lp_item = Database::get_course_table('lp_item');
  1156. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1157. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1158. if(Database::num_rows($res_parent)>0){
  1159. $row_parent = Database::fetch_array($res_parent);
  1160. $parent = $row_parent['parent_item_id'];
  1161. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1162. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1163. $list = array();
  1164. while ($row_bro = Database::fetch_array($res_bros)){
  1165. $list[] = $row_bro;
  1166. }
  1167. return $list;
  1168. }
  1169. return array();
  1170. }
  1171. /**
  1172. * Gets all the items belonging to the same parent as the item given
  1173. * Can also be called as abstract method
  1174. * @param integer Item ID
  1175. * @return array A list of all the "brother items" (or an empty array on failure)
  1176. */
  1177. function get_brother_items($id){
  1178. if($this->debug>0){error_log('New LP - In learnpath::get_brother_items('.$id.')',0);}
  1179. if(empty($id) OR $id != strval(intval($id))){ return array();}
  1180. $lp_item = Database::get_course_table('lp_item');
  1181. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1182. $res_parent = api_sql_query($sql_parent,__FILE__,__LINE__);
  1183. if(Database::num_rows($res_parent)>0){
  1184. $row_parent = Database::fetch_array($res_parent);
  1185. $parent = $row_parent['parent_item_id'];
  1186. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1187. $res_bros = api_sql_query($sql_bros,__FILE__,__LINE__);
  1188. $list = array();
  1189. while ($row_bro = Database::fetch_array($res_bros)){
  1190. $list[] = $row_bro;
  1191. }
  1192. return $list;
  1193. }
  1194. return array();
  1195. }
  1196. /**
  1197. * Get the specific prefix index terms of this learning path
  1198. * @return array Array of terms
  1199. */
  1200. function get_common_index_terms_by_prefix($prefix)
  1201. {
  1202. require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
  1203. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1204. $prefix_terms = array();
  1205. foreach($terms as $term)
  1206. {
  1207. $prefix_terms[] = $term['value'];
  1208. }
  1209. return $prefix_terms;
  1210. }
  1211. /**
  1212. * Gets the number of items currently completed
  1213. * @return integer The number of items currently completed
  1214. */
  1215. function get_complete_items_count()
  1216. {
  1217. if($this->debug>0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
  1218. $i = 0;
  1219. foreach($this->items as $id => $dummy){
  1220. //if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
  1221. //Trying failed and browsed considered "progressed" as well
  1222. 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'){
  1223. $i++;
  1224. }
  1225. }
  1226. return $i;
  1227. }
  1228. /**
  1229. * Gets the current item ID
  1230. * @return integer The current learnpath item id
  1231. */
  1232. function get_current_item_id()
  1233. {
  1234. $current = 0;
  1235. if($this->debug>0){error_log('New LP - In learnpath::get_current_item_id()',0);}
  1236. if(!empty($this->current))
  1237. {
  1238. $current = $this->current;
  1239. }
  1240. if($this->debug>2){error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current,0);}
  1241. return $current;
  1242. }
  1243. /**
  1244. * Gets the total number of items available for viewing in this SCORM
  1245. * @return integer The total number of items
  1246. */
  1247. function get_total_items_count()
  1248. {
  1249. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count()',0);}
  1250. return count($this->items);
  1251. }
  1252. /**
  1253. * Gets the total number of items available for viewing in this SCORM but without chapters
  1254. * @return integer The total no-chapters number of items
  1255. */
  1256. function get_total_items_count_without_chapters()
  1257. {
  1258. if($this->debug>0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
  1259. $total=0;
  1260. foreach($this->items as $temp=>$temp2){
  1261. if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++;
  1262. }
  1263. return $total;
  1264. }
  1265. /**
  1266. * Gets the first element URL.
  1267. * @return string URL to load into the viewer
  1268. */
  1269. function first()
  1270. {
  1271. if($this->debug>0){error_log('New LP - In learnpath::first()',0);}
  1272. //test if the last_item_seen exists and is not a dir
  1273. if ( count($this->ordered_items) == 0 ) {
  1274. $this->index = 0;
  1275. }
  1276. if(!empty($this->last_item_seen)
  1277. && !empty($this->items[$this->last_item_seen])
  1278. && $this->items[$this->last_item_seen]->get_type() != 'dir'
  1279. && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
  1280. && $this->items[$this->last_item_seen]->is_done() != true
  1281. ){
  1282. 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);}
  1283. $index = -1;
  1284. foreach($this->ordered_items as $myindex => $item_id){
  1285. if($item_id == $this->last_item_seen){
  1286. $index = $myindex;
  1287. break;
  1288. }
  1289. }
  1290. if($index==-1){
  1291. //index hasn't changed, so item not found - panic (this shouldn't happen)
  1292. 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);}
  1293. return false;
  1294. }else{
  1295. $this->last = $this->last_item_seen;
  1296. $this->current = $this->last_item_seen;
  1297. $this->index = $index;
  1298. }
  1299. }else{
  1300. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen',0);}
  1301. $index = 0;
  1302. //loop through all ordered items and stop at the first item that is
  1303. //not a directory *and* that has not been completed yet
  1304. while (!empty($this->ordered_items[$index])
  1305. AND
  1306. is_a($this->items[$this->ordered_items[$index]],'learnpathItem')
  1307. AND
  1308. (
  1309. $this->items[$this->ordered_items[$index]]->get_type() == 'dir'
  1310. OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter'
  1311. OR $this->items[$this->ordered_items[$index]]->is_done() === true
  1312. )
  1313. AND $index < $this->max_ordered_items)
  1314. {
  1315. $index ++;
  1316. }
  1317. $this->last = $this->current;
  1318. //current is
  1319. $this->current = $this->ordered_items[$index];
  1320. $this->index = $index;
  1321. if($this->debug>2){error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')',0);}
  1322. }
  1323. if($this->debug>2){error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id());}
  1324. }
  1325. /**
  1326. * Gets the information about an item in a format usable as JavaScript to update
  1327. * the JS API by just printing this content into the <head> section of the message frame
  1328. * @param integer Item ID
  1329. * @return string
  1330. */
  1331. function get_js_info($item_id=''){
  1332. if($this->debug>0){error_log('New LP - In learnpath::get_js_info('.$item_id.')',0);}
  1333. $info = '';
  1334. $item_id = $this->escape_string($item_id);
  1335. if(!empty($item_id) && is_object($this->items[$item_id])){
  1336. //if item is defined, return values from DB
  1337. $oItem = $this->items[$item_id];
  1338. $info .= '<script language="javascript">';
  1339. $info .= "top.set_score(".$oItem->get_score().");\n";
  1340. $info .= "top.set_max(".$oItem->get_max().");\n";
  1341. $info .= "top.set_min(".$oItem->get_min().");\n";
  1342. $info .= "top.set_lesson_status('".$oItem->get_status()."');";
  1343. $info .= "top.set_session_time('".$oItem->get_scorm_time('js')."');";
  1344. $info .= "top.set_suspend_data('".$oItem->get_suspend_data()."');";
  1345. $info .= "top.set_saved_lesson_status('".$oItem->get_status()."');";
  1346. $info .= "top.set_flag_synchronized();";
  1347. $info .= '</script>';
  1348. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1349. return $info;
  1350. }else{
  1351. //if item_id is empty, just update to default SCORM data
  1352. $info .= '<script language="javascript">';
  1353. $info .= "top.set_score(".learnpathItem::get_score().");\n";
  1354. $info .= "top.set_max(".learnpathItem::get_max().");\n";
  1355. $info .= "top.set_min(".learnpathItem::get_min().");\n";
  1356. $info .= "top.set_lesson_status('".learnpathItem::get_status()."');";
  1357. $info .= "top.set_session_time('".learnpathItem::get_scorm_time('js')."');";
  1358. $info .= "top.set_suspend_data('".learnpathItem::get_suspend_data()."');";
  1359. $info .= "top.set_saved_lesson_status('".learnpathItem::get_status()."');";
  1360. $info .= "top.set_flag_synchronized();";
  1361. $info .= '</script>';
  1362. if($this->debug>2){error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info,0);}
  1363. return $info;
  1364. }
  1365. }
  1366. /**
  1367. * Gets the js library from the database
  1368. * @return string The name of the javascript library to be used
  1369. */
  1370. function get_js_lib(){
  1371. $lib = '';
  1372. if(!empty($this->js_lib)){
  1373. $lib = $this->js_lib;
  1374. }
  1375. return $lib;
  1376. }
  1377. /**
  1378. * Gets the learnpath database ID
  1379. * @return integer Learnpath ID in the lp table
  1380. */
  1381. function get_id()
  1382. {
  1383. if($this->debug>0){error_log('New LP - In learnpath::get_id()',0);}
  1384. if(!empty($this->lp_id))
  1385. {
  1386. return $this->lp_id;
  1387. }else{
  1388. return 0;
  1389. }
  1390. }
  1391. /**
  1392. * Gets the last element URL.
  1393. * @return string URL to load into the viewer
  1394. */
  1395. function get_last()
  1396. {
  1397. if($this->debug>0){error_log('New LP - In learnpath::get_last()',0);}
  1398. $this->index = count($this->ordered_items)-1;
  1399. return $this->ordered_items[$this->index];
  1400. }
  1401. /**
  1402. * Gets the navigation bar for the learnpath display screen
  1403. * @return string The HTML string to use as a navigation bar
  1404. */
  1405. function get_navigation_bar()
  1406. {
  1407. if($this->debug>0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
  1408. //TODO find a good value for the following variables
  1409. $file = '';
  1410. $openDir = '';
  1411. $edoceo = '';
  1412. $time = 0;
  1413. $navbar = '';
  1414. $RequestUri = '';
  1415. $mycurrentitemid = $this->get_current_item_id();
  1416. if($this->mode == 'fullscreen')
  1417. {
  1418. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1419. ' <tr> '."\n" .
  1420. ' <td>'."\n" .
  1421. ' <div class="buttons">'."\n" .
  1422. ' <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('ScormMystatus').'"></a>'."\n" .
  1423. ' <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" .
  1424. ' <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" .
  1425. //' <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" .
  1426. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1427. ' </div>'."\n" .
  1428. ' </td>'."\n" .
  1429. ' </tr>'."\n" .
  1430. '</table>'."\n" ;
  1431. }else{
  1432. $navbar = '<table cellpadding="0" cellspacing="0" align="left">'."\n".
  1433. ' <tr> '."\n" .
  1434. ' <td>'."\n" .
  1435. ' <div class="buttons">'."\n" .
  1436. ' <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('ScormMystatus').'"></a>'."\n" .
  1437. ' <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" .
  1438. ' <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" .
  1439. // ' <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" .
  1440. ' </div>'."\n" .
  1441. ' </td>'."\n" .
  1442. ' </tr>'."\n" .
  1443. '</table>'."\n" ;
  1444. }
  1445. return $navbar;
  1446. }
  1447. /**
  1448. * Gets the next resource in queue (url).
  1449. * @return string URL to load into the viewer
  1450. */
  1451. function get_next_index()
  1452. {
  1453. if($this->debug>0){error_log('New LP - In learnpath::get_next_index()',0);}
  1454. //TODO
  1455. $index = $this->index;
  1456. $index ++;
  1457. if($this->debug>2){error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type,0);}
  1458. 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)
  1459. {
  1460. $index ++;
  1461. if($index == $this->max_ordered_items)
  1462. {
  1463. return $this->index;
  1464. }
  1465. }
  1466. if(empty($this->ordered_items[$index])){
  1467. return $this->index;
  1468. }
  1469. if($this->debug>2){error_log('New LP - index is now '.$index,0);}
  1470. return $index;
  1471. }
  1472. /**
  1473. * Gets item_id for the next element
  1474. * @return integer Next item (DB) ID
  1475. */
  1476. function get_next_item_id()
  1477. {
  1478. if($this->debug>0){error_log('New LP - In learnpath::get_next_item_id()',0);}
  1479. $new_index = $this->get_next_index();
  1480. if(!empty($new_index))
  1481. {
  1482. if(isset($this->ordered_items[$new_index]))
  1483. {
  1484. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index],0);}
  1485. return $this->ordered_items[$new_index];
  1486. }
  1487. }
  1488. if($this->debug>2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
  1489. return 0;
  1490. }
  1491. /**
  1492. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1493. *
  1494. * Generally, the package provided is in the form of a zip file, so the function
  1495. * has been written to test a zip file. If not a zip, the function will return the
  1496. * default return value: ''
  1497. * @param string the path to the file
  1498. * @param string the original name of the file
  1499. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1500. */
  1501. function get_package_type($file_path,$file_name){
  1502. //get name of the zip file without the extension
  1503. $file_info = pathinfo($file_name);
  1504. $filename = $file_info['basename'];//name including extension
  1505. $extension = $file_info['extension'];//extension only
  1506. if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
  1507. {
  1508. return 'oogie';
  1509. }
  1510. if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
  1511. {
  1512. return 'woogie';
  1513. }
  1514. $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
  1515. $zipFile = new pclZip($file_path);
  1516. // Check the zip content (real size and file extension)
  1517. $zipContentArray = $zipFile->listContent();
  1518. $package_type='';
  1519. $at_root = false;
  1520. $manifest = '';
  1521. //the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
  1522. if (is_array($zipContentArray) && count($zipContentArray)>0) {
  1523. foreach($zipContentArray as $thisContent)
  1524. {
  1525. if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
  1526. {
  1527. //New behaviour: Don't do anything. These files will be removed in scorm::import_package
  1528. }
  1529. elseif(stristr($thisContent['filename'],'imsmanifest.xml')!==FALSE)
  1530. {
  1531. $manifest = $thisContent['filename']; //just the relative directory inside scorm/
  1532. $package_type = 'scorm';
  1533. break;//exit the foreach loop
  1534. }
  1535. elseif(preg_match('/aicc\//i',$thisContent['filename'])!=false)
  1536. {//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
  1537. $package_type='aicc';
  1538. //break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
  1539. }
  1540. else
  1541. {
  1542. $package_type = '';
  1543. }
  1544. }
  1545. }
  1546. return $package_type;
  1547. }
  1548. /**
  1549. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1550. * @return string URL to load into the viewer
  1551. */
  1552. function get_previous_index()
  1553. {
  1554. if($this->debug>0){error_log('New LP - In learnpath::get_previous_index()',0);}
  1555. $index = $this->index;
  1556. if(isset($this->ordered_items[$index-1])){
  1557. $index --;
  1558. 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'))
  1559. {
  1560. $index --;
  1561. if($index < 0){
  1562. return $this->index;
  1563. }
  1564. }
  1565. }else{
  1566. if($this->debug>2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index,0);}
  1567. //no previous item
  1568. }
  1569. return $index;
  1570. }
  1571. /**
  1572. * Gets item_id for the next element
  1573. * @return integer Previous item (DB) ID
  1574. */
  1575. function get_previous_item_id()
  1576. {
  1577. $new_index = $this->get_previous_index();
  1578. return $this->ordered_items[$new_index];
  1579. }
  1580. /**
  1581. * Gets the progress value from the progress_db attribute
  1582. * @return integer Current progress value
  1583. */
  1584. function get_progress()
  1585. {
  1586. if($this->debug>0){error_log('New LP - In learnpath::get_progress()',0);}
  1587. if(!empty($this->progress_db))
  1588. {
  1589. return $this->progress_db;
  1590. }
  1591. return 0;
  1592. }
  1593. /**
  1594. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1595. * @param integer Learnpath ID
  1596. * @param integer User ID
  1597. * @param string Mode of display ('%','abs' or 'both')
  1598. * @param string Course database name (optional, defaults to '')
  1599. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1600. * @return integer Current progress value as found in the database
  1601. */
  1602. function get_db_progress($lp_id,$user_id,$mode='%', $course_db='', $sincere=false)
  1603. {
  1604. //if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
  1605. $table = Database::get_course_table('lp_view', $course_db);
  1606. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
  1607. $res = api_sql_query($sql,__FILE__,__LINE__);
  1608. $view_id = 0;
  1609. if(Database::num_rows($res)>0)
  1610. {
  1611. $row = Database::fetch_array($res);
  1612. $progress = $row['progress'];
  1613. $view_id = $row['id'];
  1614. }
  1615. else
  1616. {
  1617. if($sincere)
  1618. {
  1619. return null;
  1620. }
  1621. }
  1622. if(empty($progress))
  1623. {
  1624. $progress = '0';
  1625. }
  1626. if($mode == '%')
  1627. {
  1628. return $progress.'%';
  1629. }
  1630. else
  1631. {
  1632. //get the number of items completed and the number of items total
  1633. $tbl = Database::get_course_table('lp_item', $course_db);
  1634. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = ".$lp_id."
  1635. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1636. $res = api_sql_query($sql, __FILE__, __LINE__);
  1637. $row = Database::fetch_array($res);
  1638. $total = $row[0];
  1639. $tbl_item_view = Database::get_course_table('lp_item_view', $course_db);
  1640. $tbl_item = Database::get_course_table('lp_item', $course_db);
  1641. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1642. //trying as also counting browsed and failed items
  1643. $sql = "SELECT count(distinct(lp_item_id))
  1644. FROM $tbl_item_view as item_view
  1645. INNER JOIN $tbl_item as item
  1646. ON item.id = item_view.lp_item_id
  1647. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1648. WHERE lp_view_id = ".$view_id."
  1649. AND status IN ('passed','completed','succeeded','browsed','failed')";
  1650. $res = api_sql_query($sql, __FILE__, __LINE__);
  1651. $row = Database::fetch_array($res);
  1652. $completed = $row[0];
  1653. if($mode == 'abs')
  1654. {
  1655. return $completed.'/'.$total;
  1656. }
  1657. elseif($mode == 'both')
  1658. {
  1659. if($progress<($completed/($total?$total:1)))
  1660. {
  1661. $progress = number_format(($completed/($total?$total:1))*100,0);
  1662. }
  1663. return $progress.'% ('.$completed.'/'.$total.')';
  1664. }
  1665. }
  1666. return $progress;
  1667. }
  1668. function get_mediaplayer()
  1669. {
  1670. global $_course;
  1671. // Database table definition
  1672. $tbl_lp_item = Database::get_course_table('lp_item');
  1673. // getting all the information about the item
  1674. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = '" . $_SESSION['oLP']->current."'";
  1675. $result = api_sql_query($sql, __FILE__, __LINE__);
  1676. $row= mysql_fetch_assoc($result);
  1677. $output='';
  1678. if (!empty($row['audio']))
  1679. {
  1680. // the mp3 player
  1681. $output = '<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
  1682. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1683. $output .= '<script type="text/javascript">
  1684. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1685. s1.addParam("allowscriptaccess","always");
  1686. s1.addParam("flashvars","file='.api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  1687. s1.write("container");
  1688. </script>';
  1689. }
  1690. return $output;
  1691. }
  1692. /**
  1693. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1694. * completed so far.
  1695. * @param string Mode in which we want the values
  1696. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1697. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1698. * @param boolean true if it comes from a Diplay LP view
  1699. * @return string HTML string containing the progress bar
  1700. */
  1701. function get_progress_bar($mode='',$percentage=-1,$text_add='',$from_lp=false)
  1702. {
  1703. global $lp_theme_css;
  1704. // Setting up the CSS path of the current style if exists
  1705. if (!empty($lp_theme_css))
  1706. {
  1707. $css_path=api_get_path(WEB_CODE_PATH).'css/'.$lp_theme_css.'/images/';
  1708. }
  1709. else
  1710. {
  1711. $css_path='../img/';
  1712. }
  1713. //if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
  1714. if(isset($this) && is_object($this) && ($percentage=='-1' OR $text_add==''))
  1715. {
  1716. list ($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1717. }
  1718. $text = $percentage.$text_add;
  1719. //Default progress bar config
  1720. // times that will be greater or shorter
  1721. $factor=1.2;
  1722. if ($from_lp)
  1723. $progress_height='26';
  1724. else
  1725. $progress_height='16';
  1726. $size = str_replace('%','',$percentage);
  1727. $output = ''
  1728. //.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
  1729. .'<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
  1730. .'<img id="progress_img_limit_left" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'">'
  1731. .'<img id="progress_img_full" src="'.$css_path.'bar_1u.gif" width="'.$size*$factor.'px" height="'.$progress_height.'" id="full_portion">'
  1732. .'<img id="progress_img_limit_middle" src="'.$css_path.'bar_1m.gif" width="1" height="'.$progress_height.'">';
  1733. if($percentage <= 98)
  1734. {
  1735. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="'.(100-$size)*$factor.'px" height="'.$progress_height.'" id="empty_portion">';
  1736. }
  1737. else
  1738. {
  1739. $output .= '<img id="progress_img_empty" src="'.$css_path.'bar_1r.gif" width="0" height="'.$progress_height.'" id="empty_portion">';
  1740. }
  1741. $output .= '<img id="progress_bar_img_limit_right" src="'.$css_path.'bar_1.gif" width="1" height="'.$progress_height.'"></td></tr></table>'
  1742. .'<div class="progresstext" id="progress_text">'.$text.'</div>';
  1743. return $output;
  1744. }
  1745. /**
  1746. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1747. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1748. * //@param integer Additional steps to fake as completed
  1749. * @return list Percentage or number and symbol (% or /xx)
  1750. */
  1751. function get_progress_bar_text($mode='',$add=0)
  1752. {
  1753. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
  1754. if(empty($mode)){$mode = $this->progress_bar_mode;}
  1755. $total_items = $this->get_total_items_count_without_chapters();
  1756. if($this->debug>2){error_log('New LP - Total items available in this learnpath: '.$total_items,0);}
  1757. $i = $this->get_complete_items_count();
  1758. if($this->debug>2){error_log('New LP - Items completed so far: '.$i,0);}
  1759. if($add != 0){
  1760. $i += $add;
  1761. if($this->debug>2){error_log('New LP - Items completed so far (+modifier): '.$i,0);}
  1762. }
  1763. $text = '';
  1764. if($i>$total_items){
  1765. $i = $total_items;
  1766. }
  1767. if($mode == '%'){
  1768. if($total_items>0){
  1769. $percentage = ((float)$i/(float)$total_items)*100;
  1770. }
  1771. else
  1772. {
  1773. $percentage = 0;
  1774. }
  1775. $percentage = number_format($percentage,0);
  1776. $text = '%';
  1777. }elseif($mode == 'abs'){
  1778. $percentage = $i;
  1779. $text = '/'.$total_items;
  1780. }
  1781. return array($percentage,$text);
  1782. }
  1783. /**
  1784. * Gets the progress bar mode
  1785. * @return string The progress bar mode attribute
  1786. */
  1787. function get_progress_bar_mode()
  1788. {
  1789. if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
  1790. if(!empty($this->progress_bar_mode))
  1791. {
  1792. return $this->progress_bar_mode;
  1793. }else{
  1794. return '%';
  1795. }
  1796. }
  1797. /**
  1798. * Gets the learnpath proximity (remote or local)
  1799. * @return string Learnpath proximity
  1800. */
  1801. function get_proximity()
  1802. {
  1803. if($this->debug>0){error_log('New LP - In learnpath::get_proximity()',0);}
  1804. if(!empty($this->proximity)){return $this->proximity;}else{return '';}
  1805. }
  1806. /**
  1807. * Gets the learnpath theme (remote or local)
  1808. * @return string Learnpath theme
  1809. */
  1810. function get_theme()
  1811. {
  1812. if($this->debug>0){error_log('New LP - In learnpath::get_theme()',0);}
  1813. if(!empty($this->theme)){return $this->theme;}else{return '';}
  1814. }
  1815. /**
  1816. * Gets the learnpath image
  1817. * @return string Web URL of the LP image
  1818. */
  1819. function get_preview_image()
  1820. {
  1821. if($this->debug>0){error_log('New LP - In learnpath::get_preview_image()',0);}
  1822. if(!empty($this->preview_image)){return $this->preview_image;}else{return '';}
  1823. }
  1824. /**
  1825. * Gets the learnpath author
  1826. * @return string LP's author
  1827. */
  1828. function get_author()
  1829. {
  1830. if($this->debug>0){error_log('New LP - In learnpath::get_author()',0);}
  1831. if(!empty($this->author)){return $this->author;}else{return '';}
  1832. }
  1833. /**
  1834. * Generate a new prerequisites string for a given item. If this item was a sco and
  1835. * its prerequisites were strings (instead of IDs), then transform those strings into
  1836. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  1837. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  1838. * same rule as the scorm_export() method
  1839. * @param integer Item ID
  1840. * @return string Prerequisites string ready for the export as SCORM
  1841. */
  1842. function get_scorm_prereq_string($item_id)
  1843. {
  1844. if($this->debug>0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
  1845. if(!is_object($this->items[$item_id])){return false;}
  1846. $oItem = $this->items[$item_id];
  1847. $prereq = $oItem->get_prereq_string();
  1848. if(empty($prereq))
  1849. {
  1850. return '';
  1851. }
  1852. if(preg_match('/^\d+$/',$prereq) && is_object($this->items[$prereq]))
  1853. { //if the prerequisite is a simple integer ID and this ID exists as an item ID,
  1854. //then simply return it (with the ITEM_ prefix)
  1855. return 'ITEM_'.$prereq;
  1856. }
  1857. else
  1858. {
  1859. if(isset($this->refs_list[$prereq]))
  1860. {
  1861. //it's a simple string item from which the ID can be found in the refs list
  1862. //so we can transform it directly to an ID for export
  1863. return 'ITEM_'.$this->refs_list[$prereq];
  1864. }
  1865. else
  1866. {
  1867. //last case, if it's a complex form, then find all the IDs (SCORM strings)
  1868. //and replace them, one by one, by the internal IDs (dokeos db)
  1869. //TODO modify the '*' replacement to replace the multiplier in front of it
  1870. //by a space as well
  1871. $find = array('&','|','~','=','<>','{','}','*','(',')');
  1872. $replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
  1873. $prereq_mod = str_replace($find,$replace,$prereq);
  1874. $ids = split(' ',$prereq_mod);
  1875. foreach($ids as $id)
  1876. {
  1877. $id = trim($id);
  1878. if(isset($this->refs_list[$id]))
  1879. {
  1880. $prereq = preg_replace('/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/','ITEM_'.$this->refs_list[$id],$prereq);
  1881. }
  1882. }
  1883. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '.$prereq,0);
  1884. return $prereq;
  1885. }
  1886. }
  1887. }
  1888. /**
  1889. * Returns the XML DOM document's node
  1890. * @param resource Reference to a list of objects to search for the given ITEM_*
  1891. * @param string The identifier to look for
  1892. * @return mixed The reference to the element found with that identifier. False if not found
  1893. */
  1894. function get_scorm_xml_node(&$children,$id)
  1895. {
  1896. for($i=0;$i<$children->length;$i++){
  1897. $item_temp = $children->item($i);
  1898. if ($item_temp -> nodeName == 'item')
  1899. {
  1900. if($item_temp->getAttribute('identifier') == $id)
  1901. {
  1902. return $item_temp;
  1903. }
  1904. }
  1905. $subchildren = $item_temp->childNodes;
  1906. if($subchildren->length>0)
  1907. {
  1908. $val = $this->get_scorm_xml_node($subchildren,$id);
  1909. if(is_object($val))
  1910. {
  1911. return $val;
  1912. }
  1913. }
  1914. }
  1915. return false;
  1916. }
  1917. /**
  1918. * Returns a usable array of stats related to the current learnpath and user
  1919. * @return array Well-formatted array containing status for the current learnpath
  1920. */
  1921. function get_stats()
  1922. {
  1923. if($this->debug>0){error_log('New LP - In learnpath::get_stats()',0);}
  1924. //TODO
  1925. }
  1926. /**
  1927. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1928. * the given course (for all learnpaths and all users)
  1929. * @param string Course code
  1930. * @return array Well-formatted array containing status for the course's learnpaths
  1931. */
  1932. function get_stats_course($course)
  1933. {
  1934. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
  1935. //TODO
  1936. }
  1937. /**
  1938. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1939. * the given course and learnpath (for all users)
  1940. * @param string Course code
  1941. * @param integer Learnpath ID
  1942. * @return array Well-formatted array containing status for the specified learnpath
  1943. */
  1944. function get_stats_lp($course,$lp)
  1945. {
  1946. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
  1947. //TODO
  1948. }
  1949. /**
  1950. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1951. * the given course, learnpath and user.
  1952. * @param string Course code
  1953. * @param integer Learnpath ID
  1954. * @param integer User ID
  1955. * @return array Well-formatted array containing status for the specified learnpath and user
  1956. */
  1957. function get_stats_lp_user($course,$lp,$user)
  1958. {
  1959. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
  1960. //TODO
  1961. }
  1962. /**
  1963. * Static method. Can be re-implemented by children. Gives an array of statistics for
  1964. * the given course and learnpath (for all users)
  1965. * @param string Course code
  1966. * @param integer User ID
  1967. * @return array Well-formatted array containing status for the user's learnpaths
  1968. */
  1969. function get_stats_user($course,$user)
  1970. {
  1971. //if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
  1972. //TODO
  1973. }
  1974. /**
  1975. * Gets the status list for all LP's items
  1976. * @return array Array of [index] => [item ID => current status]
  1977. */
  1978. function get_items_status_list(){
  1979. if($this->debug>0){error_log('New LP - In learnpath::get_items_status_list()',0);}
  1980. $list = array();
  1981. foreach($this->ordered_items as $item_id)
  1982. {
  1983. $list[]= array($item_id => $this->items[$item_id]->get_status());
  1984. }
  1985. return $list;
  1986. }
  1987. /**
  1988. * Return the number of interactions for the given learnpath Item View ID.
  1989. * This method can be used as static.
  1990. * @param integer Item View ID
  1991. * @return integer Number of interactions
  1992. */
  1993. function get_interactions_count_from_db($lp_iv_id=0){
  1994. if(empty($lp_iv_id)){return -1;}
  1995. $table = Database::get_course_table('lp_iv_interaction');
  1996. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  1997. $res = api_sql_query($sql,__FILE__,__LINE__);
  1998. $row = Database::fetch_array($res);
  1999. $num = $row[0];
  2000. return $num;
  2001. }
  2002. /**
  2003. * Return the interactions as an array for the given lp_iv_id.
  2004. * This method can be used as static.
  2005. * @param integer Learnpath Item View ID
  2006. * @return array
  2007. * @todo Translate labels
  2008. */
  2009. function get_iv_interactions_array($lp_iv_id=0){
  2010. $list = array();
  2011. $table = Database::get_course_table('lp_iv_interaction');
  2012. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2013. $res = api_sql_query($sql,__FILE__,__LINE__);
  2014. $num = Database::num_rows($res);
  2015. if($num>0){
  2016. $list[] = array(
  2017. "order_id"=>htmlentities(get_lang('Order')),
  2018. "id"=>htmlentities(get_lang('InteractionID')),
  2019. "type"=>htmlentities(get_lang('Type')),
  2020. "time"=>htmlentities(get_lang('TimeFinished')),
  2021. "correct_responses"=>htmlentities(get_lang('CorrectAnswers')),
  2022. "student_response"=>htmlentities(get_lang('StudentResponse')),
  2023. "result"=>htmlentities(get_lang('Result')),
  2024. "latency"=>htmlentities(get_lang('LatencyTimeSpent')));
  2025. while ($row = Database::fetch_array($res)){
  2026. $list[] = array(
  2027. "order_id"=>($row['order_id']+1),
  2028. "id"=>urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
  2029. "type"=>$row['interaction_type'],
  2030. "time"=>$row['completion_time'],
  2031. //"correct_responses"=>$row['correct_responses'],
  2032. //hide correct responses from students
  2033. "correct_responses"=>'',
  2034. "student_response"=>$row['student_response'],
  2035. "result"=>$row['result'],
  2036. "latency"=>$row['latency']);
  2037. }
  2038. }
  2039. return $list;
  2040. }
  2041. /**
  2042. * Return the number of objectives for the given learnpath Item View ID.
  2043. * This method can be used as static.
  2044. * @param integer Item View ID
  2045. * @return integer Number of objectives
  2046. */
  2047. function get_objectives_count_from_db($lp_iv_id=0){
  2048. if(empty($lp_iv_id)){return -1;}
  2049. $table = Database::get_course_table('lp_iv_objective');
  2050. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2051. $res = api_sql_query($sql,__FILE__,__LINE__);
  2052. $row = Database::fetch_array($res);
  2053. $num = $row[0];
  2054. return $num;
  2055. }
  2056. /**
  2057. * Return the objectives as an array for the given lp_iv_id.
  2058. * This method can be used as static.
  2059. * @param integer Learnpath Item View ID
  2060. * @return array
  2061. * @todo Translate labels
  2062. */
  2063. function get_iv_objectives_array($lp_iv_id=0){
  2064. $list = array();
  2065. $table = Database::get_course_table('lp_iv_objective');
  2066. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2067. $res = api_sql_query($sql,__FILE__,__LINE__);
  2068. $num = Database::num_rows($res);
  2069. if($num>0){
  2070. $list[] = array(
  2071. "order_id"=>htmlentities(get_lang('Order')),
  2072. "objective_id"=>htmlentities(get_lang('ObjectiveID')),
  2073. "score_raw"=>htmlentities(get_lang('ObjectiveRawScore')),
  2074. "score_max"=>htmlentities(get_lang('ObjectiveMaxScore')),
  2075. "score_min"=>htmlentities(get_lang('ObjectiveMinScore')),
  2076. "status"=>htmlentities(get_lang('ObjectiveStatus')));
  2077. while ($row = Database::fetch_array($res)){
  2078. $list[] = array(
  2079. "order_id"=>($row['order_id']+1),
  2080. "objective_id"=>urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
  2081. "score_raw"=>$row['score_raw'],
  2082. "score_max"=>$row['score_max'],
  2083. "score_min"=>$row['score_min'],
  2084. "status"=>$row['status']);
  2085. }
  2086. }
  2087. return $list;
  2088. }
  2089. /**
  2090. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2091. * used by get_html_toc() to be ready to display
  2092. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2093. */
  2094. function get_toc()
  2095. {
  2096. if($this->debug>0){error_log('New LP - In learnpath::get_toc()',0);}
  2097. $toc = array();
  2098. //echo "<pre>".print_r($this->items,true)."</pre>";
  2099. foreach($this->ordered_items as $item_id)
  2100. {
  2101. if($this->debug>2){error_log('New LP - learnpath::get_toc(): getting info for item '.$item_id,0);}
  2102. //TODO change this link generation and use new function instead
  2103. $toc[] = array(
  2104. 'id'=>$item_id,
  2105. 'title'=>$this->items[$item_id]->get_title(),
  2106. //'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
  2107. 'status'=>$this->items[$item_id]->get_status(),
  2108. 'level'=>$this->items[$item_id]->get_level(),
  2109. 'type' =>$this->items[$item_id]->get_type(),
  2110. 'description'=>$this->items[$item_id]->get_description(),
  2111. 'path'=>$this->items[$item_id]->get_path(),
  2112. );
  2113. }
  2114. if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
  2115. return $toc;
  2116. }
  2117. /**
  2118. * Gets the learning path type
  2119. * @param boolean Return the name? If false, return the ID. Default is false.
  2120. * @return mixed Type ID or name, depending on the parameter
  2121. */
  2122. function get_type($get_name = false)
  2123. {
  2124. $res = false;
  2125. if($this->debug>0){error_log('New LP - In learnpath::get_type()',0);}
  2126. if(!empty($this->type))
  2127. {
  2128. if($get_name)
  2129. {
  2130. //get it from the lp_type table in main db
  2131. }else{
  2132. $res = $this->type;
  2133. }
  2134. }
  2135. if($this->debug>2){error_log('New LP - In learnpath::get_type() - Returning '.($res==false?'false':$res),0);}
  2136. return $res;
  2137. }
  2138. /**
  2139. * Gets the learning path type as static method
  2140. * @param boolean Return the name? If false, return the ID. Default is false.
  2141. * @return mixed Type ID or name, depending on the parameter
  2142. */
  2143. function get_type_static($lp_id=0)
  2144. {
  2145. $tbl_lp = Database::get_course_table('lp');
  2146. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '".$lp_id."'";
  2147. $res = api_sql_query($sql, __FILE__, __LINE__);
  2148. if($res===false){ return null;}
  2149. if(Database::num_rows($res)<=0){return null;}
  2150. $row = Database::fetch_array($res);
  2151. return $row['lp_type'];
  2152. }
  2153. /**
  2154. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2155. * This method can be used as abstract and is recursive
  2156. * @param integer Learnpath ID
  2157. * @param integer Parent ID of the items to look for
  2158. * @return mixed Ordered list of item IDs or false on error
  2159. */
  2160. function get_flat_ordered_items_list($lp,$parent=0)
  2161. {
  2162. //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
  2163. $list = array();
  2164. if(empty($lp)){return false;}
  2165. $tbl_lp_item = Database::get_course_table('lp_item');
  2166. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2167. $res = api_sql_query($sql,__FILE__,__LINE__);
  2168. while($row = Database::fetch_array($res)){
  2169. $sublist = learnpath::get_flat_ordered_items_list($lp,$row['id']);
  2170. $list[] = $row['id'];
  2171. foreach($sublist as $item){
  2172. $list[] = $item;
  2173. }
  2174. }
  2175. return $list;
  2176. }
  2177. /**
  2178. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2179. * @return string HTML TOC ready to display
  2180. */
  2181. /*function get_html_toc()
  2182. {
  2183. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2184. $list = $this->get_toc();
  2185. //echo $this->current;
  2186. //$parent = $this->items[$this->current]->get_parent();
  2187. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2188. $html = '<div class="inner_lp_toc">'."\n" ;
  2189. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2190. require_once('resourcelinker.inc.php');
  2191. //temp variables
  2192. $mycurrentitemid = $this->get_current_item_id();
  2193. foreach($list as $item)
  2194. {
  2195. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2196. //TODO complete this
  2197. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2198. 'incomplete' => '../img/incomplete.gif',
  2199. 'failed' => '../img/failed.gif',
  2200. 'completed' => '../img/completed.gif',
  2201. 'passed' => '../img/passed.gif',
  2202. 'succeeded' => '../img/succeeded.gif',
  2203. 'browsed' => '../img/completed.gif');
  2204. $style = 'scorm_item';
  2205. if($item['id'] == $this->current){
  2206. $style = 'scorm_item_highlight';
  2207. }
  2208. //the anchor will let us center the TOC on the currently viewed item &^D
  2209. $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'].'" >' .
  2210. '<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
  2211. //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
  2212. $title = $item['title'];
  2213. if(empty($title)){
  2214. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2215. $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
  2216. }
  2217. if(empty($title))$title = '-';
  2218. if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
  2219. //$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>" ;
  2220. $url = $this->get_link('http',$item['id']);
  2221. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2222. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2223. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2224. $mycurrentitemid.',' .
  2225. $item['id'].');' .
  2226. 'return false;" >'.$title.'</a>' ;
  2227. }else{
  2228. $html .= $title;
  2229. }
  2230. $html .= "</div>\n";
  2231. }
  2232. $html .= "</div>\n";
  2233. return $html;
  2234. }*/
  2235. /**
  2236. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2237. * @return string HTML TOC ready to display
  2238. */
  2239. function get_html_toc()
  2240. {
  2241. if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
  2242. $list = $this->get_toc();
  2243. $mych = api_get_setting('platform_charset');
  2244. //echo $this->current;
  2245. //$parent = $this->items[$this->current]->get_parent();
  2246. //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
  2247. $html= '<div class="scorm_title"><div class="scorm_title_text">'.mb_convert_encoding($this->get_name(),$this->encoding,$mych).'</div></div>';
  2248. // build, display
  2249. if(api_is_allowed_to_edit())
  2250. {
  2251. $html .='<div class="actions_lp">';
  2252. $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>";
  2253. $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>";
  2254. $html .= '<span>'.Display::return_icon('learnpath_view.gif', get_lang("Display")).' '.mb_convert_encoding(get_lang("Display"),$this->encoding,$mych).'</span>';
  2255. $html .= '</div>';
  2256. unset($mych);
  2257. }
  2258. $html.= '<div class="inner_lp_toc">'."\n" ;
  2259. //$html.= '<div class="scorm_title"><div class="scorm_title_text">'.mb_convert_encoding($this->get_name(),$this->encoding,$mych).'</div></div>';
  2260. // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
  2261. require_once('resourcelinker.inc.php');
  2262. //temp variables
  2263. $mycurrentitemid = $this->get_current_item_id();
  2264. $color_counter=0;
  2265. $i=0;
  2266. foreach($list as $item)
  2267. {
  2268. if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
  2269. //TODO complete this
  2270. $icon_name = array('not attempted' => '../img/notattempted.gif',
  2271. 'incomplete' => '../img/incomplete.gif',
  2272. 'failed' => '../img/failed.gif',
  2273. 'completed' => '../img/completed.gif',
  2274. 'passed' => '../img/passed.gif',
  2275. 'succeeded' => '../img/succeeded.gif',
  2276. 'browsed' => '../img/completed.gif');
  2277. $style = 'scorm_item';
  2278. $scorm_color_background='scorm_item';
  2279. $style_item ='scorm_item';
  2280. $current=false;
  2281. if($item['id'] == $this->current)
  2282. {
  2283. $style = 'scorm_item_highlight';
  2284. $scorm_color_background ='scorm_item_highlight';
  2285. }
  2286. else
  2287. if ($color_counter%2==0)
  2288. {
  2289. $scorm_color_background='scorm_item_1';
  2290. }
  2291. else
  2292. {
  2293. $scorm_color_background='scorm_item_2';
  2294. }
  2295. if ($scorm_color_background!='')
  2296. {
  2297. $html .= '<div id="toc_'.$item['id'].'" class="'.$scorm_color_background.'">';
  2298. }
  2299. //the anchor will let us center the TOC on the currently viewed item &^D
  2300. if($item['type']!='dokeos_module' AND $item['type']!='dokeos_chapter')
  2301. {
  2302. $html .= '<a name="atoc_'.$item['id'].'" />';
  2303. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*1.5).'em; padding-right:'.($item['level']/2).'em" title="'.$item['description'].'" >';
  2304. }
  2305. else
  2306. {
  2307. $html .= '<div class="'.$style_item.'" style="padding-left: '.($item['level']*2).'em; padding-right:'.($item['level']*1.5).'em" title="'.$item['description'].'" >';
  2308. }
  2309. $title=$item['title'];
  2310. if(empty($title))
  2311. {
  2312. $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
  2313. }
  2314. $title = html_entity_decode($title,ENT_QUOTES,$this->encoding);
  2315. if($item['type']!='dokeos_chapter' and $item['type']!='dir' AND $item['type']!='dokeos_module')
  2316. {
  2317. //$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>" ;
  2318. $url = $this->get_link('http',$item['id']);
  2319. //$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2320. //$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2321. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;
  2322. $html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
  2323. $mycurrentitemid.',' .
  2324. $item['id'].');' .
  2325. 'return false;" >'.stripslashes($title).'</a>' ;
  2326. }
  2327. elseif($item['type']=='dokeos_module' || $item['type']=='dokeos_chapter')
  2328. {
  2329. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;".stripslashes($title);
  2330. }
  2331. elseif($item['type']=='dir')
  2332. {
  2333. $html .= stripslashes($title);
  2334. }
  2335. $tbl_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2336. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  2337. $user_id = api_get_user_id();
  2338. $course_id = api_get_course_id();
  2339. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2340. WHERE path = '".$item['path']."' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2341. $result = api_sql_query($sql,__FILE__,__LINE__);
  2342. $count = Database::num_rows($result);
  2343. if ($item['type']=='quiz') {
  2344. if ($item['status']=='completed') {
  2345. $html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' />";
  2346. }
  2347. } else {
  2348. $html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' />";
  2349. }
  2350. $html .= "</div>";
  2351. if ($scorm_color_background!='')
  2352. {
  2353. $html .= '</div>';
  2354. }
  2355. $color_counter++;
  2356. }
  2357. $html .= "</div>\n";
  2358. return $html;
  2359. }
  2360. /**
  2361. * Gets the learnpath maker name - generally the editor's name
  2362. * @return string Learnpath maker name
  2363. */
  2364. function get_maker()
  2365. {
  2366. if($this->debug>0){error_log('New LP - In learnpath::get_maker()',0);}
  2367. if(!empty($this->maker)){return $this->maker;}else{return '';}
  2368. }
  2369. /**
  2370. * Gets the user-friendly message stored in $this->message
  2371. * @return string Message
  2372. */
  2373. function get_message(){
  2374. if($this->debug>0){error_log('New LP - In learnpath::get_message()',0);}
  2375. return $this->message;
  2376. }
  2377. /**
  2378. * Gets the learnpath name/title
  2379. * @return string Learnpath name/title
  2380. */
  2381. function get_name()
  2382. {
  2383. if($this->debug>0){error_log('New LP - In learnpath::get_name()',0);}
  2384. if(!empty($this->name)){return $this->name;}else{return 'N/A';}
  2385. }
  2386. /**
  2387. * Gets a link to the resource from the present location, depending on item ID.
  2388. * @param string Type of link expected
  2389. * @param integer Learnpath item ID
  2390. * @return string Link to the lp_item resource
  2391. */
  2392. function get_link($type='http',$item_id=null)
  2393. {
  2394. if($this->debug>0){error_log('New LP - In learnpath::get_link('.$type.','.$item_id.')',0);}
  2395. if(empty($item_id))
  2396. {
  2397. 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);}
  2398. $item_id = $this->get_current_item_id();
  2399. }
  2400. if(empty($item_id)){
  2401. if($this->debug>2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
  2402. //still empty, this means there was no item_id given and we are not in an object context or
  2403. //the object property is empty, return empty link
  2404. $item_id = $this->first();
  2405. return '';
  2406. }
  2407. $file = '';
  2408. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2409. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2410. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2411. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2412. if($this->debug>2){error_log('New LP - In learnpath::get_link() - selecting item '.$sel,0);}
  2413. $res = api_sql_query($sel, __FILE__, __LINE__);
  2414. if(Database::num_rows($res)>0)
  2415. {
  2416. $row = Database::fetch_array($res);
  2417. //var_dump($row);
  2418. $lp_type = $row['ltype'];
  2419. $lp_path = $row['lpath'];
  2420. $lp_item_type = $row['litype'];
  2421. $lp_item_path = $row['lipath'];
  2422. $lp_item_params = $row['liparams'];
  2423. if(empty($lp_item_params) && strpos($lp_item_path,'?')!==false)
  2424. {
  2425. list($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
  2426. }
  2427. //$lp_item_params = '?'.$lp_item_params;
  2428. //add ? if none - left commented to give freedom to scorm implementation
  2429. //if(substr($lp_item_params,0,1)!='?'){
  2430. // $lp_item_params = '?'.$lp_item_params;
  2431. //}
  2432. $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  2433. if($type == 'http'){
  2434. $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path(); //web path
  2435. }else{
  2436. $course_path = $sys_course_path; //system path
  2437. }
  2438. //now go through the specific cases to get the end of the path
  2439. switch($lp_type){
  2440. case 1:
  2441. if($lp_item_type == 'dokeos_chapter'){
  2442. $file = 'lp_content.php?type=dir';
  2443. }else{
  2444. require_once('resourcelinker.inc.php');
  2445. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2446. $tmp_array=explode("/",$file);
  2447. $document_name=$tmp_array[count($tmp_array)-1];
  2448. if(strpos($document_name,'_DELETED_')){
  2449. $file = 'blank.php?error=document_deleted';
  2450. }
  2451. }
  2452. break;
  2453. case 2:
  2454. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2455. if($lp_item_type!='dir'){
  2456. //Quite complex here:
  2457. //we want to make sure 'http://' (and similar) links can
  2458. //be loaded as is (withouth the Dokeos path in front) but
  2459. //some contents use this form: resource.htm?resource=http://blablabla
  2460. //which means we have to find a protocol at the path's start, otherwise
  2461. //it should not be considered as an external URL
  2462. //if($this->prerequisites_match($item_id)){
  2463. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2464. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2465. //distant url, return as is
  2466. $file = $lp_item_path;
  2467. }else{
  2468. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2469. //prevent getting untranslatable urls
  2470. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2471. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2472. //prepare the path
  2473. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2474. //TODO fix this for urls with protocol header
  2475. $file = str_replace('//','/',$file);
  2476. $file = str_replace(':/','://',$file);
  2477. if(substr($lp_path,-1)=='/')
  2478. {
  2479. $lp_path = substr($lp_path,0,-1);
  2480. }
  2481. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path)))
  2482. {//if file not found
  2483. $decoded = html_entity_decode($lp_item_path);
  2484. list($decoded) = explode('?',$decoded);
  2485. if(!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded)))
  2486. {
  2487. require_once('resourcelinker.inc.php');
  2488. $file = rl_get_resource_link_for_learnpath(api_get_course_id(),$this->get_id(),$item_id);
  2489. $tmp_array=explode("/",$file);
  2490. $document_name=$tmp_array[count($tmp_array)-1];
  2491. if(strpos($document_name,'_DELETED_')){
  2492. $file = 'blank.php?error=document_deleted';
  2493. }
  2494. }
  2495. else
  2496. {
  2497. $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
  2498. }
  2499. }
  2500. }
  2501. //}else{
  2502. //prerequisites did not match
  2503. //$file = 'blank.php';
  2504. //}
  2505. //We want to use parameters if they were defined in the imsmanifest
  2506. if($file!='blank.php')
  2507. {
  2508. $file.= (strstr($file,'?')===false?'?':'').$lp_item_params;
  2509. }
  2510. }else{
  2511. $file = 'lp_content.php?type=dir';
  2512. }
  2513. break;
  2514. case 3:
  2515. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type,0);}
  2516. //formatting AICC HACP append URL
  2517. $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'newscorm/aicc_hacp.php').'&';
  2518. if($lp_item_type!='dir'){
  2519. //Quite complex here:
  2520. //we want to make sure 'http://' (and similar) links can
  2521. //be loaded as is (withouth the Dokeos path in front) but
  2522. //some contents use this form: resource.htm?resource=http://blablabla
  2523. //which means we have to find a protocol at the path's start, otherwise
  2524. //it should not be considered as an external URL
  2525. if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!=0){
  2526. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path,0);}
  2527. //distant url, return as is
  2528. $file = $lp_item_path;
  2529. /*
  2530. if(stristr($file,'<servername>')!==false){
  2531. $file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2532. }
  2533. */
  2534. $file .= $aicc_append;
  2535. }else{
  2536. if($this->debug>2){error_log('New LP - In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path,0);}
  2537. //prevent getting untranslatable urls
  2538. $lp_item_path = preg_replace('/%2F/','/',$lp_item_path);
  2539. $lp_item_path = preg_replace('/%3A/',':',$lp_item_path);
  2540. //prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
  2541. $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
  2542. //TODO fix this for urls with protocol header
  2543. $file = str_replace('//','/',$file);
  2544. $file = str_replace(':/','://',$file);
  2545. $file .= $aicc_append;
  2546. }
  2547. }else{
  2548. $file = 'lp_content.php?type=dir';
  2549. }
  2550. break;
  2551. case 4:
  2552. break;
  2553. default:
  2554. break;
  2555. }
  2556. }
  2557. if($this->debug>2){error_log('New LP - In learnpath::get_link() - returning "'.$file.'" from get_link',0);}
  2558. return $file;
  2559. }
  2560. /**
  2561. * Gets the latest usable view or generate a new one
  2562. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2563. * @return integer DB lp_view id
  2564. */
  2565. function get_view($attempt_num=0)
  2566. {
  2567. if($this->debug>0){error_log('New LP - In learnpath::get_view()',0);}
  2568. $search = '';
  2569. //use $attempt_num to enable multi-views management (disabled so far)
  2570. if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
  2571. {
  2572. $search = 'AND view_count = '.$attempt_num;
  2573. }
  2574. //when missing $attempt_num, search for a unique lp_view record for this lp and user
  2575. $lp_view_table = Database::get_course_table('lp_view');
  2576. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2577. "WHERE lp_id = ".$this->get_id()." " .
  2578. "AND user_id = ".$this->get_user_id()." " .
  2579. $search .
  2580. " ORDER BY view_count DESC";
  2581. $res = api_sql_query($sql, __FILE__, __LINE__);
  2582. if(Database::num_rows($res)>0)
  2583. {
  2584. $row = Database::fetch_array($res);
  2585. $this->lp_view_id = $row['id'];
  2586. }else{
  2587. //no database record, create one
  2588. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2589. "VALUES (".$this->get_id().",".$this->get_user_id().",1)";
  2590. $res = api_sql_query($sql, __FILE__, __LINE__);
  2591. $id = Database::get_last_insert_id();
  2592. $this->lp_view_id = $id;
  2593. }
  2594. return $this->lp_view_id;
  2595. }
  2596. /**
  2597. * Gets the current view id
  2598. * @return integer View ID (from lp_view)
  2599. */
  2600. function get_view_id()
  2601. {
  2602. if($this->debug>0){error_log('New LP - In learnpath::get_view_id()',0);}
  2603. if(!empty($this->lp_view_id))
  2604. {
  2605. return $this->lp_view_id;
  2606. }else{
  2607. return 0;
  2608. }
  2609. }
  2610. /**
  2611. * Gets the update queue
  2612. * @return array Array containing IDs of items to be updated by JavaScript
  2613. */
  2614. function get_update_queue()
  2615. {
  2616. if($this->debug>0){error_log('New LP - In learnpath::get_update_queue()',0);}
  2617. return $this->update_queue;
  2618. }
  2619. /**
  2620. * Gets the user ID
  2621. * @return integer User ID
  2622. */
  2623. function get_user_id()
  2624. {
  2625. if($this->debug>0){error_log('New LP - In learnpath::get_user_id()',0);}
  2626. if(!empty($this->user_id))
  2627. {
  2628. return $this->user_id;
  2629. }else{
  2630. return false;
  2631. }
  2632. }
  2633. /**
  2634. * Checks if any of the items has an audio element attached
  2635. * @return bool True or false
  2636. */
  2637. function has_audio() {
  2638. $has = false;
  2639. foreach ($this->items as $i=>$item) {
  2640. if (!empty($this->items[$i]->audio)) {
  2641. $has = true;
  2642. break;
  2643. }
  2644. }
  2645. return $has;
  2646. }
  2647. /**
  2648. * Logs a message into a file
  2649. * @param string Message to log
  2650. * @return boolean True on success, false on error or if msg empty
  2651. */
  2652. function log($msg)
  2653. {
  2654. if($this->debug>0){error_log('New LP - In learnpath::log()',0);}
  2655. //TODO
  2656. $this->error .= $msg."\n";
  2657. return true;
  2658. }
  2659. /**
  2660. * Moves an item up and down at its level
  2661. * @param integer Item to move up and down
  2662. * @param string Direction 'up' or 'down'
  2663. * @return integer New display order, or false on error
  2664. */
  2665. function move_item($id, $direction){
  2666. if($this->debug>0){error_log('New LP - In learnpath::move_item('.$id.','.$direction.')',0);}
  2667. if(empty($id) or empty($direction)){return false;}
  2668. $tbl_lp_item = Database::get_course_table('lp_item');
  2669. $sql_sel = "
  2670. SELECT *
  2671. FROM " . $tbl_lp_item . "
  2672. WHERE id = " . $id;
  2673. $res_sel = api_sql_query($sql_sel,__FILE__,__LINE__);
  2674. //check if elem exists
  2675. if(Database::num_rows($res_sel)<1){return false;}
  2676. //gather data
  2677. $row = Database::fetch_array($res_sel);
  2678. $previous = $row['previous_item_id'];
  2679. $next = $row['next_item_id'];
  2680. $display = $row['display_order'];
  2681. $parent = $row['parent_item_id'];
  2682. $lp = $row['lp_id'];
  2683. //update the item (switch with previous/next one)
  2684. switch($direction)
  2685. {
  2686. case 'up':
  2687. if($this->debug>2){error_log('Movement up detected',0);}
  2688. if($display <= 1){/*do nothing*/}
  2689. else{
  2690. $sql_sel2 = "SELECT *
  2691. FROM $tbl_lp_item
  2692. WHERE id = $previous";
  2693. if($this->debug>2){error_log('Selecting previous: '.$sql_sel2,0);}
  2694. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2695. if(Database::num_rows($res_sel2)<1){$previous_previous = 0;}
  2696. //gather data
  2697. $row2 = Database::fetch_array($res_sel2);
  2698. $previous_previous = $row2['previous_item_id'];
  2699. //update previous_previous item (switch "next" with current)
  2700. if($previous_previous != 0)
  2701. {
  2702. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2703. if($this->debug>2){error_log($sql_upd2,0);}
  2704. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2705. }
  2706. //update previous item (switch with current)
  2707. if($previous != 0)
  2708. {
  2709. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2710. if($this->debug>2){error_log($sql_upd2,0);}
  2711. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2712. }
  2713. //update current item (switch with previous)
  2714. if($id != 0){
  2715. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2716. if($this->debug>2){error_log($sql_upd2,0);}
  2717. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2718. }
  2719. //update next item (new previous item)
  2720. if($next != 0){
  2721. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  2722. if($this->debug>2){error_log($sql_upd2,0);}
  2723. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2724. }
  2725. $display = $display-1;
  2726. }
  2727. break;
  2728. case 'down':
  2729. if($this->debug>2){error_log('Movement down detected',0);}
  2730. if($next == 0){/*do nothing*/}
  2731. else{
  2732. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  2733. if($this->debug>2){error_log('Selecting next: '.$sql_sel2,0);}
  2734. $res_sel2 = api_sql_query($sql_sel2,__FILE__,__LINE__);
  2735. if(Database::num_rows($res_sel2)<1){$next_next = 0;}
  2736. //gather data
  2737. $row2 = Database::fetch_array($res_sel2);
  2738. $next_next = $row2['next_item_id'];
  2739. //update previous item (switch with current)
  2740. if($previous != 0)
  2741. {
  2742. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  2743. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2744. }
  2745. //update current item (switch with previous)
  2746. if($id != 0)
  2747. {
  2748. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  2749. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2750. }
  2751. //update next item (new previous item)
  2752. if($next != 0)
  2753. {
  2754. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  2755. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2756. }
  2757. //update next_next item (switch "previous" with current)
  2758. if($next_next != 0)
  2759. {
  2760. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  2761. $res_upd2 = api_sql_query($sql_upd2, __FILE__, __LINE__);
  2762. }
  2763. $display = $display+1;
  2764. }
  2765. break;
  2766. default:
  2767. return false;
  2768. }
  2769. return $display;
  2770. }
  2771. /**
  2772. * Move a learnpath up (display_order)
  2773. * @param integer Learnpath ID
  2774. */
  2775. function move_up($lp_id)
  2776. {
  2777. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2778. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2779. $res = api_sql_query($sql, __FILE__, __LINE__);
  2780. if($res === false) return false;
  2781. $lps = array();
  2782. $lp_order = array();
  2783. $num = Database::num_rows($res);
  2784. //first check the order is correct, globally (might be wrong because
  2785. //of versions < 1.8.4)
  2786. if($num>0)
  2787. {
  2788. $i = 1;
  2789. while($row = Database::fetch_array($res))
  2790. {
  2791. if($row['display_order'] != $i)
  2792. { //if we find a gap in the order, we need to fix it
  2793. $need_fix = true;
  2794. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2795. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2796. }
  2797. $row['display_order'] = $i;
  2798. $lps[$row['id']] = $row;
  2799. $lp_order[$i] = $row['id'];
  2800. $i++;
  2801. }
  2802. }
  2803. if($num>1) //if there's only one element, no need to sort
  2804. {
  2805. $order = $lps[$lp_id]['display_order'];
  2806. if($order>1) //if it's the first element, no need to move up
  2807. {
  2808. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
  2809. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2810. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
  2811. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2812. }
  2813. }
  2814. }
  2815. /**
  2816. * Move a learnpath down (display_order)
  2817. * @param integer Learnpath ID
  2818. */
  2819. function move_down($lp_id)
  2820. {
  2821. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2822. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  2823. $res = api_sql_query($sql, __FILE__, __LINE__);
  2824. if($res === false) return false;
  2825. $lps = array();
  2826. $lp_order = array();
  2827. $num = Database::num_rows($res);
  2828. $max = 0;
  2829. //first check the order is correct, globally (might be wrong because
  2830. //of versions < 1.8.4)
  2831. if($num>0)
  2832. {
  2833. $i = 1;
  2834. while($row = Database::fetch_array($res))
  2835. {
  2836. $max = $i;
  2837. if($row['display_order'] != $i)
  2838. { //if we find a gap in the order, we need to fix it
  2839. $need_fix = true;
  2840. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  2841. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  2842. }
  2843. $row['display_order'] = $i;
  2844. $lps[$row['id']] = $row;
  2845. $lp_order[$i] = $row['id'];
  2846. $i++;
  2847. }
  2848. }
  2849. if($num>1) //if there's only one element, no need to sort
  2850. {
  2851. $order = $lps[$lp_id]['display_order'];
  2852. if($order<$max) //if it's the first element, no need to move up
  2853. {
  2854. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
  2855. $res_u1 = api_sql_query($sql_u1, __FILE__, __LINE__);
  2856. $sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
  2857. $res_u2 = api_sql_query($sql_u2, __FILE__, __LINE__);
  2858. }
  2859. }
  2860. }
  2861. /**
  2862. * Updates learnpath attributes to point to the next element
  2863. * The last part is similar to set_current_item but processing the other way around
  2864. */
  2865. function next()
  2866. {
  2867. if($this->debug>0){error_log('New LP - In learnpath::next()',0);}
  2868. $this->last = $this->get_current_item_id();
  2869. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2870. $this->autocomplete_parents($this->last);
  2871. $new_index = $this->get_next_index();
  2872. if($this->debug>2){error_log('New LP - New index: '.$new_index,0);}
  2873. $this->index = $new_index;
  2874. if($this->debug>2){error_log('New LP - Now having orderedlist['.$new_index.'] = '. $this->ordered_items[$new_index],0);}
  2875. $this->current = $this->ordered_items[$new_index];
  2876. if($this->debug>2){error_log('New LP - new item id is '.$this->current.'-'.$this->get_current_item_id(),0);}
  2877. }
  2878. /**
  2879. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  2880. * class, this might be redefined to allow several behaviours depending on the document type.
  2881. * @param integer Resource ID
  2882. * @return boolean True on success, false otherwise
  2883. */
  2884. function open($id)
  2885. {
  2886. if($this->debug>0){error_log('New LP - In learnpath::open()',0);}
  2887. //TODO
  2888. //set the current resource attribute to this resource
  2889. //switch on element type (redefine in child class?)
  2890. //set status for this item to "opened"
  2891. //start timer
  2892. //initialise score
  2893. $this->index = 0; //or = the last item seen (see $this->last)
  2894. }
  2895. /**
  2896. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  2897. * and the prerequisite string on error.
  2898. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  2899. * @param integer Optional item ID. If none given, uses the current open item.
  2900. * @return boolean True if prerequisites are matched, false otherwise
  2901. * @return string Empty string if true returned, prerequisites string otherwise.
  2902. */
  2903. function prerequisites_match($item = null)
  2904. {
  2905. if($this->debug>0){error_log('New LP - In learnpath::prerequisites_match()',0);}
  2906. if(empty($item)){$item = $this->current;}
  2907. if(is_object($this->items[$item]))
  2908. {
  2909. $prereq_string = $this->items[$item]->get_prereq_string();
  2910. if(empty($prereq_string)){return true;}
  2911. //clean spaces
  2912. $prereq_string = str_replace(' ','',$prereq_string);
  2913. if($this->debug>0){error_log('Found prereq_string: '.$prereq_string,0);}
  2914. //now send to the parse_prereq() function that will check this component's prerequisites
  2915. $result = $this->items[$item]->parse_prereq($prereq_string,$this->items,$this->refs_list,$this->get_user_id());
  2916. if($result === false)
  2917. {
  2918. $this->set_error_msg($this->items[$item]->prereq_alert);
  2919. }
  2920. }else{
  2921. $result = true;
  2922. if($this->debug>1){error_log('New LP - $this->items['.$item.'] was not an object',0);}
  2923. }
  2924. if($this->debug>1){error_log('New LP - End of prerequisites_match(). Error message is now '.$this->error,0);}
  2925. return $result;
  2926. }
  2927. /**
  2928. * Updates learnpath attributes to point to the previous element
  2929. * The last part is similar to set_current_item but processing the other way around
  2930. */
  2931. function previous()
  2932. {
  2933. if($this->debug>0){error_log('New LP - In learnpath::previous()',0);}
  2934. $this->last = $this->get_current_item_id();
  2935. $this->items[$this->last]->save(false,$this->prerequisites_match($this->last));
  2936. $this->autocomplete_parents($this->last);
  2937. $new_index = $this->get_previous_index();
  2938. $this->index = $new_index;
  2939. $this->current = $this->ordered_items[$new_index];
  2940. }
  2941. /**
  2942. * Publishes a learnpath. This basically means show or hide the learnpath
  2943. * to normal users.
  2944. * Can be used as abstract
  2945. * @param integer Learnpath ID
  2946. * @param string New visibility
  2947. */
  2948. function toggle_visibility($lp_id,$set_visibility=1)
  2949. {
  2950. //if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
  2951. $action = 'visible';
  2952. if($set_visibility != 1)
  2953. {
  2954. $action = 'invisible';
  2955. }
  2956. return api_item_property_update(api_get_course_info(),TOOL_LEARNPATH,$lp_id,$action,api_get_user_id());
  2957. }
  2958. /**
  2959. * Publishes a learnpath. This basically means show or hide the learnpath
  2960. * on the course homepage
  2961. * Can be used as abstract
  2962. * @param integer Learnpath ID
  2963. * @param string New visibility
  2964. */
  2965. function toggle_publish($lp_id,$set_visibility='v')
  2966. {
  2967. //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
  2968. $tbl_lp = Database::get_course_table('lp');
  2969. $sql="SELECT * FROM $tbl_lp where id=$lp_id";
  2970. $result=api_sql_query($sql,__FILE__,__LINE__);
  2971. $row=Database::fetch_array($result);
  2972. $name=domesticate($row['name']);
  2973. if($set_visibility == 'i') {
  2974. $s=$name." ".get_lang('_no_published');
  2975. $dialogBox=$s;
  2976. $v=0;
  2977. }
  2978. if($set_visibility == 'v')
  2979. {
  2980. $s=$name." ".get_lang('_published');
  2981. $dialogBox=$s;
  2982. $v=1;
  2983. }
  2984. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  2985. $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id;
  2986. $sql="SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
  2987. $result=api_sql_query($sql,__FILE__,__LINE__);
  2988. $num=Database::num_rows($result);
  2989. $row2=Database::fetch_array($result);
  2990. //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
  2991. if(($set_visibility == 'i') && ($num>0))
  2992. {
  2993. $sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
  2994. }
  2995. elseif(($set_visibility == 'v') && ($num==0))
  2996. {
  2997. $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)";
  2998. }
  2999. else
  3000. {
  3001. //parameter and database incompatible, do nothing
  3002. }
  3003. $result=api_sql_query($sql,__FILE__,__LINE__);
  3004. //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
  3005. }
  3006. /**
  3007. * Restart the whole learnpath. Return the URL of the first element.
  3008. * Make sure the results are saved with anoter method. This method should probably be
  3009. * redefined in children classes.
  3010. * To use a similar method statically, use the create_new_attempt() method
  3011. * @return string URL to load in the viewer
  3012. */
  3013. function restart()
  3014. {
  3015. if($this->debug>0){error_log('New LP - In learnpath::restart()',0);}
  3016. //TODO
  3017. //call autosave method to save the current progress
  3018. //$this->index = 0;
  3019. $lp_view_table = Database::get_course_table('lp_view');
  3020. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
  3021. "VALUES (".$this->lp_id.",".$this->get_user_id().",".($this->attempt+1).")";
  3022. if($this->debug>2){error_log('New LP - Inserting new lp_view for restart: '.$sql,0);}
  3023. $res = api_sql_query($sql, __FILE__, __LINE__);
  3024. if($view_id = Database::get_last_insert_id($res))
  3025. {
  3026. $this->lp_view_id = $view_id;
  3027. $this->attempt = $this->attempt+1;
  3028. }else{
  3029. $this->error = 'Could not insert into item_view table...';
  3030. return false;
  3031. }
  3032. $this->autocomplete_parents($this->current);
  3033. foreach($this->items as $index=>$dummy){
  3034. $this->items[$index]->restart();
  3035. $this->items[$index]->set_lp_view($this->lp_view_id);
  3036. }
  3037. $this->first();
  3038. return true;
  3039. }
  3040. /**
  3041. * Saves the current item
  3042. * @return boolean
  3043. */
  3044. function save_current(){
  3045. if($this->debug>0){error_log('New LP - In learnpath::save_current()',0);}
  3046. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3047. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3048. if($this->debug>2){error_log('New LP - save_current() saving item '.$this->current,0);}
  3049. if($this->debug>2){error_log(''.print_r($this->items,true),0);}
  3050. if(is_object($this->items[$this->current])){
  3051. //$res = $this->items[$this->current]->save(false);
  3052. $res = $this->items[$this->current]->save(false,$this->prerequisites_match($this->current));
  3053. $this->autocomplete_parents($this->current);
  3054. $status = $this->items[$this->current]->get_status();
  3055. $this->append_message('new_item_status: '.$status);
  3056. $this->update_queue[$this->current] = $status;
  3057. return $res;
  3058. }
  3059. return false;
  3060. }
  3061. /**
  3062. * Saves the given item
  3063. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3064. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3065. * @return boolean
  3066. */
  3067. function save_item($item_id=null,$from_outside=true){
  3068. if($this->debug>0){error_log('New LP - In learnpath::save_item('.$item_id.','.$from_outside.')',0);}
  3069. //TODO do a better check on the index pointing to the right item (it is supposed to be working
  3070. // on $ordered_items[] but not sure it's always safe to use with $items[])
  3071. if(empty($item_id)){
  3072. $item_id = $this->escape_string($_REQUEST['id']);
  3073. }
  3074. if(empty($item_id))
  3075. {
  3076. $item_id = $this->get_current_item_id();
  3077. }
  3078. if($this->debug>2){error_log('New LP - save_current() saving item '.$item_id,0);}
  3079. if(is_object($this->items[$item_id])){
  3080. $res = $this->items[$item_id]->save($from_outside,$this->prerequisites_match($item_id));
  3081. //$res = $this->items[$item_id]->save($from_outside);
  3082. $this->autocomplete_parents($item_id);
  3083. $status = $this->items[$item_id]->get_status();
  3084. $this->append_message('new_item_status: '.$status);
  3085. $this->update_queue[$item_id] = $status;
  3086. return $res;
  3087. }
  3088. return false;
  3089. }
  3090. /**
  3091. * Saves the last item seen's ID only in case
  3092. */
  3093. function save_last(){
  3094. if($this->debug>0){error_log('New LP - In learnpath::save_last()',0);}
  3095. $table = Database::get_course_table('lp_view');
  3096. if(isset($this->current)){
  3097. if($this->debug>2){error_log('New LP - Saving current item ('.$this->current.') for later review',0);}
  3098. $sql = "UPDATE $table SET last_item = ".$this->get_current_item_id()." " .
  3099. "WHERE lp_id = ".$this->get_id()." AND user_id = ".$this->get_user_id();
  3100. if($this->debug>2){error_log('New LP - Saving last item seen : '.$sql,0);}
  3101. $res = api_sql_query($sql,__FILE__,__LINE__);
  3102. }
  3103. //save progress
  3104. list($progress,$text) = $this->get_progress_bar_text('%');
  3105. if($progress>=0 AND $progress<=100){
  3106. $progress= (int)$progress;
  3107. $sql = "UPDATE $table SET progress = $progress " .
  3108. "WHERE lp_id = ".$this->get_id()." AND " .
  3109. "user_id = ".$this->get_user_id();
  3110. $res = api_sql_query($sql,__FILE__, __LINE__); //ignore errors as some tables might not have the progress field just yet
  3111. $this->progress_db = $progress;
  3112. }
  3113. }
  3114. /**
  3115. * Sets the current item ID (checks if valid and authorized first)
  3116. * @param integer New item ID. If not given or not authorized, defaults to current
  3117. */
  3118. function set_current_item($item_id=null)
  3119. {
  3120. if($this->debug>0){error_log('New LP - In learnpath::set_current_item('.$item_id.')',0);}
  3121. if(empty($item_id)){
  3122. if($this->debug>2){error_log('New LP - No new current item given, ignore...',0);}
  3123. //do nothing
  3124. }else{
  3125. if($this->debug>2){error_log('New LP - New current item given is '.$item_id.'...',0);}
  3126. $item_id = $this->escape_string($item_id);
  3127. //TODO check in database here
  3128. $this->last = $this->current;
  3129. $this->current = $item_id;
  3130. //TODO update $this->index as well
  3131. foreach($this->ordered_items as $index => $item)
  3132. {
  3133. if($item == $this->current)
  3134. {
  3135. $this->index = $index;
  3136. break;
  3137. }
  3138. }
  3139. if($this->debug>2){error_log('New LP - set_current_item('.$item_id.') done. Index is now : '.$this->index,0);}
  3140. }
  3141. }
  3142. /**
  3143. * Sets the encoding
  3144. * @param string New encoding
  3145. */
  3146. function set_encoding($enc='ISO-8859-1'){
  3147. if($this->debug>0){error_log('New LP - In learnpath::set_encoding()',0);}
  3148. $enc = strtoupper($enc);
  3149. $encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','cp1251','cp1252','KOI8-R','BIG5','GB2312','Shift_JIS','EUC-JP','');
  3150. if(in_array($enc,$encodings)){
  3151. $lp = $this->get_id();
  3152. if($lp!=0){
  3153. $tbl_lp = Database::get_course_table('lp');
  3154. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ".$lp;
  3155. $res = api_sql_query($sql, __FILE__, __LINE__);
  3156. return $res;
  3157. }
  3158. }
  3159. return false;
  3160. }
  3161. /**
  3162. * Sets the JS lib setting in the database directly.
  3163. * This is the JavaScript library file this lp needs to load on startup
  3164. * @param string Proximity setting
  3165. */
  3166. function set_jslib($lib=''){
  3167. if($this->debug>0){error_log('New LP - In learnpath::set_jslib()',0);}
  3168. $lp = $this->get_id();
  3169. if($lp!=0){
  3170. $tbl_lp = Database::get_course_table('lp');
  3171. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ".$lp;
  3172. $res = api_sql_query($sql, __FILE__, __LINE__);
  3173. return $res;
  3174. }else{
  3175. return false;
  3176. }
  3177. }
  3178. /**
  3179. * Sets the name of the LP maker (publisher) (and save)
  3180. * @param string Optional string giving the new content_maker of this learnpath
  3181. */
  3182. function set_maker($name=''){
  3183. if($this->debug>0){error_log('New LP - In learnpath::set_maker()',0);}
  3184. if(empty($name))return false;
  3185. $this->maker = $this->escape_string($name);
  3186. $lp_table = Database::get_course_table('lp');
  3187. $lp_id = $this->get_id();
  3188. $sql = "UPDATE $lp_table SET content_maker = '".$this->maker."' WHERE id = '$lp_id'";
  3189. if($this->debug>2){error_log('New LP - lp updated with new content_maker : '.$this->maker,0);}
  3190. //$res = Database::query($sql);
  3191. $res = api_sql_query($sql, __FILE__, __LINE__);
  3192. return true;
  3193. }
  3194. /**
  3195. * Sets the name of the current learnpath (and save)
  3196. * @param string Optional string giving the new name of this learnpath
  3197. */
  3198. function set_name($name=''){
  3199. if($this->debug>0){error_log('New LP - In learnpath::set_name()',0);}
  3200. if(empty($name))return false;
  3201. $this->name = $this->escape_string($name);
  3202. $lp_table = Database::get_course_table('lp');
  3203. $lp_id = $this->get_id();
  3204. $sql = "UPDATE $lp_table SET name = '".$this->name."' WHERE id = '$lp_id'";
  3205. if($this->debug>2){error_log('New LP - lp updated with new name : '.$this->name,0);}
  3206. //$res = Database::query($sql);
  3207. $res = api_sql_query($sql, __FILE__, __LINE__);
  3208. // if the lp is visible on the homepage, change his name there
  3209. if(mysql_affected_rows())
  3210. {
  3211. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3212. $sql = 'UPDATE '.$table.' SET
  3213. name = "'.$this->name.'"
  3214. WHERE link = "newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'"';
  3215. api_sql_query($sql, __FILE__, __LINE__);
  3216. }
  3217. return true;
  3218. }
  3219. /**
  3220. * Set index specified prefix terms for all items in this path
  3221. * @param string Comma-separated list of terms
  3222. * @param char Xapian term prefix
  3223. * @return boolean False on error, true otherwise
  3224. */
  3225. function set_terms_by_prefix($terms_string, $prefix) {
  3226. if (api_get_setting('search_enabled') !== 'true')
  3227. return FALSE;
  3228. $terms_string = trim($terms_string);
  3229. $terms = explode(',', $terms_string);
  3230. array_walk($terms, 'trim_value');
  3231. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3232. //var_dump($stored_terms);
  3233. //var_dump($terms);
  3234. // don't do anything if no change, verify only at DB, not the search engine
  3235. if ( (count(array_diff($terms, $stored_terms))==0) && (count(array_diff($stored_terms, $terms))==0) )
  3236. return FALSE;
  3237. require_once('xapian.php'); //TODO try catch every xapian use or make wrappers on api
  3238. require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php');
  3239. require_once(api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php');
  3240. require_once(api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php');
  3241. $items_table = Database::get_course_table('lp_item');
  3242. //TODO: make query secure agains XSS : use member attr instead of post var
  3243. $lp_id = $_POST['lp_id'];
  3244. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3245. $result = api_sql_query($sql);
  3246. $di = new DokeosIndexer();
  3247. while($lp_item = Database::fetch_array($result))
  3248. {
  3249. // get search_did
  3250. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3251. $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';
  3252. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3253. $res = api_sql_query($sql, __FILE__, __LINE__);
  3254. $se_ref = Database::fetch_array($res);
  3255. // compare terms
  3256. $doc = $di->get_document($se_ref['search_did']);
  3257. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3258. //var_dump($xapian_terms);
  3259. $xterms = array();
  3260. foreach ($xapian_terms as $xapian_term) $xterms[] = substr($xapian_term['name'],1);
  3261. $dterms = $terms;
  3262. //var_dump($xterms);
  3263. //var_dump($dterms);
  3264. $missing_terms = array_diff($dterms, $xterms);
  3265. $deprecated_terms = array_diff($xterms, $dterms);
  3266. // save it to search engine
  3267. foreach ($missing_terms as $term)
  3268. {
  3269. $doc->add_term($prefix. $term, 1);
  3270. }
  3271. foreach ($deprecated_terms as $term)
  3272. {
  3273. $doc->remove_term($prefix.$term);
  3274. }
  3275. $di->getDb()->replace_document((int)$se_ref['search_did'], $doc);
  3276. $di->getDb()->flush();
  3277. }
  3278. return true;
  3279. }
  3280. /**
  3281. * Sets the theme of the LP (local/remote) (and save)
  3282. * @param string Optional string giving the new theme of this learnpath
  3283. * @return bool returns true if theme name is not empty
  3284. */
  3285. function set_theme($name=''){
  3286. if($this->debug>0){error_log('New LP - In learnpath::set_theme()',0);}
  3287. $this->theme = $this->escape_string($name);
  3288. $lp_table = Database::get_course_table('lp');
  3289. $lp_id = $this->get_id();
  3290. $sql = "UPDATE $lp_table SET theme = '".$this->theme."' WHERE id = '$lp_id'";
  3291. if($this->debug>2){error_log('New LP - lp updated with new theme : '.$this->theme,0);}
  3292. //$res = Database::query($sql);
  3293. $res = api_sql_query($sql, __FILE__, __LINE__);
  3294. return true;
  3295. }
  3296. /**
  3297. * Sets the image of an LP (and save)
  3298. * @param string Optional string giving the new image of this learnpath
  3299. * @return bool returns true if theme name is not empty
  3300. */
  3301. function set_preview_image($name=''){
  3302. if($this->debug>0){error_log('New LP - In learnpath::set_preview_image()',0);}
  3303. $this->preview_image = $this->escape_string($name);
  3304. $lp_table = Database::get_course_table('lp');
  3305. $lp_id = $this->get_id();
  3306. $sql = "UPDATE $lp_table SET preview_image = '".$this->preview_image."' WHERE id = '$lp_id'";
  3307. if($this->debug>2){error_log('New LP - lp updated with new preview image : '.$this->preview_image,0);}
  3308. $res = api_sql_query($sql, __FILE__, __LINE__);
  3309. return true;
  3310. }
  3311. /**
  3312. * Sets the author of a LP (and save)
  3313. * @param string Optional string giving the new author of this learnpath
  3314. * @return bool returns true if author's name is not empty
  3315. */
  3316. function set_author($name=''){
  3317. if($this->debug>0){error_log('New LP - In learnpath::set_author()',0);}
  3318. $this->author = $this->escape_string($name);
  3319. $lp_table = Database::get_course_table('lp');
  3320. $lp_id = $this->get_id();
  3321. $sql = "UPDATE $lp_table SET author = '".$this->author."' WHERE id = '$lp_id'";
  3322. if($this->debug>2){error_log('New LP - lp updated with new preview author : '.$this->author,0);}
  3323. $res = api_sql_query($sql, __FILE__, __LINE__);
  3324. return true;
  3325. }
  3326. /**
  3327. * Sets the location/proximity of the LP (local/remote) (and save)
  3328. * @param string Optional string giving the new location of this learnpath
  3329. */
  3330. function set_proximity($name=''){
  3331. if($this->debug>0){error_log('New LP - In learnpath::set_proximity()',0);}
  3332. if(empty($name))return false;
  3333. $this->proximity = $this->escape_string($name);
  3334. $lp_table = Database::get_course_table('lp');
  3335. $lp_id = $this->get_id();
  3336. $sql = "UPDATE $lp_table SET content_local = '".$this->proximity."' WHERE id = '$lp_id'";
  3337. if($this->debug>2){error_log('New LP - lp updated with new proximity : '.$this->proximity,0);}
  3338. //$res = Database::query($sql);
  3339. $res = api_sql_query($sql, __FILE__, __LINE__);
  3340. return true;
  3341. }
  3342. /**
  3343. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3344. * @param integer DB ID of the item
  3345. */
  3346. function set_previous_item($id)
  3347. {
  3348. if($this->debug>0){error_log('New LP - In learnpath::set_previous_item()',0);}
  3349. $this->last = $id;
  3350. }
  3351. /**
  3352. * Sets the object's error message
  3353. * @param string Error message. If empty, reinits the error string
  3354. * @return void
  3355. */
  3356. function set_error_msg($error='')
  3357. {
  3358. if($this->debug>0){error_log('New LP - In learnpath::set_error_msg()',0);}
  3359. if(empty($error)){
  3360. $this->error = '';
  3361. }else{
  3362. $this->error .= $error;
  3363. }
  3364. }
  3365. /**
  3366. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3367. *
  3368. */
  3369. function start_current_item($allow_new_attempt=false){
  3370. if($this->debug>0){error_log('New LP - In learnpath::start_current_item()',0);}
  3371. if($this->current != 0 AND
  3372. is_object($this->items[$this->current]))
  3373. {
  3374. $type = $this->get_type();
  3375. $item_type = $this->items[$this->current]->get_type();
  3376. if(
  3377. ($type == 2 && $item_type!='sco')
  3378. OR
  3379. ($type == 3 && $item_type!='au')
  3380. OR
  3381. ($type == 1 && $item_type!=TOOL_QUIZ && $item_type!=TOOL_HOTPOTATOES)
  3382. )
  3383. {
  3384. $this->items[$this->current]->open($allow_new_attempt);
  3385. $this->autocomplete_parents($this->current);
  3386. $prereq_check = $this->prerequisites_match($this->current);
  3387. $this->items[$this->current]->save(false,$prereq_check);
  3388. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3389. }else{
  3390. //if sco, then it is supposed to have been updated by some other call
  3391. }
  3392. $this->items[$this->current]->restart();
  3393. }
  3394. if($this->debug>0){error_log('New LP - End of learnpath::start_current_item()',0);}
  3395. return true;
  3396. }
  3397. /**
  3398. * Stops the processing and counters for the old item (as held in $this->last)
  3399. * @param
  3400. */
  3401. function stop_previous_item(){
  3402. if($this->debug>0){error_log('New LP - In learnpath::stop_previous_item()',0);}
  3403. if($this->last != 0 AND $this->last!=$this->current AND is_object($this->items[$this->last]))
  3404. {
  3405. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' is object',0);}
  3406. switch($this->get_type()){
  3407. case '3':
  3408. if($this->items[$this->last]->get_type()!='au')
  3409. {
  3410. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au',0);}
  3411. $this->items[$this->last]->close();
  3412. //$this->autocomplete_parents($this->last);
  3413. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3414. }else{
  3415. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
  3416. }
  3417. case '2':
  3418. if($this->items[$this->last]->get_type()!='sco')
  3419. {
  3420. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco',0);}
  3421. $this->items[$this->last]->close();
  3422. //$this->autocomplete_parents($this->last);
  3423. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3424. }else{
  3425. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
  3426. }
  3427. break;
  3428. case '1':
  3429. default:
  3430. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset',0);}
  3431. $this->items[$this->last]->close();
  3432. break;
  3433. }
  3434. }else{
  3435. if($this->debug>2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
  3436. return false;
  3437. }
  3438. return true;
  3439. }
  3440. /**
  3441. * Updates the default view mode from fullscreen to embedded and inversely
  3442. * @return string The current default view mode ('fullscreen' or 'embedded')
  3443. */
  3444. function update_default_view_mode()
  3445. {
  3446. if($this->debug>0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
  3447. $lp_table = Database::get_course_table('lp');
  3448. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3449. $res = api_sql_query($sql, __FILE__, __LINE__);
  3450. if(Database::num_rows($res)>0){
  3451. $row = Database::fetch_array($res);
  3452. $view_mode = $row['default_view_mod'];
  3453. if($view_mode == 'fullscreen'){
  3454. $view_mode = 'embedded';
  3455. }elseif($view_mode == 'embedded'){
  3456. $view_mode = 'fullscreen';
  3457. }
  3458. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ".$this->get_id();
  3459. $res = api_sql_query($sql, __FILE__, __LINE__);
  3460. $this->mode = $view_mode;
  3461. return $view_mode;
  3462. }else{
  3463. if($this->debug>2){error_log('New LP - Problem in update_default_view() - could not find LP '.$this->get_id().' in DB',0);}
  3464. }
  3465. return -1;
  3466. }
  3467. /**
  3468. * Updates the default behaviour about auto-commiting SCORM updates
  3469. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3470. */
  3471. function update_default_scorm_commit(){
  3472. if($this->debug>0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
  3473. $lp_table = Database::get_course_table('lp');
  3474. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3475. $res = api_sql_query($sql, __FILE__, __LINE__);
  3476. if(Database::num_rows($res)>0){
  3477. $row = Database::fetch_array($res);
  3478. $force = $row['force_commit'];
  3479. if($force == 1){
  3480. $force = 0;
  3481. $force_return = false;
  3482. }elseif($force == 0){
  3483. $force = 1;
  3484. $force_return = true;
  3485. }
  3486. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ".$this->get_id();
  3487. $res = api_sql_query($sql, __FILE__, __LINE__);
  3488. $this->force_commit = $force_return;
  3489. return $force_return;
  3490. }else{
  3491. if($this->debug>2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '.$this->get_id().' in DB',0);}
  3492. }
  3493. return -1;
  3494. }
  3495. /**
  3496. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  3497. * @return bool True on success, false on failure
  3498. */
  3499. function update_display_order()
  3500. {
  3501. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  3502. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3503. $res = api_sql_query($sql, __FILE__, __LINE__);
  3504. if($res === false) return false;
  3505. $lps = array();
  3506. $lp_order = array();
  3507. $num = Database::num_rows($res);
  3508. //first check the order is correct, globally (might be wrong because
  3509. //of versions < 1.8.4)
  3510. if($num>0)
  3511. {
  3512. $i = 1;
  3513. while($row = Database::fetch_array($res))
  3514. {
  3515. if($row['display_order'] != $i)
  3516. { //if we find a gap in the order, we need to fix it
  3517. $need_fix = true;
  3518. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
  3519. $res_u = api_sql_query($sql_u, __FILE__, __LINE__);
  3520. }
  3521. $i++;
  3522. }
  3523. }
  3524. return true;
  3525. }
  3526. /**
  3527. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  3528. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  3529. */
  3530. function update_reinit(){
  3531. if($this->debug>0){error_log('New LP - In learnpath::update_reinit()',0);}
  3532. $lp_table = Database::get_course_table('lp');
  3533. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3534. $res = api_sql_query($sql, __FILE__, __LINE__);
  3535. if(Database::num_rows($res)>0){
  3536. $row = Database::fetch_array($res);
  3537. $force = $row['prevent_reinit'];
  3538. if($force == 1){
  3539. $force = 0;
  3540. }elseif($force == 0){
  3541. $force = 1;
  3542. }
  3543. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ".$this->get_id();
  3544. $res = api_sql_query($sql,__FILE__,__LINE__);
  3545. $this->prevent_reinit = $force;
  3546. return $force;
  3547. }else{
  3548. if($this->debug>2){error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB',0);}
  3549. }
  3550. return -1;
  3551. }
  3552. /**
  3553. * Updates the "scorm_debug" value that shows or hide the debug window
  3554. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  3555. */
  3556. function update_scorm_debug(){
  3557. if($this->debug>0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
  3558. $lp_table = Database::get_course_table('lp');
  3559. $sql = "SELECT * FROM $lp_table WHERE id = ".$this->get_id();
  3560. $res = api_sql_query($sql, __FILE__, __LINE__);
  3561. if(Database::num_rows($res)>0){
  3562. $row = Database::fetch_array($res);
  3563. $force = $row['debug'];
  3564. if($force == 1){
  3565. $force = 0;
  3566. }elseif($force == 0){
  3567. $force = 1;
  3568. }
  3569. $sql = "UPDATE $lp_table SET debug = $force WHERE id = ".$this->get_id();
  3570. $res = api_sql_query($sql,__FILE__,__LINE__);
  3571. $this->scorm_debug = $force;
  3572. return $force;
  3573. }else{
  3574. if($this->debug>2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB',0);}
  3575. }
  3576. return -1;
  3577. }
  3578. /**
  3579. * Function that makes a call to the function sort_tree_array and create_tree_array
  3580. *
  3581. * @author Kevin Van Den Haute
  3582. *
  3583. * @param unknown_type $array
  3584. */
  3585. function tree_array($array)
  3586. {
  3587. $array = $this->sort_tree_array($array);
  3588. $this->create_tree_array($array);
  3589. }
  3590. /**
  3591. * Creates an array with the elements of the learning path tree in it
  3592. *
  3593. * @author Kevin Van Den Haute
  3594. *
  3595. * @param array $array
  3596. * @param int $parent
  3597. * @param int $depth
  3598. * @param array $tmp
  3599. */
  3600. function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array())
  3601. {
  3602. if(is_array($array))
  3603. {
  3604. for($i = 0; $i < count($array); $i++)
  3605. {
  3606. if($array[$i]['parent_item_id'] == $parent)
  3607. {
  3608. if(!in_array($array[$i]['parent_item_id'], $tmp))
  3609. {
  3610. $tmp[] = $array[$i]['parent_item_id'];
  3611. $depth++;
  3612. }
  3613. $preq = (empty($array[$i]['prerequisite'])?'':$array[$i]['prerequisite']);
  3614. $this->arrMenu[] = array(
  3615. 'id' => $array[$i]['id'],
  3616. 'item_type' => $array[$i]['item_type'],
  3617. 'title' => $array[$i]['title'],
  3618. 'path' => $array[$i]['path'],
  3619. 'description' => $array[$i]['description'],
  3620. 'parent_item_id' => $array[$i]['parent_item_id'],
  3621. 'previous_item_id' => $array[$i]['previous_item_id'],
  3622. 'next_item_id' => $array[$i]['next_item_id'],
  3623. 'min_score' => $array[$i]['min_score'],
  3624. 'max_score' => $array[$i]['max_score'],
  3625. 'mastery_score' => $array[$i]['mastery_score'],
  3626. 'display_order' => $array[$i]['display_order'],
  3627. 'prerequisite' => $preq,
  3628. 'depth' => $depth,
  3629. 'audio' => $array[$i]['audio']
  3630. );
  3631. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  3632. }
  3633. }
  3634. }
  3635. }
  3636. /**
  3637. * Sorts a multi dimensional array by parent id and display order
  3638. * @author Kevin Van Den Haute
  3639. *
  3640. * @param array $array (array with al the learning path items in it)
  3641. *
  3642. * @return array
  3643. */
  3644. function sort_tree_array($array)
  3645. {
  3646. foreach($array as $key => $row)
  3647. {
  3648. $parent[$key] = $row['parent_item_id'];
  3649. $position[$key] = $row['display_order'];
  3650. }
  3651. if(count($array) > 0)
  3652. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  3653. return $array;
  3654. }
  3655. /**
  3656. * Function that creates a table structure with a learning path his modules, chapters and documents.
  3657. * Also the actions for the modules, chapters and documents are in this table.
  3658. *
  3659. * @author Kevin Van Den Haute
  3660. *
  3661. * @param int $lp_id
  3662. *
  3663. * @return string
  3664. */
  3665. function overview()
  3666. {
  3667. global $charset, $_course;
  3668. $return = '';
  3669. $tbl_lp_item = Database::get_course_table('lp_item');
  3670. $sql = "
  3671. SELECT *
  3672. FROM " . $tbl_lp_item . "
  3673. WHERE
  3674. lp_id = " . $this->lp_id;
  3675. $result = api_sql_query($sql, __FILE__, __LINE__);
  3676. $arrLP = array();
  3677. $mycharset=api_get_setting('platform_charset');
  3678. while($row = Database::fetch_array($result))
  3679. {
  3680. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3681. $arrLP[] = array(
  3682. 'id' => $row['id'],
  3683. 'item_type' => $row['item_type'],
  3684. 'title' => $row['title'],
  3685. 'description' => $row['description'],
  3686. 'parent_item_id' => $row['parent_item_id'],
  3687. 'previous_item_id' => $row['previous_item_id'],
  3688. 'next_item_id' => $row['next_item_id'],
  3689. 'max_score' => $row['max_score'],
  3690. 'min_score' => $row['min_score'],
  3691. 'mastery_score' => $row['mastery_score'],
  3692. 'prerequisite' => $row['prerequisite'],
  3693. 'display_order' => $row['display_order'],
  3694. 'audio' => $row['audio']
  3695. );
  3696. }
  3697. $this->tree_array($arrLP);
  3698. $arrLP = $this->arrMenu;
  3699. unset($this->arrMenu);
  3700. if(api_is_allowed_to_edit())
  3701. {
  3702. $return .= '<div class="actions">';
  3703. $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>';
  3704. $return .= '<span>'.Display::return_icon('learnpath_organize.gif', get_lang("BasicOverview")).' '.get_lang("BasicOverview").'</span>';
  3705. $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>';
  3706. $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>';
  3707. $return .= '</div>';
  3708. }
  3709. // we need to start a form when we want to update all the mp3 files
  3710. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0)
  3711. {
  3712. $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">';
  3713. $return .= Display::display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  3714. }
  3715. $return .= '<table class="data_table">' . "\n";
  3716. $return .= "\t" . '<tr>' . "\n";
  3717. $return .= "\t" . '<th width="75%">'.get_lang("Title").'</th>' . "\n";
  3718. //$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
  3719. $return .= "\t" . '<th>'.get_lang("Audio").'</th>' . "\n";
  3720. $return .= "\t" . '<th>'.get_lang("Move").'</th>' . "\n";
  3721. $return .= "\t" . '<th>'.get_lang("Actions").'</th>' . "\n";
  3722. $return .= "\t" . '</tr>' . "\n";
  3723. for($i = 0; $i < count($arrLP); $i++)
  3724. {
  3725. $title=$arrLP[$i]['title'];
  3726. if($arrLP[$i]['description'] == '')
  3727. $arrLP[$i]['description'] = '&nbsp;';
  3728. if (($i % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
  3729. $return .= "\t" . '<tr class="'.$oddclass.'">' . "\n";
  3730. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  3731. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  3732. // The audio column
  3733. $return .= "\t\t" . '<td>';
  3734. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true')
  3735. {
  3736. if (!empty($arrLP[$i]['audio']))
  3737. {
  3738. $return .= '<span id="container'.$i.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  3739. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  3740. $return .= '<script type="text/javascript">
  3741. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  3742. s1.addParam("allowscriptaccess","always");
  3743. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$arrLP[$i]['audio'].'&image=preview.jpg");
  3744. s1.write("container'.$i.'");
  3745. </script>';
  3746. }
  3747. else
  3748. {
  3749. $return .= ' - ';
  3750. }
  3751. }
  3752. else
  3753. {
  3754. $return .= ' <input type="file" name="mp3file'.$arrLP[$i]['id'].'" id="mp3file" />';
  3755. if (!empty($arrLP[$i]['audio']))
  3756. {
  3757. $return .= '<input type="checkbox" name="removemp3'.$arrLP[$i]['id'].'" id="checkbox'.$arrLP[$i]['id'].'" />'.get_lang('RemoveAudio');
  3758. }
  3759. }
  3760. $return .= '</td>' . "\n";
  3761. if(api_is_allowed_to_edit())
  3762. {
  3763. $return .= "\t\t" . '<td>' . "\n";
  3764. if($arrLP[$i]['previous_item_id'] != 0)
  3765. {
  3766. $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 . '">';
  3767. $return .= '<img alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  3768. $return .= '</a>' . "\n";
  3769. }
  3770. else
  3771. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3772. if($arrLP[$i]['next_item_id'] != 0)
  3773. {
  3774. $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 . '">';
  3775. $return .= '<img src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  3776. $return .= '</a>' . "\n";
  3777. }
  3778. else
  3779. $return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
  3780. $return .= "\t\t" . '</td>' . "\n";
  3781. $return .= "\t\t" . '<td>' . "\n";
  3782. if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
  3783. {
  3784. $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 . '">';
  3785. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3786. $return .= '</a>' . "\n";
  3787. }
  3788. else
  3789. {
  3790. $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 . '">';
  3791. $return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  3792. $return .= '</a>' . "\n";
  3793. }
  3794. $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). '\');">';
  3795. $return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  3796. $return .= '</a>' . "\n";
  3797. $return .= "\t\t" . '</td>' . "\n";
  3798. }
  3799. $return .= "\t" . '</tr>' . "\n";
  3800. }
  3801. if(count($arrLP) == 0)
  3802. {
  3803. $return .= "\t" . '<tr>' . "\n";
  3804. $return .= "\t\t" . '<td colspan="4">'.get_lang("NoItemsInLp").'</td>' . "\n";
  3805. $return .= "\t" . '</tr>' . "\n";
  3806. }
  3807. // we need to close the form when we are updating the mp3 files
  3808. if ($_GET['updateaudio'] == 'true')
  3809. {
  3810. $return .= '<tr><th></th> <th><button class="save" type="submit" name="save_audio" id="save_audio">'.get_lang('SaveAudio').'</button></th><th></th><th></th></tr>';
  3811. }
  3812. $return .= '</table>' . "\n";
  3813. // we need to close the form when we are updating the mp3 files
  3814. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0)
  3815. {
  3816. $return .= '</form>';
  3817. }
  3818. return $return;
  3819. }
  3820. /**
  3821. * This function builds the action menu
  3822. *
  3823. * */
  3824. function build_action_menu()
  3825. {
  3826. echo '<div class="actions">';
  3827. echo '<span>'.Display::return_icon('learnpath_build.gif').' '.get_lang('Build').'</span>';
  3828. echo '<a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">'.Display::return_icon('learnpath_build.gif').' '.get_lang("BasicOverview").'</a>';
  3829. echo '<a href="lp_controller.php?cidReq='.$_GET['cidReq'].'&action=view&lp_id='.$_SESSION['oLP']->lp_id.'">'.Display::return_icon('learnpath_organize.gif').' '.get_lang('Display').'</a>';
  3830. echo '<a href="' .api_get_self(). '?cidReq=' . $_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>';
  3831. echo '<a href="' .api_get_self(). '?cidReq=' . $_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>';
  3832. echo '</div>';
  3833. }
  3834. /**
  3835. * This functions builds the LP tree based on data from the database.
  3836. *
  3837. * @return string
  3838. * @uses dtree.js :: necessary javascript for building this tree
  3839. */
  3840. function build_tree()
  3841. {
  3842. $return = "<script type=\"text/javascript\">\n";
  3843. $return .= "\tm = new dTree('m');\n\n";
  3844. $return .= "\tm.config.folderLinks = true;\n";
  3845. $return .= "\tm.config.useCookies = true;\n";
  3846. $return .= "\tm.config.useIcons = true;\n";
  3847. $return .= "\tm.config.useLines = true;\n";
  3848. $return .= "\tm.config.useSelection = true;\n";
  3849. $return .= "\tm.config.useStatustext = false;\n\n";
  3850. $menu = 0;
  3851. $parent = '';
  3852. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
  3853. $tbl_lp_item = Database::get_course_table('lp_item');
  3854. $sql = "
  3855. SELECT *
  3856. FROM " . $tbl_lp_item . "
  3857. WHERE
  3858. lp_id = " . $this->lp_id;
  3859. $result = api_sql_query($sql, __FILE__, __LINE__);
  3860. $arrLP = array();
  3861. $mycharset=api_get_setting('platform_charset');
  3862. while($row = Database::fetch_array($result))
  3863. {
  3864. if($this->encoding!=$mycharset)
  3865. {
  3866. $row['title'] = mb_convert_encoding($row['title'], $mycharset,$this->encoding);
  3867. }
  3868. $arrLP[] = array(
  3869. 'id' => $row['id'],
  3870. 'item_type' => $row['item_type'],
  3871. 'title' => $row['title'],
  3872. 'path' => $row['path'],
  3873. 'description' => $row['description'],
  3874. 'parent_item_id' => $row['parent_item_id'],
  3875. 'previous_item_id' => $row['previous_item_id'],
  3876. 'next_item_id' => $row['next_item_id'],
  3877. 'max_score' => $row['max_score'],
  3878. 'min_score' => $row['min_score'],
  3879. 'mastery_score' => $row['mastery_score'],
  3880. 'display_order' => $row['display_order']);
  3881. }
  3882. $this->tree_array($arrLP);
  3883. $arrLP = $this->arrMenu;
  3884. unset($this->arrMenu);
  3885. $title='';
  3886. for($i = 0; $i < count($arrLP); $i++)
  3887. {
  3888. $title = addslashes($arrLP[$i]['title']);
  3889. $menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  3890. if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".png"))
  3891. {
  3892. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".png', '../img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
  3893. }
  3894. else if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".gif"))
  3895. {
  3896. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif');\n";
  3897. }
  3898. else
  3899. {
  3900. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
  3901. }
  3902. if($menu < $arrLP[$i]['id'])
  3903. $menu = $arrLP[$i]['id'];
  3904. }
  3905. $return .= "\n\tdocument.write(m);\n";
  3906. $return .= "\t if(!m.selectedNode) m.s(1);";
  3907. $return .= "</script>\n";
  3908. return $return;
  3909. }
  3910. /**
  3911. * Create a new document //still needs some finetuning
  3912. *
  3913. * @param array $_course
  3914. * @return string
  3915. */
  3916. function create_document($_course)
  3917. {
  3918. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3919. if(strstr($dir, '..'))
  3920. $dir = '/';
  3921. if($dir[0] == '.')
  3922. $dir = substr($dir, 1);
  3923. if($dir[0] != '/')
  3924. $dir = '/'.$dir;
  3925. if($dir[strlen($dir) - 1] != '/')
  3926. $dir .= '/';
  3927. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
  3928. if(!is_dir($filepath))
  3929. {
  3930. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  3931. $dir = '/';
  3932. }
  3933. //stripslashes before calling replace_dangerous_char() because $_POST['title']
  3934. //is already escaped twice when it gets here
  3935. $title = replace_dangerous_char(stripslashes($_POST['title']));
  3936. $title = disable_dangerous_file($title);
  3937. $title = replace_accents($title);
  3938. $filename = $title;
  3939. $content = $_POST['content_lp'];
  3940. $tmp_filename = $filename;
  3941. $i=0;
  3942. while(file_exists($filepath . $tmp_filename . '.html'))
  3943. $tmp_filename = $filename . '_' . ++$i;
  3944. $filename = $tmp_filename . '.html';
  3945. $content = stripslashes(text_filter($content));
  3946. $content = str_replace(api_get_path('WEB_COURSE_PATH'), api_get_path(REL_PATH).'courses/', $content);
  3947. // change the path of mp3 to absolute
  3948. // first regexp deals with ../../../ urls
  3949. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  3950. //second regexp deals with audio/ urls
  3951. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  3952. // for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
  3953. $content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
  3954. if(!file_exists($filepath . $filename))
  3955. {
  3956. if($fp = @fopen($filepath . $filename, 'w'))
  3957. {
  3958. fputs($fp, $content);
  3959. fclose($fp);
  3960. $file_size = filesize($filepath . $filename);
  3961. $save_file_path = $dir . $filename;
  3962. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  3963. if($document_id)
  3964. {
  3965. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
  3966. //update parent folders
  3967. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  3968. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  3969. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  3970. if($new_comment || $new_title)
  3971. {
  3972. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  3973. $ct = '';
  3974. if($new_comment)
  3975. $ct .= ", comment='" . $new_comment . "'";
  3976. if($new_title)
  3977. $ct .= ", title='" . $new_title . ".html '";
  3978. $sql_update = "
  3979. UPDATE " . $tbl_doc . "
  3980. SET " . substr($ct, 1) . "
  3981. WHERE id = " . $document_id;
  3982. api_sql_query($sql_update, __FILE__, __LINE__);
  3983. }
  3984. }
  3985. return $document_id;
  3986. }
  3987. }
  3988. }
  3989. /**
  3990. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  3991. *
  3992. * @param array $_course array
  3993. * @return void
  3994. */
  3995. function edit_document($_course)
  3996. {
  3997. global $_configuration;
  3998. $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
  3999. if(strstr($dir, '..'))
  4000. $dir = '/';
  4001. if($dir[0] == '.')
  4002. $dir = substr($dir, 1);
  4003. if($dir[0] != '/')
  4004. $dir = '/'.$dir;
  4005. if($dir[strlen($dir) - 1] != '/')
  4006. $dir .= '/';
  4007. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'.$dir;
  4008. if(!is_dir($filepath))
  4009. {
  4010. $filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
  4011. $dir = '/';
  4012. }
  4013. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  4014. $sql = "
  4015. SELECT path
  4016. FROM " . $table_doc . "
  4017. WHERE id = " . $_POST['path'];
  4018. $res = api_sql_query($sql, __FILE__, __LINE__);
  4019. $row = Database::fetch_array($res);
  4020. $content = stripslashes($_POST['content_lp']);
  4021. $file = $filepath . $row['path'];
  4022. if($fp = @fopen($file, 'w'))
  4023. {
  4024. $content = text_filter($content);
  4025. $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content);
  4026. // change the path of mp3 to absolute
  4027. // first regexp deals with ../../../ urls
  4028. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
  4029. //second regexp deals with audio/ urls
  4030. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
  4031. fputs($fp, $content);
  4032. fclose($fp);
  4033. }
  4034. }
  4035. /**
  4036. * Displays the selected item, with a panel for manipulating the item
  4037. *
  4038. * @param int $item_id
  4039. * @param string $msg
  4040. * @return string
  4041. */
  4042. function display_item($item_id, $iframe = true, $msg = '')
  4043. {
  4044. global $_course; //will disappear
  4045. $return = '';
  4046. if(is_numeric($item_id))
  4047. {
  4048. $tbl_lp_item = Database::get_course_table('lp_item');
  4049. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4050. $sql = "
  4051. SELECT
  4052. lp.*
  4053. FROM " . $tbl_lp_item . " as lp
  4054. WHERE
  4055. lp.id = " . $item_id;
  4056. $result = api_sql_query($sql, __FILE__, __LINE__);
  4057. while($row = Database::fetch_array($result))
  4058. {
  4059. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4060. $return .= '<div style="padding:10px;">';
  4061. if($msg != '')
  4062. $return .= $msg;
  4063. if($this->encoding=='UTF-8')
  4064. {
  4065. $row['title'] = utf8_decode($row['title']);
  4066. }
  4067. $return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
  4068. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4069. //$return .= '<hr />';
  4070. if($row['item_type'] == TOOL_DOCUMENT)
  4071. {
  4072. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4073. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
  4074. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  4075. $path_file=Database::result($result,0,0);
  4076. $path_parts = pathinfo($path_file);
  4077. if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
  4078. {
  4079. $return .= $this->display_document($row['path'], true, true);
  4080. }
  4081. }
  4082. $return .= '</div>';
  4083. }
  4084. }
  4085. return $return;
  4086. }
  4087. /**
  4088. * Shows the needed forms for editing a specific item
  4089. *
  4090. * @param int $item_id
  4091. * @return string
  4092. */
  4093. function display_edit_item($item_id)
  4094. {
  4095. global $_course; //will disappear
  4096. $return = '';
  4097. if(is_numeric($item_id))
  4098. {
  4099. $tbl_lp_item = Database::get_course_table('lp_item');
  4100. $sql = "
  4101. SELECT *
  4102. FROM " . $tbl_lp_item . "
  4103. WHERE id = " . $item_id;
  4104. $res = api_sql_query($sql, __FILE__, __LINE__);
  4105. $row = Database::fetch_array($res);
  4106. switch($row['item_type'])
  4107. {
  4108. case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
  4109. if(isset($_GET['view']) && $_GET['view'] == 'build')
  4110. {
  4111. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4112. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentChapter").' :', 'edit', $item_id, $row);
  4113. }
  4114. else
  4115. {
  4116. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentChapter").' :', $row);
  4117. }
  4118. break;
  4119. case TOOL_DOCUMENT:
  4120. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4121. $sql_step = "
  4122. SELECT
  4123. lp.*,
  4124. doc.path as dir
  4125. FROM " . $tbl_lp_item . " as lp
  4126. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4127. WHERE
  4128. lp.id = " . $item_id;
  4129. $res_step = api_sql_query($sql_step, __FILE__, __LINE__);
  4130. $row_step = Database::fetch_array($res_step);
  4131. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4132. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4133. break;
  4134. case TOOL_LINK:
  4135. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4136. $return .= $this->display_link_form('edit', $item_id, $row);
  4137. break;
  4138. case 'dokeos_module':
  4139. if(isset($_GET['view']) && $_GET['view'] == 'build')
  4140. {
  4141. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4142. $return .= $this->display_item_form($row['item_type'], get_lang("EditCurrentModule").' :', 'edit', $item_id, $row);
  4143. }
  4144. else
  4145. {
  4146. $return .= $this->display_item_small_form($row['item_type'], get_lang("EditCurrentModule").' :', $row);
  4147. }
  4148. break;
  4149. case TOOL_QUIZ:
  4150. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4151. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4152. break;
  4153. case TOOL_HOTPOTATOES:
  4154. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4155. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4156. break;
  4157. case TOOL_STUDENTPUBLICATION:
  4158. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4159. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4160. break;
  4161. case TOOL_FORUM:
  4162. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4163. $return .= $this->display_forum_form('edit', $item_id, $row);
  4164. break;
  4165. case TOOL_THREAD:
  4166. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4167. $return .= $this->display_thread_form('edit', $item_id, $row);
  4168. break;
  4169. }
  4170. }
  4171. return $return;
  4172. }
  4173. /**
  4174. * Function that displays a list with al the resources that could be added to the learning path
  4175. *
  4176. * @return string
  4177. */
  4178. function display_resources()
  4179. {
  4180. global $_course; //TODO: don't use globals
  4181. $return .= '<div class="sectiontitle">'.get_lang('CreateNewStep').'</div>';
  4182. $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 . '">'.get_lang("NewDocument").'</a></div>';
  4183. $return .= '<div class="sectiontitle">'.get_lang('UseAnExistingResource').'</div>';
  4184. $return .= '<div class="sectioncomment">';
  4185. /* get all the docs */
  4186. $return .= $this->get_documents();
  4187. /* get all the exercises */
  4188. $return .= $this->get_exercises();
  4189. /* get all the links */
  4190. $return .= $this->get_links();
  4191. /* get al the student publications */
  4192. $return .= $this->get_student_publications();
  4193. /* get al the forums */
  4194. $return .= $this->get_forums();
  4195. $return .= '</div>';
  4196. return $return;
  4197. }
  4198. /**
  4199. * Returns the extension of a document
  4200. *
  4201. * @param unknown_type $filename
  4202. * @return unknown
  4203. */
  4204. function get_extension($filename)
  4205. {
  4206. $explode = explode('.', $filename);
  4207. return $explode[count($explode) - 1];
  4208. }
  4209. /**
  4210. * Displays a document by id
  4211. *
  4212. * @param unknown_type $id
  4213. * @return unknown
  4214. */
  4215. function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
  4216. {
  4217. global $_course; //temporary
  4218. $return = '';
  4219. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  4220. $sql_doc = "
  4221. SELECT *
  4222. FROM " . $tbl_doc . "
  4223. WHERE id = " . $id;
  4224. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  4225. $row_doc = Database::fetch_array($res_doc);
  4226. //if($show_title)
  4227. //$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>';
  4228. //TODO: add a path filter
  4229. if($iframe){
  4230. $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>';
  4231. }
  4232. else{
  4233. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4234. }
  4235. return $return;
  4236. }
  4237. /**
  4238. * Return HTML form to add/edit a quiz
  4239. *
  4240. * @param string Action (add/edit)
  4241. * @param integer Item ID if already exists
  4242. * @param mixed Extra information (quiz ID if integer)
  4243. * @return string HTML form
  4244. */
  4245. function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
  4246. {
  4247. global $charset;
  4248. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  4249. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  4250. if($id != 0 && is_array($extra_info)) {
  4251. $item_title = stripslashes($extra_info['title']);
  4252. $item_description = stripslashes($extra_info['description']);
  4253. } elseif(is_numeric($extra_info)) {
  4254. $sql_quiz = "
  4255. SELECT
  4256. title,
  4257. description
  4258. FROM " . $tbl_quiz . "
  4259. WHERE id = " . $extra_info;
  4260. $result = api_sql_query($sql_quiz, __FILE__, __LINE__);
  4261. $row = Database::fetch_array($result);
  4262. $item_title = $row['title'];
  4263. $item_description = $row['description'];
  4264. } else {
  4265. $item_title = '';
  4266. $item_description = '';
  4267. }
  4268. $item_title = mb_convert_encoding($item_title,$charset,$this->encoding);
  4269. $return = '<div class="sectiontitle">';
  4270. if($id != 0 && is_array($extra_info))
  4271. $parent = $extra_info['parent_item_id'];
  4272. else
  4273. $parent = 0;
  4274. $sql = "
  4275. SELECT *
  4276. FROM " . $tbl_lp_item . "
  4277. WHERE
  4278. lp_id = " . $this->lp_id;
  4279. $result = api_sql_query($sql, __FILE__, __LINE__);
  4280. $arrLP = array();
  4281. while($row = Database::fetch_array($result)) {
  4282. $arrLP[] = array(
  4283. 'id' => $row['id'],
  4284. 'item_type' => $row['item_type'],
  4285. 'title' => $row['title'],
  4286. 'path' => $row['path'],
  4287. 'description' => $row['description'],
  4288. 'parent_item_id' => $row['parent_item_id'],
  4289. 'previous_item_id' => $row['previous_item_id'],
  4290. 'next_item_id' => $row['next_item_id'],
  4291. 'display_order' => $row['display_order'],
  4292. 'max_score' => $row['max_score'],
  4293. 'min_score' => $row['min_score'],
  4294. 'mastery_score' => $row['mastery_score'],
  4295. 'prerequisite' => $row['prerequisite'],
  4296. 'max_time_allowed' => $row['max_time_allowed']);
  4297. }
  4298. $this->tree_array($arrLP);
  4299. $arrLP = $this->arrMenu;
  4300. unset($this->arrMenu);
  4301. if($action == 'add')
  4302. $return .= get_lang("CreateTheExercise").'&nbsp;:' . "\n";
  4303. elseif($action == 'move')
  4304. $return .= get_lang("MoveTheCurrentExercise").'&nbsp;:' . "\n";
  4305. else
  4306. $return .= get_lang("EditCurrentExecice").'&nbsp;:' . "\n";
  4307. if(isset($_GET['edit']) && $_GET['edit'] == 'true') {
  4308. $return .= '<div class="warning-message">';
  4309. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4310. $return .= get_lang("WarningEditingDocument");
  4311. $return .= '</div>';
  4312. }
  4313. $return .= '</div>';
  4314. $return .= '<div class="sectioncomment">';
  4315. $return .= '<form method="POST">' . "\n";
  4316. $return .= "\t" . '<table>' . "\n";
  4317. if($action != 'move') {
  4318. $return .= "\t\t" . '<tr>' . "\n";
  4319. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  4320. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
  4321. $return .= "\t\t" . '</tr>' . "\n";
  4322. }
  4323. $return .= "\t\t" . '<tr>' . "\n";
  4324. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  4325. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4326. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4327. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4328. $arrHide = array($id);
  4329. for($i = 0; $i < count($arrLP); $i++) {
  4330. if($action != 'add') {
  4331. 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)) {
  4332. $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>';
  4333. } else {
  4334. $arrHide[] = $arrLP[$i]['id'];
  4335. }
  4336. } else {
  4337. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4338. $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>';
  4339. }
  4340. }
  4341. if (is_array($arrLP)) {
  4342. reset($arrLP);
  4343. }
  4344. $return .= "\t\t\t\t" . '</select>';
  4345. $return .= "\t\t\t" . '</td>' . "\n";
  4346. $return .= "\t\t" . '</tr>' . "\n";
  4347. $return .= "\t\t" . '<tr>' . "\n";
  4348. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  4349. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4350. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" id="idPosition" name="previous" size="1">';
  4351. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4352. for($i = 0; $i < count($arrLP); $i++) {
  4353. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4354. {
  4355. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4356. $selected = 'selected="selected" ';
  4357. elseif($action == 'add')
  4358. $selected = 'selected="selected" ';
  4359. else
  4360. $selected = '';
  4361. $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>';
  4362. }
  4363. }
  4364. $return .= "\t\t\t\t" . '</select>';
  4365. $return .= "\t\t\t" . '</td>' . "\n";
  4366. $return .= "\t\t" . '</tr>' . "\n";
  4367. if($action != 'move') {
  4368. $id_prerequisite=0;
  4369. if (is_array($arrLP )) {
  4370. foreach($arrLP as $key=>$value){
  4371. if($value['id']==$id){
  4372. $id_prerequisite=$value['prerequisite'];
  4373. break;
  4374. }
  4375. }
  4376. }
  4377. $arrHide=array();
  4378. for($i = 0; $i < count($arrLP); $i++) {
  4379. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4380. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4381. $s_selected_position=$arrLP[$i]['id'];
  4382. elseif($action == 'add')
  4383. $s_selected_position=0;
  4384. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4385. }
  4386. }
  4387. $return .= "\t\t" . '<tr>' . "\n";
  4388. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4389. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4390. foreach($arrHide as $key => $value){
  4391. if($key==$s_selected_position && $action == 'add'){
  4392. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4393. }
  4394. elseif($key==$id_prerequisite && $action == 'edit'){
  4395. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4396. }
  4397. else{
  4398. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4399. }
  4400. }
  4401. $return .= "</select></td>";
  4402. $return .= "\t\t" . '</tr>' . "\n";
  4403. $return .= "\t\t" . '<tr>' . "\n";
  4404. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">'.get_lang('MaxTimeAllowed').'</label></td>' . "\n";
  4405. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4406. //Remove temporaly the test description
  4407. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4408. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4409. $return .= "\t\t" . '</tr>' . "\n";
  4410. }
  4411. $return .= "\t\t" . '<tr>' . "\n";
  4412. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">'.get_lang('EditCurrentExecice').'</button></td>' . "\n";
  4413. $return .= "\t\t" . '</tr>' . "\n";
  4414. $return .= "\t" . '</table>' . "\n";
  4415. if($action == 'move') {
  4416. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4417. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4418. }
  4419. if(is_numeric($extra_info)) {
  4420. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4421. } elseif(is_array($extra_info)) {
  4422. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4423. }
  4424. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_QUIZ.'" />' . "\n";
  4425. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4426. $return .= '</form>' . "\n";
  4427. $return .= '</div>' . "\n";
  4428. return $return;
  4429. }
  4430. /**
  4431. * Addition of Hotpotatoes tests
  4432. * @param string Action
  4433. * @param integer Internal ID of the item
  4434. * @param mixed Extra information - can be an array with title and description indexes
  4435. * @return string HTML structure to display the hotpotatoes addition formular
  4436. */
  4437. function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
  4438. {
  4439. global $charset;
  4440. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4441. $tbl_lp_item = Database::get_course_table('lp_item');
  4442. if($id != 0 && is_array($extra_info))
  4443. {
  4444. $item_title = stripslashes($extra_info['title']);
  4445. $item_description = stripslashes($extra_info['description']);
  4446. }
  4447. elseif(is_numeric($extra_info))
  4448. {
  4449. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  4450. $sql_hot = "SELECT * FROM ".$TBL_DOCUMENT."
  4451. WHERE path LIKE '".$uploadPath."/%/%htm%'
  4452. ORDER BY id ASC";
  4453. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  4454. $row = Database::fetch_array($res_hot);
  4455. $item_title = $row['title'];
  4456. $item_description = $row['description'];
  4457. }
  4458. else
  4459. {
  4460. $item_title = '';
  4461. $item_description = '';
  4462. }
  4463. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4464. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4465. $return = '<div style="margin:3px 12px;">';
  4466. if($id != 0 && is_array($extra_info))
  4467. $parent = $extra_info['parent_item_id'];
  4468. else
  4469. $parent = 0;
  4470. $sql = "
  4471. SELECT *
  4472. FROM " . $tbl_lp_item . "
  4473. WHERE
  4474. lp_id = " . $this->lp_id;
  4475. $result = api_sql_query($sql, __FILE__, __LINE__);
  4476. $arrLP = array();
  4477. while($row = Database::fetch_array($result))
  4478. {
  4479. $arrLP[] = array(
  4480. 'id' => $row['id'],
  4481. 'item_type' => $row['item_type'],
  4482. 'title' => $row['title'],
  4483. 'path' => $row['path'],
  4484. 'description' => $row['description'],
  4485. 'parent_item_id' => $row['parent_item_id'],
  4486. 'previous_item_id' => $row['previous_item_id'],
  4487. 'next_item_id' => $row['next_item_id'],
  4488. 'display_order' => $row['display_order'],
  4489. 'max_score' => $row['max_score'],
  4490. 'min_score' => $row['min_score'],
  4491. 'mastery_score' => $row['mastery_score'],
  4492. 'prerequisite' => $row['prerequisite'],
  4493. 'max_time_allowed' => $row['max_time_allowed']);
  4494. }
  4495. $this->tree_array($arrLP);
  4496. $arrLP = $this->arrMenu;
  4497. unset($this->arrMenu);
  4498. if($action == 'add')
  4499. $return .= '<p class="lp_title">'.get_lang("CreateTheExercise").'&nbsp;:</p>' . "\n";
  4500. elseif($action == 'move')
  4501. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentExercise").'&nbsp;:</p>' . "\n";
  4502. else
  4503. $return .= '<p class="lp_title">'.get_lang("EditCurrentExecice").'&nbsp;:</p>' . "\n";
  4504. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  4505. {
  4506. $return .= '<div class="warning-message">';
  4507. $return .= '<p class="lp_title">'.get_lang("Warning").' !</p>';
  4508. $return .= get_lang("WarningEditingDocument");
  4509. $return .= '</div>';
  4510. }
  4511. $return .= '<form method="POST">' . "\n";
  4512. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4513. $return .= "\t\t" . '<tr>' . "\n";
  4514. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").' :</label></td>' . "\n";
  4515. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4516. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4517. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4518. $arrHide = array($id);
  4519. for($i = 0; $i < count($arrLP); $i++)
  4520. {
  4521. if($action != 'add')
  4522. {
  4523. 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))
  4524. {
  4525. $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>';
  4526. }
  4527. else
  4528. {
  4529. $arrHide[] = $arrLP[$i]['id'];
  4530. }
  4531. }
  4532. else
  4533. {
  4534. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4535. $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>';
  4536. }
  4537. }
  4538. reset($arrLP);
  4539. $return .= "\t\t\t\t" . '</select>';
  4540. $return .= "\t\t\t" . '</td>' . "\n";
  4541. $return .= "\t\t" . '</tr>' . "\n";
  4542. $return .= "\t\t" . '<tr>' . "\n";
  4543. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").' :</label></td>' . "\n";
  4544. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4545. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4546. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4547. for($i = 0; $i < count($arrLP); $i++)
  4548. {
  4549. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4550. {
  4551. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4552. $selected = 'selected="selected" ';
  4553. elseif($action == 'add')
  4554. $selected = 'selected="selected" ';
  4555. else
  4556. $selected = '';
  4557. $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>';
  4558. }
  4559. }
  4560. $return .= "\t\t\t\t" . '</select>';
  4561. $return .= "\t\t\t" . '</td>' . "\n";
  4562. $return .= "\t\t" . '</tr>' . "\n";
  4563. if($action != 'move')
  4564. {
  4565. $return .= "\t\t" . '<tr>' . "\n";
  4566. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").' :</label></td>' . "\n";
  4567. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4568. $return .= "\t\t" . '</tr>' . "\n";
  4569. $id_prerequisite=0;
  4570. foreach($arrLP as $key=>$value){
  4571. if($value['id']==$id){
  4572. $id_prerequisite=$value['prerequisite'];
  4573. break;
  4574. }
  4575. }
  4576. $arrHide=array();
  4577. for($i = 0; $i < count($arrLP); $i++)
  4578. {
  4579. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4580. {
  4581. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4582. $s_selected_position=$arrLP[$i]['id'];
  4583. elseif($action == 'add')
  4584. $s_selected_position=0;
  4585. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4586. }
  4587. }
  4588. $return .= "\t\t" . '<tr>' . "\n";
  4589. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").' :</label></td>' . "\n";
  4590. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4591. foreach($arrHide as $key => $value){
  4592. if($key==$s_selected_position && $action == 'add'){
  4593. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4594. }
  4595. elseif($key==$id_prerequisite && $action == 'edit'){
  4596. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4597. }
  4598. else{
  4599. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4600. }
  4601. }
  4602. $return .= "</select></td>";
  4603. $return .= "\t\t" . '</tr>' . "\n";
  4604. $return .= "\t\t" . '<tr>' . "\n";
  4605. //Remove temporaly the test description
  4606. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4607. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4608. $return .= "\t\t" . '</tr>' . "\n";
  4609. }
  4610. $return .= "\t\t" . '<tr>' . "\n";
  4611. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  4612. $return .= "\t\t" . '</tr>' . "\n";
  4613. $return .= "\t" . '</table>' . "\n";
  4614. if($action == 'move')
  4615. {
  4616. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4617. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4618. }
  4619. if(is_numeric($extra_info))
  4620. {
  4621. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4622. }
  4623. elseif(is_array($extra_info))
  4624. {
  4625. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4626. }
  4627. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />' . "\n";
  4628. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4629. $return .= '</form>' . "\n";
  4630. $return .= '</div>' . "\n";
  4631. return $return;
  4632. }
  4633. //fin du hotpot form
  4634. /**
  4635. * Return the form to display the forum edit/add option
  4636. *
  4637. * @param string Action (add/edit)
  4638. * @param integer ID of the lp_item if already exists
  4639. * @param mixed Forum ID or title
  4640. * @return string HTML form
  4641. */
  4642. function display_forum_form($action = 'add', $id = 0, $extra_info = '')
  4643. {
  4644. global $charset;
  4645. $tbl_lp_item = Database::get_course_table('lp_item');
  4646. $tbl_forum = Database::get_course_table(TABLE_FORUM);
  4647. if($id != 0 && is_array($extra_info)) {
  4648. $item_title = stripslashes($extra_info['title']);
  4649. } elseif(is_numeric($extra_info)) {
  4650. $sql_forum = "
  4651. SELECT
  4652. forum_title as title, forum_comment as comment
  4653. FROM " . $tbl_forum . "
  4654. WHERE forum_id = " . $extra_info;
  4655. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4656. $row = Database::fetch_array($result);
  4657. $item_title = $row['title'];
  4658. $item_description = $row['comment'];
  4659. } else {
  4660. $item_title = '';
  4661. $item_description = '';
  4662. }
  4663. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4664. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4665. $return = '<div class="sectiontitle">';
  4666. if($id != 0 && is_array($extra_info))
  4667. $parent = $extra_info['parent_item_id'];
  4668. else
  4669. $parent = 0;
  4670. $sql = "
  4671. SELECT *
  4672. FROM " . $tbl_lp_item . "
  4673. WHERE
  4674. lp_id = " . $this->lp_id;
  4675. $result = api_sql_query($sql, __FILE__, __LINE__);
  4676. $arrLP = array();
  4677. while($row = Database::fetch_array($result)) {
  4678. $arrLP[] = array(
  4679. 'id' => $row['id'],
  4680. 'item_type' => $row['item_type'],
  4681. 'title' => $row['title'],
  4682. 'path' => $row['path'],
  4683. 'description' => $row['description'],
  4684. 'parent_item_id' => $row['parent_item_id'],
  4685. 'previous_item_id' => $row['previous_item_id'],
  4686. 'next_item_id' => $row['next_item_id'],
  4687. 'display_order' => $row['display_order'],
  4688. 'max_score' => $row['max_score'],
  4689. 'min_score' => $row['min_score'],
  4690. 'mastery_score' => $row['mastery_score'],
  4691. 'prerequisite' => $row['prerequisite']);
  4692. }
  4693. $this->tree_array($arrLP);
  4694. $arrLP = $this->arrMenu;
  4695. unset($this->arrMenu);
  4696. if($action == 'add')
  4697. $return .= get_lang("CreateTheForum").'&nbsp;:' . "\n";
  4698. elseif($action == 'move')
  4699. $return .= get_lang("MoveTheCurrentForum").'&nbsp;:' . "\n";
  4700. else
  4701. $return .= get_lang("EditCurrentForum").'&nbsp;:' . "\n";
  4702. $return .= '</div>';
  4703. $return .= '<div class="sectioncomment">';
  4704. $return .= '<form method="POST">' . "\n";
  4705. $return .= "\t" . '<table>' . "\n";
  4706. if($action != 'move') {
  4707. $return .= "\t\t" . '<tr>' . "\n";
  4708. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  4709. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  4710. $return .= "\t\t" . '</tr>' . "\n";
  4711. }
  4712. $return .= "\t\t" . '<tr>' . "\n";
  4713. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  4714. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4715. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4716. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4717. $arrHide = array($id);
  4718. for($i = 0; $i < count($arrLP); $i++)
  4719. {
  4720. if($action != 'add')
  4721. {
  4722. 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))
  4723. {
  4724. $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>';
  4725. }
  4726. else
  4727. {
  4728. $arrHide[] = $arrLP[$i]['id'];
  4729. }
  4730. }
  4731. else
  4732. {
  4733. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4734. $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>';
  4735. }
  4736. }
  4737. if (is_array($arrLP)) {
  4738. reset($arrLP);
  4739. }
  4740. $return .= "\t\t\t\t" . '</select>';
  4741. $return .= "\t\t\t" . '</td>' . "\n";
  4742. $return .= "\t\t" . '</tr>' . "\n";
  4743. $return .= "\t\t" . '<tr>' . "\n";
  4744. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  4745. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4746. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1" class="learnpath_item_form">';
  4747. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4748. for($i = 0; $i < count($arrLP); $i++)
  4749. {
  4750. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4751. {
  4752. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4753. $selected = 'selected="selected" ';
  4754. elseif($action == 'add')
  4755. $selected = 'selected="selected" ';
  4756. else
  4757. $selected = '';
  4758. $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>';
  4759. }
  4760. }
  4761. $return .= "\t\t\t\t" . '</select>';
  4762. $return .= "\t\t\t" . '</td>' . "\n";
  4763. $return .= "\t\t" . '</tr>' . "\n";
  4764. if($action != 'move')
  4765. {
  4766. $return .= "\t\t" . '<tr>' . "\n";
  4767. //Remove temporaly the test description
  4768. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4769. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4770. $return .= "\t\t" . '</tr>' . "\n";
  4771. $id_prerequisite=0;
  4772. if (is_array($arrLP)) {
  4773. foreach($arrLP as $key=>$value){
  4774. if($value['id']==$id){
  4775. $id_prerequisite=$value['prerequisite'];
  4776. break;
  4777. }
  4778. }
  4779. }
  4780. $arrHide=array();
  4781. for($i = 0; $i < count($arrLP); $i++) {
  4782. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4783. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4784. $s_selected_position=$arrLP[$i]['id'];
  4785. elseif($action == 'add')
  4786. $s_selected_position=0;
  4787. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4788. }
  4789. }
  4790. $return .= "\t\t" . '<tr>' . "\n";
  4791. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4792. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4793. foreach($arrHide as $key => $value) {
  4794. if($key==$s_selected_position && $action == 'add') {
  4795. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4796. }elseif($key==$id_prerequisite && $action == 'edit') {
  4797. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4798. } else {
  4799. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4800. }
  4801. }
  4802. $return .= "</select></td>";
  4803. $return .= "\t\t" . '</tr>' . "\n";
  4804. }
  4805. $return .= "\t\t" . '<tr>' . "\n";
  4806. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit"> '.get_lang('Ok').' </button></td>' . "\n";
  4807. $return .= "\t\t" . '</tr>' . "\n";
  4808. $return .= "\t" . '</table>' . "\n";
  4809. if($action == 'move') {
  4810. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4811. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4812. }
  4813. if(is_numeric($extra_info)) {
  4814. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4815. } elseif(is_array($extra_info)) {
  4816. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4817. }
  4818. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_FORUM.'" />' . "\n";
  4819. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4820. $return .= '</form>' . "\n";
  4821. $return .= '</div>' . "\n";
  4822. return $return;
  4823. }
  4824. /**
  4825. * Return HTML form to add/edit forum threads
  4826. * @param string Action (add/edit)
  4827. * @param integer Item ID if already exists in learning path
  4828. * @param mixed Extra information (thread ID if integer)
  4829. * @return string HTML form
  4830. */
  4831. function display_thread_form($action = 'add', $id = 0, $extra_info = '')
  4832. {
  4833. global $charset;
  4834. echo '
  4835. <style>
  4836. div.row div.label {
  4837. width:110px;
  4838. }
  4839. div.row div.formw {
  4840. width: 82%;
  4841. }
  4842. </style>';
  4843. $tbl_lp_item = Database::get_course_table('lp_item');
  4844. $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
  4845. if($id != 0 && is_array($extra_info))
  4846. {
  4847. $item_title = stripslashes($extra_info['title']);
  4848. }
  4849. elseif(is_numeric($extra_info))
  4850. {
  4851. $sql_forum = "
  4852. SELECT
  4853. thread_title as title
  4854. FROM " . $tbl_forum . "
  4855. WHERE thread_id = " . $extra_info;
  4856. $result = api_sql_query($sql_forum, __FILE__, __LINE__);
  4857. $row = Database::fetch_array($result);
  4858. $item_title = $row['title'];
  4859. $item_description = '';
  4860. }
  4861. else
  4862. {
  4863. $item_title = '';
  4864. $item_description = '';
  4865. }
  4866. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  4867. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  4868. $return = '<div style="margin:3px 12px;">';
  4869. if($id != 0 && is_array($extra_info))
  4870. $parent = $extra_info['parent_item_id'];
  4871. else
  4872. $parent = 0;
  4873. $sql = "
  4874. SELECT *
  4875. FROM " . $tbl_lp_item . "
  4876. WHERE
  4877. lp_id = " . $this->lp_id;
  4878. $result = api_sql_query($sql, __FILE__, __LINE__);
  4879. $arrLP = array();
  4880. while($row = Database::fetch_array($result))
  4881. {
  4882. $arrLP[] = array(
  4883. 'id' => $row['id'],
  4884. 'item_type' => $row['item_type'],
  4885. 'title' => $row['title'],
  4886. 'path' => $row['path'],
  4887. 'description' => $row['description'],
  4888. 'parent_item_id' => $row['parent_item_id'],
  4889. 'previous_item_id' => $row['previous_item_id'],
  4890. 'next_item_id' => $row['next_item_id'],
  4891. 'display_order' => $row['display_order'],
  4892. 'max_score' => $row['max_score'],
  4893. 'min_score' => $row['min_score'],
  4894. 'mastery_score' => $row['mastery_score'],
  4895. 'prerequisite' => $row['prerequisite']);
  4896. }
  4897. $this->tree_array($arrLP);
  4898. $arrLP = $this->arrMenu;
  4899. unset($this->arrMenu);
  4900. if($action == 'add')
  4901. $return .= '<p class="lp_title">'.get_lang("CreateTheForum").'&nbsp;:</p>' . "\n";
  4902. elseif($action == 'move')
  4903. $return .= '<p class="lp_title">'.get_lang("MoveTheCurrentForum").'&nbsp;:</p>' . "\n";
  4904. else
  4905. $return .= '<p class="lp_title">'.get_lang("EditCurrentForum").'&nbsp;:</p>' . "\n";
  4906. $return .= '<form method="POST">' . "\n";
  4907. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4908. $return .= "\t\t" . '<tr>' . "\n";
  4909. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang("Parent").'&nbsp;:</label></td>' . "\n";
  4910. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4911. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
  4912. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4913. $arrHide = array($id);
  4914. for($i = 0; $i < count($arrLP); $i++)
  4915. {
  4916. if($action != 'add')
  4917. {
  4918. 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))
  4919. {
  4920. $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>';
  4921. }
  4922. else
  4923. {
  4924. $arrHide[] = $arrLP[$i]['id'];
  4925. }
  4926. }
  4927. else
  4928. {
  4929. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4930. $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>';
  4931. }
  4932. }
  4933. if ($arrLP!=null) {
  4934. reset($arrLP);
  4935. }
  4936. $return .= "\t\t\t\t" . '</select>';
  4937. $return .= "\t\t\t" . '</td>' . "\n";
  4938. $return .= "\t\t" . '</tr>' . "\n";
  4939. $return .= "\t\t" . '<tr>' . "\n";
  4940. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang("Position").'&nbsp;:</label></td>' . "\n";
  4941. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4942. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  4943. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
  4944. for($i = 0; $i < count($arrLP); $i++)
  4945. {
  4946. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  4947. {
  4948. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4949. $selected = 'selected="selected" ';
  4950. elseif($action == 'add')
  4951. $selected = 'selected="selected" ';
  4952. else
  4953. $selected = '';
  4954. $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>';
  4955. }
  4956. }
  4957. $return .= "\t\t\t\t" . '</select>';
  4958. $return .= "\t\t\t" . '</td>' . "\n";
  4959. $return .= "\t\t" . '</tr>' . "\n";
  4960. if($action != 'move')
  4961. {
  4962. $return .= "\t\t" . '<tr>' . "\n";
  4963. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang("Title").'&nbsp;:</label></td>' . "\n";
  4964. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  4965. $return .= "\t\t" . '</tr>' . "\n";
  4966. $return .= "\t\t" . '<tr>' . "\n";
  4967. //Remove temporaly the test description
  4968. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
  4969. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4970. $return .= "\t\t" . '</tr>' . "\n";
  4971. $id_prerequisite=0;
  4972. if ($arrLP!=null) {
  4973. foreach($arrLP as $key=>$value){
  4974. if($value['id']==$id){
  4975. $id_prerequisite=$value['prerequisite'];
  4976. break;
  4977. }
  4978. }
  4979. }
  4980. $arrHide=array();
  4981. for($i = 0; $i < count($arrLP); $i++)
  4982. {
  4983. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  4984. {
  4985. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4986. $s_selected_position=$arrLP[$i]['id'];
  4987. elseif($action == 'add')
  4988. $s_selected_position=0;
  4989. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  4990. }
  4991. }
  4992. $return .= "\t\t" . '<tr>' . "\n";
  4993. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang("Prerequisites").'&nbsp;:</label></td>' . "\n";
  4994. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  4995. foreach($arrHide as $key => $value){
  4996. if($key==$s_selected_position && $action == 'add'){
  4997. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4998. }
  4999. elseif($key==$id_prerequisite && $action == 'edit'){
  5000. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5001. }
  5002. else{
  5003. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5004. }
  5005. }
  5006. $return .= "</select></td>";
  5007. $return .= "\t\t" . '</tr>' . "\n";
  5008. }
  5009. $return .= "\t\t" . '<tr>' . "\n";
  5010. $return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'.get_lang('Ok').'" /></td>' . "\n";
  5011. $return .= "\t\t" . '</tr>' . "\n";
  5012. $return .= "\t" . '</table>' . "\n";
  5013. if($action == 'move')
  5014. {
  5015. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5016. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5017. }
  5018. if(is_numeric($extra_info))
  5019. {
  5020. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5021. }
  5022. elseif(is_array($extra_info))
  5023. {
  5024. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5025. }
  5026. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_THREAD.'" />' . "\n";
  5027. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5028. $return .= '</form>' . "\n";
  5029. $return .= '</div>' . "\n";
  5030. return $return;
  5031. }
  5032. /**
  5033. * Return the HTML form to display an item (generally a section/module item)
  5034. *
  5035. * @param string Item type (module/dokeos_module)
  5036. * @param string Title (optional, only when creating)
  5037. * @param string Action ('add'/'edit')
  5038. * @param integer lp_item ID
  5039. * @param mixed Extra info
  5040. * @return string HTML form
  5041. */
  5042. function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
  5043. {
  5044. global $_course;
  5045. global $charset;
  5046. $tbl_lp_item = Database::get_course_table('lp_item');
  5047. if($id != 0 && is_array($extra_info))
  5048. {
  5049. $item_title = $extra_info['title'];
  5050. $item_description = $extra_info['description'];
  5051. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
  5052. }
  5053. else
  5054. {
  5055. $item_title = '';
  5056. $item_description = '';
  5057. }
  5058. $return = '<div class="sectiontitle">';
  5059. if($id != 0 && is_array($extra_info))
  5060. $parent = $extra_info['parent_item_id'];
  5061. else
  5062. $parent = 0;
  5063. $sql = "
  5064. SELECT *
  5065. FROM " . $tbl_lp_item . "
  5066. WHERE lp_id = " . $this->lp_id. " AND id != " . $id. " ";
  5067. if($item_type == 'module')
  5068. $sql .= " AND parent_item_id = 0";
  5069. $result = api_sql_query($sql, __FILE__, __LINE__);
  5070. $arrLP = array();
  5071. while($row = Database::fetch_array($result))
  5072. {
  5073. $arrLP[] = array(
  5074. 'id' => $row['id'],
  5075. 'item_type' => $row['item_type'],
  5076. 'title' => $row['title'],
  5077. 'path' => $row['path'],
  5078. 'description' => $row['description'],
  5079. 'parent_item_id' => $row['parent_item_id'],
  5080. 'previous_item_id' => $row['previous_item_id'],
  5081. 'next_item_id' => $row['next_item_id'],
  5082. 'max_score' => $row['max_score'],
  5083. 'min_score' => $row['min_score'],
  5084. 'mastery_score' => $row['mastery_score'],
  5085. 'prerequisite' => $row['prerequisite'],
  5086. 'display_order' => $row['display_order']);
  5087. }
  5088. $this->tree_array($arrLP);
  5089. $arrLP = $this->arrMenu;
  5090. unset($this->arrMenu);
  5091. $return .= $title . "\n";
  5092. $return .= '</div>';
  5093. $return .= '<div class="sectioncomment">';
  5094. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5095. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"]);
  5096. $defaults["title"]=mb_convert_encoding($item_title,$charset,$this->encoding);
  5097. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5098. $form->addElement('html',$return);
  5099. //$arrHide = array($id);
  5100. $arrHide[0]['value']=$this->name;
  5101. $arrHide[0]['padding']=3;
  5102. if($item_type != 'module' && $item_type != 'dokeos_module')
  5103. {
  5104. for($i = 0; $i < count($arrLP); $i++)
  5105. {
  5106. if($action != 'add')
  5107. {
  5108. 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))
  5109. {
  5110. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5111. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5112. if($parent == $arrLP[$i]['id'])
  5113. {
  5114. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5115. }
  5116. }
  5117. }
  5118. else
  5119. {
  5120. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5121. {
  5122. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5123. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5124. if($parent == $arrLP[$i]['id'])
  5125. {
  5126. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5127. }
  5128. }
  5129. }
  5130. }
  5131. if($action != 'move')
  5132. {
  5133. $form->addElement('text','title', get_lang('Title'),'id="idTitle" class="learnpath_chapter_form"');
  5134. //$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription"');
  5135. }
  5136. else
  5137. {
  5138. $form->addElement('hidden','title');
  5139. }
  5140. $parent_select = &$form->addElement('select', 'parent', get_lang("Parent"), '', 'class="learnpath_chapter_form" id="Parent" onchange="load_cbo(this.value);"');
  5141. foreach($arrHide as $key => $value)
  5142. {
  5143. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5144. }
  5145. $parent_select -> setSelected($s_selected_parent);
  5146. }
  5147. if(is_array($arrLP)) { reset($arrLP); }
  5148. $arrHide=array();
  5149. //POSITION
  5150. for($i = 0; $i < count($arrLP); $i++)
  5151. {
  5152. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5153. {
  5154. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5155. $s_selected_position=$arrLP[$i]['id'];
  5156. elseif($action == 'add')
  5157. $s_selected_position=$arrLP[$i]['id'];
  5158. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5159. }
  5160. }
  5161. $position = &$form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form"');
  5162. $position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'.$value['padding'].'px;"');
  5163. foreach($arrHide as $key => $value)
  5164. {
  5165. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5166. }
  5167. if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
  5168. if(is_array($arrLP)) { reset($arrLP); }
  5169. $form->addElement('style_submit_button', 'submit_button', get_lang('Save'),'class="save"');
  5170. if($item_type == 'module' || $item_type == 'dokeos_module')
  5171. {
  5172. $form->addElement('hidden', 'parent', '0');
  5173. }
  5174. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5175. if(($item_type=='asset' || $item_type=='sco') && ($extension == 'html' || $extension == 'htm'))
  5176. {
  5177. if($item_type=='sco')
  5178. {
  5179. $form->addElement('html','<script type="text/javascript">alert("'.get_lang('WarningWhenEditingScorm').'")</script>');
  5180. }
  5181. $renderer = $form->defaultRenderer();
  5182. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5183. $form->addElement('html_editor','content_lp','');
  5184. //$form->addElement('html_editor','content_lp','');
  5185. $defaults["content_lp"]=file_get_contents($item_path);
  5186. }
  5187. $form->addElement('hidden', 'type', 'dokeos_'.$item_type);
  5188. $form->addElement('hidden', 'post_time', time());
  5189. $form->setDefaults($defaults);
  5190. $form->addElement('html','</div>');
  5191. return $form->return_form();
  5192. }
  5193. /**
  5194. * Returns the form to update or create a document
  5195. *
  5196. * @param string Action (add/edit)
  5197. * @param integer ID of the lp_item (if already exists)
  5198. * @param mixed Integer if document ID, string if info ('new')
  5199. * @return string HTML form
  5200. */
  5201. function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
  5202. {
  5203. global $charset;
  5204. $tbl_lp_item = Database::get_course_table('lp_item');
  5205. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  5206. $path_parts = pathinfo($extra_info['dir']);
  5207. $no_display_edit_textarea=false;
  5208. //If action==edit document
  5209. //We don't display the document form if it's not an editable document (html or txt file)
  5210. if($action=="edit"){
  5211. if(is_array($extra_info)){
  5212. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5213. $no_display_edit_textarea=true;
  5214. }
  5215. }
  5216. }
  5217. $no_display_add=false;
  5218. //If action==add an existing document
  5219. //We don't display the document form if it's not an editable document (html or txt file)
  5220. if($action=="add"){
  5221. if(is_numeric($extra_info)){
  5222. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
  5223. $result=api_sql_query($sql_doc, __FILE__, __LINE__);
  5224. $path_file=Database::result($result,0,0);
  5225. $path_parts = pathinfo($path_file);
  5226. if($path_parts['extension']!="txt" && $path_parts['extension']!="html"){
  5227. $no_display_add=true;
  5228. }
  5229. }
  5230. }
  5231. if($id != 0 && is_array($extra_info))
  5232. {
  5233. $item_title = stripslashes($extra_info['title']);
  5234. $item_description = stripslashes($extra_info['description']);
  5235. $item_terms = stripslashes($extra_info['terms']);
  5236. if(empty($item_title))
  5237. {
  5238. $path_parts = pathinfo($extra_info['path']);
  5239. $item_title = stripslashes($path_parts['filename']);
  5240. }
  5241. }
  5242. elseif(is_numeric($extra_info))
  5243. {
  5244. $sql_doc = "
  5245. SELECT path, title
  5246. FROM " . $tbl_doc . "
  5247. WHERE id = " . $extra_info;
  5248. $result = api_sql_query($sql_doc, __FILE__, __LINE__);
  5249. $row = Database::fetch_array($result);
  5250. $explode = explode('.', $row['title']);
  5251. if(count($explode)>1){
  5252. for($i = 0; $i < count($explode) - 1; $i++)
  5253. $item_title .= $explode[$i];
  5254. }
  5255. else{
  5256. $item_title=$row['title'];
  5257. }
  5258. $item_title = str_replace('_', ' ', $item_title);
  5259. if(empty($item_title))
  5260. {
  5261. $path_parts = pathinfo($row['path']);
  5262. $item_title = stripslashes($path_parts['filename']);
  5263. }
  5264. }
  5265. else
  5266. {
  5267. $item_title = '';
  5268. $item_description = '';
  5269. }
  5270. $return = '<div class="sectiontitle">';
  5271. if($id != 0 && is_array($extra_info))
  5272. $parent = $extra_info['parent_item_id'];
  5273. else
  5274. $parent = 0;
  5275. $sql = "
  5276. SELECT *
  5277. FROM " . $tbl_lp_item . "
  5278. WHERE
  5279. lp_id = " . $this->lp_id;
  5280. $result = api_sql_query($sql, __FILE__, __LINE__);
  5281. $arrLP = array();
  5282. while($row = Database::fetch_array($result))
  5283. {
  5284. $arrLP[] = array(
  5285. 'id' => $row['id'],
  5286. 'item_type' => $row['item_type'],
  5287. 'title' => $row['title'],
  5288. 'path' => $row['path'],
  5289. 'description' => $row['description'],
  5290. 'parent_item_id' => $row['parent_item_id'],
  5291. 'previous_item_id' => $row['previous_item_id'],
  5292. 'next_item_id' => $row['next_item_id'],
  5293. 'display_order' => $row['display_order'],
  5294. 'max_score' => $row['max_score'],
  5295. 'min_score' => $row['min_score'],
  5296. 'mastery_score' => $row['mastery_score'],
  5297. 'prerequisite' => $row['prerequisite']);
  5298. }
  5299. $this->tree_array($arrLP);
  5300. $arrLP = $this->arrMenu;
  5301. unset($this->arrMenu);
  5302. if($action == 'add')
  5303. {
  5304. $return .= get_lang("CreateTheDocument") . "\n";
  5305. }
  5306. elseif($action == 'move')
  5307. {
  5308. $return .= get_lang("MoveTheCurrentDocument") . "\n";
  5309. }
  5310. else
  5311. {
  5312. $return .= get_lang("EditTheCurrentDocument") . "\n";
  5313. }
  5314. $return .= '</div>';
  5315. if(isset($_GET['edit']) && $_GET['edit'] == 'true')
  5316. {
  5317. $return .= '<div class="warning-message">';
  5318. $return .= '<strong>'.get_lang("Warning").' !</strong><br />';
  5319. $return .= get_lang("WarningEditingDocument");
  5320. $return .= '</div>';
  5321. }
  5322. /*
  5323. if($no_display_add==true){
  5324. $return .= '<div class="warning-message">';
  5325. $return .= get_lang("CantEditDocument");
  5326. $return .= '</div>';
  5327. return $return;
  5328. }
  5329. */
  5330. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  5331. $form = new FormValidator('form','POST',api_get_self()."?".$_SERVER["QUERY_STRING"],'','enctype="multipart/form-data"');
  5332. $defaults["title"] = html_entity_decode($item_title);
  5333. $defaults["title"]=mb_convert_encoding($defaults["title"],$charset,$this->encoding);
  5334. if(empty($defaults["title"]))
  5335. {
  5336. $defaults["title"] = html_entity_decode($item_title);
  5337. }
  5338. $defaults["description"]=mb_convert_encoding($item_description,$charset,$this->encoding);
  5339. $form->addElement('html',$return);
  5340. if($action != 'move')
  5341. {
  5342. $form->addElement('text','title', get_lang('Title'),'id="idTitle" class="learnpath_item_form"');
  5343. }
  5344. //$arrHide = array($id);
  5345. $arrHide[0]['value']=$this->name;
  5346. $arrHide[0]['padding']=3;
  5347. for($i = 0; $i < count($arrLP); $i++)
  5348. {
  5349. if($action != 'add'){
  5350. 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)){
  5351. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5352. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5353. if($parent == $arrLP[$i]['id']){
  5354. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5355. }
  5356. }
  5357. }
  5358. else{
  5359. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
  5360. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5361. $arrHide[$arrLP[$i]['id']]['padding']=3+ $arrLP[$i]['depth'] * 10;
  5362. if($parent == $arrLP[$i]['id']){
  5363. $s_selected_parent=$arrHide[$arrLP[$i]['id']];
  5364. }
  5365. }
  5366. }
  5367. }
  5368. $parent_select = &$form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" onchange="load_cbo(this.value);"');
  5369. foreach($arrHide as $key => $value) {
  5370. $parent_select->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5371. }
  5372. $parent_select -> setSelected($parent);
  5373. if(is_array($arrLP)) {
  5374. reset($arrLP);
  5375. }
  5376. $arrHide=array();
  5377. //POSITION
  5378. for($i = 0; $i < count($arrLP); $i++) {
  5379. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5380. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5381. $s_selected_position=$arrLP[$i]['id'];
  5382. elseif($action == 'add')
  5383. $s_selected_position=$arrLP[$i]['id'];
  5384. $arrHide[$arrLP[$i]['id']]['value']=get_lang("After").' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding).'"';
  5385. }
  5386. }
  5387. $position = &$form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form"');
  5388. $position->addOption(get_lang("FirstPosition"),0);
  5389. foreach($arrHide as $key => $value) {
  5390. $position->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5391. }
  5392. $position -> setSelected($s_selected_position);
  5393. if(is_array($arrLP)) {
  5394. reset($arrLP);
  5395. }
  5396. if($action != 'move') {
  5397. $id_prerequisite=0;
  5398. if(is_array($arrLP)) {
  5399. foreach($arrLP as $key=>$value){
  5400. if($value['id']==$id){
  5401. $id_prerequisite=$value['prerequisite'];
  5402. break;
  5403. }
  5404. }
  5405. }
  5406. $select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'), '', 'id="prerequisites" class="learnpath_item_form"');
  5407. $select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
  5408. // form element for uploading an mp3 file
  5409. $form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5410. $form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5411. /* Code deprecated - moved to lp level (not lp-item)
  5412. if ( api_get_setting('search_enabled') === 'true' )
  5413. {
  5414. //add terms field
  5415. $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
  5416. $terms->setValue($item_terms);
  5417. }
  5418. */
  5419. $arrHide=array();
  5420. for($i = 0; $i < count($arrLP); $i++)
  5421. {
  5422. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5423. {
  5424. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5425. $s_selected_position=$arrLP[$i]['id'];
  5426. elseif($action == 'add')
  5427. $s_selected_position=$arrLP[$i]['id'];
  5428. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5429. }
  5430. }
  5431. foreach($arrHide as $key => $value){
  5432. $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
  5433. if($key==$s_selected_position && $action == 'add'){
  5434. $select_prerequisites -> setSelected(0);
  5435. }
  5436. elseif($key==$id_prerequisite && $action == 'edit'){
  5437. $select_prerequisites -> setSelected($id_prerequisite);
  5438. }
  5439. }
  5440. if(!$no_display_add)
  5441. {
  5442. if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
  5443. {
  5444. if(isset($_POST['content']))
  5445. $content = stripslashes($_POST['content']);
  5446. elseif(is_array($extra_info)){
  5447. //If it's an html document or a text file
  5448. if(!$no_display_edit_textarea){
  5449. $content = $this->display_document($extra_info['path'], false, false);
  5450. }
  5451. }
  5452. elseif(is_numeric($extra_info))
  5453. $content = $this->display_document($extra_info, false, false);
  5454. else
  5455. $content = '';
  5456. if(!$no_display_edit_textarea)
  5457. {
  5458. // We need to claculate here some specific settings for the online editor.
  5459. // The calculated settings work for documents in the Documents tool
  5460. // (on the root or in subfolders).
  5461. // For documents in native scorm packages it is unclear whether the
  5462. // online editor should be activated or not.
  5463. global $fck_attribute;
  5464. $fck_attribute['Width'] = '100%';
  5465. $fck_attribute['Height'] = '700';
  5466. $fck_attribute['ToolbarSet'] = 'LearnPath';
  5467. $fck_attribute['Config']['FullPage'] = true;
  5468. $relative_path = $extra_info['dir'];
  5469. if ($relative_path == 'n/')
  5470. {
  5471. // A new document, it is in the root of the repository.
  5472. $relative_path = '';
  5473. $relative_prefix = '';
  5474. }
  5475. else
  5476. {
  5477. // The document already exists. Whe have to determine its relative path towards the repository root.
  5478. $relative_path = explode('/', $relative_path);
  5479. $relative_prefix = str_repeat('../', count($relative_path) - 2);
  5480. $relative_path = array_slice($relative_path, 1, count($relative_path) - 2);
  5481. $relative_path = implode('/', $relative_path);
  5482. if (strlen($relative_path) > 0)
  5483. {
  5484. $relative_path = $relative_path.'/';
  5485. }
  5486. }
  5487. $fck_attribute['Config']['CreateDocumentDir'] = $relative_prefix;
  5488. $fck_attribute['Config']['CreateDocumentWebDir'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/';
  5489. $fck_attribute['Config']['BaseHref'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/'.$relative_path;
  5490. $form->addElement('style_submit_button', 'submit_button', get_lang('Ok'));
  5491. $renderer = $form->defaultRenderer();
  5492. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}','content_lp');
  5493. $form->addElement('html','<div style="margin:3px 12px">');
  5494. $form->addElement('html_editor','content_lp','');
  5495. $form->addElement('html','</div>');
  5496. $defaults["content_lp"]=$content;
  5497. }
  5498. }
  5499. elseif(is_numeric($extra_info))
  5500. {
  5501. $form->addElement('style_submit_button', 'submit_button', get_lang('AddEdit'), 'class="save"');
  5502. $return = $this->display_document($extra_info, true, true, true);
  5503. $form->addElement('html',$return);
  5504. }
  5505. }
  5506. }
  5507. if($action == 'move')
  5508. {
  5509. $form->addElement('hidden', 'title', $item_title);
  5510. $form->addElement('hidden', 'description', $item_description);
  5511. }
  5512. if(is_numeric($extra_info))
  5513. {
  5514. $form->addElement('style_submit_button', 'submit_button', get_lang('AddEdit'), 'value="submit_button", class="save"');
  5515. $form->addElement('hidden', 'path', $extra_info);
  5516. }
  5517. elseif(is_array($extra_info))
  5518. {
  5519. $form->addElement('style_submit_button', 'submit_button', get_lang('TitleManipulateDocument'), 'class="save"');
  5520. $form->addElement('hidden', 'path', $extra_info['path']);
  5521. }
  5522. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5523. $form->addElement('hidden', 'post_time', time());
  5524. $form->setDefaults($defaults);
  5525. return $form->return_form();
  5526. }
  5527. /**
  5528. * Return HTML form to add/edit a link item
  5529. *
  5530. * @param string Action (add/edit)
  5531. * @param integer Item ID if exists
  5532. * @param mixed Extra info
  5533. * @return string HTML form
  5534. */
  5535. function display_link_form($action = 'add', $id = 0, $extra_info = '')
  5536. {
  5537. global $charset;
  5538. $tbl_lp_item = Database::get_course_table('lp_item');
  5539. $tbl_link = Database::get_course_table(TABLE_LINK);
  5540. if($id != 0 && is_array($extra_info)) {
  5541. $item_title = stripslashes($extra_info['title']);
  5542. $item_description = stripslashes($extra_info['description']);
  5543. } elseif(is_numeric($extra_info)) {
  5544. $sql_link = "
  5545. SELECT
  5546. title,
  5547. description,
  5548. url
  5549. FROM " . $tbl_link . "
  5550. WHERE id = " . $extra_info;
  5551. $result = api_sql_query($sql_link, __FILE__, __LINE__);
  5552. $row = Database::fetch_array($result);
  5553. $item_title = $row['title'];
  5554. $item_description = $row['description'];
  5555. $item_url = $row['url'];
  5556. } else {
  5557. $item_title = '';
  5558. $item_description = '';
  5559. }
  5560. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5561. $item_description=mb_convert_encoding($item_description,$charset,$this->encoding);
  5562. $return = '<div class="sectiontitle">';
  5563. if($id != 0 && is_array($extra_info))
  5564. $parent = $extra_info['parent_item_id'];
  5565. else
  5566. $parent = 0;
  5567. $sql = "
  5568. SELECT *
  5569. FROM " . $tbl_lp_item . "
  5570. WHERE
  5571. lp_id = " . $this->lp_id;
  5572. $result = api_sql_query($sql, __FILE__, __LINE__);
  5573. $arrLP = array();
  5574. while($row = Database::fetch_array($result)) {
  5575. $arrLP[] = array(
  5576. 'id' => $row['id'],
  5577. 'item_type' => $row['item_type'],
  5578. 'title' => $row['title'],
  5579. 'path' => $row['path'],
  5580. 'description' => $row['description'],
  5581. 'parent_item_id' => $row['parent_item_id'],
  5582. 'previous_item_id' => $row['previous_item_id'],
  5583. 'next_item_id' => $row['next_item_id'],
  5584. 'display_order' => $row['display_order'],
  5585. 'max_score' => $row['max_score'],
  5586. 'min_score' => $row['min_score'],
  5587. 'mastery_score' => $row['mastery_score'],
  5588. 'prerequisite' => $row['prerequisite']);
  5589. }
  5590. $this->tree_array($arrLP);
  5591. $arrLP = $this->arrMenu;
  5592. unset($this->arrMenu);
  5593. if($action == 'add')
  5594. $return .= get_lang("CreateTheLink").'&nbsp;:' . "\n";
  5595. elseif($action == 'move')
  5596. $return .= get_lang("MoveCurrentLink").'&nbsp;:' . "\n";
  5597. else
  5598. $return .= get_lang("EditCurrentLink").'&nbsp;:' . "\n";
  5599. $return .= '</div>';
  5600. $return .= '<div class="sectioncomment">';
  5601. $return .= '<form method="POST">' . "\n";
  5602. $return .= "\t" . '<table>' . "\n";
  5603. if($action != 'move') {
  5604. $return .= "\t\t" . '<tr>' . "\n";
  5605. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  5606. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
  5607. $return .= "\t\t" . '</tr>' . "\n";
  5608. }
  5609. $return .= "\t\t" . '<tr>' . "\n";
  5610. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  5611. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5612. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5613. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5614. $arrHide = array($id);
  5615. for($i = 0; $i < count($arrLP); $i++) {
  5616. if($action != 'add') {
  5617. 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))
  5618. {
  5619. $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>';
  5620. } else {
  5621. $arrHide[] = $arrLP[$i]['id'];
  5622. }
  5623. } else {
  5624. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5625. $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>';
  5626. }
  5627. }
  5628. if(is_array($arrLP)) {
  5629. reset($arrLP);
  5630. }
  5631. $return .= "\t\t\t\t" . '</select>';
  5632. $return .= "\t\t\t" . '</td>' . "\n";
  5633. $return .= "\t\t" . '</tr>' . "\n";
  5634. $return .= "\t\t" . '<tr>' . "\n";
  5635. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  5636. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5637. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1" class="learnpath_item_form">';
  5638. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5639. for($i = 0; $i < count($arrLP); $i++)
  5640. {
  5641. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5642. {
  5643. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5644. $selected = 'selected="selected" ';
  5645. elseif($action == 'add')
  5646. $selected = 'selected="selected" ';
  5647. else
  5648. $selected = '';
  5649. $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>';
  5650. }
  5651. }
  5652. $return .= "\t\t\t\t" . '</select>';
  5653. $return .= "\t\t\t" . '</td>' . "\n";
  5654. $return .= "\t\t" . '</tr>' . "\n";
  5655. if($action != 'move') {
  5656. $return .= "\t\t" . '<tr>' . "\n";
  5657. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').'</label></td>' . "\n";
  5658. $return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" class="learnpath_item_form" rows="4">' . $item_description . '</textarea></td>' . "\n";
  5659. $return .= "\t\t" . '</tr>' . "\n";
  5660. $return .= "\t\t" . '<tr>' . "\n";
  5661. $return .= "\t\t\t" . '<td class="label"><label for="idURL">'.get_lang('Url').'</label></td>' . "\n";
  5662. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>' . "\n";
  5663. $return .= "\t\t" . '</tr>' . "\n";
  5664. $id_prerequisite=0;
  5665. if (is_array($arrLP)){
  5666. foreach($arrLP as $key=>$value){
  5667. if($value['id']==$id){
  5668. $id_prerequisite=$value['prerequisite'];
  5669. break;
  5670. }
  5671. }
  5672. }
  5673. $arrHide=array();
  5674. for($i = 0; $i < count($arrLP); $i++) {
  5675. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5676. {
  5677. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5678. $s_selected_position=$arrLP[$i]['id'];
  5679. elseif($action == 'add')
  5680. $s_selected_position=0;
  5681. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5682. }
  5683. }
  5684. $return .= "\t\t" . '<tr>' . "\n";
  5685. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5686. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5687. foreach($arrHide as $key => $value)
  5688. {
  5689. if($key==$s_selected_position && $action == 'add')
  5690. {
  5691. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5692. }
  5693. elseif($key==$id_prerequisite && $action == 'edit'){
  5694. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5695. }
  5696. else{
  5697. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5698. }
  5699. }
  5700. $return .= "</select></td>";
  5701. $return .= "\t\t" . '</tr>' . "\n";
  5702. }
  5703. $return .= "\t\t" . '<tr>' . "\n";
  5704. $return .= "\t\t\t" . '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">'.get_lang("Ok").'</button></td>' . "\n";
  5705. $return .= "\t\t" . '</tr>' . "\n";
  5706. $return .= "\t" . '</table>' . "\n";
  5707. if($action == 'move')
  5708. {
  5709. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5710. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5711. }
  5712. if(is_numeric($extra_info))
  5713. {
  5714. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5715. }
  5716. elseif(is_array($extra_info))
  5717. {
  5718. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5719. }
  5720. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_LINK.'" />' . "\n";
  5721. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5722. $return .= '</form>' . "\n";
  5723. $return .= '</div>' . "\n";
  5724. return $return;
  5725. }
  5726. /**
  5727. * Return HTML form to add/edit a student publication (work)
  5728. *
  5729. * @param string Action (add/edit)
  5730. * @param integer Item ID if already exists
  5731. * @param mixed Extra info (work ID if integer)
  5732. * @return string HTML form
  5733. */
  5734. function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
  5735. {
  5736. global $charset;
  5737. $tbl_lp_item = Database::get_course_table('lp_item');
  5738. $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  5739. if($id != 0 && is_array($extra_info)) {
  5740. $item_title = stripslashes($extra_info['title']);
  5741. $item_description = stripslashes($extra_info['description']);
  5742. } elseif(is_numeric($extra_info)) {
  5743. $sql_publication = "
  5744. SELECT
  5745. title,
  5746. description
  5747. FROM " . $tbl_publication . "
  5748. WHERE id = " . $extra_info;
  5749. $result = api_sql_query($sql_publication, __FILE__, __LINE__);
  5750. $row = Database::fetch_array($result);
  5751. $item_title = $row['title'];
  5752. } else {
  5753. $item_title = '';
  5754. }
  5755. $item_title=mb_convert_encoding($item_title,$charset,$this->encoding);
  5756. $return = '<div class="sectiontitle">';
  5757. if($id != 0 && is_array($extra_info))
  5758. $parent = $extra_info['parent_item_id'];
  5759. else
  5760. $parent = 0;
  5761. $sql = "
  5762. SELECT *
  5763. FROM " . $tbl_lp_item . "
  5764. WHERE
  5765. lp_id = " . $this->lp_id;
  5766. $result = api_sql_query($sql, __FILE__, __LINE__);
  5767. $arrLP = array();
  5768. while($row = Database::fetch_array($result)) {
  5769. $arrLP[] = array(
  5770. 'id' => $row['id'],
  5771. 'item_type' => $row['item_type'],
  5772. 'title' => $row['title'],
  5773. 'path' => $row['path'],
  5774. 'description' => $row['description'],
  5775. 'parent_item_id' => $row['parent_item_id'],
  5776. 'previous_item_id' => $row['previous_item_id'],
  5777. 'next_item_id' => $row['next_item_id'],
  5778. 'display_order' => $row['display_order'],
  5779. 'max_score' => $row['max_score'],
  5780. 'min_score' => $row['min_score'],
  5781. 'mastery_score' => $row['mastery_score'],
  5782. 'prerequisite' => $row['prerequisite']);
  5783. }
  5784. $this->tree_array($arrLP);
  5785. $arrLP = $this->arrMenu;
  5786. unset($this->arrMenu);
  5787. if($action == 'add')
  5788. $return .= get_lang("Student_publication").'&nbsp;:' . "\n";
  5789. elseif($action == 'move')
  5790. $return .= get_lang("MoveCurrentStudentPublication").'&nbsp;:' . "\n";
  5791. else
  5792. $return .= get_lang("EditCurrentStudentPublication").'&nbsp;:' . "\n";
  5793. $return .= '</div>';
  5794. $return .= '<div class="sectioncomment">';
  5795. $return .= '<form method="POST">' . "\n";
  5796. $return .= "\t" . '<table>' . "\n";
  5797. if($action != 'move')
  5798. {
  5799. $return .= "\t\t" . '<tr>' . "\n";
  5800. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">'.get_lang('Title').'</label></td>' . "\n";
  5801. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  5802. $return .= "\t\t" . '</tr>' . "\n";
  5803. }
  5804. $return .= "\t\t" . '<tr>' . "\n";
  5805. $return .= "\t\t\t" . '<td class="label"><label for="idParent">'.get_lang('Parent').'</label></td>' . "\n";
  5806. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5807. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5808. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5809. $arrHide = array($id);
  5810. for($i = 0; $i < count($arrLP); $i++)
  5811. {
  5812. if($action != 'add')
  5813. {
  5814. 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))
  5815. {
  5816. $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>';
  5817. }
  5818. else
  5819. {
  5820. $arrHide[] = $arrLP[$i]['id'];
  5821. }
  5822. }
  5823. else
  5824. {
  5825. if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5826. $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>';
  5827. }
  5828. }
  5829. if(is_array($arrLP))
  5830. {
  5831. reset($arrLP);
  5832. }
  5833. $return .= "\t\t\t\t" . '</select>';
  5834. $return .= "\t\t\t" . '</td>' . "\n";
  5835. $return .= "\t\t" . '</tr>' . "\n";
  5836. $return .= "\t\t" . '<tr>' . "\n";
  5837. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">'.get_lang('Position').'</label></td>' . "\n";
  5838. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5839. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1" class="learnpath_item_form">';
  5840. $return .= "\t\t\t\t\t" . '<option class="top" value="0">'.get_lang("FirstPosition").'</option>';
  5841. for($i = 0; $i < count($arrLP); $i++)
  5842. {
  5843. if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
  5844. {
  5845. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5846. $selected = 'selected="selected" ';
  5847. elseif($action == 'add')
  5848. $selected = 'selected="selected" ';
  5849. else
  5850. $selected = '';
  5851. $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>';
  5852. }
  5853. }
  5854. $return .= "\t\t\t\t" . '</select>';
  5855. $return .= "\t\t\t" . '</td>' . "\n";
  5856. $return .= "\t\t" . '</tr>' . "\n";
  5857. if($action != 'move')
  5858. {
  5859. $id_prerequisite=0;
  5860. if(is_array($arrLP))
  5861. {
  5862. foreach($arrLP as $key=>$value){
  5863. if($value['id']==$id){
  5864. $id_prerequisite=$value['prerequisite'];
  5865. break;
  5866. }
  5867. }
  5868. }
  5869. $arrHide=array();
  5870. for($i = 0; $i < count($arrLP); $i++)
  5871. {
  5872. if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
  5873. {
  5874. if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5875. $s_selected_position=$arrLP[$i]['id'];
  5876. elseif($action == 'add')
  5877. $s_selected_position=0;
  5878. $arrHide[$arrLP[$i]['id']]['value']=mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding);
  5879. }
  5880. }
  5881. $return .= "\t\t" . '<tr>' . "\n";
  5882. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  5883. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang("NoPrerequisites").'</option>';
  5884. foreach($arrHide as $key => $value){
  5885. if($key==$s_selected_position && $action == 'add'){
  5886. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5887. }
  5888. elseif($key==$id_prerequisite && $action == 'edit'){
  5889. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5890. }
  5891. else{
  5892. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5893. }
  5894. }
  5895. $return .= "</select></td>";
  5896. $return .= "\t\t" . '</tr>' . "\n";
  5897. }
  5898. $return .= "\t\t" . '<tr>' . "\n";
  5899. $return .= "\t\t\t" . '<td>&nbsp</td><td colspan="2"><button class="save" name="submit_button" type="submit">'.get_lang("Ok").'</button></td>' . "\n";
  5900. $return .= "\t\t" . '</tr>' . "\n";
  5901. $return .= "\t" . '</table>' . "\n";
  5902. if($action == 'move')
  5903. {
  5904. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5905. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5906. }
  5907. if(is_numeric($extra_info))
  5908. {
  5909. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5910. }
  5911. elseif(is_array($extra_info))
  5912. {
  5913. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5914. }
  5915. $return .= "\t" . '<input name="type" type="hidden" value="'.TOOL_STUDENTPUBLICATION.'" />' . "\n";
  5916. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5917. $return .= '</form>' . "\n";
  5918. $return .= '</div>' . "\n";
  5919. return $return;
  5920. }
  5921. /**
  5922. * Displays the menu for manipulating a step
  5923. *
  5924. * @return unknown
  5925. */
  5926. function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
  5927. {
  5928. global $charset, $_course;
  5929. $return = '<div class="actions">';
  5930. switch($item_type)
  5931. {
  5932. case 'dokeos_chapter':
  5933. case 'chapter':
  5934. $lang = get_lang('TitleManipulateChapter');
  5935. break;
  5936. case 'dokeos_module':
  5937. case 'module':
  5938. $lang = get_lang('TitleManipulateModule');
  5939. break;
  5940. case TOOL_DOCUMENT:
  5941. $lang = get_lang('TitleManipulateDocument');
  5942. break;
  5943. case TOOL_LINK:
  5944. case 'link':
  5945. $lang = get_lang('TitleManipulateLink');
  5946. break;
  5947. case TOOL_QUIZ:
  5948. $lang = get_lang('TitleManipulateQuiz');
  5949. break;
  5950. case TOOL_STUDENTPUBLICATION:
  5951. $lang = get_lang('TitleManipulateStudentPublication');
  5952. break;
  5953. }
  5954. $tbl_lp_item = Database::get_course_table('lp_item');
  5955. $sql = "
  5956. SELECT
  5957. *
  5958. FROM " . $tbl_lp_item . " as lp
  5959. WHERE
  5960. lp.id = " . $item_id;
  5961. $result = api_sql_query($sql, __FILE__, __LINE__);
  5962. $row= mysql_fetch_assoc($result);
  5963. $s_title = $row['title'];
  5964. $s_title=mb_convert_encoding($s_title,$charset,$this->encoding);
  5965. // we display an audio player if needed
  5966. if (!empty($row['audio']))
  5967. {
  5968. $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>';
  5969. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  5970. $return .= '<script type="text/javascript">
  5971. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  5972. s1.addParam("allowscriptaccess","always");
  5973. s1.addParam("flashvars","file=../../courses/'.$_course['path'].'/document/audio/'.$row['audio'].'&image=preview.jpg&autostart=true");
  5974. s1.write("container");
  5975. </script>';
  5976. }
  5977. $return .= $lang.': ';
  5978. $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 . '" title="'.get_lang('Edit').'"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="'.get_lang("Edit").'" /> '.get_lang("Edit").'</a>';
  5979. $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>';
  5980. // commented for now as prerequisites cannot be added to chapters
  5981. if($item_type != 'dokeos_chapter' && $item_type != 'chapter')
  5982. {
  5983. $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>';
  5984. }
  5985. $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>';
  5986. //$return .= '<br><br><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang("NoDescription").'' : stripslashes(nl2br($s_description))) . '</p>';
  5987. //$return.="</td><td valign='top'>";
  5988. // get the audiorecorder. Use of ob_* functions since there are echos in the file
  5989. ob_start();
  5990. $audio_recorder_studentview = 'false';
  5991. $audio_recorder_item_id = $item_id;
  5992. if(api_get_setting('service_visio','active')=='true'){
  5993. include('audiorecorder.inc.php');
  5994. }
  5995. $return .= ob_get_contents();
  5996. ob_end_clean();
  5997. // end of audiorecorder include
  5998. $return .= '</div>';
  5999. return $return;
  6000. }
  6001. /**
  6002. * Creates the javascript needed for filling up the checkboxes without page reload
  6003. *
  6004. * @return string
  6005. */
  6006. function create_js()
  6007. {
  6008. $return = '<script language="javascript" type="text/javascript">' . "\n";
  6009. $return .= 'function load_cbo(id){' . "\n";
  6010. $return .= "var cbo = document.getElementById('idPosition');\n";
  6011. $return .= 'for(var i = cbo.length - 1; i > 0; i--)';
  6012. $return .= 'cbo.options[i] = null;'."\n";
  6013. $return .= 'var k=0;'."\n";
  6014. $return .= 'for(var i = 1; i <= child_name[id].length; i++){'."\n";
  6015. $return .= ' cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);'."\n";
  6016. $return .= 'k=i;';
  6017. $return .= '}' . "\n\n";
  6018. $return .= 'if( typeof cbo != "undefined" ) {cbo.options[k].selected = true;}';
  6019. $return .='}';
  6020. $return .= 'var child_name = new Array();' . "\n";
  6021. $return .= 'var child_value = new Array();' . "\n\n";
  6022. $return .= 'child_name[0] = new Array();' . "\n";
  6023. $return .= 'child_value[0] = new Array();' . "\n\n";
  6024. $tbl_lp_item = Database::get_course_table('lp_item');
  6025. $sql_zero = "
  6026. SELECT *
  6027. FROM " . $tbl_lp_item . "
  6028. WHERE
  6029. lp_id = " . $this->lp_id . " AND
  6030. parent_item_id = 0
  6031. ORDER BY display_order ASC";
  6032. $res_zero = api_sql_query($sql_zero, __FILE__, __LINE__);
  6033. global $charset;
  6034. $i = 0;
  6035. while($row_zero = Database::fetch_array($res_zero))
  6036. {
  6037. $return .= 'child_name[0][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_zero['title'],$charset,$this->encoding) . '\"";' . "\n";
  6038. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6039. }
  6040. $return .= "\n";
  6041. $sql = "
  6042. SELECT *
  6043. FROM " . $tbl_lp_item . "
  6044. WHERE
  6045. lp_id = " . $this->lp_id;
  6046. $res = api_sql_query($sql, __FILE__, __LINE__);
  6047. while($row = Database::fetch_array($res))
  6048. {
  6049. $sql_parent = "
  6050. SELECT *
  6051. FROM " . $tbl_lp_item . "
  6052. WHERE parent_item_id = " . $row['id'] . "
  6053. ORDER BY display_order ASC";
  6054. $res_parent = api_sql_query($sql_parent, __FILE__, __LINE__);
  6055. $i = 0;
  6056. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6057. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6058. while($row_parent = Database::fetch_array($res_parent))
  6059. {
  6060. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "'.get_lang("After").' \"' . mb_convert_encoding($row_parent['title'],$charset,$this->encoding) . '\"";' . "\n";
  6061. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6062. }
  6063. $return .= "\n";
  6064. }
  6065. $return .= '</script>' . "\n";
  6066. return $return;
  6067. }
  6068. /**
  6069. * Display the form to allow moving an item
  6070. *
  6071. * @param integer Item ID
  6072. * @return string HTML form
  6073. */
  6074. function display_move_item($item_id)
  6075. {
  6076. global $_course; //will disappear
  6077. global $charset;
  6078. $return = '';
  6079. if(is_numeric($item_id))
  6080. {
  6081. $tbl_lp_item = Database::get_course_table('lp_item');
  6082. $sql = "
  6083. SELECT *
  6084. FROM " . $tbl_lp_item . "
  6085. WHERE id = " . $item_id;
  6086. $res = api_sql_query($sql, __FILE__, __LINE__);
  6087. $row = Database::fetch_array($res);
  6088. switch($row['item_type'])
  6089. {
  6090. case 'dokeos_chapter': case 'dir' : case 'asset' :
  6091. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6092. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6093. break;
  6094. case 'dokeos_module':
  6095. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6096. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6097. break;
  6098. case TOOL_DOCUMENT:
  6099. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6100. $return .= $this->display_document_form('move', $item_id, $row);
  6101. break;
  6102. case TOOL_LINK:
  6103. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6104. $return .= $this->display_link_form('move', $item_id, $row);
  6105. break;
  6106. case TOOL_HOTPOTATOES:
  6107. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6108. $return .= $this->display_link_form('move', $item_id, $row);
  6109. break;
  6110. case TOOL_QUIZ:
  6111. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6112. $return .= $this->display_quiz_form('move', $item_id, $row);
  6113. break;
  6114. case TOOL_STUDENTPUBLICATION:
  6115. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6116. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6117. break;
  6118. case TOOL_FORUM :
  6119. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6120. $return .= $this->display_forum_form('move', $item_id, $row);
  6121. }
  6122. }
  6123. return $return;
  6124. }
  6125. /**
  6126. * Displays a basic form on the overview page for changing the item title and the item description.
  6127. *
  6128. * @param string $item_type
  6129. * @param string $title
  6130. * @param array $data
  6131. * @return string
  6132. */
  6133. function display_item_small_form($item_type, $title = '', $data)
  6134. {
  6135. $return .= '<div class="lp_small_form">' . "\n";
  6136. $return .= '<p class="lp_title">' . $title . '</p>';
  6137. $return .= '<form method="post">' . "\n";
  6138. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6139. $return .= "\t\t" . '<tr>' . "\n";
  6140. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6141. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . $data['title'] . '" /></td>' . "\n";
  6142. $return .= "\t\t" . '</tr>' . "\n";
  6143. $return .= "\t\t" . '<tr>' . "\n";
  6144. $return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6145. $return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6146. $return .= "\t\t" . '</tr>' . "\n";
  6147. $return .= "\t\t" . '<tr>' . "\n";
  6148. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">'.get_lang('Save').'</button></td>' . "\n";
  6149. $return .= "\t\t" . '</tr>' . "\n";
  6150. $return .= "\t\t" . '</table>' . "\n";
  6151. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6152. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6153. $return .= '</form>';
  6154. $return .= '</div>';
  6155. return $return;
  6156. }
  6157. /**
  6158. * Return HTML form to allow prerequisites selection
  6159. *
  6160. * @param integer Item ID
  6161. * @return string HTML form
  6162. */
  6163. function display_item_prerequisites_form($item_id)
  6164. {
  6165. global $charset;
  6166. $tbl_lp_item = Database::get_course_table('lp_item');
  6167. /* current prerequisite */
  6168. $sql = "
  6169. SELECT *
  6170. FROM " . $tbl_lp_item . "
  6171. WHERE id = " . $item_id;
  6172. $result = api_sql_query($sql, __FILE__, __LINE__);
  6173. $row = Database::fetch_array($result);
  6174. $preq_id = $row['prerequisite'];
  6175. //$preq_mastery = $row['mastery_score'];
  6176. //$preq_max = $row['max_score'];
  6177. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6178. $return .= '<div class="sectiontitle">';
  6179. $return .= get_lang('AddEditPrerequisites');
  6180. $return .= '</div>';
  6181. $return .= '<div class="sectioncomment">';
  6182. $return .= '<form method="POST">';
  6183. $return .= '<table class="lp_prerequisites">';
  6184. $return .= '<tr>';
  6185. $return .= '<th></th>';
  6186. $return .= '<th >'.get_lang('Minimum').'</th>';
  6187. $return .= '<th>'.get_lang('Maximum').'</th>';
  6188. $return .= '</tr>';
  6189. $return .= '<tr>';
  6190. $return .= '<td class="radio">';
  6191. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6192. $return .= '<label for="idNone">'.get_lang('None').'</label>';
  6193. $return .= '</td><td colspan="2" />';
  6194. $return .= '</tr>';
  6195. $sql = "
  6196. SELECT *
  6197. FROM " . $tbl_lp_item . "
  6198. WHERE
  6199. lp_id = " . $this->lp_id;
  6200. $result = api_sql_query($sql, __FILE__, __LINE__);
  6201. $arrLP = array();
  6202. while($row = Database::fetch_array($result))
  6203. {
  6204. $arrLP[] = array(
  6205. 'id' => $row['id'],
  6206. 'item_type' => $row['item_type'],
  6207. 'title' => mb_convert_encoding($row['title'],$charset,$this->encoding),
  6208. 'ref' => $row['ref'],
  6209. 'description' => $row['description'],
  6210. 'parent_item_id' => $row['parent_item_id'],
  6211. 'previous_item_id' => $row['previous_item_id'],
  6212. 'next_item_id' => $row['next_item_id'],
  6213. 'max_score' => $row['max_score'],
  6214. 'min_score' => $row['min_score'],
  6215. 'mastery_score' => $row['mastery_score'],
  6216. 'prerequisite' => $row['prerequisite'],
  6217. 'next_item_id' => $row['next_item_id'],
  6218. 'display_order' => $row['display_order']);
  6219. if($row['ref'] == $preq_id)
  6220. {
  6221. $preq_mastery = $row['mastery_score'];
  6222. $preq_max = $row['max_score'];
  6223. }
  6224. }
  6225. $this->tree_array($arrLP);
  6226. $arrLP = $this->arrMenu;
  6227. unset($this->arrMenu);
  6228. for($i = 0; $i < count($arrLP); $i++)
  6229. {
  6230. if($arrLP[$i]['id'] == $item_id)
  6231. break;
  6232. $return .= '<tr>';
  6233. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6234. $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'] . '" />';
  6235. $return .= '<img alt="" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:5px;" title="" />';
  6236. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6237. $return .= '</td>';
  6238. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6239. if($arrLP[$i]['item_type'] == TOOL_QUIZ)
  6240. {
  6241. $return .= '<td class="exercise">';
  6242. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6243. $return .= '</td>';
  6244. $return .= '<td class="exercise">';
  6245. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6246. $return .= '</td>';
  6247. }
  6248. if($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES)
  6249. {
  6250. $return .= '<td class="exercise">';
  6251. $return .= '<input maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" />';
  6252. $return .= '</td>';
  6253. $return .= '<td class="exercise">';
  6254. $return .= '<input maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" />';
  6255. $return .= '</td>';
  6256. }
  6257. $return .='</tr>';
  6258. }
  6259. $return .= '<tr>';
  6260. $return .= '<td colspan="3">';
  6261. $return .= '<button class="save" name="submit_button" type="submit">'.get_lang("ModifyPrerequisities").' </button></td>' . "\n";
  6262. $return .= '</td>';
  6263. $return .= '</tr>';
  6264. $return .= '</table>';
  6265. $return .= '</form>';
  6266. $return .= '</div>';
  6267. return $return;
  6268. }
  6269. /**
  6270. * Creates a list with all the documents in it
  6271. *
  6272. * @return string
  6273. */
  6274. function get_documents()
  6275. {
  6276. global $_course;
  6277. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6278. $sql_doc = "
  6279. SELECT *
  6280. FROM " . $tbl_doc . "
  6281. WHERE
  6282. path NOT LIKE '%_DELETED_%'
  6283. ORDER BY path ASC";
  6284. $res_doc = api_sql_query($sql_doc, __FILE__, __LINE__);
  6285. $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>';
  6286. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6287. $resources=api_store_result($res_doc);
  6288. $resources_sorted = array();
  6289. // if you want to debug it, I advise you to do "echo" on the eval statements
  6290. foreach($resources as $resource)
  6291. {
  6292. $resource_paths = explode('/',$resource['path']);
  6293. array_shift($resource_paths);
  6294. $path_to_eval = $last_path = '';
  6295. $is_file = false;
  6296. foreach($resource_paths as $key => $resource_path)
  6297. {
  6298. if(strpos($resource_path,'.')===false && $key != count($resource_paths)-1)
  6299. { // it's a folder
  6300. $path_to_eval .= '["'.$resource_path.'"]["files"]';
  6301. }
  6302. else if(strpos($resource_path,'.')!==false)
  6303. $is_file = true;
  6304. $last_path = $resource_path;
  6305. }
  6306. if($is_file)
  6307. {
  6308. eval('$resources_sorted'.$path_to_eval.'['.$resource['id'].'] = "'.$last_path.'";');
  6309. }
  6310. else
  6311. {
  6312. eval('$resources_sorted'.$path_to_eval.'["'.$last_path.'"]["id"]='.$resource['id'].';');
  6313. }
  6314. }
  6315. $return .=$this->write_resources_tree($resources_sorted);
  6316. $return .='</div>';
  6317. if(Database::num_rows($res_doc) == 0)
  6318. $return .= '<div class="lp_resource_element">'.get_lang("NoDocuments").'</div>';
  6319. return $return;
  6320. }
  6321. /**
  6322. * Generate and return an HTML list of resources based on a given array.
  6323. *
  6324. * This list is used to show the course creator a list of available resources to choose from
  6325. * when creating a learning path.
  6326. * @param array Array of elements to add to the list
  6327. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6328. * @return string The HTML list
  6329. */
  6330. function write_resources_tree($resources_sorted, $num=0){
  6331. include_once(api_get_path(LIBRARY_PATH).'fileDisplay.lib.php');
  6332. if(count($resources_sorted)>0)
  6333. {
  6334. foreach($resources_sorted as $key=>$resource)
  6335. {
  6336. if(is_int($resource['id']))
  6337. { // it's a folder
  6338. $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'].'">';
  6339. $return .= $this->write_resources_tree($resource['files'], $num+1);
  6340. $return .= "</div></div>\r\n";
  6341. }
  6342. else
  6343. {
  6344. // it's a file
  6345. $icon = choose_image($resource);
  6346. $position = strrpos($icon,'.');
  6347. $icon=substr($icon,0,$position).'_small.gif';
  6348. $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";
  6349. }
  6350. }
  6351. }
  6352. return $return;
  6353. }
  6354. /**
  6355. * Creates a list with all the exercises (quiz) in it
  6356. *
  6357. * @return string
  6358. */
  6359. function get_exercises()
  6360. {
  6361. // new for hotpotatoes
  6362. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6363. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  6364. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  6365. $sql_quiz = "
  6366. SELECT *
  6367. FROM " . $tbl_quiz . "
  6368. WHERE active<>'-1'
  6369. ORDER BY title ASC";
  6370. $sql_hot = "SELECT * FROM ".$tbl_doc." " .
  6371. " WHERE path LIKE '".$uploadPath."/%/%htm%'" .
  6372. " ORDER BY id ASC";
  6373. $res_quiz = api_sql_query($sql_quiz, __FILE__, __LINE__);
  6374. $res_hot = api_sql_query($sql_hot, __FILE__, __LINE__);
  6375. $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>';
  6376. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6377. while ($row_hot = Database::fetch_array($res_hot)) {
  6378. $return .= '<div class="lp_resource_element">';
  6379. //display quizhotpotatoes
  6380. $return .= '<img alt="" src="../img/jqz.gif" style="margin-right:5px;" title="" />';
  6381. $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>';
  6382. //$return .= $row_quiz['title'];
  6383. $return .= '</div>';
  6384. }
  6385. while($row_quiz = Database::fetch_array($res_quiz)) {
  6386. $return .= '<div class="lp_resource_element">';
  6387. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6388. $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>';
  6389. //$return .= $row_quiz['title'];
  6390. $return .= '</div>';
  6391. }
  6392. if(Database::num_rows($res_quiz) == 0)
  6393. $return .= '<div class="lp_resource_element">'.get_lang("NoExercisesAvailable").'</div>';
  6394. $return .= '<div class="lp_resource_element">';
  6395. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6396. $return .= '<a href="'.api_get_path(REL_CODE_PATH).'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6397. $return .= '</div>';
  6398. $return .= '</div>';
  6399. return $return;
  6400. }
  6401. /**
  6402. * Creates a list with all the links in it
  6403. *
  6404. * @return string
  6405. */
  6406. function get_links()
  6407. {
  6408. $tbl_link = Database::get_course_table(TABLE_LINK);
  6409. $sql_link = "
  6410. SELECT *
  6411. FROM " . $tbl_link . "
  6412. ORDER BY title ASC";
  6413. $res_link = api_sql_query($sql_link, __FILE__, __LINE__);
  6414. $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>';
  6415. $return .= '<div class="lp_resource_elements" id="resLink">';
  6416. while($row_link = Database::fetch_array($res_link))
  6417. {
  6418. $return .= '<div class="lp_resource_element">';
  6419. $return .= '<img alt="" src="../img/file_html_small.gif" style="margin-right:5px;" title="" />';
  6420. $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>';
  6421. $return .= '</div>';
  6422. }
  6423. $return .= '<div class="lp_resource_element">';
  6424. $return .= '<img alt="" src="../img/file_html_new_small.gif" style="margin-right:5px;" title="" />';
  6425. $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>';
  6426. $return .= '</div>';
  6427. if(Database::num_rows($res_link) == 0)
  6428. $return .= '<div class="lp_resource_element">'.get_lang("NoLinksAvailable").'</div>';
  6429. $return .= '</div>';
  6430. return $return;
  6431. }
  6432. /**
  6433. * Creates a list with all the student publications in it
  6434. *
  6435. * @return unknown
  6436. */
  6437. function get_student_publications()
  6438. {
  6439. $tbl_student = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  6440. $sql_student = "
  6441. SELECT *
  6442. FROM " . $tbl_student . "
  6443. ORDER BY title ASC";
  6444. $res_student = api_sql_query($sql_student, __FILE__, __LINE__);
  6445. $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>';
  6446. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6447. $return .= '<div class="lp_resource_element">';
  6448. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6449. $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>';
  6450. $return .= '</div>';
  6451. $return .= '</div>';
  6452. return $return;
  6453. }
  6454. /**
  6455. * Creates a list with all the forums in it
  6456. *
  6457. * @return string
  6458. */
  6459. function get_forums()
  6460. {
  6461. include ('../forum/forumfunction.inc.php');
  6462. include ('../forum/forumconfig.inc.php');
  6463. global $table_forums, $table_threads,$table_posts, $table_item_property, $table_users;
  6464. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6465. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6466. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6467. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6468. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6469. $a_forums = get_forums();
  6470. $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>';
  6471. $return .= '<div class="lp_resource_elements" id="forums">';
  6472. foreach($a_forums as $forum)
  6473. {
  6474. $return .= '<div class="lp_resource_element">';
  6475. $return .= '<script type="text/javascript">
  6476. function toggle_forum(forum_id){
  6477. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6478. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6479. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'remove.gif";
  6480. }
  6481. else {
  6482. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6483. document.getElementById("forum_"+forum_id+"_opener").src = "'.api_get_path(WEB_IMG_PATH).'add.gif";
  6484. }
  6485. }
  6486. </script>
  6487. ';
  6488. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6489. $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>
  6490. <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">';
  6491. $a_threads = get_threads($forum['forum_id']);
  6492. if(is_array($a_threads)){
  6493. foreach($a_threads as $thread)
  6494. {
  6495. $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>';
  6496. }
  6497. }
  6498. $return .= '</ul></div>';
  6499. }
  6500. $return .= '<div class="lp_resource_element">';
  6501. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6502. $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>';
  6503. $return .= '</div>';
  6504. return $return;
  6505. }
  6506. /**
  6507. * Exports the learning path as a SCORM package. This is the main function that
  6508. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6509. * whole thing and returns the zip.
  6510. *
  6511. * This method needs to be called in PHP5, as it will fail with non-adequate
  6512. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6513. * you need to call it on a learnpath object.
  6514. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6515. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6516. * path has been modified, it should use the generic method here below.
  6517. * @TODO link this function with the export_lp() function in the same class
  6518. * @param string Optional name of zip file. If none, title of learnpath is
  6519. * domesticated and trailed with ".zip"
  6520. * @return string Returns the zip package string, or null if error
  6521. */
  6522. function scorm_export()
  6523. {
  6524. global $_course;
  6525. if (!class_exists('DomDocument'))
  6526. {
  6527. error_log('DOM functions not supported for PHP version below 5.0',0);
  6528. $this->error = 'PHP DOM functions not supported for PHP versions below 5.0';
  6529. return null;
  6530. }
  6531. //remove memory and time limits as much as possible as this might be a long process...
  6532. if(function_exists('ini_set'))
  6533. {
  6534. $mem = ini_get('memory_limit');
  6535. if(substr($mem,-1,1)=='M')
  6536. {
  6537. $mem_num = substr($mem,0,-1);
  6538. if($mem_num<128)
  6539. {
  6540. ini_set('memory_limit','128M');
  6541. }
  6542. }
  6543. else
  6544. {
  6545. ini_set('memory_limit','128M');
  6546. }
  6547. ini_set('max_execution_time',600);
  6548. //}else{
  6549. //error_log('Scorm export: could not change memory and time limits',0);
  6550. }
  6551. //Create the zip handler (this will remain available throughout the method)
  6552. $garbage_path = api_get_path(GARBAGE_PATH);
  6553. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6554. $temp_dir_short = uniqid();
  6555. $temp_zip_dir = $garbage_path."/".$temp_dir_short;
  6556. $temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
  6557. $zip_folder=new PclZip($temp_zip_file);
  6558. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6559. $root_path = $main_path = api_get_path(SYS_PATH);
  6560. $files_cleanup = array();
  6561. //place to temporarily stash the zipfiles
  6562. //create the temp dir if it doesn't exist
  6563. //or do a cleanup befor creating the zipfile
  6564. if(!is_dir($temp_zip_dir))
  6565. {
  6566. mkdir($temp_zip_dir);
  6567. }
  6568. else
  6569. {//cleanup: check the temp dir for old files and delete them
  6570. $handle=opendir($temp_zip_dir);
  6571. while (false!==($file = readdir($handle)))
  6572. {
  6573. if ($file != "." && $file != "..")
  6574. {
  6575. unlink("$temp_zip_dir/$file");
  6576. }
  6577. }
  6578. closedir($handle);
  6579. }
  6580. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6581. if(is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml'))
  6582. {
  6583. // remove the possible . at the end of the path
  6584. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6585. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6586. $perm = api_get_setting('permissions_for_new_directories');
  6587. $perm = octdec(!empty($perm)?$perm:'0770');
  6588. mkdir ($dest_path_to_scorm_folder, $perm, true);
  6589. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6590. }
  6591. //Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it)
  6592. //This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6593. //Aggregation Model official document, secion "2.3 Content Packaging"
  6594. $xmldoc = new DOMDocument('1.0',$this->encoding);
  6595. $root = $xmldoc->createElement('manifest');
  6596. $root->setAttribute('identifier','SingleCourseManifest');
  6597. $root->setAttribute('version','1.1');
  6598. $root->setAttribute('xmlns','http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6599. $root->setAttribute('xmlns:adlcp','http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6600. $root->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
  6601. $root->setAttribute('xsi:schemaLocation','http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd
  6602. http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd
  6603. http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  6604. //Build mandatory sub-root container elements
  6605. $metadata = $xmldoc->createElement('metadata');
  6606. $md_schema = $xmldoc->createElement('schema','ADL SCORM');
  6607. $metadata->appendChild($md_schema);
  6608. $md_schemaversion = $xmldoc->createElement('schemaversion','1.2');
  6609. $metadata->appendChild($md_schemaversion);
  6610. $root->appendChild($metadata);
  6611. $organizations = $xmldoc->createElement('organizations');
  6612. $resources = $xmldoc->createElement('resources');
  6613. //Build the only organization we will use in building our learnpaths
  6614. $organizations->setAttribute('default','dokeos_scorm_export');
  6615. $organization = $xmldoc->createElement('organization');
  6616. $organization->setAttribute('identifier','dokeos_scorm_export');
  6617. //to set the title of the SCORM entity (=organization), we take the name given
  6618. //in Dokeos and convert it to HTML entities using the Dokeos charset (not the
  6619. //learning path charset) as it is the encoding that defines how it is stored
  6620. //in the database. Then we convert it to HTML entities again as the "&" character
  6621. //alone is not authorized in XML (must be &amp;)
  6622. //The title is then decoded twice when extracting (see scorm::parse_manifest)
  6623. global $charset;
  6624. $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset)));
  6625. $organization->appendChild($org_title);
  6626. //For each element, add it to the imsmanifest structure, then add it to the zip.
  6627. //Always call the learnpathItem->scorm_export() method to change it to the SCORM
  6628. //format
  6629. $link_updates = array();
  6630. foreach($this->items as $index => $item){
  6631. if(!in_array($item->type , array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION)))
  6632. {
  6633. //get included documents from this item
  6634. if($item->type=='sco')
  6635. $inc_docs = $item->get_resources_from_source(null,api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  6636. else
  6637. $inc_docs = $item->get_resources_from_source();
  6638. //give a child element <item> to the <organization> element
  6639. $my_item_id = $item->get_id();
  6640. $my_item = $xmldoc->createElement('item');
  6641. $my_item->setAttribute('identifier','ITEM_'.$my_item_id);
  6642. $my_item->setAttribute('identifierref','RESOURCE_'.$my_item_id);
  6643. $my_item->setAttribute('isvisible','true');
  6644. //give a child element <title> to the <item> element
  6645. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6646. $my_item->appendChild($my_title);
  6647. //give a child element <adlcp:prerequisites> to the <item> element
  6648. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$this->get_scorm_prereq_string($my_item_id));
  6649. $my_prereqs->setAttribute('type','aicc_script');
  6650. $my_item->appendChild($my_prereqs);
  6651. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6652. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6653. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6654. //$xmldoc->createElement('adlcp:timelimitaction','');
  6655. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6656. //$xmldoc->createElement('adlcp:datafromlms','');
  6657. //give a child element <adlcp:masteryscore> to the <item> element
  6658. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6659. $my_item->appendChild($my_masteryscore);
  6660. //attach this item to the organization element or hits parent if there is one
  6661. if(!empty($item->parent) && $item->parent!=0)
  6662. {
  6663. $children = $organization->childNodes;
  6664. $possible_parent = &$this->get_scorm_xml_node($children,'ITEM_'.$item->parent);
  6665. if(is_object($possible_parent))
  6666. {
  6667. $possible_parent->appendChild($my_item);
  6668. }
  6669. else
  6670. {
  6671. if($this->debug>0){error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');}
  6672. }
  6673. }
  6674. else
  6675. {
  6676. if($this->debug>0){error_log('No parent');}
  6677. $organization->appendChild($my_item);
  6678. }
  6679. //get the path of the file(s) from the course directory root
  6680. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  6681. $my_xml_file_path = htmlentities($my_file_path);
  6682. $my_sub_dir = dirname($my_file_path);
  6683. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6684. //give a <resource> child to the <resources> element
  6685. $my_resource = $xmldoc->createElement('resource');
  6686. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6687. $my_resource->setAttribute('type','webcontent');
  6688. $my_resource->setAttribute('href',$my_xml_file_path);
  6689. //adlcp:scormtype can be either 'sco' or 'asset'
  6690. if($item->type=='sco')
  6691. {
  6692. $my_resource->setAttribute('adlcp:scormtype','sco');
  6693. }
  6694. else
  6695. {
  6696. $my_resource->setAttribute('adlcp:scormtype','asset');
  6697. }
  6698. //xml:base is the base directory to find the files declared in this resource
  6699. $my_resource->setAttribute('xml:base','');
  6700. //give a <file> child to the <resource> element
  6701. $my_file = $xmldoc->createElement('file');
  6702. $my_file->setAttribute('href',$my_xml_file_path);
  6703. $my_resource->appendChild($my_file);
  6704. //dependency to other files - not yet supported
  6705. $i = 1;
  6706. foreach($inc_docs as $doc_info)
  6707. {
  6708. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  6709. $my_dep = $xmldoc->createElement('resource');
  6710. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  6711. $my_dep->setAttribute('identifier',$res_id);
  6712. $my_dep->setAttribute('type','webcontent');
  6713. $my_dep->setAttribute('adlcp:scormtype','asset');
  6714. $my_dep_file = $xmldoc->createElement('file');
  6715. //check type of URL
  6716. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  6717. if($doc_info[1] == 'remote')
  6718. { //remote file. Save url as is
  6719. $my_dep_file->setAttribute('href',$doc_info[0]);
  6720. $my_dep->setAttribute('xml:base','');
  6721. }elseif($doc_info[1] == 'local'){
  6722. switch($doc_info[2])
  6723. {
  6724. case 'url': //local URL - save path as url for now, don't zip file
  6725. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  6726. $current_dir = dirname($abs_path);
  6727. $file_path = realpath($abs_path);
  6728. $my_dep_file->setAttribute('href',$file_path);
  6729. $my_dep->setAttribute('xml:base','');
  6730. if(strstr($file_path,$main_path) !== false)
  6731. {//the calculated real path is really inside the dokeos root path
  6732. //reduce file path to what's under the DocumentRoot
  6733. $file_path = substr($file_path,strlen($root_path)-1);
  6734. //echo $file_path;echo '<br><br>';
  6735. //error_log(__LINE__.'Reduced url path: '.$file_path,0);
  6736. $zip_files_abs[] = $file_path;
  6737. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6738. $my_dep_file->setAttribute('href',$file_path);
  6739. $my_dep->setAttribute('xml:base','');
  6740. }
  6741. else if (empty($file_path))
  6742. {
  6743. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6744. if(strpos($document_root,-1)=='/')
  6745. {
  6746. $document_root = substr(0, -1, $document_root);
  6747. }*/
  6748. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  6749. $file_path = str_replace('//','/',$file_path);
  6750. if(file_exists($file_path))
  6751. {
  6752. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6753. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6754. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6755. $my_dep_file->setAttribute('href',$file_path);
  6756. $my_dep->setAttribute('xml:base','');
  6757. }
  6758. }
  6759. break;
  6760. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  6761. $my_dep_file->setAttribute('href',$doc_info[0]);
  6762. $my_dep->setAttribute('xml:base','');
  6763. //$current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6764. //the next lines fix a bug when using the "subdir" mode of Dokeos, whereas
  6765. //an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  6766. $abs_img_path_without_subdir = $doc_info[0];
  6767. $relp = api_get_path(REL_PATH); //the url-append config param
  6768. $pos = strpos($abs_img_path_without_subdir,$relp);
  6769. if($pos===0)
  6770. {
  6771. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir,strlen($relp));
  6772. }
  6773. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  6774. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  6775. $file_path = str_replace('//','/',$file_path);
  6776. //error_log(__LINE__.'Abs path: '.$file_path,0);
  6777. //prepare the current directory path (until just under 'document') with a trailing slash
  6778. $cur_path = substr($current_course_path,-1)=='/'?$current_course_path:$current_course_path.'/';
  6779. //check if the current document is in that path
  6780. if(strstr($file_path,$cur_path) !== false)
  6781. {
  6782. //the document is in that path, now get the relative path
  6783. //to the containing document
  6784. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  6785. $relative_path ='';
  6786. if(strstr($file_path,$cur_path)!==false)
  6787. {
  6788. $relative_path = substr($file_path,strlen($orig_file_path));
  6789. $file_path = substr($file_path,strlen($cur_path));
  6790. }
  6791. else
  6792. {
  6793. //this case is still a problem as it's difficult to calculate a relative path easily
  6794. //might still generate wrong links
  6795. //$file_path = substr($file_path,strlen($cur_path));
  6796. //calculate the directory path to the current file (without trailing slash)
  6797. $my_relative_path = dirname($file_path);
  6798. $my_relative_file = basename($file_path);
  6799. //calculate the directory path to the containing file (without trailing slash)
  6800. $my_orig_file_path = substr($orig_file_path,0,-1);
  6801. $dotdot = '';
  6802. $subdir = '';
  6803. while(strstr($my_relative_path,$my_orig_file_path)===false && (strlen($my_orig_file_path)>1) && (strlen($my_relative_path)>1))
  6804. {
  6805. $my_relative_path2 = dirname($my_relative_path);
  6806. $my_orig_file_path = dirname($my_orig_file_path);
  6807. $subdir = substr($my_relative_path,strlen($my_relative_path2)+1)."/".$subdir;
  6808. $dotdot += '../';
  6809. $my_relative_path = $my_relative_path2;
  6810. }
  6811. $relative_path = $dotdot.$subdir.$my_relative_file;
  6812. }
  6813. //put the current document in the zip (this array is the array
  6814. //that will manage documents already in the course folder - relative)
  6815. $zip_files[] = $file_path;
  6816. //update the links to the current document in the containing document (make them relative)
  6817. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$relative_path);
  6818. $my_dep_file->setAttribute('href',$file_path);
  6819. $my_dep->setAttribute('xml:base','');
  6820. }
  6821. elseif(strstr($file_path,$main_path) !== false)
  6822. {//the calculated real path is really inside the dokeos root path
  6823. //reduce file path to what's under the DocumentRoot
  6824. $file_path = substr($file_path,strlen($root_path));
  6825. //echo $file_path;echo '<br><br>';
  6826. //error_log('Reduced path: '.$file_path,0);
  6827. $zip_files_abs[] = $file_path;
  6828. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6829. $my_dep_file->setAttribute('href','document/'.$file_path);
  6830. $my_dep->setAttribute('xml:base','');
  6831. }
  6832. else if (empty($file_path))
  6833. {
  6834. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  6835. if(strpos($document_root,-1)=='/')
  6836. {
  6837. $document_root = substr(0, -1, $document_root);
  6838. }*/
  6839. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  6840. $file_path = str_replace('//','/',$file_path);
  6841. if(file_exists($file_path))
  6842. {
  6843. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  6844. $zip_files[] = $my_sub_dir.'/'.$file_path;
  6845. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  6846. $my_dep_file->setAttribute('href','document/'.$file_path);
  6847. $my_dep->setAttribute('xml:base','');
  6848. }
  6849. }
  6850. break;
  6851. 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
  6852. if(substr($doc_info[0],0,2)=='..')
  6853. { //relative path going up
  6854. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  6855. $file_path = realpath($current_dir.$doc_info[0]);
  6856. //error_log($file_path.' <-> '.$main_path,0);
  6857. if(strstr($file_path,$main_path) !== false)
  6858. {//the calculated real path is really inside the dokeos root path
  6859. //reduce file path to what's under the DocumentRoot
  6860. $file_path = substr($file_path,strlen($root_path));
  6861. //error_log('Reduced 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','document/'.$file_path);
  6865. $my_dep->setAttribute('xml:base','');
  6866. }
  6867. }else{
  6868. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  6869. $my_dep_file->setAttribute('href',$doc_info[0]);
  6870. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  6871. }
  6872. break;
  6873. default:
  6874. $my_dep_file->setAttribute('href',$doc_info[0]);
  6875. $my_dep->setAttribute('xml:base','');
  6876. break;
  6877. }
  6878. }
  6879. $my_dep->appendChild($my_dep_file);
  6880. $resources->appendChild($my_dep);
  6881. $dependency = $xmldoc->createElement('dependency');
  6882. $dependency->setAttribute('identifierref',$res_id);
  6883. $my_resource->appendChild($dependency);
  6884. $i++;
  6885. }
  6886. //$my_dependency = $xmldoc->createElement('dependency');
  6887. //$my_dependency->setAttribute('identifierref','');
  6888. $resources->appendChild($my_resource);
  6889. $zip_files[] = $my_file_path;
  6890. //error_log('File '.$my_file_path. ' added to $zip_files',0);
  6891. }
  6892. else
  6893. { // if the item is a quiz or a link or whatever non-exportable, we include a step indicating it
  6894. if($item->type == TOOL_LINK)
  6895. {
  6896. $my_item = $xmldoc->createElement('item');
  6897. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6898. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6899. $my_item->setAttribute('isvisible','true');
  6900. //give a child element <title> to the <item> element
  6901. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6902. $my_item->appendChild($my_title);
  6903. //give a child element <adlcp:prerequisites> to the <item> element
  6904. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6905. $my_prereqs->setAttribute('type','aicc_script');
  6906. $my_item->appendChild($my_prereqs);
  6907. //give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported
  6908. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  6909. //give a child element <adlcp:timelimitaction> to the <item> element - not yet supported
  6910. //$xmldoc->createElement('adlcp:timelimitaction','');
  6911. //give a child element <adlcp:datafromlms> to the <item> element - not yet supported
  6912. //$xmldoc->createElement('adlcp:datafromlms','');
  6913. //give a child element <adlcp:masteryscore> to the <item> element
  6914. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6915. $my_item->appendChild($my_masteryscore);
  6916. //attach this item to the organization element or its parent if there is one
  6917. if(!empty($item->parent) && $item->parent!=0)
  6918. {
  6919. $children = $organization->childNodes;
  6920. for($i=0;$i<$children->length;$i++){
  6921. $item_temp = $children->item($i);
  6922. if ($item_temp -> nodeName == 'item')
  6923. {
  6924. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6925. {
  6926. $item_temp -> appendChild($my_item);
  6927. }
  6928. }
  6929. }
  6930. }
  6931. else
  6932. {
  6933. $organization->appendChild($my_item);
  6934. }
  6935. $my_file_path = 'link_'.$item->get_id().'.html';
  6936. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  6937. $rs = api_sql_query($sql, __FILE__, __LINE__);
  6938. if($link = Database :: fetch_array($rs))
  6939. {
  6940. $url = $link['url'];
  6941. $title = stripslashes($link['title']);
  6942. $links_to_create[$my_file_path] = array('title'=>$title,'url'=>$url);
  6943. $my_xml_file_path = htmlentities($my_file_path);
  6944. $my_sub_dir = dirname($my_file_path);
  6945. $my_xml_sub_dir = htmlentities($my_sub_dir);
  6946. //give a <resource> child to the <resources> element
  6947. $my_resource = $xmldoc->createElement('resource');
  6948. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  6949. $my_resource->setAttribute('type','webcontent');
  6950. $my_resource->setAttribute('href',$my_xml_file_path);
  6951. //adlcp:scormtype can be either 'sco' or 'asset'
  6952. $my_resource->setAttribute('adlcp:scormtype','asset');
  6953. //xml:base is the base directory to find the files declared in this resource
  6954. $my_resource->setAttribute('xml:base','');
  6955. //give a <file> child to the <resource> element
  6956. $my_file = $xmldoc->createElement('file');
  6957. $my_file->setAttribute('href',$my_xml_file_path);
  6958. $my_resource->appendChild($my_file);
  6959. $resources->appendChild($my_resource);
  6960. }
  6961. }
  6962. elseif($item->type == TOOL_QUIZ)
  6963. {
  6964. require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');
  6965. $exe_id = $item->path; //should be using ref when everything will be cleaned up in this regard
  6966. $exe = new Exercise();
  6967. $exe->read($exe_id);
  6968. $my_item = $xmldoc->createElement('item');
  6969. $my_item->setAttribute('identifier','ITEM_'.$item->get_id());
  6970. $my_item->setAttribute('identifierref','RESOURCE_'.$item->get_id());
  6971. $my_item->setAttribute('isvisible','true');
  6972. //give a child element <title> to the <item> element
  6973. $my_title = $xmldoc->createElement('title',htmlspecialchars($item->get_title(),ENT_QUOTES));
  6974. $my_item->appendChild($my_title);
  6975. //give a child element <adlcp:prerequisites> to the <item> element
  6976. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites',$item->get_prereq_string());
  6977. $my_prereqs->setAttribute('type','aicc_script');
  6978. $my_item->appendChild($my_prereqs);
  6979. //give a child element <adlcp:masteryscore> to the <item> element
  6980. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore',$item->masteryscore);
  6981. $my_item->appendChild($my_masteryscore);
  6982. //attach this item to the organization element or hits parent if there is one
  6983. if(!empty($item->parent) && $item->parent!=0)
  6984. {
  6985. $children = $organization->childNodes;
  6986. for($i=0;$i<$children->length;$i++){
  6987. $item_temp = $children->item($i);
  6988. if ($item_temp -> nodeName == 'item')
  6989. {
  6990. if($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent)
  6991. {
  6992. $item_temp -> appendChild($my_item);
  6993. }
  6994. }
  6995. }
  6996. }
  6997. else
  6998. {
  6999. $organization->appendChild($my_item);
  7000. }
  7001. //include export scripts
  7002. require_once(api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php');
  7003. //get the path of the file(s) from the course directory root
  7004. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7005. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7006. //write the contents of the exported exercise into a (big) html file
  7007. //to later pack it into the exported SCORM. The file will be removed afterwards
  7008. $contents = export_exercise($exe_id,true);
  7009. $tmp_file_path = $garbage_path.$temp_dir_short.'/'.$my_file_path;
  7010. $res = file_put_contents($tmp_file_path,$contents);
  7011. if($res === false){error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__,0);}
  7012. $files_cleanup[] = $tmp_file_path;
  7013. //error_log($tmp_path);die();
  7014. $my_xml_file_path = htmlentities($my_file_path);
  7015. $my_sub_dir = dirname($my_file_path);
  7016. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7017. //give a <resource> child to the <resources> element
  7018. $my_resource = $xmldoc->createElement('resource');
  7019. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7020. $my_resource->setAttribute('type','webcontent');
  7021. $my_resource->setAttribute('href',$my_xml_file_path);
  7022. //adlcp:scormtype can be either 'sco' or 'asset'
  7023. $my_resource->setAttribute('adlcp:scormtype','sco');
  7024. //xml:base is the base directory to find the files declared in this resource
  7025. $my_resource->setAttribute('xml:base','');
  7026. //give a <file> child to the <resource> element
  7027. $my_file = $xmldoc->createElement('file');
  7028. $my_file->setAttribute('href',$my_xml_file_path);
  7029. $my_resource->appendChild($my_file);
  7030. //get included docs
  7031. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7032. //dependency to other files - not yet supported
  7033. $i = 1;
  7034. foreach($inc_docs as $doc_info)
  7035. {
  7036. if(count($doc_info)<1 or empty($doc_info[0])){continue;}
  7037. $my_dep = $xmldoc->createElement('resource');
  7038. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7039. $my_dep->setAttribute('identifier',$res_id);
  7040. $my_dep->setAttribute('type','webcontent');
  7041. $my_dep->setAttribute('adlcp:scormtype','asset');
  7042. $my_dep_file = $xmldoc->createElement('file');
  7043. //check type of URL
  7044. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2],0);
  7045. if($doc_info[1] == 'remote')
  7046. { //remote file. Save url as is
  7047. $my_dep_file->setAttribute('href',$doc_info[0]);
  7048. $my_dep->setAttribute('xml:base','');
  7049. }elseif($doc_info[1] == 'local'){
  7050. switch($doc_info[2])
  7051. {
  7052. case 'url': //local URL - save path as url for now, don't zip file
  7053. //save file but as local file (retrieve from URL)
  7054. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH),'',$doc_info[0]);
  7055. $current_dir = dirname($abs_path);
  7056. $file_path = realpath($abs_path);
  7057. $my_dep_file->setAttribute('href','document/'.$file_path);
  7058. $my_dep->setAttribute('xml:base','');
  7059. if(strstr($file_path,$main_path) !== false)
  7060. {//the calculated real path is really inside the dokeos root path
  7061. //reduce file path to what's under the DocumentRoot
  7062. $file_path = substr($file_path,strlen($root_path));
  7063. //echo $file_path;echo '<br><br>';
  7064. //error_log('Reduced path: '.$file_path,0);
  7065. $zip_files_abs[] = $file_path;
  7066. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7067. $my_dep_file->setAttribute('href','document/'.$file_path);
  7068. $my_dep->setAttribute('xml:base','');
  7069. }
  7070. else if (empty($file_path))
  7071. {
  7072. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7073. if(strpos($document_root,-1)=='/')
  7074. {
  7075. $document_root = substr(0, -1, $document_root);
  7076. }*/
  7077. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7078. $file_path = str_replace('//','/',$file_path);
  7079. if(file_exists($file_path))
  7080. {
  7081. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7082. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7083. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>'document/'.$file_path);
  7084. $my_dep_file->setAttribute('href','document/'.$file_path);
  7085. $my_dep->setAttribute('xml:base','');
  7086. }
  7087. }
  7088. break;
  7089. case 'abs': //absolute path from DocumentRoot. Save file and leave path as is in the zip
  7090. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7091. $file_path = realpath($doc_info[0]);
  7092. $my_dep_file->setAttribute('href',$file_path);
  7093. $my_dep->setAttribute('xml:base','');
  7094. if(strstr($file_path,$main_path) !== false)
  7095. {//the calculated real path is really inside the dokeos root path
  7096. //reduce file path to what's under the DocumentRoot
  7097. $file_path = substr($file_path,strlen($root_path));
  7098. //echo $file_path;echo '<br><br>';
  7099. //error_log('Reduced path: '.$file_path,0);
  7100. $zip_files_abs[] = $file_path;
  7101. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7102. $my_dep_file->setAttribute('href','document/'.$file_path);
  7103. $my_dep->setAttribute('xml:base','');
  7104. }
  7105. else if (empty($file_path))
  7106. {
  7107. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7108. if(strpos($document_root,-1)=='/')
  7109. {
  7110. $document_root = substr(0, -1, $document_root);
  7111. }*/
  7112. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7113. $file_path = str_replace('//','/',$file_path);
  7114. if(file_exists($file_path))
  7115. {
  7116. $file_path = substr($file_path,strlen($current_dir)); // we get the relative path
  7117. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7118. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7119. $my_dep_file->setAttribute('href','document/'.$file_path);
  7120. $my_dep->setAttribute('xml:base','');
  7121. }
  7122. }
  7123. break;
  7124. 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
  7125. if(substr($doc_info[0],0,2)=='..')
  7126. { //relative path going up
  7127. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7128. $file_path = realpath($current_dir.$doc_info[0]);
  7129. //error_log($file_path.' <-> '.$main_path,0);
  7130. if(strstr($file_path,$main_path) !== false)
  7131. {//the calculated real path is really inside the dokeos root path
  7132. //reduce file path to what's under the DocumentRoot
  7133. $file_path = substr($file_path,strlen($root_path));
  7134. //error_log('Reduced path: '.$file_path,0);
  7135. $zip_files_abs[] = $file_path;
  7136. $link_updates[$my_file_path][] = array('orig'=>$doc_info[0],'dest'=>$file_path);
  7137. $my_dep_file->setAttribute('href','document/'.$file_path);
  7138. $my_dep->setAttribute('xml:base','');
  7139. }
  7140. }else{
  7141. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7142. $my_dep_file->setAttribute('href',$doc_info[0]);
  7143. $my_dep->setAttribute('xml:base',$my_xml_sub_dir);
  7144. }
  7145. break;
  7146. default:
  7147. $my_dep_file->setAttribute('href',$doc_info[0]);
  7148. $my_dep->setAttribute('xml:base','');
  7149. break;
  7150. }
  7151. }
  7152. $my_dep->appendChild($my_dep_file);
  7153. $resources->appendChild($my_dep);
  7154. $dependency = $xmldoc->createElement('dependency');
  7155. $dependency->setAttribute('identifierref',$res_id);
  7156. $my_resource->appendChild($dependency);
  7157. $i++;
  7158. }
  7159. $resources->appendChild($my_resource);
  7160. $zip_files[] = $my_file_path;
  7161. }
  7162. else
  7163. {
  7164. //get the path of the file(s) from the course directory root
  7165. $my_file_path = 'non_exportable.html';
  7166. $my_xml_file_path = htmlentities($my_file_path);
  7167. $my_sub_dir = dirname($my_file_path);
  7168. $my_xml_sub_dir = htmlentities($my_sub_dir);
  7169. //give a <resource> child to the <resources> element
  7170. $my_resource = $xmldoc->createElement('resource');
  7171. $my_resource->setAttribute('identifier','RESOURCE_'.$item->get_id());
  7172. $my_resource->setAttribute('type','webcontent');
  7173. $my_resource->setAttribute('href','document/'.$my_xml_file_path);
  7174. //adlcp:scormtype can be either 'sco' or 'asset'
  7175. $my_resource->setAttribute('adlcp:scormtype','asset');
  7176. //xml:base is the base directory to find the files declared in this resource
  7177. $my_resource->setAttribute('xml:base','');
  7178. //give a <file> child to the <resource> element
  7179. $my_file = $xmldoc->createElement('file');
  7180. $my_file->setAttribute('href','document/'.$my_xml_file_path);
  7181. $my_resource->appendChild($my_file);
  7182. $resources->appendChild($my_resource);
  7183. }
  7184. }
  7185. }
  7186. $organizations->appendChild($organization);
  7187. $root->appendChild($organizations);
  7188. $root->appendChild($resources);
  7189. $xmldoc->appendChild($root);
  7190. //todo: add a readme file here, with a short description and a link to the Reload player
  7191. //then add the file to the zip, then destroy the file (this is done automatically)
  7192. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7193. //error_log(print_r($zip_files,true),0);
  7194. foreach($zip_files as $file_path)
  7195. {
  7196. if(empty($file_path)){continue;}
  7197. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7198. $dest_file = $garbage_path.$temp_dir_short.'/'.$file_path;
  7199. $this->create_path($dest_file);
  7200. //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);
  7201. //echo $main_path.$file_path.'<br>';
  7202. @copy($sys_course_path.$_course['path'].'/'.$file_path,$dest_file);
  7203. //check if the file needs a link update
  7204. if(in_array($file_path,array_keys($link_updates))){
  7205. $string = file_get_contents($dest_file);
  7206. unlink($dest_file);
  7207. foreach($link_updates[$file_path] as $old_new)
  7208. {
  7209. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7210. //this is an ugly hack that allows .flv files to be found by the flv player that
  7211. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7212. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7213. // ../../.. to return from inc/lib/flv_player to the document/main path
  7214. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7215. {
  7216. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7217. }
  7218. elseif(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,6)=='video/')
  7219. {
  7220. $old_new['dest'] = str_replace('video/','../../../../video/',$old_new['dest']);
  7221. }
  7222. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7223. }
  7224. file_put_contents($dest_file,$string);
  7225. }
  7226. }
  7227. foreach($zip_files_abs as $file_path)
  7228. {
  7229. if(empty($file_path)){continue;}
  7230. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'',0);
  7231. if(!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)){continue;}
  7232. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path('SYS_COURSE_PATH').$_course['path'].'/',0);
  7233. $dest_file = $garbage_path.$temp_dir_short.'/document/'.$file_path;
  7234. $this->create_path($dest_file);
  7235. //error_log('Created path '.api_get_path('GARBAGE_PATH').$temp_dir_short.'/document/'.$file_path,0);
  7236. //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);
  7237. //echo $main_path.$file_path.' - '.$dest_file.'<br>';
  7238. copy($main_path.$file_path,$dest_file);
  7239. //check if the file needs a link update
  7240. if(in_array($file_path,array_keys($link_updates)))
  7241. {
  7242. $string = file_get_contents($dest_file);
  7243. unlink($dest_file);
  7244. foreach($link_updates[$file_path] as $old_new)
  7245. {
  7246. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path,0);
  7247. //this is an ugly hack that allows .flv files to be found by the flv player that
  7248. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7249. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7250. // ../../.. to return from inc/lib/flv_player to the document/main path
  7251. if(substr($old_new['dest'],-3)=='flv' && substr($old_new['dest'],0,5)=='main/')
  7252. {
  7253. $old_new['dest'] = str_replace('main/','../../../',$old_new['dest']);
  7254. }
  7255. $string = str_replace($old_new['orig'],$old_new['dest'],$string);
  7256. }
  7257. file_put_contents($dest_file,$string);
  7258. }
  7259. }
  7260. if(is_array($links_to_create))
  7261. {
  7262. foreach($links_to_create as $file=>$link)
  7263. {
  7264. $file_content = '<html><body><div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div></body></html>';
  7265. file_put_contents($garbage_path.$temp_dir_short.'/'.$file, $file_content);
  7266. }
  7267. }
  7268. // add non exportable message explanation
  7269. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7270. $file_content =
  7271. <<<EOD
  7272. <html>
  7273. <head>
  7274. <style>
  7275. .error-message {
  7276. font-family: arial, verdana, helvetica, sans-serif;
  7277. border-width: 1px;
  7278. border-style: solid;
  7279. left: 50%;
  7280. margin: 10px auto;
  7281. min-height: 30px;
  7282. padding: 5px;
  7283. right: 50%;
  7284. width: 500px;
  7285. background-color: #FFD1D1;
  7286. border-color: #FF0000;
  7287. color: #000;
  7288. }
  7289. </style>
  7290. <body>
  7291. <div class="error-message">
  7292. $lang_not_exportable
  7293. </div>
  7294. </body>
  7295. </html>
  7296. EOD;
  7297. if(!is_dir($garbage_path.$temp_dir_short.'/document'))
  7298. {
  7299. @mkdir($garbage_path.$temp_dir_short.'/document');
  7300. }
  7301. file_put_contents($garbage_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7302. //Add the extra files that go along with a SCORM package
  7303. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7304. $extra_files = scandir($main_code_path);
  7305. foreach($extra_files as $extra_file)
  7306. {
  7307. if(strpos($extra_file,'.')===0) continue;
  7308. else
  7309. {
  7310. $dest_file = $garbage_path.$temp_dir_short.'/'.$extra_file;
  7311. $this->create_path($dest_file);
  7312. copy($main_code_path.$extra_file,$dest_file);
  7313. }
  7314. }
  7315. //Finalize the imsmanifest structure, add to the zip, then return the zip
  7316. $xmldoc->save($garbage_path.'/'.$temp_dir_short.'/imsmanifest.xml');
  7317. $zip_folder->add($garbage_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $garbage_path.'/'.$temp_dir_short.'/');
  7318. //clean possible temporary files
  7319. foreach($files_cleanup as $file)
  7320. {
  7321. $res = unlink($file);
  7322. if($res === false){error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,0);}
  7323. }
  7324. //Send file to client
  7325. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7326. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  7327. $name = preg_replace('([^a-zA-Z0-9_\.])','-',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip';
  7328. DocumentManager::file_send_for_download($temp_zip_file,true,$name);
  7329. }
  7330. /**
  7331. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7332. * if it doesn't exist
  7333. */
  7334. function create_path($path){
  7335. $path_bits = split('/',dirname($path));
  7336. $path_built = '/';
  7337. foreach($path_bits as $bit){
  7338. if(!empty($bit)){
  7339. $new_path = $path_built.$bit;
  7340. if(is_dir($new_path)){
  7341. $path_built = $new_path.'/';
  7342. }
  7343. else
  7344. {
  7345. mkdir($new_path);
  7346. $path_built = $new_path.'/';
  7347. }
  7348. }
  7349. }
  7350. }
  7351. /**
  7352. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7353. * @return boolean The results of the unlink function, or false if there was no image to start with
  7354. */
  7355. function delete_lp_image()
  7356. {
  7357. $img = $this->get_preview_image();
  7358. if ($img!='')
  7359. {
  7360. $del_file = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$img;
  7361. $this->set_preview_image('');
  7362. return @unlink($del_file);
  7363. }
  7364. else
  7365. {
  7366. return false;
  7367. }
  7368. }
  7369. /**
  7370. * Uploads an author image to the upload/learning_path/images directory
  7371. * @param array The image array, coming from the $_FILES superglobal
  7372. * @return boolean True on success, false on error
  7373. */
  7374. function upload_image($image_array)
  7375. {
  7376. $image_moved=false;
  7377. if(!empty($image_array['name']))
  7378. {
  7379. $upload_ok = process_uploaded_file($image_array);
  7380. $has_attachment=true;
  7381. }
  7382. else
  7383. {
  7384. $image_moved=true;
  7385. }
  7386. if($upload_ok)
  7387. {
  7388. if ($has_attachment)
  7389. {
  7390. $courseDir = api_get_course_path().'/upload/learning_path/images';
  7391. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7392. $updir = $sys_course_path.$courseDir;
  7393. // Try to add an extension to the file if it hasn't one
  7394. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7395. if (!filter_extension($new_file_name))
  7396. {
  7397. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7398. $image_moved=false;
  7399. }
  7400. else
  7401. {
  7402. $file_extension = explode('.', $image_array['name']);
  7403. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7404. $new_file_name = uniqid('').'.'.$file_extension;
  7405. $new_path=$updir.'/'.$new_file_name;
  7406. //$result= @move_uploaded_file($image_array['tmp_name'], $new_path);
  7407. // resize the image
  7408. include_once (api_get_path(LIBRARY_PATH).'image.lib.php');
  7409. $temp = new image($image_array['tmp_name']);
  7410. $picture_infos=getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7411. if ($picture_infos[0]>240)
  7412. $thumbwidth=240;
  7413. else
  7414. $thumbwidth=$picture_infos[0];
  7415. if ($picture_infos[1]>100)
  7416. $new_height=100;
  7417. else
  7418. $new_height = $picture_infos[1];
  7419. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7420. $temp->resize($thumbwidth,$new_height,0);
  7421. $type=$picture_infos[2];
  7422. $result=false;
  7423. switch ($type)
  7424. {
  7425. case 2 :
  7426. $result=$temp->send_image('JPG',$new_path);
  7427. break;
  7428. case 3 :
  7429. $result=$temp->send_image('PNG',$new_path);
  7430. break;
  7431. case 1 :
  7432. $result=$temp->send_image('GIF',$new_path);
  7433. break;
  7434. }
  7435. // Storing the image filename
  7436. if ($result)
  7437. {
  7438. $image_moved=true;
  7439. $this->set_preview_image($new_file_name);
  7440. return true;
  7441. }
  7442. }
  7443. }
  7444. }
  7445. return false;
  7446. }
  7447. }
  7448. if (!function_exists('trim_value')) {
  7449. function trim_value(&$value) {
  7450. $value = trim($value);
  7451. }
  7452. }
  7453. ?>