learnpath.class.php 420 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This class defines the parent attributes and methods for Chamilo learnpaths and SCORM
  5. * learnpaths. It is used by the scorm class.
  6. *
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @author Julio Montoya <gugli100@gmail.com> Several improvements and fixes
  10. */
  11. /**
  12. * Defines the learnpath parent class
  13. * @package chamilo.learnpath
  14. */
  15. class learnpath {
  16. public $attempt = 0; // The number for the current ID view.
  17. public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
  18. public $current; // Id of the current item the user is viewing.
  19. public $current_score; // The score of the current item.
  20. public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
  21. public $current_time_stop; // The time the user closed this resource.
  22. public $default_status = 'not attempted';
  23. public $encoding = 'UTF-8';
  24. public $error = '';
  25. public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath.
  26. public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue().
  27. public $index; // The index of the active learnpath_item in $ordered_items array.
  28. public $items = array();
  29. public $last; // item_id of last item viewed in the learning path.
  30. public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized.
  31. public $license; // Which license this course has been given - not used yet on 20060522.
  32. public $lp_id; // DB ID for this learnpath.
  33. public $lp_view_id; // DB ID for lp_view
  34. public $log_file; // File where to log learnpath API msg.
  35. public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
  36. public $message = '';
  37. public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
  38. public $name; // Learnpath name (they generally have one).
  39. public $ordered_items = array(); // List of the learnpath items in the order they are to be read.
  40. public $path = ''; // Path inside the scorm directory (if scorm).
  41. public $theme; // The current theme of the learning path.
  42. public $preview_image; // The current image of the learning path.
  43. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
  44. public $prevent_reinit = 1;
  45. // Describes the mode of progress bar display.
  46. public $progress_bar_mode = '%';
  47. // Percentage progress as saved in the db.
  48. public $progress_db = '0';
  49. public $proximity; // Wether the content is distant or local or unknown.
  50. public $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  51. // !!!This array (refs_list) is built differently depending on the nature of the LP.
  52. // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
  53. public $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  54. // TODO: Check if this type variable is useful here (instead of just in the controller script).
  55. public $user_id; //ID of the user that is viewing/using the course
  56. public $update_queue = array();
  57. public $scorm_debug = 0;
  58. public $arrMenu = array(); // Array for the menu items.
  59. public $debug = 0; // Logging level.
  60. public $lp_session_id =0;
  61. public $lp_view_session_id =0; // The specific view might be bound to a session.
  62. public $prerequisite = 0;
  63. public $use_max_score = 1; // 1 or 0
  64. public $created_on = '';
  65. public $modified_on = '';
  66. public $publicated_on = '';
  67. public $expired_on = '';
  68. /**
  69. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  70. * Also builds the list of items into $this->items.
  71. * @param string Course code
  72. * @param integer Learnpath ID
  73. * @param integer User ID
  74. * @return boolean True on success, false on error
  75. */
  76. public function __construct($course, $lp_id, $user_id) {
  77. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  78. // Check params.
  79. // Check course code.
  80. $course_db = '';
  81. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  82. if (empty($course)) {
  83. $this->error = 'Course code is empty';
  84. return false;
  85. } else {
  86. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  87. //$course = Database::escape_string($course);
  88. $course = $this->escape_string($course);
  89. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  90. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
  91. $res = Database::query($sql);
  92. if (Database::num_rows($res) > 0) {
  93. $this->cc = $course;
  94. $row_course = Database::fetch_array($res);
  95. $course_db = $row_course['db_name'];
  96. } else {
  97. $this->error = 'Course code does not exist in database ('.$sql.')';
  98. return false;
  99. }
  100. }
  101. // Check learnpath ID.
  102. if (empty($lp_id)) {
  103. $this->error = 'Learnpath ID is empty';
  104. return false;
  105. } else {
  106. // TODO: Make it flexible to use any course_code (still using env course code here).
  107. $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_db);
  108. //$id = Database::escape_integer($id);
  109. $lp_id = $this->escape_string($lp_id);
  110. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  111. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  112. $res = Database::query($sql);
  113. if (Database::num_rows($res) > 0) {
  114. $this->lp_id = $lp_id;
  115. $row = Database::fetch_array($res);
  116. $this->type = $row['lp_type'];
  117. $this->name = stripslashes($row['name']);
  118. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  119. $this->proximity = $row['content_local'];
  120. $this->theme = $row['theme'];
  121. $this->maker = $row['content_maker'];
  122. $this->prevent_reinit = $row['prevent_reinit'];
  123. $this->license = $row['content_license'];
  124. $this->scorm_debug = $row['debug'];
  125. $this->js_lib = $row['js_lib'];
  126. $this->path = $row['path'];
  127. $this->preview_image = $row['preview_image'];
  128. $this->author = $row['author'];
  129. $this->lp_session_id = $row['session_id'];
  130. $this->use_max_score = $row['use_max_score'];
  131. $this->created_on = $row['created_on'];
  132. $this->modified_on = $row['modified_on'];
  133. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  134. $this->publicated_on = $row['publicated_on'];
  135. }
  136. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  137. $this->expired_on = $row['expired_on'];
  138. }
  139. if ($this->type == 2) {
  140. if ($row['force_commit'] == 1) {
  141. $this->force_commit = true;
  142. }
  143. }
  144. $this->mode = $row['default_view_mod'];
  145. } else {
  146. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  147. return false;
  148. }
  149. }
  150. // Check user ID.
  151. if (empty($user_id)) {
  152. $this->error = 'User ID is empty';
  153. return false;
  154. } else {
  155. //$main_table = Database::get_main_user_table();
  156. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  157. //$user_id = Database::escape_integer($user_id);
  158. $user_id = $this->escape_string($user_id);
  159. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  160. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  161. $res = Database::query($sql);
  162. if (Database::num_rows($res) > 0) {
  163. $this->user_id = $user_id;
  164. } else {
  165. $this->error = 'User ID does not exist in database ('.$sql.')';
  166. return false;
  167. }
  168. }
  169. // End of variables checking.
  170. $session_id = api_get_session_id();
  171. // Get the session condition for learning paths of the base + session.
  172. $session = api_get_session_condition($session_id);
  173. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  174. $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
  175. // Selecting by view_count descending allows to get the highest view_count first.
  176. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  177. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  178. $res = Database::query($sql);
  179. $view_id = 0; // Used later to query lp_item_view.
  180. if (Database :: num_rows($res) > 0) {
  181. if ($this->debug > 2) {
  182. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  183. }
  184. $row = Database :: fetch_array($res);
  185. $this->attempt = $row['view_count'];
  186. $this->lp_view_id = $row['id'];
  187. $this->last_item_seen = $row['last_item'];
  188. $this->progress_db = $row['progress'];
  189. $this->lp_view_session_id = $row['session_id'];
  190. } else {
  191. if ($this->debug > 2) {
  192. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  193. }
  194. $this->attempt = 1;
  195. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  196. $res_ins = Database::query($sql_ins);
  197. $this->lp_view_id = Database :: insert_id();
  198. if ($this->debug > 2) {
  199. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  200. }
  201. }
  202. // Initialise items.
  203. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
  204. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  205. $res = Database::query($sql);
  206. while ($row = Database::fetch_array($res)) {
  207. $oItem = '';
  208. //$this->ordered_items[] = $row['id'];
  209. switch ($this->type) {
  210. case 3: //aicc
  211. $oItem = new aiccItem('db', $row['id'], $course_db);
  212. if (is_object($oItem)) {
  213. $my_item_id = $oItem->get_id();
  214. $oItem->set_lp_view($this->lp_view_id, $course_db);
  215. $oItem->set_prevent_reinit($this->prevent_reinit);
  216. // Don't use reference here as the next loop will make the pointed object change.
  217. $this->items[$my_item_id] = $oItem;
  218. $this->refs_list[$oItem->ref] = $my_item_id;
  219. if ($this->debug > 2) {
  220. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  221. }
  222. }
  223. break;
  224. case 2:
  225. require_once 'scorm.class.php';
  226. require_once 'scormItem.class.php';
  227. $oItem = new scormItem('db', $row['id'], $course_db);
  228. if (is_object($oItem)) {
  229. $my_item_id = $oItem->get_id();
  230. $oItem->set_lp_view($this->lp_view_id, $course_db);
  231. $oItem->set_prevent_reinit($this->prevent_reinit);
  232. // Don't use reference here as the next loop will make the pointed object change.
  233. $this->items[$my_item_id] = $oItem;
  234. $this->refs_list[$oItem->ref] = $my_item_id;
  235. if ($this->debug > 2) {
  236. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  237. }
  238. }
  239. break;
  240. case 1:
  241. default:
  242. require_once 'learnpathItem.class.php';
  243. $oItem = new learnpathItem($row['id'], $user_id, $course_db);
  244. if (is_object($oItem)) {
  245. $my_item_id = $oItem->get_id();
  246. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  247. $oItem->set_prevent_reinit($this->prevent_reinit);
  248. // Don't use reference here as the next loop will make the pointed object change.
  249. $this->items[$my_item_id] = $oItem;
  250. $this->refs_list[$my_item_id] = $my_item_id;
  251. if ($this->debug > 2) {
  252. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  253. }
  254. }
  255. break;
  256. }
  257. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  258. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  259. if (is_object($this->items[$row['id']])) {
  260. $this->items[$row['id']]->set_level(0);
  261. }
  262. } else {
  263. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  264. $this->items[$row['id']]->set_level($level);
  265. if (is_object($this->items[$row['parent_item_id']])) {
  266. // Items is a list of pointers from item DB ids to item objects.
  267. $this->items[$row['parent_item_id']]->add_child($row['id']);
  268. } else {
  269. if ($this->debug > 2) {
  270. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  271. }
  272. }
  273. }
  274. // Get last viewing vars.
  275. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  276. // This query should only return one or zero result.
  277. $sql = "SELECT * " .
  278. "FROM $lp_item_view_table " .
  279. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  280. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  281. if ($this->debug > 2) {
  282. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  283. }
  284. // Get the item status.
  285. $res2 = Database::query($sql);
  286. if (Database :: num_rows($res2) > 0) {
  287. // If this learnpath has already been used by this user, get his last attempt count and
  288. // the last item seen back into this object.
  289. //$max = 0;
  290. $row2 = Database :: fetch_array($res2);
  291. if ($this->debug > 2) {
  292. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  293. }
  294. if (is_object($this->items[$row['id']])) {
  295. $this->items[$row['id']]->set_status($row2['status']);
  296. if (empty ($row2['status'])) {
  297. $this->items[$row['id']]->set_status($this->default_status);
  298. }
  299. }
  300. //$this->attempt = $row['view_count'];
  301. //$this->last_item = $row['id'];
  302. } else { // No item has been found in lp_item_view for this view.
  303. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  304. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  305. //$this->attempt = 1;
  306. //$this->last_item = 0;
  307. if (is_object($this->items[$row['id']])) {
  308. $this->items[$row['id']]->set_status($this->default_status);
  309. }
  310. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  311. $sql_ins = "INSERT INTO $lp_item_view_table " .
  312. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  313. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  314. if ($this->debug > 2) {
  315. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  316. }
  317. $res_ins = Database::query($sql_ins);
  318. }
  319. // Setting the view in the item object.
  320. if (is_object($this->items[$row['id']])) {
  321. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
  322. }
  323. }
  324. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
  325. $this->max_ordered_items = 0;
  326. foreach ($this->ordered_items as $index => $dummy) {
  327. if ($index > $this->max_ordered_items && !empty($dummy)) {
  328. $this->max_ordered_items = $index;
  329. }
  330. }
  331. // TODO: Define the current item better.
  332. $this->first();
  333. if ($this->debug > 2) {
  334. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  335. }
  336. }
  337. /**
  338. * 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
  339. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  340. *
  341. * @param int $parent
  342. * @param int $previous
  343. * @param string $type
  344. * @param int resource ID (ref)
  345. * @param string $title
  346. * @param string $description
  347. * @return int
  348. */
  349. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  350. if ($this->debug > 0) {
  351. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  352. }
  353. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  354. $parent = intval($parent);
  355. $previous = intval($previous);
  356. $type = $this->escape_string($type);
  357. $id = intval($id);
  358. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  359. if (empty ($max_time_allowed)) {
  360. $max_time_allowed = 0;
  361. }
  362. $title = $this->escape_string($title);
  363. $description = $this->escape_string($description);
  364. $sql_count = " SELECT COUNT(id) AS num
  365. FROM " . $tbl_lp_item . "
  366. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  367. $res_count = Database::query($sql_count);
  368. $row = Database :: fetch_array($res_count);
  369. $num = $row['num'];
  370. if ($num > 0) {
  371. if ($previous == 0) {
  372. $sql = "SELECT id, next_item_id, display_order
  373. FROM " . $tbl_lp_item . "
  374. WHERE
  375. lp_id = " . $this->get_id() . " AND
  376. parent_item_id = " . $parent . " AND
  377. previous_item_id = 0 OR previous_item_id=" . $parent;
  378. $result = Database::query($sql);
  379. $row = Database :: fetch_array($result);
  380. $tmp_previous = 0;
  381. $next = $row['id'];
  382. $display_order = 0;
  383. } else {
  384. $previous = (int) $previous;
  385. $sql = "
  386. SELECT
  387. id,
  388. previous_item_id,
  389. next_item_id,
  390. display_order
  391. FROM " . $tbl_lp_item . "
  392. WHERE
  393. lp_id = " . $this->get_id() . " AND
  394. id = " . $previous;
  395. $result = Database::query($sql);
  396. $row = Database :: fetch_array($result);
  397. $tmp_previous = $row['id'];
  398. $next = $row['next_item_id'];
  399. $display_order = $row['display_order'];
  400. }
  401. } else {
  402. $tmp_previous = 0;
  403. $next = 0;
  404. $display_order = 0;
  405. }
  406. $new_item_id = -1;
  407. $id = $this->escape_string($id);
  408. if ($type == 'quiz') {
  409. $sql = 'SELECT SUM(ponderation)
  410. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  411. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  412. ON quiz_question.id = quiz_rel_question.question_id
  413. AND quiz_rel_question.exercice_id = ' . $id;
  414. $rsQuiz = Database::query($sql);
  415. $max_score = Database :: result($rsQuiz, 0, 0);
  416. } else {
  417. $max_score = 100;
  418. }
  419. if ($prerequisites != 0) {
  420. $sql_ins = "
  421. INSERT INTO " . $tbl_lp_item . " ( ".
  422. "lp_id, ".
  423. "item_type, ".
  424. "ref, ".
  425. "title, ".
  426. "description, ".
  427. "path, ".
  428. "max_score, ".
  429. "parent_item_id, ".
  430. "previous_item_id, ".
  431. "next_item_id, ".
  432. "display_order, ".
  433. "prerequisite, ".
  434. "max_time_allowed ".
  435. ") VALUES ( ".
  436. $this->get_id() . ", ".
  437. "'" . $type . "', ".
  438. "'', ".
  439. "'" . $title . "', ".
  440. "'" . $description . "', ".
  441. "'" . $id . "', ".
  442. "'" . $max_score . "', ".
  443. $parent . ", ".
  444. $previous . ", ".
  445. $next . ", ".
  446. ($display_order +1) . ", ".
  447. $prerequisites . ", ".
  448. $max_time_allowed .
  449. ")";
  450. } else {
  451. // Insert new item.
  452. $sql_ins = "
  453. INSERT INTO " . $tbl_lp_item . " ( ".
  454. "lp_id, ".
  455. "item_type, ".
  456. "ref, ".
  457. "title, ".
  458. "description, ".
  459. "path, ".
  460. "max_score, ".
  461. "parent_item_id, ".
  462. "previous_item_id, ".
  463. "next_item_id, ".
  464. "display_order, ".
  465. "max_time_allowed ".
  466. ") VALUES (".
  467. $this->get_id() . ",".
  468. "'" . $type . "',".
  469. "'',".
  470. "'" . $title . "',".
  471. "'" . $description . "',".
  472. "'" . $id . "',".
  473. "'" . $max_score . "',".
  474. $parent . ",".
  475. $previous . ",".
  476. $next . ",".
  477. ($display_order +1) . ",".
  478. $max_time_allowed .
  479. ")";
  480. }
  481. if ($this->debug > 2) {
  482. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  483. }
  484. $res_ins = Database::query($sql_ins);
  485. if ($res_ins > 0) {
  486. $new_item_id = Database :: insert_id($res_ins);
  487. // Update the item that should come after the new item.
  488. $sql_update_next = "
  489. UPDATE " . $tbl_lp_item . "
  490. SET previous_item_id = " . $new_item_id . "
  491. WHERE id = " . $next;
  492. $res_update_next = Database::query($sql_update_next);
  493. // Update the item that should be before the new item.
  494. $sql_update_previous = "
  495. UPDATE " . $tbl_lp_item . "
  496. SET next_item_id = " . $new_item_id . "
  497. WHERE id = " . $tmp_previous;
  498. $res_update_previous = Database::query($sql_update_previous);
  499. // Update all the items after the new item.
  500. $sql_update_order = "
  501. UPDATE " . $tbl_lp_item . "
  502. SET display_order = display_order + 1
  503. WHERE
  504. lp_id = " . $this->get_id() . " AND
  505. id <> " . $new_item_id . " AND
  506. parent_item_id = " . $parent . " AND
  507. display_order > " . $display_order;
  508. $res_update_previous = Database::query($sql_update_order);
  509. // Update the item that should come after the new item.
  510. $sql_update_ref = "
  511. UPDATE " . $tbl_lp_item . "
  512. SET ref = " . $new_item_id . "
  513. WHERE id = " . $new_item_id;
  514. Database::query($sql_update_ref);
  515. }
  516. // Upload audio.
  517. if (!empty ($_FILES['mp3']['name'])) {
  518. // Create the audio folder if it does not exist yet.
  519. global $_course;
  520. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  521. if (!is_dir($filepath . 'audio')) {
  522. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  523. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  524. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  525. }
  526. // Upload the file in the documents tool.
  527. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  528. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  529. // Getting the filename only.
  530. $file_components = explode('/', $file_path);
  531. $file = $file_components[count($file_components) - 1];
  532. // Store the mp3 file in the lp_item table.
  533. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  534. Database::query($sql_insert_audio);
  535. }
  536. return $new_item_id;
  537. }
  538. /**
  539. * Static admin function allowing addition of a learnpath to a course.
  540. * @param string Course code
  541. * @param string Learnpath name
  542. * @param string Learnpath description string, if provided
  543. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  544. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  545. * @param string Zip file containing the learnpath or directory containing the learnpath
  546. * @return integer The new learnpath ID on success, 0 on failure
  547. */
  548. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  549. global $charset;
  550. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  551. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  552. // Check course code exists.
  553. // Check lp_name doesn't exist, otherwise append something.
  554. $i = 0;
  555. $name = learnpath :: escape_string($name);
  556. // Session id.
  557. $session_id = api_get_session_id();
  558. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  559. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  560. $res_name = Database::query($check_name);
  561. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  562. //by default the publication date is the same that the creation date
  563. $publicated_on = api_get_utc_datetime();
  564. } else {
  565. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  566. }
  567. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  568. $expired_on = '';
  569. } else {
  570. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  571. }
  572. while (Database :: num_rows($res_name)) {
  573. // There is already one such name, update the current one a bit.
  574. $i++;
  575. $name = $name . ' - ' . $i;
  576. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  577. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  578. $res_name = Database::query($check_name);
  579. }
  580. // New name does not exist yet; keep it.
  581. // Escape description.
  582. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  583. $type = 1;
  584. switch ($learnpath) {
  585. case 'guess':
  586. break;
  587. case 'dokeos':
  588. case 'chamilo':
  589. $type = 1;
  590. break;
  591. case 'aicc':
  592. break;
  593. }
  594. switch ($origin) {
  595. case 'zip':
  596. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  597. break;
  598. case 'manual':
  599. default:
  600. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  601. $res_max = Database::query($get_max);
  602. if (Database :: num_rows($res_max) < 1) {
  603. $dsp = 1;
  604. } else {
  605. $row = Database :: fetch_array($res_max);
  606. $dsp = $row[0] + 1;
  607. }
  608. $sql_insert = "INSERT INTO $tbl_lp (lp_type,name,description,path,default_view_mod, default_encoding,display_order,content_maker,content_local,js_lib,session_id, created_on, publicated_on, expired_on) " .
  609. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  610. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  611. $res_insert = Database::query($sql_insert);
  612. $id = Database :: insert_id();
  613. if ($id > 0) {
  614. // Insert into item_property.
  615. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  616. return $id;
  617. }
  618. break;
  619. }
  620. }
  621. /**
  622. * Appends a message to the message attribute
  623. * @param string Message to append.
  624. */
  625. public function append_message($string) {
  626. if ($this->debug > 0) {
  627. error_log('New LP - In learnpath::append_message()', 0);
  628. }
  629. $this->message .= $string;
  630. }
  631. /**
  632. * Autocompletes the parents of an item in case it's been completed or passed
  633. * @param integer Optional ID of the item from which to look for parents
  634. */
  635. public function autocomplete_parents($item) {
  636. if ($this->debug > 0) {
  637. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  638. }
  639. if (empty ($item)) {
  640. $item = $this->current;
  641. }
  642. $parent_id = $this->items[$item]->get_parent();
  643. if ($this->debug > 2) {
  644. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  645. }
  646. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  647. // if $item points to an object and there is a parent.
  648. if ($this->debug > 2) {
  649. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  650. }
  651. $current_item = & $this->items[$item];
  652. $parent = & $this->items[$parent_id]; // Get the parent.
  653. // New experiment including failed and browsed in completed status.
  654. $current_status = $current_item->get_status();
  655. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  656. // If the current item is completed or passes or succeeded.
  657. $completed = true;
  658. if ($this->debug > 2) {
  659. error_log('New LP - Status of current item is alright', 0);
  660. }
  661. foreach ($parent->get_children() as $child) {
  662. // Check all his brothers (his parent's children) for completion status.
  663. if ($child != $item) {
  664. if ($this->debug > 2) {
  665. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  666. }
  667. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  668. // Trying completing parents of failed and browsed items as well.
  669. if ($this->items[$child]->status_is(array (
  670. 'completed',
  671. 'passed',
  672. 'succeeded',
  673. 'browsed',
  674. 'failed'
  675. ))) {
  676. // Keep completion status to true.
  677. } else {
  678. if ($this->debug > 2) {
  679. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  680. }
  681. $completed = false;
  682. }
  683. }
  684. }
  685. if ($completed) { // If all the children were completed:
  686. $parent->set_status('completed');
  687. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  688. $this->update_queue[$parent->get_id()] = $parent->get_status();
  689. if ($this->debug > 2) {
  690. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  691. }
  692. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  693. }
  694. } else {
  695. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  696. }
  697. }
  698. }
  699. /**
  700. * Autosaves the current results into the database for the whole learnpath
  701. */
  702. public function autosave() {
  703. if ($this->debug > 0) {
  704. error_log('New LP - In learnpath::autosave()', 0);
  705. }
  706. // TODO: Add save operations for the learnpath itself.
  707. }
  708. /**
  709. * Clears the message attribute
  710. */
  711. public function clear_message() {
  712. if ($this->debug > 0) {
  713. error_log('New LP - In learnpath::clear_message()', 0);
  714. }
  715. $this->message = '';
  716. }
  717. /**
  718. * Closes the current resource
  719. *
  720. * Stops the timer
  721. * Saves into the database if required
  722. * Clears the current resource data from this object
  723. * @return boolean True on success, false on failure
  724. */
  725. public function close() {
  726. if ($this->debug > 0) {
  727. error_log('New LP - In learnpath::close()', 0);
  728. }
  729. if (empty ($this->lp_id)) {
  730. $this->error = 'Trying to close this learnpath but no ID is set';
  731. return false;
  732. }
  733. $this->current_time_stop = time();
  734. if ($this->save) {
  735. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  736. /*
  737. $sql = "UPDATE $learnpath_view_table " .
  738. "SET " .
  739. "stop_time = ".$this->current_time_stop.", " .
  740. "score = ".$this->current_score.", ".
  741. "WHERE learnpath_id = '".$this->lp_id."'";
  742. //$res = Database::query($sql);
  743. $res = Database::query($res);
  744. if (Database::affected_rows($res) < 1) {
  745. $this->error = 'Could not update learnpath_view table while closing learnpath';
  746. return false;
  747. }
  748. */
  749. }
  750. $this->ordered_items = array ();
  751. $this->index = 0;
  752. unset ($this->lp_id);
  753. //unset other stuff
  754. return true;
  755. }
  756. /**
  757. * Static admin function allowing removal of a learnpath
  758. * @param string Course code
  759. * @param integer Learnpath ID
  760. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  761. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  762. */
  763. public function delete($course = null, $id = null, $delete = 'keep') {
  764. // TODO: Implement a way of getting this to work when the current object is not set.
  765. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  766. //if (empty($course)) { $course = api_get_course_id(); }
  767. //if (empty($id)) { $id = $this->get_id(); }
  768. // If an ID is specifically given and the current LP is not the same, prevent delete.
  769. if (!empty ($id) && ($id != $this->lp_id)) {
  770. return false;
  771. }
  772. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  773. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  774. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  775. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  776. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  777. // Delete lp item id.
  778. foreach ($this->items as $id => $dummy) {
  779. //$this->items[$id]->delete();
  780. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  781. $res_del_item_view = Database::query($sql_del_view);
  782. }
  783. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  784. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  785. $res_del_item = Database::query($sql_del_item);
  786. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  787. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  788. $res_del_view = Database::query($sql_del_view);
  789. $this->toggle_publish($this->lp_id, 'i');
  790. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  791. if ($this->type == 2 || $this->type == 3) {
  792. // This is a scorm learning path, delete the files as well.
  793. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  794. $res = Database::query($sql);
  795. if (Database :: num_rows($res) > 0) {
  796. $row = Database :: fetch_array($res);
  797. $path = $row['path'];
  798. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  799. $res = Database::query($sql);
  800. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  801. if ($this->debug > 2) {
  802. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  803. }
  804. } else {
  805. // No other LP uses that directory, delete it.
  806. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  807. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  808. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  809. if ($this->debug > 2) {
  810. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  811. }
  812. // Proposed by Christophe (clefevre).
  813. if (strcmp(substr($path, -2), "/.") == 0) {
  814. $path = substr($path, 0, -1); // Remove "." at the end.
  815. }
  816. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  817. rmdirr($course_scorm_dir . $path);
  818. }
  819. }
  820. }
  821. }
  822. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  823. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  824. $res_del_lp = Database::query($sql_del_lp);
  825. $this->update_display_order(); // Updates the display order of all lps.
  826. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  827. require_once '../gradebook/lib/be.inc.php';
  828. // Delete link of gradebook tool
  829. //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  830. /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  831. $result = Database::query($sql);
  832. $row = Database :: fetch_array($result, 'ASSOC');*/
  833. // Fixing gradebook link deleted see #5229.
  834. /*
  835. if (!empty($row['id'])) {
  836. $link = LinkFactory :: load($row['id']);
  837. if ($link[0] != null) {
  838. $link[0]->delete();
  839. }
  840. }*/
  841. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  842. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
  843. if ($link_id !== false) {
  844. remove_resource_from_course_gradebook($link_id);
  845. }
  846. if (api_get_setting('search_enabled') == 'true') {
  847. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  848. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  849. }
  850. }
  851. /**
  852. * Removes all the children of one item - dangerous!
  853. * @param integer Element ID of which children have to be removed
  854. * @return integer Total number of children removed
  855. */
  856. public function delete_children_items($id) {
  857. if ($this->debug > 0) {
  858. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  859. }
  860. $num = 0;
  861. if (empty ($id) || $id != strval(intval($id))) {
  862. return false;
  863. }
  864. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  865. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  866. $res = Database::query($sql);
  867. while ($row = Database :: fetch_array($res)) {
  868. $num += $this->delete_children_items($row['id']);
  869. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  870. $res_del = Database::query($sql_del);
  871. $num++;
  872. }
  873. return $num;
  874. }
  875. /**
  876. * Removes an item from the current learnpath
  877. * @param integer Elem ID (0 if first)
  878. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  879. * @return integer Number of elements moved
  880. * @todo implement resource removal
  881. */
  882. public function delete_item($id, $remove = 'keep') {
  883. if ($this->debug > 0) {
  884. error_log('New LP - In learnpath::delete_item()', 0);
  885. }
  886. // TODO: Implement the resource removal.
  887. if (empty ($id) || $id != strval(intval($id))) {
  888. return false;
  889. }
  890. // First select item to get previous, next, and display order.
  891. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  892. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  893. $res_sel = Database::query($sql_sel);
  894. if (Database :: num_rows($res_sel) < 1) {
  895. return false;
  896. }
  897. $row = Database :: fetch_array($res_sel);
  898. $previous = $row['previous_item_id'];
  899. $next = $row['next_item_id'];
  900. $display = $row['display_order'];
  901. $parent = $row['parent_item_id'];
  902. $lp = $row['lp_id'];
  903. // Delete children items.
  904. $num = $this->delete_children_items($id);
  905. if ($this->debug > 2) {
  906. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  907. }
  908. // Now delete the item.
  909. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  910. if ($this->debug > 2) {
  911. error_log('New LP - Deleting item: ' . $sql_del, 0);
  912. }
  913. $res_del = Database::query($sql_del);
  914. // Now update surrounding items.
  915. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  916. $res_upd = Database::query($sql_upd);
  917. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  918. $res_upd = Database::query($sql_upd);
  919. // Now update all following items with new display order.
  920. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  921. $res_all = Database::query($sql_all);
  922. //Removing prerequisites since the item will not longer exist
  923. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  924. $res_all = Database::query($sql_all);
  925. // Remove from search engine if enabled.
  926. if (api_get_setting('search_enabled') == 'true') {
  927. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  928. $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';
  929. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  930. $res = Database::query($sql);
  931. if (Database :: num_rows($res) > 0) {
  932. $row2 = Database :: fetch_array($res);
  933. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  934. $di = new DokeosIndexer();
  935. $di->remove_document((int) $row2['search_did']);
  936. }
  937. $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';
  938. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  939. Database::query($sql);
  940. }
  941. }
  942. /**
  943. * Updates an item's content in place
  944. * @param integer Element ID
  945. * @param integer Parent item ID
  946. * @param integer Previous item ID
  947. * @param string Item title
  948. * @param string Item description
  949. * @param string Prerequisites (optional)
  950. * @param string Indexing terms (optional)
  951. * @param array The array resulting of the $_FILES[mp3] element
  952. * @return boolean True on success, false on error
  953. */
  954. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  955. if ($this->debug > 0) {
  956. error_log('New LP - In learnpath::edit_item()', 0);
  957. }
  958. if (empty ($max_time_allowed)) {
  959. $max_time_allowed = 0;
  960. }
  961. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  962. return false;
  963. }
  964. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  965. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  966. $res_select = Database::query($sql_select);
  967. $row_select = Database :: fetch_array($res_select);
  968. $audio_update_sql = '';
  969. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  970. // Create the audio folder if it does not exist yet.
  971. global $_course;
  972. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  973. if (!is_dir($filepath . 'audio')) {
  974. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  975. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  976. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  977. }
  978. // Upload file in documents.
  979. $pi = pathinfo($audio['name']);
  980. if ($pi['extension'] == 'mp3') {
  981. $c_det = api_get_course_info($this->cc);
  982. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  983. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  984. $path = substr($path, 7);
  985. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  986. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  987. }
  988. }
  989. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  990. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  991. // TODO: htmlspecialchars to be checked for encoding related problems.
  992. if ($same_parent && $same_previous) {
  993. // Only update title and description.
  994. $sql_update = " UPDATE " . $tbl_lp_item . "
  995. SET title = '" . $this->escape_string($title) . "',
  996. prerequisite = '" . $prerequisites . "',
  997. description = '" . $this->escape_string($description) . "'
  998. " . $audio_update_sql . ",
  999. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  1000. WHERE id = " . $id;
  1001. $res_update = Database::query($sql_update);
  1002. } else {
  1003. $old_parent = $row_select['parent_item_id'];
  1004. $old_previous = $row_select['previous_item_id'];
  1005. $old_next = $row_select['next_item_id'];
  1006. $old_order = $row_select['display_order'];
  1007. $old_prerequisite = $row_select['prerequisite'];
  1008. $old_max_time_allowed = $row_select['max_time_allowed'];
  1009. /* BEGIN -- virtually remove the current item id */
  1010. /* for the next and previous item it is like the current item doesn't exist anymore */
  1011. if ($old_previous != 0) {
  1012. $sql_update_next = "
  1013. UPDATE " . $tbl_lp_item . "
  1014. SET next_item_id = " . $old_next . "
  1015. WHERE id = " . $old_previous;
  1016. $res_update_next = Database::query($sql_update_next);
  1017. //echo '<p>' . $sql_update_next . '</p>';
  1018. }
  1019. if ($old_next != 0) {
  1020. $sql_update_previous = "
  1021. UPDATE " . $tbl_lp_item . "
  1022. SET previous_item_id = " . $old_previous . "
  1023. WHERE id = " . $old_next;
  1024. $res_update_previous = Database::query($sql_update_previous);
  1025. //echo '<p>' . $sql_update_previous . '</p>';
  1026. }
  1027. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1028. $sql_update_order = "
  1029. UPDATE " . $tbl_lp_item . "
  1030. SET display_order = display_order - 1
  1031. WHERE
  1032. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1033. parent_item_id = " . $old_parent;
  1034. $res_update_order = Database::query($sql_update_order);
  1035. //echo '<p>' . $sql_update_order . '</p>';
  1036. /* END -- virtually remove the current item id */
  1037. /* BEGIN -- update the current item id to his new location */
  1038. if ($previous == 0) {
  1039. // Select the data of the item that should come after the current item.
  1040. $sql_select_old = "
  1041. SELECT
  1042. id,
  1043. display_order
  1044. FROM " . $tbl_lp_item . "
  1045. WHERE
  1046. lp_id = " . $this->lp_id . " AND
  1047. parent_item_id = " . $parent . " AND
  1048. previous_item_id = " . $previous;
  1049. $res_select_old = Database::query($sql_select_old);
  1050. $row_select_old = Database :: fetch_array($res_select_old);
  1051. //echo '<p>' . $sql_select_old . '</p>';
  1052. // If the new parent didn't have children before.
  1053. if (Database :: num_rows($res_select_old) == 0) {
  1054. $new_next = 0;
  1055. $new_order = 1;
  1056. } else {
  1057. $new_next = $row_select_old['id'];
  1058. $new_order = $row_select_old['display_order'];
  1059. }
  1060. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1061. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1062. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1063. } else {
  1064. // Select the data of the item that should come before the current item.
  1065. $sql_select_old = "
  1066. SELECT
  1067. next_item_id,
  1068. display_order
  1069. FROM " . $tbl_lp_item . "
  1070. WHERE id = " . $previous;
  1071. $res_select_old = Database::query($sql_select_old);
  1072. $row_select_old = Database :: fetch_array($res_select_old);
  1073. //echo '<p>' . $sql_select_old . '</p>';
  1074. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1075. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1076. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1077. $new_next = $row_select_old['next_item_id'];
  1078. $new_order = $row_select_old['display_order'] + 1;
  1079. }
  1080. // TODO: htmlspecialchars to be checked for encoding related problems.
  1081. // Update the current item with the new data.
  1082. $sql_update = "
  1083. UPDATE " . $tbl_lp_item . "
  1084. SET
  1085. title = '" . $this->escape_string($title) . "',
  1086. description = '" . $this->escape_string($description) . "',
  1087. parent_item_id = " . $parent . ",
  1088. previous_item_id = " . $previous . ",
  1089. next_item_id = " . $new_next . ",
  1090. display_order = " . $new_order . "
  1091. " . $audio_update_sql . "
  1092. WHERE id = " . $id;
  1093. $res_update_next = Database::query($sql_update);
  1094. //echo '<p>' . $sql_update . '</p>';
  1095. if ($previous != 0) {
  1096. // Update the previous item's next_item_id.
  1097. $sql_update_previous = "
  1098. UPDATE " . $tbl_lp_item . "
  1099. SET next_item_id = " . $id . "
  1100. WHERE id = " . $previous;
  1101. $res_update_next = Database::query($sql_update_previous);
  1102. //echo '<p>' . $sql_update_previous . '</p>';
  1103. }
  1104. if ($new_next != 0) {
  1105. // Update the next item's previous_item_id.
  1106. $sql_update_next = "
  1107. UPDATE " . $tbl_lp_item . "
  1108. SET previous_item_id = " . $id . "
  1109. WHERE id = " . $new_next;
  1110. $res_update_next = Database::query($sql_update_next);
  1111. //echo '<p>' . $sql_update_next . '</p>';
  1112. }
  1113. if ($old_prerequisite != $prerequisites) {
  1114. $sql_update_next = "
  1115. UPDATE " . $tbl_lp_item . "
  1116. SET prerequisite = " . $prerequisites . "
  1117. WHERE id = " . $id;
  1118. $res_update_next = Database::query($sql_update_next);
  1119. }
  1120. if ($old_max_time_allowed != $max_time_allowed) {
  1121. $sql_update_max_time_allowed = "
  1122. UPDATE " . $tbl_lp_item . "
  1123. SET max_time_allowed = " . $max_time_allowed . "
  1124. WHERE id = " . $id;
  1125. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1126. }
  1127. // Update all the items with the same or a bigger display_order than the current item.
  1128. $sql_update_order = "
  1129. UPDATE " . $tbl_lp_item . "
  1130. SET display_order = display_order + 1
  1131. WHERE
  1132. lp_id = " . $this->get_id() . " AND
  1133. id <> " . $id . " AND
  1134. parent_item_id = " . $parent . " AND
  1135. display_order >= " . $new_order;
  1136. $res_update_next = Database::query($sql_update_order);
  1137. }
  1138. }
  1139. /**
  1140. * Updates an item's prereq in place
  1141. * @param integer Element ID
  1142. * @param string Prerequisite Element ID
  1143. * @param string Prerequisite item type
  1144. * @param string Prerequisite min score
  1145. * @param string Prerequisite max score
  1146. * @return boolean True on success, false on error
  1147. */
  1148. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1149. if ($this->debug > 0) {
  1150. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1151. }
  1152. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1153. return false;
  1154. }
  1155. $prerequisite_id = $this->escape_string($prerequisite_id);
  1156. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1157. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1158. $mastery_score = 0;
  1159. if (!is_numeric($max_score) || $max_score < 0)
  1160. $max_score = 100;
  1161. if ($mastery_score > $max_score)
  1162. $max_score = $mastery_score;
  1163. if (!is_numeric($prerequisite_id))
  1164. $prerequisite_id = 'NULL';
  1165. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1166. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1167. $res_upd = Database::query($sql_upd);
  1168. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1169. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1170. mastery_score = " . $mastery_score .
  1171. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1172. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1173. $res_upd = Database::query($sql_upd);
  1174. }
  1175. // TODO: Update the item object (can be ignored for now because refreshed).
  1176. return true;
  1177. }
  1178. /**
  1179. * Escapes a string with the available database escape function
  1180. * @param string String to escape
  1181. * @return string String escaped
  1182. */
  1183. public function escape_string($string) {
  1184. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1185. return Database :: escape_string($string);
  1186. }
  1187. /**
  1188. * Static admin function exporting a learnpath into a zip file
  1189. * @param string Export type (scorm, zip, cd)
  1190. * @param string Course code
  1191. * @param integer Learnpath ID
  1192. * @param string Zip file name
  1193. * @return string Zip file path (or false on error)
  1194. */
  1195. public function export_lp($type, $course, $id, $zipname) {
  1196. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1197. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1198. return false;
  1199. }
  1200. $url = '';
  1201. switch ($type) {
  1202. case 'scorm':
  1203. break;
  1204. case 'zip':
  1205. break;
  1206. case 'cdrom':
  1207. break;
  1208. }
  1209. return $url;
  1210. }
  1211. /**
  1212. * Gets all the chapters belonging to the same parent as the item/chapter given
  1213. * Can also be called as abstract method
  1214. * @param integer Item ID
  1215. * @return array A list of all the "brother items" (or an empty array on failure)
  1216. */
  1217. public function get_brother_chapters($id) {
  1218. if ($this->debug > 0) {
  1219. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1220. }
  1221. if (empty ($id) OR $id != strval(intval($id))) {
  1222. return array ();
  1223. }
  1224. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1225. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1226. $res_parent = Database::query($sql_parent);
  1227. if (Database :: num_rows($res_parent) > 0) {
  1228. $row_parent = Database :: fetch_array($res_parent);
  1229. $parent = $row_parent['parent_item_id'];
  1230. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1231. $res_bros = Database::query($sql_bros);
  1232. $list = array ();
  1233. while ($row_bro = Database :: fetch_array($res_bros)) {
  1234. $list[] = $row_bro;
  1235. }
  1236. return $list;
  1237. }
  1238. return array ();
  1239. }
  1240. /**
  1241. * Gets all the items belonging to the same parent as the item given
  1242. * Can also be called as abstract method
  1243. * @param integer Item ID
  1244. * @return array A list of all the "brother items" (or an empty array on failure)
  1245. */
  1246. public function get_brother_items($id) {
  1247. if ($this->debug > 0) {
  1248. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1249. }
  1250. if (empty ($id) OR $id != strval(intval($id))) {
  1251. return array ();
  1252. }
  1253. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1254. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1255. $res_parent = Database::query($sql_parent);
  1256. if (Database :: num_rows($res_parent) > 0) {
  1257. $row_parent = Database :: fetch_array($res_parent);
  1258. $parent = $row_parent['parent_item_id'];
  1259. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1260. $res_bros = Database::query($sql_bros);
  1261. $list = array ();
  1262. while ($row_bro = Database :: fetch_array($res_bros)) {
  1263. $list[] = $row_bro;
  1264. }
  1265. return $list;
  1266. }
  1267. return array ();
  1268. }
  1269. /**
  1270. * Get the specific prefix index terms of this learning path
  1271. * @return array Array of terms
  1272. */
  1273. public function get_common_index_terms_by_prefix($prefix) {
  1274. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1275. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1276. $prefix_terms = array();
  1277. if (!empty($terms)) {
  1278. foreach ($terms as $term) {
  1279. $prefix_terms[] = $term['value'];
  1280. }
  1281. }
  1282. return $prefix_terms;
  1283. }
  1284. /**
  1285. * Gets the number of items currently completed
  1286. * @return integer The number of items currently completed
  1287. */
  1288. public function get_complete_items_count() {
  1289. if ($this->debug > 0) {
  1290. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1291. }
  1292. $i = 0;
  1293. foreach ($this->items as $id => $dummy) {
  1294. // Trying failed and browsed considered "progressed" as well.
  1295. if ($this->items[$id]->status_is(array (
  1296. 'completed',
  1297. 'passed',
  1298. 'succeeded',
  1299. 'browsed',
  1300. 'failed'
  1301. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1302. $i++;
  1303. }
  1304. }
  1305. return $i;
  1306. }
  1307. /**
  1308. * Gets the current item ID
  1309. * @return integer The current learnpath item id
  1310. */
  1311. public function get_current_item_id() {
  1312. $current = 0;
  1313. if ($this->debug > 0) {
  1314. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1315. }
  1316. if (!empty ($this->current)) {
  1317. $current = $this->current;
  1318. }
  1319. if ($this->debug > 2) {
  1320. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1321. }
  1322. return $current;
  1323. }
  1324. /**
  1325. * Force to get the first learnpath item id
  1326. * @return integer The current learnpath item id
  1327. */
  1328. public function get_first_item_id() {
  1329. $current = 0;
  1330. if (is_array($this->ordered_items)) {
  1331. $current = $this->ordered_items[0];
  1332. }
  1333. return $current;
  1334. }
  1335. /**
  1336. * Gets the total number of items available for viewing in this SCORM
  1337. * @return integer The total number of items
  1338. */
  1339. public function get_total_items_count() {
  1340. if ($this->debug > 0) {
  1341. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1342. }
  1343. return count($this->items);
  1344. }
  1345. /**
  1346. * Gets the total number of items available for viewing in this SCORM but without chapters
  1347. * @return integer The total no-chapters number of items
  1348. */
  1349. public function get_total_items_count_without_chapters() {
  1350. if ($this->debug > 0) {
  1351. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1352. }
  1353. $total = 0;
  1354. foreach ($this->items as $temp => $temp2) {
  1355. if (!in_array($temp2->get_type(), array (
  1356. 'dokeos_chapter',
  1357. 'chapter',
  1358. 'dir'
  1359. )))
  1360. $total++;
  1361. }
  1362. return $total;
  1363. }
  1364. /**
  1365. * Gets the first element URL.
  1366. * @return string URL to load into the viewer
  1367. */
  1368. public function first() {
  1369. if ($this->debug > 0) {
  1370. error_log('New LP - In learnpath::first()', 0);
  1371. }
  1372. // Test if the last_item_seen exists and is not a dir.
  1373. if (count($this->ordered_items) == 0) {
  1374. $this->index = 0;
  1375. }
  1376. if (!empty($this->last_item_seen) && !empty($this->items[$this->last_item_seen]) && $this->items[$this->last_item_seen]->get_type() != 'dir' && $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' && !$this->items[$this->last_item_seen]->is_done()) {
  1377. if ($this->debug > 2) {
  1378. 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);
  1379. }
  1380. $index = -1;
  1381. foreach ($this->ordered_items as $myindex => $item_id) {
  1382. if ($item_id == $this->last_item_seen) {
  1383. $index = $myindex;
  1384. break;
  1385. }
  1386. }
  1387. if ($index == -1) {
  1388. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1389. if ($this->debug > 2) {
  1390. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1391. }
  1392. return false;
  1393. } else {
  1394. $this->last = $this->last_item_seen;
  1395. $this->current = $this->last_item_seen;
  1396. $this->index = $index;
  1397. }
  1398. } else {
  1399. if ($this->debug > 2) {
  1400. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1401. }
  1402. $index = 0;
  1403. // Loop through all ordered items and stop at the first item that is
  1404. // not a directory *and* that has not been completed yet.
  1405. while (!empty($this->ordered_items[$index]) AND is_a($this->items[$this->ordered_items[$index]], 'learnpathItem') AND ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' OR $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter' OR $this->items[$this->ordered_items[$index]]->is_done() === true) AND $index < $this->max_ordered_items) {
  1406. $index++;
  1407. }
  1408. $this->last = $this->current;
  1409. // current is
  1410. $this->current = $this->ordered_items[$index];
  1411. $this->index = $index;
  1412. if ($this->debug > 2) {
  1413. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1414. }
  1415. }
  1416. if ($this->debug > 2) {
  1417. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1418. }
  1419. }
  1420. /**
  1421. * Gets the information about an item in a format usable as JavaScript to update
  1422. * the JS API by just printing this content into the <head> section of the message frame
  1423. * @param integer Item ID
  1424. * @return string
  1425. */
  1426. public function get_js_info($item_id = '') {
  1427. if ($this->debug > 0) {
  1428. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1429. }
  1430. $info = '';
  1431. $item_id = $this->escape_string($item_id);
  1432. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1433. //if item is defined, return values from DB
  1434. $oItem = $this->items[$item_id];
  1435. $info .= '<script language="javascript">';
  1436. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1437. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1438. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1439. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1440. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1441. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1442. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1443. $info .= "top.set_flag_synchronized();";
  1444. $info .= '</script>';
  1445. if ($this->debug > 2) {
  1446. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1447. }
  1448. return $info;
  1449. } else {
  1450. // If item_id is empty, just update to default SCORM data.
  1451. $info .= '<script language="javascript">';
  1452. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1453. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1454. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1455. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1456. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1457. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1458. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1459. $info .= "top.set_flag_synchronized();";
  1460. $info .= '</script>';
  1461. if ($this->debug > 2) {
  1462. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1463. }
  1464. return $info;
  1465. }
  1466. }
  1467. /**
  1468. * Gets the js library from the database
  1469. * @return string The name of the javascript library to be used
  1470. */
  1471. public function get_js_lib() {
  1472. $lib = '';
  1473. if (!empty ($this->js_lib)) {
  1474. $lib = $this->js_lib;
  1475. }
  1476. return $lib;
  1477. }
  1478. /**
  1479. * Gets the learnpath database ID
  1480. * @return integer Learnpath ID in the lp table
  1481. */
  1482. public function get_id() {
  1483. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1484. if (!empty ($this->lp_id)) {
  1485. return $this->lp_id;
  1486. } else {
  1487. return 0;
  1488. }
  1489. }
  1490. /**
  1491. * Gets the last element URL.
  1492. * @return string URL to load into the viewer
  1493. */
  1494. public function get_last() {
  1495. if ($this->debug > 0) {
  1496. error_log('New LP - In learnpath::get_last()', 0);
  1497. }
  1498. $this->index = count($this->ordered_items) - 1;
  1499. return $this->ordered_items[$this->index];
  1500. }
  1501. /**
  1502. * Gets the navigation bar for the learnpath display screen
  1503. * @return string The HTML string to use as a navigation bar
  1504. */
  1505. public function get_navigation_bar() {
  1506. if ($this->debug > 0) {
  1507. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1508. }
  1509. // TODO: Find a good value for the following variables.
  1510. $file = '';
  1511. $openDir = '';
  1512. $edoceo = '';
  1513. $time = 0;
  1514. $navbar = '';
  1515. $RequestUri = '';
  1516. $mycurrentitemid = $this->get_current_item_id();
  1517. if ($this->mode == 'fullscreen') {
  1518. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1519. ' <tr> ' . "\n" .
  1520. ' <td>' . "\n" .
  1521. ' <div class="buttons">' . "\n" .
  1522. ' <a href="lp_controller.php?action=stats" onClick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
  1523. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1524. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1525. //' <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" .
  1526. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1527. ' </div>' . "\n" .
  1528. ' </td>' . "\n" .
  1529. ' </tr>' . "\n" .
  1530. '</table>';
  1531. } else {
  1532. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1533. ' <tr> ' . "\n" .
  1534. ' <td>' . "\n" .
  1535. ' <div class="buttons">' . "\n" .
  1536. ' <a href="lp_controller.php?action=stats" onClick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
  1537. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1538. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1539. // ' <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" .
  1540. ' </div>' . "\n" .
  1541. ' </td>' . "\n" .
  1542. ' </tr>' . "\n" .
  1543. '</table>';
  1544. }
  1545. return $navbar;
  1546. }
  1547. /**
  1548. * Gets the next resource in queue (url).
  1549. * @return string URL to load into the viewer
  1550. */
  1551. public function get_next_index() {
  1552. if ($this->debug > 0) {
  1553. error_log('New LP - In learnpath::get_next_index()', 0);
  1554. }
  1555. // TODO
  1556. $index = $this->index;
  1557. $index++;
  1558. if ($this->debug > 2) {
  1559. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1560. }
  1561. 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) {
  1562. $index++;
  1563. if ($index == $this->max_ordered_items){
  1564. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1565. return $this->index;
  1566. } else {
  1567. return $index;
  1568. }
  1569. }
  1570. }
  1571. if (empty ($this->ordered_items[$index])) {
  1572. return $this->index;
  1573. }
  1574. if ($this->debug > 2) {
  1575. error_log('New LP - index is now ' . $index, 0);
  1576. }
  1577. return $index;
  1578. }
  1579. /**
  1580. * Gets item_id for the next element
  1581. * @return integer Next item (DB) ID
  1582. */
  1583. public function get_next_item_id() {
  1584. if ($this->debug > 0) {
  1585. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1586. }
  1587. $new_index = $this->get_next_index();
  1588. if (!empty ($new_index)) {
  1589. if (isset ($this->ordered_items[$new_index])) {
  1590. if ($this->debug > 2) {
  1591. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1592. }
  1593. return $this->ordered_items[$new_index];
  1594. }
  1595. }
  1596. if ($this->debug > 2) {
  1597. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1598. }
  1599. return 0;
  1600. }
  1601. /**
  1602. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1603. *
  1604. * Generally, the package provided is in the form of a zip file, so the function
  1605. * has been written to test a zip file. If not a zip, the function will return the
  1606. * default return value: ''
  1607. * @param string the path to the file
  1608. * @param string the original name of the file
  1609. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1610. */
  1611. public function get_package_type($file_path, $file_name) {
  1612. // Get name of the zip file without the extension.
  1613. $file_info = pathinfo($file_name);
  1614. $filename = $file_info['basename']; // Name including extension.
  1615. $extension = $file_info['extension']; // Extension only.
  1616. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1617. 'dll',
  1618. 'exe'
  1619. ))) {
  1620. return 'oogie';
  1621. }
  1622. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1623. 'dll',
  1624. 'exe'
  1625. ))) {
  1626. return 'woogie';
  1627. }
  1628. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1629. $zipFile = new pclZip($file_path);
  1630. // Check the zip content (real size and file extension).
  1631. $zipContentArray = $zipFile->listContent();
  1632. $package_type = '';
  1633. $at_root = false;
  1634. $manifest = '';
  1635. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1636. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1637. foreach ($zipContentArray as $thisContent) {
  1638. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1639. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1640. }
  1641. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1642. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1643. $package_type = 'scorm';
  1644. break; // Exit the foreach loop.
  1645. }
  1646. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1647. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1648. $package_type = 'aicc';
  1649. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1650. } else {
  1651. $package_type = '';
  1652. }
  1653. }
  1654. }
  1655. return $package_type;
  1656. }
  1657. /**
  1658. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1659. * @return string URL to load into the viewer
  1660. */
  1661. public function get_previous_index() {
  1662. if ($this->debug > 0) {
  1663. error_log('New LP - In learnpath::get_previous_index()', 0);
  1664. }
  1665. $index = $this->index;
  1666. if (isset ($this->ordered_items[$index -1])) {
  1667. $index--;
  1668. 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')) {
  1669. $index--;
  1670. if ($index < 0) {
  1671. return $this->index;
  1672. }
  1673. }
  1674. } else {
  1675. if ($this->debug > 2) {
  1676. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1677. }
  1678. // There is no previous item.
  1679. }
  1680. return $index;
  1681. }
  1682. /**
  1683. * Gets item_id for the next element
  1684. * @return integer Previous item (DB) ID
  1685. */
  1686. public function get_previous_item_id() {
  1687. if ($this->debug > 0) {
  1688. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1689. }
  1690. $new_index = $this->get_previous_index();
  1691. return $this->ordered_items[$new_index];
  1692. }
  1693. /**
  1694. * Gets the progress value from the progress_db attribute
  1695. * @return integer Current progress value
  1696. */
  1697. public function get_progress() {
  1698. if ($this->debug > 0) {
  1699. error_log('New LP - In learnpath::get_progress()', 0);
  1700. }
  1701. if (!empty ($this->progress_db)) {
  1702. return $this->progress_db;
  1703. }
  1704. return 0;
  1705. }
  1706. /**
  1707. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1708. * @param integer Learnpath ID
  1709. * @param integer User ID
  1710. * @param string Mode of display ('%','abs' or 'both')
  1711. * @param string Course database name (optional, defaults to '')
  1712. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1713. * @return integer Current progress value as found in the database
  1714. */
  1715. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1716. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1717. $session_id = intval($session_id);
  1718. $session_condition = api_get_session_condition($session_id);
  1719. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1720. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1721. $res = Database::query($sql);
  1722. $view_id = 0;
  1723. if (Database :: num_rows($res) > 0) {
  1724. $row = Database :: fetch_array($res);
  1725. $progress = $row['progress'];
  1726. $view_id = $row['id'];
  1727. } else {
  1728. if ($sincere) {
  1729. return null;
  1730. }
  1731. }
  1732. if (empty ($progress)) {
  1733. $progress = '0';
  1734. }
  1735. if ($mode == '%') {
  1736. return $progress . '%';
  1737. } else {
  1738. // Get the number of items completed and the number of items total.
  1739. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1740. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1741. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1742. $res = Database::query($sql);
  1743. $row = Database :: fetch_array($res);
  1744. $total = $row[0];
  1745. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1746. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1747. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1748. // Trying as also counting browsed and failed items.
  1749. $sql = "SELECT count(distinct(lp_item_id))
  1750. FROM $tbl_item_view as item_view
  1751. INNER JOIN $tbl_item as item
  1752. ON item.id = item_view.lp_item_id
  1753. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1754. WHERE lp_view_id = " . $view_id . "
  1755. AND status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1756. $res = Database::query($sql);
  1757. $row = Database :: fetch_array($res);
  1758. $completed = $row[0];
  1759. if ($mode == 'abs') {
  1760. return $completed . '/' . $total;
  1761. }
  1762. elseif ($mode == 'both') {
  1763. if ($progress < ($completed / ($total ? $total : 1))) {
  1764. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1765. }
  1766. return $progress . '% (' . $completed . '/' . $total . ')';
  1767. }
  1768. }
  1769. return $progress;
  1770. }
  1771. /**
  1772. * Returns the HTML necessary to print a mediaplayer block inside a page
  1773. * @return string The mediaplayer HTML
  1774. */
  1775. public function get_mediaplayer($autostart='true') {
  1776. global $_course;
  1777. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1778. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1779. // Getting all the information about the item.
  1780. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp inner join " . $tbl_lp_item_view . " as lp_view on lp.id = lp_view.lp_item_id " .
  1781. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1782. $result = Database::query($sql);
  1783. $row = Database::fetch_assoc($result);
  1784. $output = '';
  1785. if (!empty ($row['audio'])) {
  1786. $list = $_SESSION['oLP']->get_toc();
  1787. $type_quiz = false;
  1788. foreach($list as $toc) {
  1789. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1790. $type_quiz = true;
  1791. }
  1792. }
  1793. if ($type_quiz) {
  1794. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1795. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1796. } else {
  1797. $autostart_audio = $autostart;
  1798. }
  1799. } else {
  1800. $autostart_audio = 'true';
  1801. }
  1802. // The mp3 player.
  1803. $output = '<div id="container">';
  1804. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1805. $output .= '<script type="text/javascript">
  1806. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1807. s1.addParam("allowscriptaccess","always");
  1808. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1809. s1.write("container");
  1810. </script></div>';
  1811. }
  1812. return $output;
  1813. }
  1814. /**
  1815. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1816. * @param int Learnpath id
  1817. * @param int Student id
  1818. * @param string Course code (optional)
  1819. * @return bool True if
  1820. */
  1821. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1822. $lp_id = (int)$lp_id;
  1823. $course = api_get_course_info($course);
  1824. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
  1825. // Get current prerequisite
  1826. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
  1827. $rs = Database::query($sql);
  1828. if (Database::num_rows($rs)>0) {
  1829. $row = Database::fetch_array($rs);
  1830. $prerequisite = $row['prerequisite'];
  1831. $find = array(' ','-',':');
  1832. $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
  1833. $to = str_replace($find,'',api_get_local_time($row['expired_on']));
  1834. $is_visible = true;
  1835. $progress = 0;
  1836. if (!empty($prerequisite)) {
  1837. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1838. $progress = intval($progress);
  1839. if ($progress < 100) {
  1840. $is_visible = false;
  1841. }
  1842. }
  1843. // Also check the time availability of the learning path
  1844. if ($is_visible) {
  1845. $now = str_replace($find,'',api_get_local_time());
  1846. if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
  1847. $is_visible = false;
  1848. }
  1849. }
  1850. return $is_visible;
  1851. }
  1852. return false;
  1853. }
  1854. /**
  1855. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1856. * completed so far.
  1857. * @param string Mode in which we want the values
  1858. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1859. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1860. * @param boolean true if it comes from a Diplay LP view
  1861. * @return string HTML string containing the progress bar
  1862. */
  1863. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1864. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1865. global $lp_theme_css;
  1866. // Setting up the CSS path of the current style if exists.
  1867. if (!empty ($lp_theme_css)) {
  1868. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1869. } else {
  1870. $css_path = '../img/';
  1871. }
  1872. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1873. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1874. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1875. }
  1876. $text = $percentage . $text_add;
  1877. // Default progress bar config
  1878. // times that will be greater or shorter
  1879. $factor = 1.2;
  1880. if ($from_lp)
  1881. $progress_height = '26';
  1882. else
  1883. $progress_height = '16';
  1884. $size = str_replace('%', '', $percentage);
  1885. $output ='<div style="width:135px">' .
  1886. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1887. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1888. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1889. if ($percentage <= 98) {
  1890. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1891. } else {
  1892. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1893. }
  1894. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1895. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1896. return $output;
  1897. }
  1898. /**
  1899. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1900. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1901. * @param integer Additional steps to fake as completed
  1902. * @return list Percentage or number and symbol (% or /xx)
  1903. */
  1904. public function get_progress_bar_text($mode = '', $add = 0) {
  1905. if ($this->debug > 0) {
  1906. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1907. }
  1908. if (empty ($mode)) {
  1909. $mode = $this->progress_bar_mode;
  1910. }
  1911. $total_items = $this->get_total_items_count_without_chapters();
  1912. if ($this->debug > 2) {
  1913. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1914. }
  1915. $i = $this->get_complete_items_count();
  1916. if ($this->debug > 2) {
  1917. error_log('New LP - Items completed so far: ' . $i, 0);
  1918. }
  1919. if ($add != 0) {
  1920. $i += $add;
  1921. if ($this->debug > 2) {
  1922. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1923. }
  1924. }
  1925. $text = '';
  1926. if ($i > $total_items) {
  1927. $i = $total_items;
  1928. }
  1929. if ($mode == '%') {
  1930. if ($total_items > 0) {
  1931. $percentage = ((float) $i / (float) $total_items) * 100;
  1932. } else {
  1933. $percentage = 0;
  1934. }
  1935. $percentage = number_format($percentage, 0);
  1936. $text = '%';
  1937. }
  1938. elseif ($mode == 'abs') {
  1939. $percentage = $i;
  1940. $text = '/' . $total_items;
  1941. }
  1942. return array (
  1943. $percentage,
  1944. $text
  1945. );
  1946. }
  1947. /**
  1948. * Gets the progress bar mode
  1949. * @return string The progress bar mode attribute
  1950. */
  1951. public function get_progress_bar_mode() {
  1952. if ($this->debug > 0) {
  1953. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1954. }
  1955. if (!empty ($this->progress_bar_mode)) {
  1956. return $this->progress_bar_mode;
  1957. } else {
  1958. return '%';
  1959. }
  1960. }
  1961. /**
  1962. * Gets the learnpath proximity (remote or local)
  1963. * @return string Learnpath proximity
  1964. */
  1965. public function get_proximity() {
  1966. if ($this->debug > 0) {
  1967. error_log('New LP - In learnpath::get_proximity()', 0);
  1968. }
  1969. if (!empty ($this->proximity)) {
  1970. return $this->proximity;
  1971. } else {
  1972. return '';
  1973. }
  1974. }
  1975. /**
  1976. * Gets the learnpath theme (remote or local)
  1977. * @return string Learnpath theme
  1978. */
  1979. public function get_theme() {
  1980. if ($this->debug > 0) {
  1981. error_log('New LP - In learnpath::get_theme()', 0);
  1982. }
  1983. if (!empty ($this->theme)) {
  1984. return $this->theme;
  1985. } else {
  1986. return '';
  1987. }
  1988. }
  1989. /**
  1990. * Gets the learnpath session id
  1991. * @return string Learnpath theme
  1992. */
  1993. public function get_lp_session_id() {
  1994. if ($this->debug > 0) {
  1995. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1996. }
  1997. if (!empty ($this->lp_session_id)) {
  1998. return $this->lp_session_id;
  1999. } else {
  2000. return 0;
  2001. }
  2002. }
  2003. /**
  2004. * Gets the learnpath image
  2005. * @return string Web URL of the LP image
  2006. */
  2007. public function get_preview_image() {
  2008. if ($this->debug > 0) {
  2009. error_log('New LP - In learnpath::get_preview_image()', 0);
  2010. }
  2011. if (!empty ($this->preview_image)) {
  2012. return $this->preview_image;
  2013. } else {
  2014. return '';
  2015. }
  2016. }
  2017. /**
  2018. * Gets the learnpath author
  2019. * @return string LP's author
  2020. */
  2021. public function get_author() {
  2022. if ($this->debug > 0) {
  2023. error_log('New LP - In learnpath::get_author()', 0);
  2024. }
  2025. if (!empty ($this->author)) {
  2026. return $this->author;
  2027. } else {
  2028. return '';
  2029. }
  2030. }
  2031. /**
  2032. * Generate a new prerequisites string for a given item. If this item was a sco and
  2033. * its prerequisites were strings (instead of IDs), then transform those strings into
  2034. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2035. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2036. * same rule as the scorm_export() method
  2037. * @param integer Item ID
  2038. * @return string Prerequisites string ready for the export as SCORM
  2039. */
  2040. public function get_scorm_prereq_string($item_id) {
  2041. if ($this->debug > 0) {
  2042. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2043. }
  2044. if (!is_object($this->items[$item_id])) {
  2045. return false;
  2046. }
  2047. $oItem = $this->items[$item_id];
  2048. $prereq = $oItem->get_prereq_string();
  2049. if (empty ($prereq)) {
  2050. return '';
  2051. }
  2052. if (preg_match('/^\d+$/', $prereq) && is_object($this->items[$prereq])) { // If the prerequisite is a simple integer ID and this ID exists as an item ID,
  2053. // then simply return it (with the ITEM_ prefix).
  2054. return 'ITEM_' . $prereq;
  2055. } else {
  2056. if (isset ($this->refs_list[$prereq])) {
  2057. // It's a simple string item from which the ID can be found in the refs list,
  2058. // so we can transform it directly to an ID for export.
  2059. return 'ITEM_' . $this->refs_list[$prereq];
  2060. } else {
  2061. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2062. // and replace them, one by one, by the internal IDs (chamilo db)
  2063. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2064. // by a space as well.
  2065. $find = array (
  2066. '&',
  2067. '|',
  2068. '~',
  2069. '=',
  2070. '<>',
  2071. '{',
  2072. '}',
  2073. '*',
  2074. '(',
  2075. ')'
  2076. );
  2077. $replace = array (
  2078. ' ',
  2079. ' ',
  2080. ' ',
  2081. ' ',
  2082. ' ',
  2083. ' ',
  2084. ' ',
  2085. ' ',
  2086. ' ',
  2087. ' '
  2088. );
  2089. $prereq_mod = str_replace($find, $replace, $prereq);
  2090. $ids = split(' ', $prereq_mod);
  2091. foreach ($ids as $id) {
  2092. $id = trim($id);
  2093. if (isset ($this->refs_list[$id])) {
  2094. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2095. }
  2096. }
  2097. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2098. return $prereq;
  2099. }
  2100. }
  2101. }
  2102. /**
  2103. * Returns the XML DOM document's node
  2104. * @param resource Reference to a list of objects to search for the given ITEM_*
  2105. * @param string The identifier to look for
  2106. * @return mixed The reference to the element found with that identifier. False if not found
  2107. */
  2108. public function get_scorm_xml_node(& $children, $id) {
  2109. for ($i = 0; $i < $children->length; $i++) {
  2110. $item_temp = $children->item($i);
  2111. if ($item_temp->nodeName == 'item') {
  2112. if ($item_temp->getAttribute('identifier') == $id) {
  2113. return $item_temp;
  2114. }
  2115. }
  2116. $subchildren = $item_temp->childNodes;
  2117. if ($subchildren->length > 0) {
  2118. $val = $this->get_scorm_xml_node($subchildren, $id);
  2119. if (is_object($val)) {
  2120. return $val;
  2121. }
  2122. }
  2123. }
  2124. return false;
  2125. }
  2126. /**
  2127. * Returns a usable array of stats related to the current learnpath and user
  2128. * @return array Well-formatted array containing status for the current learnpath
  2129. */
  2130. public function get_stats() {
  2131. if ($this->debug > 0) {
  2132. error_log('New LP - In learnpath::get_stats()', 0);
  2133. }
  2134. // TODO
  2135. }
  2136. /**
  2137. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2138. * the given course (for all learnpaths and all users)
  2139. * @param string Course code
  2140. * @return array Well-formatted array containing status for the course's learnpaths
  2141. */
  2142. public function get_stats_course($course) {
  2143. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2144. // TODO
  2145. }
  2146. /**
  2147. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2148. * the given course and learnpath (for all users)
  2149. * @param string Course code
  2150. * @param integer Learnpath ID
  2151. * @return array Well-formatted array containing status for the specified learnpath
  2152. */
  2153. public function get_stats_lp($course, $lp) {
  2154. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2155. // TODO
  2156. }
  2157. /**
  2158. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2159. * the given course, learnpath and user.
  2160. * @param string Course code
  2161. * @param integer Learnpath ID
  2162. * @param integer User ID
  2163. * @return array Well-formatted array containing status for the specified learnpath and user
  2164. */
  2165. public function get_stats_lp_user($course, $lp, $user) {
  2166. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2167. // TODO
  2168. }
  2169. /**
  2170. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2171. * the given course and learnpath (for all users)
  2172. * @param string Course code
  2173. * @param integer User ID
  2174. * @return array Well-formatted array containing status for the user's learnpaths
  2175. */
  2176. public function get_stats_user($course, $user) {
  2177. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2178. // TODO
  2179. }
  2180. /**
  2181. * Gets the status list for all LP's items
  2182. * @return array Array of [index] => [item ID => current status]
  2183. */
  2184. public function get_items_status_list() {
  2185. if ($this->debug > 0) {
  2186. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2187. }
  2188. $list = array ();
  2189. foreach ($this->ordered_items as $item_id) {
  2190. $list[] = array (
  2191. $item_id => $this->items[$item_id]->get_status()
  2192. );
  2193. }
  2194. return $list;
  2195. }
  2196. /**
  2197. * Return the number of interactions for the given learnpath Item View ID.
  2198. * This method can be used as static.
  2199. * @param integer Item View ID
  2200. * @return integer Number of interactions
  2201. */
  2202. public function get_interactions_count_from_db($lp_iv_id = 0, $course_code = null) {
  2203. if (empty ($lp_iv_id)) {
  2204. return -1;
  2205. }
  2206. $course_info = api_get_course_info($course_code);
  2207. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION, $course_info['db_name']);
  2208. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2209. $res = Database::query($sql);
  2210. $row = Database :: fetch_array($res);
  2211. $num = $row[0];
  2212. return $num;
  2213. }
  2214. /**
  2215. * Return the interactions as an array for the given lp_iv_id.
  2216. * This method can be used as static.
  2217. * @param integer Learnpath Item View ID
  2218. * @return array
  2219. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2220. */
  2221. public function get_iv_interactions_array($lp_iv_id = 0) {
  2222. $list = array ();
  2223. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2224. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2225. $res = Database::query($sql);
  2226. $num = Database :: num_rows($res);
  2227. if ($num > 0) {
  2228. $list[] = array (
  2229. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2230. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2231. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2232. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2233. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2234. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2235. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2236. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2237. );
  2238. while ($row = Database :: fetch_array($res)) {
  2239. $list[] = array (
  2240. 'order_id' => ($row['order_id'] + 1),
  2241. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2242. 'type' => $row['interaction_type'],
  2243. 'time' => $row['completion_time'],
  2244. //'correct_responses' => $row['correct_responses'],
  2245. 'correct_responses' => '', // Hide correct responses from students.
  2246. 'student_response' => $row['student_response'],
  2247. 'result' => $row['result'],
  2248. 'latency' => $row['latency']
  2249. );
  2250. }
  2251. }
  2252. return $list;
  2253. }
  2254. /**
  2255. * Return the number of objectives for the given learnpath Item View ID.
  2256. * This method can be used as static.
  2257. * @param integer Item View ID
  2258. * @return integer Number of objectives
  2259. */
  2260. public function get_objectives_count_from_db($lp_iv_id = 0, $course_code = null) {
  2261. if (empty ($lp_iv_id)) {
  2262. return -1;
  2263. }
  2264. $course_info = api_get_course_info($course_code);
  2265. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE, $course_info['db_name']);
  2266. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2267. $res = Database::query($sql);
  2268. $row = Database :: fetch_array($res);
  2269. $num = $row[0];
  2270. return $num;
  2271. }
  2272. /**
  2273. * Return the objectives as an array for the given lp_iv_id.
  2274. * This method can be used as static.
  2275. * @param integer Learnpath Item View ID
  2276. * @return array
  2277. * @todo Translate labels
  2278. */
  2279. public function get_iv_objectives_array($lp_iv_id = 0) {
  2280. $list = array();
  2281. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2282. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2283. $res = Database::query($sql);
  2284. $num = Database :: num_rows($res);
  2285. if ($num > 0) {
  2286. $list[] = array (
  2287. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2288. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2289. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2290. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2291. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2292. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2293. );
  2294. while ($row = Database :: fetch_array($res)) {
  2295. $list[] = array (
  2296. 'order_id' => ($row['order_id'] + 1),
  2297. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2298. 'score_raw' => $row['score_raw'],
  2299. 'score_max' => $row['score_max'],
  2300. 'score_min' => $row['score_min'],
  2301. 'status' => $row['status']
  2302. );
  2303. }
  2304. }
  2305. return $list;
  2306. }
  2307. /**
  2308. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2309. * used by get_html_toc() to be ready to display
  2310. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2311. */
  2312. public function get_toc() {
  2313. if ($this->debug > 0) {
  2314. error_log('New LP - In learnpath::get_toc()', 0);
  2315. }
  2316. $toc = array ();
  2317. //echo "<pre>".print_r($this->items,true)."</pre>";
  2318. foreach ($this->ordered_items as $item_id) {
  2319. if ($this->debug > 2) {
  2320. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2321. }
  2322. // TODO: Change this link generation and use new function instead.
  2323. $toc[] = array (
  2324. 'id' => $item_id,
  2325. 'title' => $this->items[$item_id]->get_title(),
  2326. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2327. 'status' => $this->items[$item_id]->get_status(),
  2328. 'level' => $this->items[$item_id]->get_level(),
  2329. 'type' => $this->items[$item_id]->get_type(),
  2330. 'description' => $this->items[$item_id]->get_description(),
  2331. 'path' => $this->items[$item_id]->get_path(),
  2332. );
  2333. }
  2334. if ($this->debug > 2) {
  2335. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2336. }
  2337. return $toc;
  2338. }
  2339. /**
  2340. * Generate and return the table of contents for this learnpath. The JS
  2341. * table returned is used inside of scorm_api.php
  2342. * @return string A JS array vairiable construction
  2343. */
  2344. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2345. if ($this->debug > 0) {
  2346. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2347. }
  2348. $toc = $varname.' = new Array();';
  2349. //echo "<pre>".print_r($this->items,true)."</pre>";
  2350. foreach ($this->ordered_items as $item_id) {
  2351. if ($this->debug > 2) {
  2352. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2353. }
  2354. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2355. }
  2356. if ($this->debug > 2) {
  2357. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2358. }
  2359. return $toc;
  2360. }
  2361. /**
  2362. * Gets the learning path type
  2363. * @param boolean Return the name? If false, return the ID. Default is false.
  2364. * @return mixed Type ID or name, depending on the parameter
  2365. */
  2366. public function get_type($get_name = false) {
  2367. $res = false;
  2368. if ($this->debug > 0) {
  2369. error_log('New LP - In learnpath::get_type()', 0);
  2370. }
  2371. if (!empty ($this->type)) {
  2372. if ($get_name) {
  2373. // Get it from the lp_type table in main db.
  2374. } else {
  2375. $res = $this->type;
  2376. }
  2377. }
  2378. if ($this->debug > 2) {
  2379. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2380. }
  2381. return $res;
  2382. }
  2383. /**
  2384. * Gets the learning path type as static method
  2385. * @param boolean Return the name? If false, return the ID. Default is false.
  2386. * @return mixed Type ID or name, depending on the parameter
  2387. */
  2388. public function get_type_static($lp_id = 0) {
  2389. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2390. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2391. $res = Database::query($sql);
  2392. if ($res === false) {
  2393. return null;
  2394. }
  2395. if (Database :: num_rows($res) <= 0) {
  2396. return null;
  2397. }
  2398. $row = Database :: fetch_array($res);
  2399. return $row['lp_type'];
  2400. }
  2401. /**
  2402. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2403. * This method can be used as abstract and is recursive
  2404. * @param integer Learnpath ID
  2405. * @param integer Parent ID of the items to look for
  2406. * @return mixed Ordered list of item IDs or false on error
  2407. */
  2408. public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
  2409. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2410. $list = array();
  2411. if (empty ($lp)) {
  2412. return false;
  2413. }
  2414. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  2415. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2416. $res = Database::query($sql);
  2417. while ($row = Database :: fetch_array($res)) {
  2418. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
  2419. $list[] = $row['id'];
  2420. foreach ($sublist as $item) {
  2421. $list[] = $item;
  2422. }
  2423. }
  2424. return $list;
  2425. }
  2426. /**
  2427. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2428. * @return string HTML TOC ready to display
  2429. */
  2430. public function get_html_toc() {
  2431. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2432. $charset = api_get_system_encoding();
  2433. $display_action_links_with_icons = false;
  2434. if ($this->debug > 0) {
  2435. error_log('New LP - In learnpath::get_html_toc()', 0);
  2436. }
  2437. $list = $this->get_toc();
  2438. //echo $this->current;
  2439. //$parent = $this->items[$this->current]->get_parent();
  2440. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2441. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2442. // Build, display.
  2443. if ($is_allowed_to_edit) {
  2444. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2445. if ($this->get_lp_session_id() == api_get_session_id()) {
  2446. $html .= '<div id="actions_lp" class="actions_lp">';
  2447. if ($display_action_links_with_icons) {
  2448. $html .= '<div style = "text-align:center;">';
  2449. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32')."</a>";
  2450. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32')."</a>";
  2451. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2452. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2453. $html .= '</div>';
  2454. } else {
  2455. $html .= '<div style = "text-align:center;">';
  2456. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;gradebook=$gradebook&amp;action=build&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('Build') . "</a>";
  2457. $html .= "<a href='lp_controller.php?" . api_get_cidreq() . "&amp;action=admin_view&amp;lp_id=" . $this->lp_id . "' target='_parent'>" . get_lang('BasicOverview') . "</a>";
  2458. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2459. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2460. $html .= '</div>';
  2461. }
  2462. $html .= '</div>';
  2463. }
  2464. }
  2465. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2466. require_once 'resourcelinker.inc.php';
  2467. // Temporary variables.
  2468. $mycurrentitemid = $this->get_current_item_id();
  2469. $color_counter = 0;
  2470. $i = 0;
  2471. foreach ($list as $item) {
  2472. if ($this->debug > 2) {
  2473. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2474. }
  2475. // TODO: Complete this.
  2476. $icon_name = array (
  2477. 'not attempted' => '../img/notattempted.gif',
  2478. 'incomplete' => '../img/incomplete.png',
  2479. 'failed' => '../img/delete.png',
  2480. 'completed' => '../img/completed.png',
  2481. 'passed' => '../img/passed.png',
  2482. 'succeeded' => '../img/succeeded.png',
  2483. 'browsed' => '../img/completed.png',
  2484. );
  2485. $style = 'scorm_item';
  2486. $scorm_color_background = 'scorm_item';
  2487. $style_item = 'scorm_item';
  2488. $current = false;
  2489. if ($item['id'] == $this->current) {
  2490. $style = 'scorm_item_highlight';
  2491. $scorm_color_background = 'scorm_item_highlight';
  2492. } else
  2493. if ($color_counter % 2 == 0) {
  2494. $scorm_color_background = 'scorm_item_1';
  2495. } else {
  2496. $scorm_color_background = 'scorm_item_2';
  2497. }
  2498. if ($scorm_color_background != '') {
  2499. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2500. }
  2501. // The anchor will let us center the TOC on the currently viewed item &^D
  2502. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2503. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2504. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2505. } else {
  2506. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2507. }
  2508. $title = $item['title'];
  2509. if (empty ($title)) {
  2510. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2511. }
  2512. $title = Security::remove_XSS($title);
  2513. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2514. //$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>" ;
  2515. $url = $this->get_link('http', $item['id']);
  2516. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2517. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2518. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2519. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2520. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2521. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2522. } elseif ($item['type'] == 'dir') {
  2523. $html .= stripslashes($title);
  2524. }
  2525. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2526. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2527. $user_id = api_get_user_id();
  2528. $course_id = api_get_course_id();
  2529. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2530. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2531. $result = Database::query($sql);
  2532. $count = Database :: num_rows($result);
  2533. if ($item['type'] == 'quiz') {
  2534. if ($item['status'] == 'completed') {
  2535. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2536. }
  2537. } else {
  2538. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2539. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2540. }
  2541. }
  2542. $html .= "</div>";
  2543. if ($scorm_color_background != '') {
  2544. $html .= '</div>';
  2545. }
  2546. $color_counter++;
  2547. }
  2548. $html .= "</div>";
  2549. return $html;
  2550. }
  2551. /**
  2552. * Gets the learnpath maker name - generally the editor's name
  2553. * @return string Learnpath maker name
  2554. */
  2555. public function get_maker() {
  2556. if ($this->debug > 0) {
  2557. error_log('New LP - In learnpath::get_maker()', 0);
  2558. }
  2559. if (!empty ($this->maker)) {
  2560. return $this->maker;
  2561. } else {
  2562. return '';
  2563. }
  2564. }
  2565. /**
  2566. * Gets the user-friendly message stored in $this->message
  2567. * @return string Message
  2568. */
  2569. public function get_message() {
  2570. if ($this->debug > 0) {
  2571. error_log('New LP - In learnpath::get_message()', 0);
  2572. }
  2573. return $this->message;
  2574. }
  2575. /**
  2576. * Gets the learnpath name/title
  2577. * @return string Learnpath name/title
  2578. */
  2579. public function get_name() {
  2580. if ($this->debug > 0) {
  2581. error_log('New LP - In learnpath::get_name()', 0);
  2582. }
  2583. if (!empty ($this->name)) {
  2584. return $this->name;
  2585. } else {
  2586. return 'N/A';
  2587. }
  2588. }
  2589. /**
  2590. * Gets a link to the resource from the present location, depending on item ID.
  2591. * @param string Type of link expected
  2592. * @param integer Learnpath item ID
  2593. * @return string Link to the lp_item resource
  2594. */
  2595. public function get_link($type = 'http', $item_id = null) {
  2596. if ($this->debug > 0) {
  2597. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2598. }
  2599. if (empty($item_id)) {
  2600. if ($this->debug > 2) {
  2601. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2602. }
  2603. $item_id = $this->get_current_item_id();
  2604. }
  2605. if (empty ($item_id)) {
  2606. if ($this->debug > 2) {
  2607. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2608. }
  2609. //still empty, this means there was no item_id given and we are not in an object context or
  2610. //the object property is empty, return empty link
  2611. $item_id = $this->first();
  2612. return '';
  2613. }
  2614. $file = '';
  2615. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2616. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2617. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2618. $item_id = Database::escape_string($item_id);
  2619. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2620. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2621. if ($this->debug > 2) {
  2622. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2623. }
  2624. $res = Database::query($sel);
  2625. if (Database :: num_rows($res) > 0) {
  2626. $row = Database :: fetch_array($res);
  2627. $lp_type = $row['ltype'];
  2628. $lp_path = $row['lpath'];
  2629. $lp_item_type = $row['litype'];
  2630. $lp_item_path = $row['lipath'];
  2631. $lp_item_params = $row['liparams'];
  2632. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2633. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2634. }
  2635. //$lp_item_params = '?'.$lp_item_params;
  2636. //add ? if none - left commented to give freedom to scorm implementation
  2637. //if(substr($lp_item_params,0,1)!='?'){
  2638. // $lp_item_params = '?'.$lp_item_params;
  2639. //}
  2640. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2641. if ($type == 'http') {
  2642. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2643. } else {
  2644. $course_path = $sys_course_path; //system path
  2645. }
  2646. // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc), then change the lp type to thread it as a normal Chamilo LP not a SCO.
  2647. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2648. $lp_type = 1;
  2649. }
  2650. // Now go through the specific cases to get the end of the path.
  2651. // @todo Use constants instead of int values.
  2652. switch ($lp_type) {
  2653. case 1 :
  2654. if ($lp_item_type == 'dokeos_chapter') {
  2655. $file = 'lp_content.php?type=dir';
  2656. } else {
  2657. require_once 'resourcelinker.inc.php';
  2658. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2659. //CEV CHANGE
  2660. if ($lp_item_type == 'link') {
  2661. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2662. if (is_youtube_link($file)) {
  2663. $src = get_youtube_video_id($file);
  2664. $file = 'embed.php?type=youtube&src='.$src;
  2665. }
  2666. } else {
  2667. // check how much attempts of a exercise exits in lp
  2668. $lp_item_id = $this->get_current_item_id();
  2669. $lp_view_id = $this->get_view_id();
  2670. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2671. $list = $this->get_toc();
  2672. $type_quiz = false;
  2673. foreach ($list as $toc) {
  2674. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2675. $type_quiz = true;
  2676. }
  2677. }
  2678. if ($type_quiz) {
  2679. $lp_item_id = Database :: escape_string($lp_item_id);
  2680. $lp_view_id = Database :: escape_string($lp_view_id);
  2681. $sql = "SELECT count(*) FROM $lp_item_view_table WHERE lp_item_id='" . (int) $lp_item_id . "' AND lp_view_id ='" . (int) $lp_view_id . "' AND status='completed'";
  2682. $result = Database::query($sql);
  2683. $row_count = Database :: fetch_row($result);
  2684. $count_item_view = (int) $row_count[0];
  2685. $not_multiple_attempt = 0;
  2686. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2687. $not_multiple_attempt = 1;
  2688. }
  2689. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2690. }
  2691. $tmp_array = explode('/', $file);
  2692. $document_name = $tmp_array[count($tmp_array) - 1];
  2693. if (strpos($document_name, '_DELETED_')) {
  2694. $file = 'blank.php?error=document_deleted';
  2695. }
  2696. }
  2697. }
  2698. break;
  2699. case 2 :
  2700. if ($this->debug > 2) {
  2701. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2702. }
  2703. if ($lp_item_type != 'dir') {
  2704. // Quite complex here:
  2705. // We want to make sure 'http://' (and similar) links can
  2706. // be loaded as is (withouth the Chamilo path in front) but
  2707. // some contents use this form: resource.htm?resource=http://blablabla
  2708. // which means we have to find a protocol at the path's start, otherwise
  2709. // it should not be considered as an external URL.
  2710. //if ($this->prerequisites_match($item_id)) {
  2711. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2712. if ($this->debug > 2) {
  2713. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2714. }
  2715. // Distant url, return as is.
  2716. $file = $lp_item_path;
  2717. } else {
  2718. if ($this->debug > 2) {
  2719. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2720. }
  2721. // Prevent getting untranslatable urls.
  2722. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2723. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2724. // Prepare the path.
  2725. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2726. // TODO: Fix this for urls with protocol header.
  2727. $file = str_replace('//', '/', $file);
  2728. $file = str_replace(':/', '://', $file);
  2729. if (substr($lp_path, -1) == '/') {
  2730. $lp_path = substr($lp_path, 0, -1);
  2731. }
  2732. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2733. // if file not found.
  2734. $decoded = html_entity_decode($lp_item_path);
  2735. list ($decoded) = explode('?', $decoded);
  2736. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2737. require_once 'resourcelinker.inc.php';
  2738. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2739. if (empty($file)) {
  2740. $file = 'blank.php?error=document_not_found';
  2741. } else {
  2742. $tmp_array = explode('/', $file);
  2743. $document_name = $tmp_array[count($tmp_array) - 1];
  2744. if (strpos($document_name, '_DELETED_')) {
  2745. $file = 'blank.php?error=document_deleted';
  2746. } else {
  2747. $file = 'blank.php?error=document_not_found';
  2748. }
  2749. }
  2750. } else {
  2751. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2752. }
  2753. }
  2754. }
  2755. //}else{
  2756. //prerequisites did not match
  2757. //$file = 'blank.php';
  2758. //}
  2759. // We want to use parameters if they were defined in the imsmanifest.
  2760. if ($file != 'blank.php') {
  2761. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2762. }
  2763. } else {
  2764. $file = 'lp_content.php?type=dir';
  2765. }
  2766. break;
  2767. case 3 :
  2768. if ($this->debug > 2) {
  2769. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2770. }
  2771. // Formatting AICC HACP append URL.
  2772. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2773. if ($lp_item_type != 'dir') {
  2774. // Quite complex here:
  2775. // We want to make sure 'http://' (and similar) links can
  2776. // be loaded as is (withouth the Chamilo path in front) but
  2777. // some contents use this form: resource.htm?resource=http://blablabla
  2778. // which means we have to find a protocol at the path's start, otherwise
  2779. // it should not be considered as an external URL.
  2780. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2781. if ($this->debug > 2) {
  2782. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2783. }
  2784. // Distant url, return as is.
  2785. $file = $lp_item_path;
  2786. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2787. /*
  2788. if (stristr($file,'<servername>') !== false) {
  2789. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2790. }
  2791. */
  2792. if (stripos($file, '<servername>') !== false) {
  2793. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2794. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2795. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2796. }
  2797. //
  2798. $file .= $aicc_append;
  2799. } else {
  2800. if ($this->debug > 2) {
  2801. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2802. }
  2803. // Prevent getting untranslatable urls.
  2804. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2805. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2806. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2807. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2808. // TODO: Fix this for urls with protocol header.
  2809. $file = str_replace('//', '/', $file);
  2810. $file = str_replace(':/', '://', $file);
  2811. $file .= $aicc_append;
  2812. }
  2813. } else {
  2814. $file = 'lp_content.php?type=dir';
  2815. }
  2816. break;
  2817. case 4 :
  2818. break;
  2819. default :
  2820. break;
  2821. }
  2822. }
  2823. if ($this->debug > 2) {
  2824. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2825. }
  2826. return $file;
  2827. }
  2828. /**
  2829. * Gets the latest usable view or generate a new one
  2830. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2831. * @return integer DB lp_view id
  2832. */
  2833. public function get_view($attempt_num = 0) {
  2834. if ($this->debug > 0) {
  2835. error_log('New LP - In learnpath::get_view()', 0);
  2836. }
  2837. $search = '';
  2838. // Use $attempt_num to enable multi-views management (disabled so far).
  2839. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2840. $search = 'AND view_count = ' . $attempt_num;
  2841. }
  2842. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2843. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2844. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2845. "WHERE lp_id = " . $this->get_id() . " " .
  2846. "AND user_id = " . $this->get_user_id() . " " .
  2847. $search .
  2848. " ORDER BY view_count DESC";
  2849. $res = Database::query($sql);
  2850. if (Database :: num_rows($res) > 0) {
  2851. $row = Database :: fetch_array($res);
  2852. $this->lp_view_id = $row['id'];
  2853. } else {
  2854. // There is no database record, create one.
  2855. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2856. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2857. $res = Database::query($sql);
  2858. $id = Database :: insert_id();
  2859. $this->lp_view_id = $id;
  2860. }
  2861. return $this->lp_view_id;
  2862. }
  2863. /**
  2864. * Gets the current view id
  2865. * @return integer View ID (from lp_view)
  2866. */
  2867. public function get_view_id() {
  2868. if ($this->debug > 0) {
  2869. error_log('New LP - In learnpath::get_view_id()', 0);
  2870. }
  2871. if (!empty ($this->lp_view_id)) {
  2872. return $this->lp_view_id;
  2873. } else {
  2874. return 0;
  2875. }
  2876. }
  2877. /**
  2878. * Gets the update queue
  2879. * @return array Array containing IDs of items to be updated by JavaScript
  2880. */
  2881. public function get_update_queue() {
  2882. if ($this->debug > 0) {
  2883. error_log('New LP - In learnpath::get_update_queue()', 0);
  2884. }
  2885. return $this->update_queue;
  2886. }
  2887. /**
  2888. * Gets the user ID
  2889. * @return integer User ID
  2890. */
  2891. public function get_user_id() {
  2892. if ($this->debug > 0) {
  2893. error_log('New LP - In learnpath::get_user_id()', 0);
  2894. }
  2895. if (!empty ($this->user_id)) {
  2896. return $this->user_id;
  2897. } else {
  2898. return false;
  2899. }
  2900. }
  2901. /**
  2902. * Checks if any of the items has an audio element attached
  2903. * @return bool True or false
  2904. */
  2905. public function has_audio() {
  2906. if ($this->debug > 1) {
  2907. error_log('New LP - In learnpath::has_audio()', 0);
  2908. }
  2909. $has = false;
  2910. foreach ($this->items as $i => $item) {
  2911. if (!empty ($this->items[$i]->audio)) {
  2912. $has = true;
  2913. break;
  2914. }
  2915. }
  2916. return $has;
  2917. }
  2918. /**
  2919. * Logs a message into a file
  2920. * @param string Message to log
  2921. * @return boolean True on success, false on error or if msg empty
  2922. */
  2923. public function log($msg) {
  2924. if ($this->debug > 0) {
  2925. error_log('New LP - In learnpath::log()', 0);
  2926. }
  2927. // TODO
  2928. $this->error .= $msg;
  2929. return true;
  2930. }
  2931. /**
  2932. * Moves an item up and down at its level
  2933. * @param integer Item to move up and down
  2934. * @param string Direction 'up' or 'down'
  2935. * @return integer New display order, or false on error
  2936. */
  2937. public function move_item($id, $direction) {
  2938. if ($this->debug > 0) {
  2939. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2940. }
  2941. if (empty ($id) or empty ($direction)) {
  2942. return false;
  2943. }
  2944. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2945. $sql_sel = "
  2946. SELECT *
  2947. FROM " . $tbl_lp_item . "
  2948. WHERE id = " . $id;
  2949. $res_sel = Database::query($sql_sel);
  2950. // Check if elem exists.
  2951. if (Database :: num_rows($res_sel) < 1) {
  2952. return false;
  2953. }
  2954. // Gather data.
  2955. $row = Database :: fetch_array($res_sel);
  2956. $previous = $row['previous_item_id'];
  2957. $next = $row['next_item_id'];
  2958. $display = $row['display_order'];
  2959. $parent = $row['parent_item_id'];
  2960. $lp = $row['lp_id'];
  2961. // Update the item (switch with previous/next one).
  2962. switch ($direction) {
  2963. case 'up' :
  2964. if ($this->debug > 2) {
  2965. error_log('Movement up detected', 0);
  2966. }
  2967. if ($display <= 1) { /*do nothing*/
  2968. } else {
  2969. $sql_sel2 = "SELECT *
  2970. FROM $tbl_lp_item
  2971. WHERE id = $previous";
  2972. if ($this->debug > 2) {
  2973. error_log('Selecting previous: ' . $sql_sel2, 0);
  2974. }
  2975. $res_sel2 = Database::query($sql_sel2);
  2976. if (Database :: num_rows($res_sel2) < 1) {
  2977. $previous_previous = 0;
  2978. }
  2979. // Gather data.
  2980. $row2 = Database :: fetch_array($res_sel2);
  2981. $previous_previous = $row2['previous_item_id'];
  2982. // Update previous_previous item (switch "next" with current).
  2983. if ($previous_previous != 0) {
  2984. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2985. if ($this->debug > 2) {
  2986. error_log($sql_upd2, 0);
  2987. }
  2988. $res_upd2 = Database::query($sql_upd2);
  2989. }
  2990. // Update previous item (switch with current).
  2991. if ($previous != 0) {
  2992. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2993. if ($this->debug > 2) {
  2994. error_log($sql_upd2, 0);
  2995. }
  2996. $res_upd2 = Database::query($sql_upd2);
  2997. }
  2998. // Update current item (switch with previous).
  2999. if ($id != 0) {
  3000. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  3001. if ($this->debug > 2) {
  3002. error_log($sql_upd2, 0);
  3003. }
  3004. $res_upd2 = Database::query($sql_upd2);
  3005. }
  3006. // Update next item (new previous item).
  3007. if ($next != 0) {
  3008. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  3009. if ($this->debug > 2) {
  3010. error_log($sql_upd2, 0);
  3011. }
  3012. $res_upd2 = Database::query($sql_upd2);
  3013. }
  3014. $display = $display -1;
  3015. }
  3016. break;
  3017. case 'down' :
  3018. if ($this->debug > 2) {
  3019. error_log('Movement down detected', 0);
  3020. }
  3021. if ($next == 0) { /* Do nothing. */
  3022. } else {
  3023. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  3024. if ($this->debug > 2) {
  3025. error_log('Selecting next: ' . $sql_sel2, 0);
  3026. }
  3027. $res_sel2 = Database::query($sql_sel2);
  3028. if (Database :: num_rows($res_sel2) < 1) {
  3029. $next_next = 0;
  3030. }
  3031. // Gather data.
  3032. $row2 = Database :: fetch_array($res_sel2);
  3033. $next_next = $row2['next_item_id'];
  3034. // Update previous item (switch with current).
  3035. if ($previous != 0) {
  3036. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3037. $res_upd2 = Database::query($sql_upd2);
  3038. }
  3039. // Update current item (switch with previous).
  3040. if ($id != 0) {
  3041. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3042. $res_upd2 = Database::query($sql_upd2);
  3043. }
  3044. // Update next item (new previous item).
  3045. if ($next != 0) {
  3046. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3047. $res_upd2 = Database::query($sql_upd2);
  3048. }
  3049. // Update next_next item (switch "previous" with current).
  3050. if ($next_next != 0) {
  3051. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3052. $res_upd2 = Database::query($sql_upd2);
  3053. }
  3054. $display = $display +1;
  3055. }
  3056. break;
  3057. default :
  3058. return false;
  3059. }
  3060. return $display;
  3061. }
  3062. /**
  3063. * Move a learnpath up (display_order)
  3064. * @param integer Learnpath ID
  3065. */
  3066. public function move_up($lp_id) {
  3067. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3068. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3069. $res = Database::query($sql);
  3070. if ($res === false)
  3071. return false;
  3072. $lps = array ();
  3073. $lp_order = array ();
  3074. $num = Database :: num_rows($res);
  3075. // First check the order is correct, globally (might be wrong because
  3076. // of versions < 1.8.4)
  3077. if ($num > 0) {
  3078. $i = 1;
  3079. while ($row = Database :: fetch_array($res)) {
  3080. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3081. $need_fix = true;
  3082. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3083. $res_u = Database::query($sql_u);
  3084. }
  3085. $row['display_order'] = $i;
  3086. $lps[$row['id']] = $row;
  3087. $lp_order[$i] = $row['id'];
  3088. $i++;
  3089. }
  3090. }
  3091. if ($num > 1) { // If there's only one element, no need to sort.
  3092. $order = $lps[$lp_id]['display_order'];
  3093. if ($order > 1) { // If it's the first element, no need to move up.
  3094. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3095. $res_u1 = Database::query($sql_u1);
  3096. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3097. $res_u2 = Database::query($sql_u2);
  3098. }
  3099. }
  3100. }
  3101. /**
  3102. * Move a learnpath down (display_order)
  3103. * @param integer Learnpath ID
  3104. */
  3105. public function move_down($lp_id) {
  3106. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3107. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3108. $res = Database::query($sql);
  3109. if ($res === false)
  3110. return false;
  3111. $lps = array ();
  3112. $lp_order = array ();
  3113. $num = Database :: num_rows($res);
  3114. $max = 0;
  3115. // First check the order is correct, globally (might be wrong because
  3116. // of versions < 1.8.4).
  3117. if ($num > 0) {
  3118. $i = 1;
  3119. while ($row = Database :: fetch_array($res)) {
  3120. $max = $i;
  3121. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3122. $need_fix = true;
  3123. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3124. $res_u = Database::query($sql_u);
  3125. }
  3126. $row['display_order'] = $i;
  3127. $lps[$row['id']] = $row;
  3128. $lp_order[$i] = $row['id'];
  3129. $i++;
  3130. }
  3131. }
  3132. if ($num > 1) { // If there's only one element, no need to sort.
  3133. $order = $lps[$lp_id]['display_order'];
  3134. if ($order < $max) { // If it's the first element, no need to move up.
  3135. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3136. $res_u1 = Database::query($sql_u1);
  3137. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3138. $res_u2 = Database::query($sql_u2);
  3139. }
  3140. }
  3141. }
  3142. /**
  3143. * Updates learnpath attributes to point to the next element
  3144. * The last part is similar to set_current_item but processing the other way around
  3145. */
  3146. public function next() {
  3147. if ($this->debug > 0) {
  3148. error_log('New LP - In learnpath::next()', 0);
  3149. }
  3150. $this->last = $this->get_current_item_id();
  3151. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3152. $this->autocomplete_parents($this->last);
  3153. $new_index = $this->get_next_index();
  3154. if ($this->debug > 2) {
  3155. error_log('New LP - New index: ' . $new_index, 0);
  3156. }
  3157. $this->index = $new_index;
  3158. if ($this->debug > 2) {
  3159. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3160. }
  3161. $this->current = $this->ordered_items[$new_index];
  3162. if ($this->debug > 2) {
  3163. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3164. }
  3165. }
  3166. /**
  3167. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3168. * class, this might be redefined to allow several behaviours depending on the document type.
  3169. * @param integer Resource ID
  3170. * @return boolean True on success, false otherwise
  3171. */
  3172. public function open($id) {
  3173. if ($this->debug > 0) {
  3174. error_log('New LP - In learnpath::open()', 0);
  3175. }
  3176. // TODO:
  3177. // set the current resource attribute to this resource
  3178. // switch on element type (redefine in child class?)
  3179. // set status for this item to "opened"
  3180. // start timer
  3181. // initialise score
  3182. $this->index = 0; //or = the last item seen (see $this->last)
  3183. }
  3184. /**
  3185. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3186. * and the prerequisite string on error.
  3187. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3188. * @param integer Optional item ID. If none given, uses the current open item.
  3189. * @return boolean True if prerequisites are matched, false otherwise
  3190. * @return string Empty string if true returned, prerequisites string otherwise.
  3191. */
  3192. public function prerequisites_match($item = null) {
  3193. if ($this->debug > 0) {
  3194. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3195. }
  3196. if (empty ($item)) {
  3197. $item = $this->current;
  3198. }
  3199. if (is_object($this->items[$item])) {
  3200. $prereq_string = $this->items[$item]->get_prereq_string();
  3201. if (empty ($prereq_string)) {
  3202. return true;
  3203. }
  3204. // Clean spaces.
  3205. $prereq_string = str_replace(' ', '', $prereq_string);
  3206. if ($this->debug > 0) {
  3207. error_log('Found prereq_string: ' . $prereq_string, 0);
  3208. }
  3209. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3210. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3211. if ($result === false) {
  3212. $this->set_error_msg($this->items[$item]->prereq_alert);
  3213. }
  3214. } else {
  3215. $result = true;
  3216. if ($this->debug > 1) {
  3217. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3218. }
  3219. }
  3220. if ($this->debug > 1) {
  3221. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3222. }
  3223. return $result;
  3224. }
  3225. /**
  3226. * Updates learnpath attributes to point to the previous element
  3227. * The last part is similar to set_current_item but processing the other way around
  3228. */
  3229. public function previous() {
  3230. if ($this->debug > 0) {
  3231. error_log('New LP - In learnpath::previous()', 0);
  3232. }
  3233. $this->last = $this->get_current_item_id();
  3234. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3235. $this->autocomplete_parents($this->last);
  3236. $new_index = $this->get_previous_index();
  3237. $this->index = $new_index;
  3238. $this->current = $this->ordered_items[$new_index];
  3239. }
  3240. /**
  3241. * Publishes a learnpath. This basically means show or hide the learnpath
  3242. * to normal users.
  3243. * Can be used as abstract
  3244. * @param integer Learnpath ID
  3245. * @param string New visibility
  3246. */
  3247. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3248. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3249. $action = 'visible';
  3250. if ($set_visibility != 1) {
  3251. $action = 'invisible';
  3252. }
  3253. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3254. }
  3255. /**
  3256. * Publishes a learnpath. This basically means show or hide the learnpath
  3257. * on the course homepage
  3258. * Can be used as abstract
  3259. * @param integer Learnpath id
  3260. * @param string New visibility (v/s - visible/invisible)
  3261. */
  3262. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3263. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3264. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3265. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3266. $result = Database::query($sql);
  3267. $row = Database :: fetch_array($result);
  3268. $name = domesticate($row['name']);
  3269. if ($set_visibility == 'i') {
  3270. $s = $name . " " . get_lang('_no_published');
  3271. $dialogBox = $s;
  3272. $v = 0;
  3273. }
  3274. if ($set_visibility == 'v') {
  3275. $s = $name . " " . get_lang('_published');
  3276. $dialogBox = $s;
  3277. $v = 1;
  3278. }
  3279. $session_id = api_get_session_id();
  3280. $session_condition = api_get_session_condition($session_id);
  3281. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3282. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3283. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3284. $result = Database::query($sql);
  3285. $num = Database :: num_rows($result);
  3286. $row2 = Database :: fetch_array($result);
  3287. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3288. if (($set_visibility == 'i') && ($num > 0)) {
  3289. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3290. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3291. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool, session_id) VALUES ('$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3292. } else {
  3293. // Parameter and database incompatible, do nothing.
  3294. }
  3295. $result = Database::query($sql);
  3296. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3297. }
  3298. /**
  3299. * Restart the whole learnpath. Return the URL of the first element.
  3300. * Make sure the results are saved with anoter method. This method should probably be
  3301. * redefined in children classes.
  3302. * To use a similar method statically, use the create_new_attempt() method
  3303. * @return string URL to load in the viewer
  3304. */
  3305. public function restart() {
  3306. if ($this->debug > 0) {
  3307. error_log('New LP - In learnpath::restart()', 0);
  3308. }
  3309. // TODO
  3310. // Call autosave method to save the current progress.
  3311. //$this->index = 0;
  3312. $session_id = api_get_session_id();
  3313. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3314. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3315. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3316. if ($this->debug > 2) {
  3317. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3318. }
  3319. $res = Database::query($sql);
  3320. if ($view_id = Database :: insert_id($res)) {
  3321. $this->lp_view_id = $view_id;
  3322. $this->attempt = $this->attempt + 1;
  3323. } else {
  3324. $this->error = 'Could not insert into item_view table...';
  3325. return false;
  3326. }
  3327. $this->autocomplete_parents($this->current);
  3328. foreach ($this->items as $index => $dummy) {
  3329. $this->items[$index]->restart();
  3330. $this->items[$index]->set_lp_view($this->lp_view_id);
  3331. }
  3332. $this->first();
  3333. return true;
  3334. }
  3335. /**
  3336. * Saves the current item
  3337. * @return boolean
  3338. */
  3339. public function save_current() {
  3340. if ($this->debug > 0) {
  3341. error_log('New LP - In learnpath::save_current()', 0);
  3342. }
  3343. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3344. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3345. if ($this->debug > 2) {
  3346. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3347. }
  3348. if ($this->debug > 2) {
  3349. error_log('' . print_r($this->items, true), 0);
  3350. }
  3351. if (is_object($this->items[$this->current])) {
  3352. //$res = $this->items[$this->current]->save(false);
  3353. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3354. $this->autocomplete_parents($this->current);
  3355. $status = $this->items[$this->current]->get_status();
  3356. $this->append_message('new_item_status: ' . $status);
  3357. $this->update_queue[$this->current] = $status;
  3358. return $res;
  3359. }
  3360. return false;
  3361. }
  3362. /**
  3363. * Saves the given item
  3364. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3365. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3366. * @return boolean
  3367. */
  3368. public function save_item($item_id = null, $from_outside = true) {
  3369. if ($this->debug > 0) {
  3370. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3371. }
  3372. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3373. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3374. if (empty ($item_id)) {
  3375. $item_id = $this->escape_string($_REQUEST['id']);
  3376. }
  3377. if (empty ($item_id)) {
  3378. $item_id = $this->get_current_item_id();
  3379. }
  3380. if ($this->debug > 2) {
  3381. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3382. }
  3383. if (is_object($this->items[$item_id])) {
  3384. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3385. //$res = $this->items[$item_id]->save($from_outside);
  3386. $this->autocomplete_parents($item_id);
  3387. $status = $this->items[$item_id]->get_status();
  3388. $this->append_message('new_item_status: ' . $status);
  3389. $this->update_queue[$item_id] = $status;
  3390. return $res;
  3391. }
  3392. return false;
  3393. }
  3394. /**
  3395. * Saves the last item seen's ID only in case
  3396. */
  3397. public function save_last() {
  3398. if ($this->debug > 0) {
  3399. error_log('New LP - In learnpath::save_last()', 0);
  3400. }
  3401. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3402. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3403. if (isset ($this->current)) {
  3404. if ($this->debug > 2) {
  3405. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3406. }
  3407. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3408. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3409. if ($this->debug > 2) {
  3410. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3411. }
  3412. $res = Database::query($sql);
  3413. }
  3414. // Save progress.
  3415. list($progress, $text) = $this->get_progress_bar_text('%');
  3416. if ($progress >= 0 && $progress <= 100) {
  3417. $progress = (int) $progress;
  3418. $sql = "UPDATE $table SET progress = $progress " .
  3419. "WHERE lp_id = " . $this->get_id() . " AND " .
  3420. "user_id = " . $this->get_user_id().' '.$session_condition;
  3421. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3422. $this->progress_db = $progress;
  3423. }
  3424. }
  3425. /**
  3426. * Sets the current item ID (checks if valid and authorized first)
  3427. * @param integer New item ID. If not given or not authorized, defaults to current
  3428. */
  3429. public function set_current_item($item_id = null) {
  3430. if ($this->debug > 0) {
  3431. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3432. }
  3433. if (empty ($item_id)) {
  3434. if ($this->debug > 2) {
  3435. error_log('New LP - No new current item given, ignore...', 0);
  3436. }
  3437. // Do nothing.
  3438. } else {
  3439. if ($this->debug > 2) {
  3440. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3441. }
  3442. if (is_numeric($item_id)) {
  3443. $item_id = $this->escape_string($item_id);
  3444. // TODO: Check in database here.
  3445. $this->last = $this->current;
  3446. $this->current = $item_id;
  3447. // TODO: Update $this->index as well.
  3448. foreach ($this->ordered_items as $index => $item) {
  3449. if ($item == $this->current) {
  3450. $this->index = $index;
  3451. break;
  3452. }
  3453. }
  3454. if ($this->debug > 2) {
  3455. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3456. }
  3457. } else {
  3458. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3459. }
  3460. }
  3461. }
  3462. /**
  3463. * Sets the encoding
  3464. * @param string New encoding
  3465. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3466. */
  3467. public function set_encoding($enc = 'UTF-8') {
  3468. if ($this->debug > 0) {
  3469. error_log('New LP - In learnpath::set_encoding()', 0);
  3470. }
  3471. /* // Deprecated code (Chamilo 1.8.8).
  3472. $enc = strtoupper($enc);
  3473. $encodings = array (
  3474. 'UTF-8',
  3475. 'ISO-8859-1',
  3476. 'ISO-8859-15',
  3477. 'cp1251',
  3478. 'cp1252',
  3479. 'KOI8-R',
  3480. 'BIG5',
  3481. 'GB2312',
  3482. 'Shift_JIS',
  3483. 'EUC-JP',
  3484. ''
  3485. );
  3486. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3487. $lp = $this->get_id();
  3488. if ($lp != 0) {
  3489. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3490. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3491. $res = Database::query($sql);
  3492. return $res;
  3493. }
  3494. }
  3495. return false;
  3496. */
  3497. $enc = api_refine_encoding_id($enc);
  3498. if (empty($enc)) {
  3499. $enc = api_get_system_encoding();
  3500. }
  3501. if (api_is_encoding_supported($enc)) {
  3502. $lp = $this->get_id();
  3503. if ($lp != 0) {
  3504. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3505. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3506. $res = Database::query($sql);
  3507. return $res;
  3508. }
  3509. }
  3510. return false;
  3511. }
  3512. /**
  3513. * Sets the JS lib setting in the database directly.
  3514. * This is the JavaScript library file this lp needs to load on startup
  3515. * @param string Proximity setting
  3516. * @return boolean True on update success. False otherwise.
  3517. */
  3518. public function set_jslib($lib = '') {
  3519. if ($this->debug > 0) {
  3520. error_log('New LP - In learnpath::set_jslib()', 0);
  3521. }
  3522. $lp = $this->get_id();
  3523. if ($lp != 0) {
  3524. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3525. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3526. $res = Database::query($sql);
  3527. return $res;
  3528. } else {
  3529. return false;
  3530. }
  3531. }
  3532. /**
  3533. * Sets the name of the LP maker (publisher) (and save)
  3534. * @param string Optional string giving the new content_maker of this learnpath
  3535. * @return boolean True
  3536. */
  3537. public function set_maker($name = '') {
  3538. if ($this->debug > 0) {
  3539. error_log('New LP - In learnpath::set_maker()', 0);
  3540. }
  3541. if (empty ($name))
  3542. return false;
  3543. $this->maker = $this->escape_string($name);
  3544. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3545. $lp_id = $this->get_id();
  3546. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3547. if ($this->debug > 2) {
  3548. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3549. }
  3550. $res = Database::query($sql);
  3551. return true;
  3552. }
  3553. /**
  3554. * Sets the name of the current learnpath (and save)
  3555. * @param string Optional string giving the new name of this learnpath
  3556. * @return boolean True/False
  3557. */
  3558. public function set_name($name = '') {
  3559. if ($this->debug > 0) {
  3560. error_log('New LP - In learnpath::set_name()', 0);
  3561. }
  3562. if (empty ($name))
  3563. return false;
  3564. $this->name = $this->escape_string($name);
  3565. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3566. $lp_id = $this->get_id();
  3567. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3568. if ($this->debug > 2) {
  3569. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3570. }
  3571. $res = Database::query($sql);
  3572. // If the lp is visible on the homepage, change his name there.
  3573. if (Database::affected_rows()) {
  3574. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3575. $sql = 'UPDATE ' . $table . ' SET
  3576. name = "' . $this->name . '"
  3577. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3578. Database::query($sql);
  3579. }
  3580. return true;
  3581. }
  3582. /**
  3583. * Set index specified prefix terms for all items in this path
  3584. * @param string Comma-separated list of terms
  3585. * @param char Xapian term prefix
  3586. * @return boolean False on error, true otherwise
  3587. */
  3588. public function set_terms_by_prefix($terms_string, $prefix) {
  3589. if (api_get_setting('search_enabled') !== 'true')
  3590. return false;
  3591. if (!extension_loaded('xapian')) {
  3592. return false;
  3593. }
  3594. $terms_string = trim($terms_string);
  3595. $terms = explode(',', $terms_string);
  3596. array_walk($terms, 'trim_value');
  3597. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3598. // Don't do anything if no change, verify only at DB, not the search engine.
  3599. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3600. return false;
  3601. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3602. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3603. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3604. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3605. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3606. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3607. $lp_id = intval($_POST['lp_id']);
  3608. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3609. $result = Database::query($sql);
  3610. $di = new DokeosIndexer();
  3611. while ($lp_item = Database :: fetch_array($result)) {
  3612. // Get search_did.
  3613. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3614. $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';
  3615. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3616. //echo $sql; echo '<br>';
  3617. $res = Database::query($sql);
  3618. if (Database::num_rows($res) > 0) {
  3619. $se_ref = Database :: fetch_array($res);
  3620. // Compare terms.
  3621. $doc = $di->get_document($se_ref['search_did']);
  3622. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3623. $xterms = array ();
  3624. foreach ($xapian_terms as $xapian_term) {
  3625. $xterms[] = substr($xapian_term['name'], 1);
  3626. }
  3627. $dterms = $terms;
  3628. $missing_terms = array_diff($dterms, $xterms);
  3629. $deprecated_terms = array_diff($xterms, $dterms);
  3630. // Save it to search engine.
  3631. foreach ($missing_terms as $term) {
  3632. $doc->add_term($prefix . $term, 1);
  3633. }
  3634. foreach ($deprecated_terms as $term) {
  3635. $doc->remove_term($prefix . $term);
  3636. }
  3637. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3638. $di->getDb()->flush();
  3639. } else {
  3640. //@todo What we should do here?
  3641. }
  3642. }
  3643. return true;
  3644. }
  3645. /**
  3646. * Sets the theme of the LP (local/remote) (and save)
  3647. * @param string Optional string giving the new theme of this learnpath
  3648. * @return bool Returns true if theme name is not empty
  3649. */
  3650. public function set_theme($name = '') {
  3651. if ($this->debug > 0) {
  3652. error_log('New LP - In learnpath::set_theme()', 0);
  3653. }
  3654. $this->theme = $this->escape_string($name);
  3655. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3656. $lp_id = $this->get_id();
  3657. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3658. if ($this->debug > 2) {
  3659. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3660. }
  3661. //$res = Database::query($sql);
  3662. $res = Database::query($sql);
  3663. return true;
  3664. }
  3665. /**
  3666. * Sets the image of an LP (and save)
  3667. * @param string Optional string giving the new image of this learnpath
  3668. * @return bool Returns true if theme name is not empty
  3669. */
  3670. public function set_preview_image($name = '') {
  3671. if ($this->debug > 0) {
  3672. error_log('New LP - In learnpath::set_preview_image()', 0);
  3673. }
  3674. $this->preview_image = $this->escape_string($name);
  3675. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3676. $lp_id = $this->get_id();
  3677. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3678. if ($this->debug > 2) {
  3679. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3680. }
  3681. $res = Database::query($sql);
  3682. return true;
  3683. }
  3684. /**
  3685. * Sets the author of a LP (and save)
  3686. * @param string Optional string giving the new author of this learnpath
  3687. * @return bool Returns true if author's name is not empty
  3688. */
  3689. public function set_author($name = '') {
  3690. if ($this->debug > 0) {
  3691. error_log('New LP - In learnpath::set_author()', 0);
  3692. }
  3693. $this->author = $this->escape_string($name);
  3694. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3695. $lp_id = $this->get_id();
  3696. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3697. if ($this->debug > 2) {
  3698. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3699. }
  3700. $res = Database::query($sql);
  3701. return true;
  3702. }
  3703. /**
  3704. * Sets the prerequisite of a LP (and save)
  3705. * @param int integer giving the new prerequisite of this learnpath
  3706. * @return bool returns true if prerequisite is not empty
  3707. */
  3708. public function set_prerequisite($prerequisite) {
  3709. if ($this->debug > 0) {
  3710. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3711. }
  3712. $this->prerequisite = intval($prerequisite);
  3713. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3714. $lp_id = $this->get_id();
  3715. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3716. if ($this->debug > 2) {
  3717. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3718. }
  3719. $res = Database::query($sql);
  3720. return true;
  3721. }
  3722. /**
  3723. * Sets the location/proximity of the LP (local/remote) (and save)
  3724. * @param string Optional string giving the new location of this learnpath
  3725. * @return boolean True on success / False on error
  3726. */
  3727. public function set_proximity($name = '') {
  3728. if ($this->debug > 0) {
  3729. error_log('New LP - In learnpath::set_proximity()', 0);
  3730. }
  3731. if (empty ($name))
  3732. return false;
  3733. $this->proximity = $this->escape_string($name);
  3734. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3735. $lp_id = $this->get_id();
  3736. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3737. if ($this->debug > 2) {
  3738. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3739. }
  3740. $res = Database::query($sql);
  3741. return true;
  3742. }
  3743. /**
  3744. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3745. * @param integer DB ID of the item
  3746. */
  3747. public function set_previous_item($id) {
  3748. if ($this->debug > 0) {
  3749. error_log('New LP - In learnpath::set_previous_item()', 0);
  3750. }
  3751. $this->last = $id;
  3752. }
  3753. /**
  3754. * Sets use_max_score
  3755. * @param string Optional string giving the new location of this learnpath
  3756. * @return boolean True on success / False on error
  3757. */
  3758. public function set_use_max_score($use_max_score = 1) {
  3759. if ($this->debug > 0) {
  3760. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3761. }
  3762. $use_max_score = intval($use_max_score);
  3763. $this->use_max_score = $use_max_score;
  3764. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3765. $lp_id = $this->get_id();
  3766. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3767. if ($this->debug > 2) {
  3768. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3769. }
  3770. $res = Database::query($sql);
  3771. return true;
  3772. }
  3773. /**
  3774. * Sets and saves the expired_on date
  3775. * @param string Optional string giving the new author of this learnpath
  3776. * @return bool Returns true if author's name is not empty
  3777. */
  3778. public function set_expired_on($expired_on) {
  3779. if ($this->debug > 0) {
  3780. error_log('New LP - In learnpath::set_expired_on()', 0);
  3781. }
  3782. if (!empty($expired_on)) {
  3783. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3784. } else {
  3785. $this->expired_on = '';
  3786. }
  3787. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3788. $lp_id = $this->get_id();
  3789. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3790. if ($this->debug > 2) {
  3791. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3792. }
  3793. $res = Database::query($sql);
  3794. return true;
  3795. }
  3796. /**
  3797. * Sets and saves the publicated_on date
  3798. * @param string Optional string giving the new author of this learnpath
  3799. * @return bool Returns true if author's name is not empty
  3800. */
  3801. public function set_publicated_on($publicated_on) {
  3802. if ($this->debug > 0) {
  3803. error_log('New LP - In learnpath::set_expired_on()', 0);
  3804. }
  3805. if (!empty($publicated_on)) {
  3806. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3807. } else {
  3808. $this->publicated_on = '';
  3809. }
  3810. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3811. $lp_id = $this->get_id();
  3812. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3813. if ($this->debug > 2) {
  3814. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3815. }
  3816. $res = Database::query($sql);
  3817. return true;
  3818. }
  3819. /**
  3820. * Sets and saves the expired_on date
  3821. * @param string Optional string giving the new author of this learnpath
  3822. * @return bool Returns true if author's name is not empty
  3823. */
  3824. public function set_modified_on() {
  3825. if ($this->debug > 0) {
  3826. error_log('New LP - In learnpath::set_expired_on()', 0);
  3827. }
  3828. $this->modified_on = api_get_utc_datetime();
  3829. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3830. $lp_id = $this->get_id();
  3831. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3832. if ($this->debug > 2) {
  3833. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3834. }
  3835. $res = Database::query($sql);
  3836. return true;
  3837. }
  3838. /**
  3839. * Sets the object's error message
  3840. * @param string Error message. If empty, reinits the error string
  3841. * @return void
  3842. */
  3843. public function set_error_msg($error = '') {
  3844. if ($this->debug > 0) {
  3845. error_log('New LP - In learnpath::set_error_msg()', 0);
  3846. }
  3847. if (empty ($error)) {
  3848. $this->error = '';
  3849. } else {
  3850. $this->error .= $error;
  3851. }
  3852. }
  3853. /**
  3854. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3855. * @param boolean Whether to allow a new attempt or not
  3856. * @return boolean True
  3857. */
  3858. public function start_current_item($allow_new_attempt = false) {
  3859. if ($this->debug > 0) {
  3860. error_log('New LP - In learnpath::start_current_item()', 0);
  3861. }
  3862. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3863. $type = $this->get_type();
  3864. $item_type = $this->items[$this->current]->get_type();
  3865. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3866. $this->items[$this->current]->open($allow_new_attempt);
  3867. $this->autocomplete_parents($this->current);
  3868. $prereq_check = $this->prerequisites_match($this->current);
  3869. $this->items[$this->current]->save(false, $prereq_check);
  3870. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3871. } else {
  3872. // If sco, then it is supposed to have been updated by some other call.
  3873. }
  3874. if ($item_type == 'sco') {
  3875. $this->items[$this->current]->restart();
  3876. }
  3877. }
  3878. if ($this->debug > 0) {
  3879. error_log('New LP - End of learnpath::start_current_item()', 0);
  3880. }
  3881. return true;
  3882. }
  3883. /**
  3884. * Stops the processing and counters for the old item (as held in $this->last)
  3885. * @return boolean True/False
  3886. */
  3887. public function stop_previous_item() {
  3888. if ($this->debug > 0) {
  3889. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3890. }
  3891. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3892. if ($this->debug > 2) {
  3893. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3894. }
  3895. switch ($this->get_type()) {
  3896. case '3' :
  3897. if ($this->items[$this->last]->get_type() != 'au') {
  3898. if ($this->debug > 2) {
  3899. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3900. }
  3901. $this->items[$this->last]->close();
  3902. //$this->autocomplete_parents($this->last);
  3903. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3904. } else {
  3905. if ($this->debug > 2) {
  3906. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3907. }
  3908. }
  3909. case '2' :
  3910. if ($this->items[$this->last]->get_type() != 'sco') {
  3911. if ($this->debug > 2) {
  3912. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3913. }
  3914. $this->items[$this->last]->close();
  3915. //$this->autocomplete_parents($this->last);
  3916. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3917. } else {
  3918. if ($this->debug > 2) {
  3919. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3920. }
  3921. }
  3922. break;
  3923. case '1' :
  3924. default :
  3925. if ($this->debug > 2) {
  3926. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3927. }
  3928. $this->items[$this->last]->close();
  3929. break;
  3930. }
  3931. } else {
  3932. if ($this->debug > 2) {
  3933. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3934. }
  3935. return false;
  3936. }
  3937. return true;
  3938. }
  3939. /**
  3940. * Updates the default view mode from fullscreen to embedded and inversely
  3941. * @return string The current default view mode ('fullscreen' or 'embedded')
  3942. */
  3943. public function update_default_view_mode() {
  3944. if ($this->debug > 0) {
  3945. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3946. }
  3947. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3948. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3949. $res = Database::query($sql);
  3950. if (Database :: num_rows($res) > 0) {
  3951. $row = Database :: fetch_array($res);
  3952. $view_mode = $row['default_view_mod'];
  3953. if ($view_mode == 'fullscreen') {
  3954. $view_mode = 'embedded';
  3955. } elseif ($view_mode == 'embedded') {
  3956. $view_mode = 'embedframe';
  3957. } elseif ($view_mode == 'embedframe') {
  3958. $view_mode = 'fullscreen';
  3959. }
  3960. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3961. $res = Database::query($sql);
  3962. $this->mode = $view_mode;
  3963. return $view_mode;
  3964. } else {
  3965. if ($this->debug > 2) {
  3966. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3967. }
  3968. }
  3969. return -1;
  3970. }
  3971. /**
  3972. * Updates the default behaviour about auto-commiting SCORM updates
  3973. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3974. */
  3975. public function update_default_scorm_commit() {
  3976. if ($this->debug > 0) {
  3977. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3978. }
  3979. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3980. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3981. $res = Database::query($sql);
  3982. if (Database :: num_rows($res) > 0) {
  3983. $row = Database :: fetch_array($res);
  3984. $force = $row['force_commit'];
  3985. if ($force == 1) {
  3986. $force = 0;
  3987. $force_return = false;
  3988. } elseif ($force == 0) {
  3989. $force = 1;
  3990. $force_return = true;
  3991. }
  3992. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3993. $res = Database::query($sql);
  3994. $this->force_commit = $force_return;
  3995. return $force_return;
  3996. } else {
  3997. if ($this->debug > 2) {
  3998. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3999. }
  4000. }
  4001. return -1;
  4002. }
  4003. /**
  4004. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4005. * @return bool True on success, false on failure
  4006. */
  4007. public function update_display_order() {
  4008. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4009. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  4010. $res = Database::query($sql);
  4011. if ($res === false)
  4012. return false;
  4013. $lps = array ();
  4014. $lp_order = array ();
  4015. $num = Database :: num_rows($res);
  4016. // First check the order is correct, globally (might be wrong because
  4017. // of versions < 1.8.4).
  4018. if ($num > 0) {
  4019. $i = 1;
  4020. while ($row = Database :: fetch_array($res)) {
  4021. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4022. $need_fix = true;
  4023. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  4024. $res_u = Database::query($sql_u);
  4025. }
  4026. $i++;
  4027. }
  4028. }
  4029. return true;
  4030. }
  4031. /**
  4032. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4033. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4034. */
  4035. public function update_reinit() {
  4036. if ($this->debug > 0) {
  4037. error_log('New LP - In learnpath::update_reinit()', 0);
  4038. }
  4039. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4040. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4041. $res = Database::query($sql);
  4042. if (Database :: num_rows($res) > 0) {
  4043. $row = Database :: fetch_array($res);
  4044. $force = $row['prevent_reinit'];
  4045. if ($force == 1) {
  4046. $force = 0;
  4047. } elseif ($force == 0) {
  4048. $force = 1;
  4049. }
  4050. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4051. $res = Database::query($sql);
  4052. $this->prevent_reinit = $force;
  4053. return $force;
  4054. } else {
  4055. if ($this->debug > 2) {
  4056. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4057. }
  4058. }
  4059. return -1;
  4060. }
  4061. /**
  4062. * Updates the "scorm_debug" value that shows or hide the debug window
  4063. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4064. */
  4065. public function update_scorm_debug() {
  4066. if ($this->debug > 0) {
  4067. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4068. }
  4069. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4070. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4071. $res = Database::query($sql);
  4072. if (Database :: num_rows($res) > 0) {
  4073. $row = Database :: fetch_array($res);
  4074. $force = $row['debug'];
  4075. if ($force == 1) {
  4076. $force = 0;
  4077. } elseif ($force == 0) {
  4078. $force = 1;
  4079. }
  4080. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4081. $res = Database::query($sql);
  4082. $this->scorm_debug = $force;
  4083. return $force;
  4084. } else {
  4085. if ($this->debug > 2) {
  4086. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4087. }
  4088. }
  4089. return -1;
  4090. }
  4091. /**
  4092. * Function that makes a call to the function sort_tree_array and create_tree_array
  4093. * @author Kevin Van Den Haute
  4094. * @param array
  4095. */
  4096. public function tree_array($array) {
  4097. if ($this->debug > 1) {
  4098. error_log('New LP - In learnpath::tree_array()', 0);
  4099. }
  4100. $array = $this->sort_tree_array($array);
  4101. $this->create_tree_array($array);
  4102. }
  4103. /**
  4104. * Creates an array with the elements of the learning path tree in it
  4105. *
  4106. * @author Kevin Van Den Haute
  4107. * @param array $array
  4108. * @param int $parent
  4109. * @param int $depth
  4110. * @param array $tmp
  4111. */
  4112. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4113. if ($this->debug > 1) {
  4114. error_log('New LP - In learnpath::create_tree_array())', 0);
  4115. }
  4116. if (is_array($array)) {
  4117. for ($i = 0; $i < count($array); $i++) {
  4118. if ($array[$i]['parent_item_id'] == $parent) {
  4119. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4120. $tmp[] = $array[$i]['parent_item_id'];
  4121. $depth++;
  4122. }
  4123. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4124. $audio = isset($array[$i]['audio']) ? $array[$i]['audio'] : null;
  4125. $this->arrMenu[] = array (
  4126. 'id' => $array[$i]['id'],
  4127. 'item_type' => $array[$i]['item_type'],
  4128. 'title' => $array[$i]['title'],
  4129. 'path' => $array[$i]['path'],
  4130. 'description' => $array[$i]['description'],
  4131. 'parent_item_id' => $array[$i]['parent_item_id'],
  4132. 'previous_item_id' => $array[$i]['previous_item_id'],
  4133. 'next_item_id' => $array[$i]['next_item_id'],
  4134. 'min_score' => $array[$i]['min_score'],
  4135. 'max_score' => $array[$i]['max_score'],
  4136. 'mastery_score' => $array[$i]['mastery_score'],
  4137. 'display_order' => $array[$i]['display_order'],
  4138. 'prerequisite' => $preq,
  4139. 'depth' => $depth,
  4140. 'audio' => $audio
  4141. );
  4142. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4143. }
  4144. }
  4145. }
  4146. }
  4147. /**
  4148. * Sorts a multi dimensional array by parent id and display order
  4149. * @author Kevin Van Den Haute
  4150. *
  4151. * @param array $array (array with al the learning path items in it)
  4152. *
  4153. * @return array
  4154. */
  4155. public function sort_tree_array($array) {
  4156. foreach ($array as $key => $row) {
  4157. $parent[$key] = $row['parent_item_id'];
  4158. $position[$key] = $row['display_order'];
  4159. }
  4160. if (count($array) > 0)
  4161. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4162. return $array;
  4163. }
  4164. /**
  4165. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4166. * Also the actions for the modules, chapters and documents are in this table.
  4167. * @author Kevin Van Den Haute
  4168. * @param int $lp_id
  4169. * @return string
  4170. */
  4171. public function overview() {
  4172. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4173. if ($this->debug > 0) {
  4174. error_log('New LP - In learnpath::overview()', 0);
  4175. }
  4176. global $charset, $_course;
  4177. $_SESSION['gradebook'] = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4178. $return = '';
  4179. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4180. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4181. WHERE lp_id = " . $this->lp_id;
  4182. $result = Database::query($sql);
  4183. $arrLP = array ();
  4184. while ($row = Database :: fetch_array($result)) {
  4185. $row['title'] = Security :: remove_XSS($row['title']);
  4186. $row['description'] = Security :: remove_XSS($row['description']);
  4187. $arrLP[] = array (
  4188. 'id' => $row['id'],
  4189. 'item_type' => $row['item_type'],
  4190. 'title' => $row['title'],
  4191. 'path' => $row['path'],
  4192. 'description' => $row['description'],
  4193. 'parent_item_id' => $row['parent_item_id'],
  4194. 'previous_item_id' => $row['previous_item_id'],
  4195. 'next_item_id' => $row['next_item_id'],
  4196. 'max_score' => $row['max_score'],
  4197. 'min_score' => $row['min_score'],
  4198. 'mastery_score' => $row['mastery_score'],
  4199. 'prerequisite' => $row['prerequisite'],
  4200. 'display_order' => $row['display_order'],
  4201. 'audio' => $row['audio']
  4202. );
  4203. }
  4204. $this->tree_array($arrLP);
  4205. $arrLP = $this->arrMenu;
  4206. unset ($this->arrMenu);
  4207. $update_audio = isset($_GET['updateaudio']) ? $_GET['updateaudio'] : null;
  4208. if ($is_allowed_to_edit) {
  4209. $token = Security::get_token();
  4210. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4211. $return .= '<div class="actions">';
  4212. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=build&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('Build') . '">' . Display :: return_icon('build_learnpath.png', get_lang('Build'),'','32').'</a>';
  4213. if ($update_audio == 'true') {
  4214. $return .='<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']) .'&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang('BasicOverview').'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4215. } else {
  4216. $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
  4217. }
  4218. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&action=view&lp_id=' . $this->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a>';
  4219. $return .= ' '.Display :: return_icon('i.gif');
  4220. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">
  4221. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4222. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">
  4223. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4224. if ($update_audio == 'true') {
  4225. $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'','32'),'#');
  4226. } else {
  4227. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4228. }
  4229. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4230. $return .= '</div>';
  4231. }
  4232. // we need to start a form when we want to update all the mp3 files
  4233. if ($update_audio == 'true' AND count($arrLP) <> 0) {
  4234. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4235. $return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
  4236. }
  4237. $return .= '<div id="message"></div>';
  4238. /*
  4239. $return .= '<table class="data_table">';
  4240. $return .= '<tr>';
  4241. $return .= '<th width="60%">' . get_lang('Title') . '</th>';
  4242. //$return .= '<th>'.get_lang('Description').'</th>';
  4243. $return .= '<th>' . get_lang('Audio') . '</th>';
  4244. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4245. $return .= '<th>' . get_lang('Move') . '</th>';
  4246. }
  4247. $return .= '<th>' . get_lang('Actions') . '</th>';
  4248. $return .= '</tr>';*/
  4249. $start_chapter = false;
  4250. $elements = array();
  4251. for ($i = 0; $i < count($arrLP); $i++) {
  4252. $title = $arrLP[$i]['title'];
  4253. /*if (($i % 2) == 0) {
  4254. $oddclass = 'row_odd';
  4255. } else {
  4256. $oddclass = 'row_even';
  4257. }*/
  4258. $oddclass = 'row_even';
  4259. if ($arrLP[$i]['item_type'] == 'dokeos_chapter') {
  4260. $oddclass = 'row_odd';
  4261. $start_chapter = true;
  4262. } else {
  4263. $start_chapter = false;
  4264. }
  4265. // "lp_item_'.$i.' is important for the drag and drop otherwise the LP will not work
  4266. //$return .= '<tr id ="lp_item_'.$arrLP[$i]['id'] .'" class="' . $oddclass . '">';
  4267. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4268. /*
  4269. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4270. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>';
  4271. } else {
  4272. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4273. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>';
  4274. } else {
  4275. //$return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>';
  4276. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
  4277. }
  4278. }*/
  4279. $icon = '';
  4280. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4281. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />';
  4282. } else {
  4283. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4284. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />';
  4285. } else {
  4286. $icon = '<img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />';
  4287. }
  4288. }
  4289. // The audio column.
  4290. //$return .= '<td align="center">';
  4291. $audio = '';
  4292. if (!$update_audio OR $update_audio <> 'true') {
  4293. if (!empty ($arrLP[$i]['audio'])) {
  4294. $audio .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4295. $audio .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4296. $audio .= '<script type="text/javascript">
  4297. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4298. s1.addParam("allowscriptaccess","always");
  4299. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4300. s1.write("container' . $i . '");
  4301. </script>';
  4302. } else {
  4303. $audio .= '';
  4304. }
  4305. } else {
  4306. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4307. $audio .= '<input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4308. if (!empty ($arrLP[$i]['audio'])) {
  4309. $audio .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4310. }
  4311. }
  4312. }
  4313. //$return .= '</td>';
  4314. $move_icon = '';
  4315. $edit_icon = '';
  4316. $delete_icon = '';
  4317. if ($is_allowed_to_edit) {
  4318. if (!$update_audio OR $update_audio <> 'true') {
  4319. $move_icon .= '<a class="moved" href="#">';
  4320. $move_icon .= Display::return_icon('move.png', get_lang('Move'), array(), 24);
  4321. $move_icon .= '</a>';
  4322. /*
  4323. if ($arrLP[$i]['previous_item_id'] != 0) {
  4324. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=move_item&amp;direction=up&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;sec_token='.$token.'">';
  4325. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4326. $return .= '</a>';
  4327. } else {
  4328. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4329. }
  4330. if ($arrLP[$i]['next_item_id'] != 0) {
  4331. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']). '&amp;action=move_item&amp;direction=down&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;sec_token='.$token.'">';
  4332. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4333. $return .= '</a>';
  4334. } else
  4335. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4336. */
  4337. }
  4338. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4339. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4340. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4341. $edit_icon .= '</a>';
  4342. } else {
  4343. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4344. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4345. $edit_icon .= '</a>';
  4346. }
  4347. $delete_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($title) . '\');">';
  4348. $delete_icon .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
  4349. $delete_icon .= '</a>';
  4350. }
  4351. if ($update_audio != 'true') {
  4352. $row = $move_icon.Display::span($title.$icon).Display::span($audio.$edit_icon.$delete_icon, array('class'=>'button_actions'));
  4353. } else {
  4354. $row = Display::span($title.$icon).Display::span($audio, array('class'=>'button_actions'));
  4355. }
  4356. $parent_id = $arrLP[$i]['parent_item_id'];
  4357. $default_data[$arrLP[$i]['id']] = $row;
  4358. if (empty($parent_id)) {
  4359. $elements[$arrLP[$i]['id']]['data'] = $row;
  4360. $elements[$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4361. } else {
  4362. $parent_arrays = array();
  4363. if ($arrLP[$i]['depth'] > 1) {
  4364. //Getting list of parents
  4365. for($j = 0; $j < $arrLP[$i]['depth']; $j++) {
  4366. foreach($arrLP as $item) {
  4367. if ($item['id'] == $parent_id) {
  4368. if ($item['parent_item_id'] == 0) {
  4369. $parent_id = $item['id'];
  4370. //$parent_arrays[] = $parent_id;
  4371. break;
  4372. } else {
  4373. $parent_id = $item['parent_item_id'];
  4374. if (empty($parent_arrays)) {
  4375. $parent_arrays[] = $item['id'];
  4376. }
  4377. $parent_arrays[] = $parent_id;
  4378. break;
  4379. }
  4380. }
  4381. }
  4382. }
  4383. }
  4384. if (!empty($parent_arrays)) {
  4385. $parent_arrays = array_reverse($parent_arrays);
  4386. $value_to_insert = array();
  4387. $val = '$elements';
  4388. $x = 0;
  4389. foreach($parent_arrays as $item) {
  4390. if ($x != count($parent_arrays) -1) {
  4391. $val .= '["'.$item.'"]["children"]';
  4392. } else {
  4393. $val .= '["'.$item.'"]["children"]';
  4394. }
  4395. $x++;
  4396. }
  4397. $val .= "";
  4398. $generated_array = null;
  4399. //".$row."
  4400. $code_str = $val."[".$arrLP[$i]['id']."][\"load_data\"] = '".$arrLP[$i]['id']."' ; ";
  4401. //var_dump($code_str);
  4402. eval($code_str);
  4403. } else {
  4404. //var_dump($parent_arrays);
  4405. $elements[$parent_id]['children'][$arrLP[$i]['id']]['data'] = $row;
  4406. $elements[$parent_id]['children'][$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4407. }
  4408. }
  4409. }
  4410. function print_recursive($elements, $default_data) {
  4411. $return = '';
  4412. foreach($elements as $key => $item) {
  4413. if (isset($item['load_data']) || empty($item['data'])) {
  4414. $item['data'] = $default_data[$item['load_data']];
  4415. }
  4416. $sub_list = '';
  4417. if (isset($item['type']) && $item['type'] == 'dokeos_chapter') {
  4418. $sub_list = Display::tag('li', '', array('class'=>'sub_item empty')); // empty value
  4419. }
  4420. if (empty($item['children'])) {
  4421. $sub_list = Display::tag('ul', $sub_list, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4422. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4423. } else {
  4424. //sections
  4425. if (isset($item['children'])) {
  4426. $data = print_recursive($item['children'], $default_data);
  4427. }
  4428. /*foreach($item['children'] as $my_key => $sub_item) {
  4429. $sub_list .= Display::tag('li', $sub_item['data'], array('id'=>$my_key,'class'=>'record item'));
  4430. }*/
  4431. $sub_list = Display::tag('ul', $data, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4432. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4433. }
  4434. }
  4435. return $return;
  4436. }
  4437. $return .= '<div style="width:90%;"><ul id="lp_item_list">';
  4438. $return .= print_recursive($elements,$default_data);
  4439. $return .='</ul></div>';
  4440. if ($update_audio != 'true') {
  4441. $return .= Display::div(Display::url(get_lang('Save'), '#', array('id'=>'listSubmit', 'class'=>'a_button orange medium')), array('style'=>'float:left; width:100%'));
  4442. }
  4443. /*
  4444. if (count($arrLP) == 0) {
  4445. $return .= '<tr>';
  4446. $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
  4447. $return .= '</tr>';
  4448. }*/
  4449. // We need to close the form when we are updating the mp3 files.
  4450. if ($update_audio == 'true') {
  4451. $return .= '<div style="margin:40px 0; float:right;"><button class="save" type="submit" name="save_audio" id="save_audio">' . get_lang('SaveAudioAndOrganization') . '</button></div>'; // TODO: What kind of language variable is this?
  4452. }
  4453. // We need to close the form when we are updating the mp3 files.
  4454. if ($update_audio == 'true' && count($arrLP) != 0) {
  4455. $return .= '</form>';
  4456. }
  4457. return $return;
  4458. }
  4459. /**
  4460. * This function builds the action menu
  4461. * @return void
  4462. */
  4463. public function build_action_menu() {
  4464. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4465. echo '<div class="actions">';
  4466. //echo '<span>'.Display::return_icon('build_learnpath.png','-','','32').' '.get_lang('Build').'</span>';
  4467. echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
  4468. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('BasicOverview') . '">' . Display :: return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4469. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&action=view&lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('view_left_right.png', get_lang('Display'),'','32').'</a> ';
  4470. Display :: display_icon('i.gif');
  4471. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=step&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewStep') . '">' . Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4472. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;gradebook=' . $gradebook . '&amp;action=add_item&amp;type=chapter&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="' . get_lang('NewChapter') . '">' . Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4473. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4474. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4475. echo '</div>';
  4476. }
  4477. /**
  4478. * This functions builds the LP tree based on data from the database.
  4479. * @return string
  4480. * @uses dtree.js :: necessary javascript for building this tree
  4481. */
  4482. public function build_tree() {
  4483. $return = "<script type=\"text/javascript\">\n";
  4484. $return .= "\tm = new dTree('m');\n\n";
  4485. $return .= "\tm.config.folderLinks = true;\n";
  4486. $return .= "\tm.config.useCookies = true;\n";
  4487. $return .= "\tm.config.useIcons = true;\n";
  4488. $return .= "\tm.config.useLines = true;\n";
  4489. $return .= "\tm.config.useSelection = true;\n";
  4490. $return .= "\tm.config.useStatustext = false;\n\n";
  4491. $menu = 0;
  4492. $parent = '';
  4493. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4494. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4495. $sql = " SELECT id, title, description, item_type, path, parent_item_id, previous_item_id, next_item_id, max_score, min_score, mastery_score, display_order
  4496. FROM $tbl_lp_item
  4497. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4498. $result = Database::query($sql);
  4499. $arrLP = array ();
  4500. while ($row = Database :: fetch_array($result)) {
  4501. $row['title'] = Security :: remove_XSS($row['title']);
  4502. $row['description'] = Security :: remove_XSS($row['description']);
  4503. $arrLP[] = array (
  4504. 'id' => $row['id'],
  4505. 'item_type' => $row['item_type'],
  4506. 'title' => $row['title'],
  4507. 'path' => $row['path'],
  4508. 'description' => $row['description'],
  4509. 'parent_item_id' => $row['parent_item_id'],
  4510. 'previous_item_id' => $row['previous_item_id'],
  4511. 'next_item_id' => $row['next_item_id'],
  4512. 'max_score' => $row['max_score'],
  4513. 'min_score' => $row['min_score'],
  4514. 'mastery_score' => $row['mastery_score'],
  4515. 'display_order' => $row['display_order']
  4516. );
  4517. }
  4518. $this->tree_array($arrLP);
  4519. $arrLP = $this->arrMenu;
  4520. unset ($this->arrMenu);
  4521. $title = '';
  4522. for ($i = 0; $i < count($arrLP); $i++) {
  4523. $title = addslashes($arrLP[$i]['title']);
  4524. $menu_page = api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=view_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $_SESSION['oLP']->lp_id;
  4525. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4526. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4527. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".png', '../img/lp_" . $icon_name . ".png');\n";
  4528. } else
  4529. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4530. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $icon_name . ".gif', '../img/lp_" . $icon_name . ".gif');\n";
  4531. } else {
  4532. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4533. }
  4534. if ($menu < $arrLP[$i]['id'])
  4535. $menu = $arrLP[$i]['id'];
  4536. }
  4537. $return .= "\n\tdocument.write(m);\n";
  4538. $return .= "\t if(!m.selectedNode) m.s(1);";
  4539. $return .= "</script>\n";
  4540. return $return;
  4541. }
  4542. /**
  4543. * Create a new document //still needs some finetuning
  4544. * @param array $_course
  4545. * @return string
  4546. */
  4547. public function create_document($_course) {
  4548. global $charset;
  4549. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4550. if (strstr($dir, '..'))
  4551. $dir = '/';
  4552. if ($dir[0] == '.')
  4553. $dir = substr($dir, 1);
  4554. if ($dir[0] != '/')
  4555. $dir = '/' . $dir;
  4556. if ($dir[strlen($dir) - 1] != '/')
  4557. $dir .= '/';
  4558. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4559. if (empty($_POST['dir']) && empty($_GET['dir'])) {
  4560. //Creating learning_path folder
  4561. $dir = '/learning_path';
  4562. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  4563. $folder = null;
  4564. if (!is_dir($filepath.'/'.$dir)) {
  4565. $folder = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'));
  4566. } else {
  4567. $folder = true;
  4568. }
  4569. $dir = '/learning_path/';
  4570. //Creating LP folder
  4571. if ($folder) {
  4572. $title = replace_dangerous_char($this->name);
  4573. $dir = $dir.$title;
  4574. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  4575. if (!is_dir($filepath.'/'.$dir)) {
  4576. $folder = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $this->name);
  4577. } else {
  4578. $folder = true;
  4579. }
  4580. $dir = $dir.'/';
  4581. if ($folder) {
  4582. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document'.$dir;
  4583. }
  4584. }
  4585. }
  4586. if (!is_dir($filepath)) {
  4587. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4588. $dir = '/';
  4589. }
  4590. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4591. // is already escaped twice when it gets here.
  4592. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4593. $title = disable_dangerous_file($title);
  4594. $filename = $title;
  4595. $content = $_POST['content_lp'];
  4596. $tmp_filename = $filename;
  4597. $i = 0;
  4598. while (file_exists($filepath . $tmp_filename . '.html'))
  4599. $tmp_filename = $filename . '_' . ++ $i;
  4600. $filename = $tmp_filename . '.html';
  4601. $content = stripslashes(text_filter($content));
  4602. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4603. // Change the path of mp3 to absolute.
  4604. // The first regexp deals with ../../../ urls.
  4605. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4606. // The second regexp deals with audio/ urls.
  4607. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4608. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4609. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4610. if (!file_exists($filepath . $filename)) {
  4611. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4612. fputs($fp, $content);
  4613. fclose($fp);
  4614. $file_size = filesize($filepath . $filename);
  4615. $save_file_path = $dir . $filename;
  4616. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4617. if ($document_id) {
  4618. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4619. // Update parent folders.
  4620. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4621. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4622. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4623. if ($new_comment || $new_title) {
  4624. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4625. $ct = '';
  4626. if ($new_comment)
  4627. $ct .= ", comment='" . $new_comment . "'";
  4628. if ($new_title)
  4629. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4630. $sql_update = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." WHERE id = " . $document_id;
  4631. Database::query($sql_update);
  4632. }
  4633. }
  4634. return $document_id;
  4635. }
  4636. }
  4637. }
  4638. /**
  4639. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4640. * @param array $_course array
  4641. * @return void
  4642. */
  4643. public function edit_document($_course) {
  4644. global $_configuration;
  4645. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4646. if (strstr($dir, '..'))
  4647. $dir = '/';
  4648. if ($dir[0] == '.')
  4649. $dir = substr($dir, 1);
  4650. if ($dir[0] != '/')
  4651. $dir = '/' . $dir;
  4652. if ($dir[strlen($dir) - 1] != '/')
  4653. $dir .= '/';
  4654. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4655. if (!is_dir($filepath)) {
  4656. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4657. $dir = '/';
  4658. }
  4659. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4660. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4661. $sql = "SELECT path
  4662. FROM " . $table_doc . "
  4663. WHERE id = " . Database::escape_string($_POST['path']);
  4664. $res = Database::query($sql);
  4665. $row = Database :: fetch_array($res);
  4666. $content = stripslashes($_POST['content_lp']);
  4667. $file = $filepath . $row['path'];
  4668. if ($fp = @ fopen($file, 'w')) {
  4669. $content = text_filter($content);
  4670. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4671. // Change the path of mp3 to absolute.
  4672. // The first regexp deals with ../../../ urls.
  4673. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4674. // The second regexp deals with audio/ urls.
  4675. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4676. fputs($fp, $content);
  4677. fclose($fp);
  4678. }
  4679. }
  4680. }
  4681. /**
  4682. * Displays the selected item, with a panel for manipulating the item
  4683. * @param int $item_id
  4684. * @param string $msg
  4685. * @return string
  4686. */
  4687. public function display_item($item_id, $iframe = true, $msg = '') {
  4688. global $_course; // It will disappear.
  4689. $return = '';
  4690. if (is_numeric($item_id)) {
  4691. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4692. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4693. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4694. WHERE lp.id = " . Database :: escape_string($item_id);
  4695. $result = Database::query($sql);
  4696. while ($row = Database :: fetch_array($result)) {
  4697. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4698. // Prevents wrong parent selection for document, see Bug#1251.
  4699. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4700. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4701. }
  4702. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4703. $return .= '<div style="padding:10px;">';
  4704. if ($msg != '')
  4705. $return .= $msg;
  4706. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4707. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4708. //$return .= '<hr />';
  4709. switch ($row['item_type']) {
  4710. case TOOL_QUIZ:
  4711. if (!empty($row['path'])) {
  4712. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4713. $exercise = new Exercise();
  4714. $exercise->read($row['path']);
  4715. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4716. $return .=$exercise->description.'<br />';
  4717. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4718. }
  4719. break;
  4720. case TOOL_DOCUMENT:
  4721. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4722. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4723. $result = Database::query($sql_doc);
  4724. $path_file = Database :: result($result, 0, 0);
  4725. $path_parts = pathinfo($path_file);
  4726. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4727. if (in_array($path_parts['extension'], array (
  4728. 'html',
  4729. 'txt',
  4730. 'png',
  4731. 'jpg',
  4732. 'JPG',
  4733. 'jpeg',
  4734. 'JPEG',
  4735. 'gif',
  4736. 'swf'
  4737. ))) {
  4738. $return .= $this->display_document($row['path'], true, true);
  4739. }
  4740. break;
  4741. }
  4742. $return .= '</div>';
  4743. }
  4744. }
  4745. return $return;
  4746. }
  4747. /**
  4748. * Shows the needed forms for editing a specific item
  4749. * @param int $item_id
  4750. * @return string
  4751. */
  4752. public function display_edit_item($item_id) {
  4753. global $_course; // It will disappear.
  4754. $return = '';
  4755. if (is_numeric($item_id)) {
  4756. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4757. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . Database :: escape_string($item_id);
  4758. $res = Database::query($sql);
  4759. $row = Database::fetch_array($res);
  4760. switch ($row['item_type']) {
  4761. case 'dokeos_chapter' :
  4762. case 'dir' :
  4763. case 'asset' :
  4764. case 'sco' :
  4765. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4766. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4767. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4768. } else {
  4769. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4770. }
  4771. break;
  4772. case TOOL_DOCUMENT :
  4773. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4774. $sql_step = " SELECT lp.*, doc.path as dir
  4775. FROM " . $tbl_lp_item . " as lp
  4776. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4777. WHERE lp.id = " . Database :: escape_string($item_id);
  4778. $res_step = Database::query($sql_step);
  4779. $row_step = Database :: fetch_array($res_step);
  4780. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4781. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4782. break;
  4783. case TOOL_LINK :
  4784. $link_id = (string) $row['path'];
  4785. if (ctype_digit($link_id)) {
  4786. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4787. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4788. $res_link = Database::query($sql_select);
  4789. $row_link = Database :: fetch_array($res_link);
  4790. if (is_array($row_link)) {
  4791. $row['url'] = $row_link['url'];
  4792. }
  4793. }
  4794. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4795. $return .= $this->display_link_form('edit', $item_id, $row);
  4796. break;
  4797. case 'dokeos_module' :
  4798. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4799. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4800. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4801. } else {
  4802. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4803. }
  4804. break;
  4805. case TOOL_QUIZ :
  4806. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4807. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4808. break;
  4809. case TOOL_HOTPOTATOES :
  4810. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4811. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4812. break;
  4813. case TOOL_STUDENTPUBLICATION :
  4814. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4815. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4816. break;
  4817. case TOOL_FORUM :
  4818. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4819. $return .= $this->display_forum_form('edit', $item_id, $row);
  4820. break;
  4821. case TOOL_THREAD :
  4822. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4823. $return .= $this->display_thread_form('edit', $item_id, $row);
  4824. break;
  4825. }
  4826. }
  4827. return $return;
  4828. }
  4829. /**
  4830. * Function that displays a list with al the resources that could be added to the learning path
  4831. * @return string
  4832. */
  4833. public function display_resources() {
  4834. global $_course; // TODO: Don't use globals.
  4835. /*$return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4836. $return .= '<div class="sectioncomment"><a href="' . api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . '<img title="Nuevo documento" src="../img/new_doc.gif" alt="Nuevo documento"/> ' . get_lang('NewDocument') . '</a></div>';
  4837. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';*/
  4838. //Get all the docs
  4839. $documents = $this->get_documents();
  4840. //Get all the exercises
  4841. $exercises = $this->get_exercises();
  4842. // Get all the links
  4843. $links = $this->get_links();
  4844. //Get al the student publications
  4845. $works = $this->get_student_publications();
  4846. //Get al the forums
  4847. $forums = $this->get_forums();
  4848. $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
  4849. Display::return_icon('quiz.png', get_lang('Quiz'), array(), 64),
  4850. Display::return_icon('links.png', get_lang('Links'), array(), 64),
  4851. Display::return_icon('works.png', get_lang('Works'), array(), 64),
  4852. Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
  4853. );
  4854. echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums), 'resource_tab');
  4855. return true;
  4856. }
  4857. /**
  4858. * Returns the extension of a document
  4859. * @param string filename
  4860. * @return string Extension (part after the last dot)
  4861. */
  4862. public function get_extension($filename) {
  4863. $explode = explode('.', $filename);
  4864. return $explode[count($explode) - 1];
  4865. }
  4866. /**
  4867. * Displays a document by id
  4868. *
  4869. * @param unknown_type $id
  4870. * @return unknown
  4871. */
  4872. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4873. global $_course; // It is temporary.
  4874. $return = '';
  4875. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4876. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4877. WHERE id = " . $id;
  4878. $res_doc = Database::query($sql_doc);
  4879. $row_doc = Database :: fetch_array($res_doc);
  4880. //if ($show_title)
  4881. //$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>';
  4882. // TODO: Add a path filter.
  4883. if ($iframe) {
  4884. $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>';
  4885. } else {
  4886. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4887. }
  4888. return $return;
  4889. }
  4890. /**
  4891. * Return HTML form to add/edit a quiz
  4892. * @param string Action (add/edit)
  4893. * @param integer Item ID if already exists
  4894. * @param mixed Extra information (quiz ID if integer)
  4895. * @return string HTML form
  4896. */
  4897. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4898. global $charset;
  4899. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4900. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4901. if ($id != 0 && is_array($extra_info)) {
  4902. $item_title = stripslashes($extra_info['title']);
  4903. $item_description = stripslashes($extra_info['description']);
  4904. }
  4905. elseif (is_numeric($extra_info)) {
  4906. $sql_quiz = "
  4907. SELECT
  4908. title,
  4909. description
  4910. FROM " . $tbl_quiz . "
  4911. WHERE id = " . $extra_info;
  4912. $result = Database::query($sql_quiz);
  4913. $row = Database :: fetch_array($result);
  4914. $item_title = $row['title'];
  4915. $item_description = $row['description'];
  4916. } else {
  4917. $item_title = '';
  4918. $item_description = '';
  4919. }
  4920. $return = ' <div class="row">
  4921. <div class="form_header">';
  4922. if ($id != 0 && is_array($extra_info))
  4923. $parent = $extra_info['parent_item_id'];
  4924. else
  4925. $parent = 0;
  4926. $sql = "
  4927. SELECT *
  4928. FROM " . $tbl_lp_item . "
  4929. WHERE
  4930. lp_id = " . $this->lp_id;
  4931. $result = Database::query($sql);
  4932. $arrLP = array ();
  4933. while ($row = Database :: fetch_array($result)) {
  4934. $arrLP[] = array (
  4935. 'id' => $row['id'],
  4936. 'item_type' => $row['item_type'],
  4937. 'title' => $row['title'],
  4938. 'path' => $row['path'],
  4939. 'description' => $row['description'],
  4940. 'parent_item_id' => $row['parent_item_id'],
  4941. 'previous_item_id' => $row['previous_item_id'],
  4942. 'next_item_id' => $row['next_item_id'],
  4943. 'display_order' => $row['display_order'],
  4944. 'max_score' => $row['max_score'],
  4945. 'min_score' => $row['min_score'],
  4946. 'mastery_score' => $row['mastery_score'],
  4947. 'prerequisite' => $row['prerequisite'],
  4948. 'max_time_allowed' => $row['max_time_allowed']
  4949. );
  4950. }
  4951. $this->tree_array($arrLP);
  4952. $arrLP = $this->arrMenu;
  4953. unset ($this->arrMenu);
  4954. if ($action == 'add')
  4955. $return .= get_lang('CreateTheExercise') . '&nbsp;:';
  4956. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:';
  4957. else
  4958. $return .= get_lang('EditCurrentExecice') . '&nbsp;:';
  4959. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4960. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4961. }
  4962. $return .= ' </div>
  4963. </div>';
  4964. $return .= '<div class="sectioncomment">';
  4965. $return .= '<form method="POST">';
  4966. $return .= '<table class="lp_form">';
  4967. if ($action != 'move') {
  4968. $return .= '<tr>';
  4969. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  4970. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
  4971. $return .= '</tr>';
  4972. }
  4973. $return .= '<tr>';
  4974. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  4975. $return .= '<td class="input">';
  4976. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  4977. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4978. $arrHide = array (
  4979. $id
  4980. );
  4981. //$parent_item_id = $_SESSION['parent_item_id'];
  4982. for ($i = 0; $i < count($arrLP); $i++) {
  4983. if ($action != 'add') {
  4984. 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)) {
  4985. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  4986. } else {
  4987. $arrHide[] = $arrLP[$i]['id'];
  4988. }
  4989. } else {
  4990. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4991. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  4992. }
  4993. }
  4994. if (is_array($arrLP)) {
  4995. reset($arrLP);
  4996. }
  4997. $return .= '</select>';
  4998. $return .= '</td>';
  4999. $return .= '</tr>';
  5000. $return .= '<tr>';
  5001. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5002. $return .= '<td class="input">';
  5003. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
  5004. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5005. for ($i = 0; $i < count($arrLP); $i++) {
  5006. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5007. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5008. $selected = 'selected="selected" ';
  5009. elseif ($action == 'add') $selected = 'selected="selected" ';
  5010. else
  5011. $selected = '';
  5012. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5013. }
  5014. }
  5015. $return .= "\t\t\t\t" . '</select>';
  5016. $return .= '</td>';
  5017. $return .= '</tr>';
  5018. if ($action != 'move') {
  5019. $id_prerequisite = 0;
  5020. if (is_array($arrLP)) {
  5021. foreach ($arrLP as $key => $value) {
  5022. if ($value['id'] == $id) {
  5023. $id_prerequisite = $value['prerequisite'];
  5024. break;
  5025. }
  5026. }
  5027. }
  5028. $arrHide = array ();
  5029. for ($i = 0; $i < count($arrLP); $i++) {
  5030. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5031. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5032. $s_selected_position = $arrLP[$i]['id'];
  5033. elseif ($action == 'add') $s_selected_position = 0;
  5034. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5035. }
  5036. }
  5037. /*// Commented the prerequisites, only visible in edit (exercise).
  5038. $return .= '<tr>';
  5039. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  5040. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5041. foreach($arrHide as $key => $value){
  5042. if($key==$s_selected_position && $action == 'add'){
  5043. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5044. }
  5045. elseif($key==$id_prerequisite && $action == 'edit'){
  5046. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5047. }
  5048. else{
  5049. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5050. }
  5051. }
  5052. $return .= "</select></td>";
  5053. */
  5054. $return .= '</tr>';
  5055. /*$return .= '<tr>';
  5056. $return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
  5057. $return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  5058. // Remove temporarily the test description.
  5059. //$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
  5060. //$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
  5061. $return .= '</tr>'; */
  5062. }
  5063. $return .= '<tr>';
  5064. if ($action == 'add') {
  5065. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  5066. } else {
  5067. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  5068. }
  5069. $return .= '</tr>';
  5070. $return .= '</table>';
  5071. if ($action == 'move') {
  5072. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5073. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5074. }
  5075. if (is_numeric($extra_info)) {
  5076. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5077. }
  5078. elseif (is_array($extra_info)) {
  5079. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5080. }
  5081. $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
  5082. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5083. $return .= '</form>';
  5084. $return .= '</div>';
  5085. return $return;
  5086. }
  5087. /**
  5088. * Addition of Hotpotatoes tests
  5089. * @param string Action
  5090. * @param integer Internal ID of the item
  5091. * @param mixed Extra information - can be an array with title and description indexes
  5092. * @return string HTML structure to display the hotpotatoes addition formular
  5093. */
  5094. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  5095. global $charset;
  5096. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5097. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5098. if ($id != 0 && is_array($extra_info)) {
  5099. $item_title = stripslashes($extra_info['title']);
  5100. $item_description = stripslashes($extra_info['description']);
  5101. } elseif (is_numeric($extra_info)) {
  5102. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  5103. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  5104. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  5105. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  5106. $res_hot = Database::query($sql_hot);
  5107. $row = Database::fetch_array($res_hot);
  5108. $item_title = $row['title'];
  5109. $item_description = $row['description'];
  5110. if (!empty ($row['comment'])) {
  5111. $item_title = $row['comment'];
  5112. }
  5113. } else {
  5114. $item_title = '';
  5115. $item_description = '';
  5116. }
  5117. if ($id != 0 && is_array($extra_info))
  5118. $parent = $extra_info['parent_item_id'];
  5119. else
  5120. $parent = 0;
  5121. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = " . $this->lp_id;
  5122. $result = Database::query($sql);
  5123. $arrLP = array ();
  5124. while ($row = Database :: fetch_array($result)) {
  5125. $arrLP[] = array (
  5126. 'id' => $row['id'],
  5127. 'item_type' => $row['item_type'],
  5128. 'title' => $row['title'],
  5129. 'path' => $row['path'],
  5130. 'description' => $row['description'],
  5131. 'parent_item_id' => $row['parent_item_id'],
  5132. 'previous_item_id' => $row['previous_item_id'],
  5133. 'next_item_id' => $row['next_item_id'],
  5134. 'display_order' => $row['display_order'],
  5135. 'max_score' => $row['max_score'],
  5136. 'min_score' => $row['min_score'],
  5137. 'mastery_score' => $row['mastery_score'],
  5138. 'prerequisite' => $row['prerequisite'],
  5139. 'max_time_allowed' => $row['max_time_allowed']
  5140. );
  5141. }
  5142. /*
  5143. $this->tree_array($arrLP);
  5144. $arrLP = $this->arrMenu;
  5145. unset ($this->arrMenu);*/
  5146. if ($action == 'add')
  5147. $return .= '<div class="row"><div class="form_header">' . get_lang('CreateTheExercise') . '&nbsp;:</div></div>';
  5148. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>';
  5149. else
  5150. //$return .= '<p class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>';
  5151. $return .= '<div class="row"><div class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</div></div>';
  5152. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5153. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5154. }
  5155. $return .= '<form method="POST">';
  5156. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5157. $return .= '<tr>';
  5158. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
  5159. $return .= '<td class="input">';
  5160. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5161. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5162. $arrHide = array (
  5163. $id
  5164. );
  5165. if (count($arrLP) > 0) {
  5166. for ($i = 0; $i < count($arrLP); $i++) {
  5167. if ($action != 'add') {
  5168. 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)) {
  5169. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5170. } else {
  5171. $arrHide[] = $arrLP[$i]['id'];
  5172. }
  5173. } else {
  5174. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5175. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5176. }
  5177. }
  5178. reset($arrLP);
  5179. }
  5180. $return .= "\t\t\t\t" . '</select>';
  5181. $return .= '</td>';
  5182. $return .= '</tr>';
  5183. $return .= '<tr>';
  5184. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
  5185. $return .= '<td class="input">';
  5186. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5187. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5188. for ($i = 0; $i < count($arrLP); $i++) {
  5189. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5190. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5191. $selected = 'selected="selected" ';
  5192. elseif ($action == 'add') $selected = 'selected="selected" ';
  5193. else
  5194. $selected = '';
  5195. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5196. }
  5197. }
  5198. $return .= "\t\t\t\t" . '</select>';
  5199. $return .= '</td>';
  5200. $return .= '</tr>';
  5201. if ($action != 'move') {
  5202. $return .= '<tr>';
  5203. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
  5204. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5205. $return .= '</tr>';
  5206. $id_prerequisite = 0;
  5207. if (is_array($arrLP) && count($arrLP) > 0) {
  5208. foreach ($arrLP as $key => $value) {
  5209. if ($value['id'] == $id) {
  5210. $id_prerequisite = $value['prerequisite'];
  5211. break;
  5212. }
  5213. }
  5214. $arrHide = array ();
  5215. for ($i = 0; $i < count($arrLP); $i++) {
  5216. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5217. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5218. $s_selected_position = $arrLP[$i]['id'];
  5219. elseif ($action == 'add') $s_selected_position = 0;
  5220. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5221. }
  5222. }
  5223. }
  5224. //$return .= '<tr>';
  5225. //$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>';
  5226. //$return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5227. /*
  5228. foreach ($arrHide as $key => $value) {
  5229. if ($key == $s_selected_position && $action == 'add') {
  5230. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5231. }
  5232. elseif ($key == $id_prerequisite && $action == 'edit') {
  5233. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5234. } else {
  5235. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5236. }
  5237. }
  5238. */
  5239. //$return .= "</select></td>";
  5240. //$return .= '</tr>';
  5241. //$return .= '<tr>';
  5242. //$return .= '</tr>';
  5243. }
  5244. $return .= '<tr>';
  5245. $return .= '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
  5246. $return .= '</tr>';
  5247. $return .= '</table>';
  5248. if ($action == 'move') {
  5249. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5250. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5251. }
  5252. if (is_numeric($extra_info)) {
  5253. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5254. }
  5255. elseif (is_array($extra_info)) {
  5256. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5257. }
  5258. $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
  5259. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5260. $return .= '</form>';
  5261. return $return;
  5262. }
  5263. /**
  5264. * Return the form to display the forum edit/add option
  5265. * @param string Action (add/edit)
  5266. * @param integer ID of the lp_item if already exists
  5267. * @param mixed Forum ID or title
  5268. * @return string HTML form
  5269. */
  5270. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5271. global $charset;
  5272. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5273. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5274. if ($id != 0 && is_array($extra_info)) {
  5275. $item_title = stripslashes($extra_info['title']);
  5276. }
  5277. elseif (is_numeric($extra_info)) {
  5278. $sql_forum = "
  5279. SELECT
  5280. forum_title as title, forum_comment as comment
  5281. FROM " . $tbl_forum . "
  5282. WHERE forum_id = " . $extra_info;
  5283. $result = Database::query($sql_forum);
  5284. $row = Database :: fetch_array($result);
  5285. $item_title = $row['title'];
  5286. $item_description = $row['comment'];
  5287. } else {
  5288. $item_title = '';
  5289. $item_description = '';
  5290. }
  5291. $return = ' <div class="row">
  5292. <div class="form_header">';
  5293. if ($id != 0 && is_array($extra_info))
  5294. $parent = $extra_info['parent_item_id'];
  5295. else
  5296. $parent = 0;
  5297. $sql = "
  5298. SELECT *
  5299. FROM " . $tbl_lp_item . "
  5300. WHERE
  5301. lp_id = " . $this->lp_id;
  5302. $result = Database::query($sql);
  5303. $arrLP = array ();
  5304. while ($row = Database :: fetch_array($result)) {
  5305. $arrLP[] = array (
  5306. 'id' => $row['id'],
  5307. 'item_type' => $row['item_type'],
  5308. 'title' => $row['title'],
  5309. 'path' => $row['path'],
  5310. 'description' => $row['description'],
  5311. 'parent_item_id' => $row['parent_item_id'],
  5312. 'previous_item_id' => $row['previous_item_id'],
  5313. 'next_item_id' => $row['next_item_id'],
  5314. 'display_order' => $row['display_order'],
  5315. 'max_score' => $row['max_score'],
  5316. 'min_score' => $row['min_score'],
  5317. 'mastery_score' => $row['mastery_score'],
  5318. 'prerequisite' => $row['prerequisite']
  5319. );
  5320. }
  5321. $this->tree_array($arrLP);
  5322. $arrLP = $this->arrMenu;
  5323. unset ($this->arrMenu);
  5324. if ($action == 'add')
  5325. $return .= get_lang('CreateTheForum') . '&nbsp;:';
  5326. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:';
  5327. else
  5328. $return .= get_lang('EditCurrentForum') . '&nbsp;:';
  5329. $return .= ' </div>
  5330. </div>';
  5331. $return .= '<div class="sectioncomment">';
  5332. $return .= '<form method="POST">';
  5333. $return .= '<table class="lp_form">';
  5334. if ($action != 'move') {
  5335. $return .= '<tr>';
  5336. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5337. $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  5338. $return .= '</tr>';
  5339. }
  5340. $return .= '<tr>';
  5341. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5342. $return .= '<td class="input">';
  5343. $return .= "\t\t\t\t" . '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5344. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5345. $arrHide = array (
  5346. $id
  5347. );
  5348. //$parent_item_id = $_SESSION['parent_item_id'];
  5349. for ($i = 0; $i < count($arrLP); $i++) {
  5350. if ($action != 'add') {
  5351. 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)) {
  5352. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5353. } else {
  5354. $arrHide[] = $arrLP[$i]['id'];
  5355. }
  5356. } else {
  5357. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5358. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5359. }
  5360. }
  5361. if (is_array($arrLP)) {
  5362. reset($arrLP);
  5363. }
  5364. $return .= "\t\t\t\t" . '</select>';
  5365. $return .= '</td>';
  5366. $return .= '</tr>';
  5367. $return .= '<tr>';
  5368. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5369. $return .= '<td class="input">';
  5370. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5371. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5372. for ($i = 0; $i < count($arrLP); $i++) {
  5373. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5374. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5375. $selected = 'selected="selected" ';
  5376. elseif ($action == 'add') $selected = 'selected="selected" ';
  5377. else
  5378. $selected = '';
  5379. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5380. }
  5381. }
  5382. $return .= "\t\t\t\t" . '</select>';
  5383. $return .= '</td>';
  5384. $return .= '</tr>';
  5385. if ($action != 'move') {
  5386. $return .= '<tr>';
  5387. $return .= '</tr>';
  5388. $id_prerequisite = 0;
  5389. if (is_array($arrLP)) {
  5390. foreach ($arrLP as $key => $value) {
  5391. if ($value['id'] == $id) {
  5392. $id_prerequisite = $value['prerequisite'];
  5393. break;
  5394. }
  5395. }
  5396. }
  5397. $arrHide = array ();
  5398. for ($i = 0; $i < count($arrLP); $i++) {
  5399. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5400. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5401. $s_selected_position = $arrLP[$i]['id'];
  5402. elseif ($action == 'add') $s_selected_position = 0;
  5403. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5404. }
  5405. }
  5406. $return .= '</tr>';
  5407. }
  5408. $return .= '<tr>';
  5409. if ($action == 'add') {
  5410. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5411. } else {
  5412. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5413. }
  5414. $return .= '</tr>';
  5415. $return .= '</table>';
  5416. if ($action == 'move') {
  5417. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5418. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5419. }
  5420. if (is_numeric($extra_info)) {
  5421. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5422. }
  5423. elseif (is_array($extra_info)) {
  5424. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5425. }
  5426. $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
  5427. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5428. $return .= '</form>';
  5429. $return .= '</div>';
  5430. return $return;
  5431. }
  5432. /**
  5433. * Return HTML form to add/edit forum threads
  5434. * @param string Action (add/edit)
  5435. * @param integer Item ID if already exists in learning path
  5436. * @param mixed Extra information (thread ID if integer)
  5437. * @return string HTML form
  5438. */
  5439. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5440. global $charset;
  5441. echo '
  5442. <style>
  5443. div.row div.label {
  5444. width:110px;
  5445. }
  5446. div.row div.formw {
  5447. width: 82%;
  5448. }
  5449. </style>';
  5450. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5451. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5452. if ($id != 0 && is_array($extra_info)) {
  5453. $item_title = stripslashes($extra_info['title']);
  5454. }
  5455. elseif (is_numeric($extra_info)) {
  5456. $sql_forum = "
  5457. SELECT
  5458. thread_title as title
  5459. FROM " . $tbl_forum . "
  5460. WHERE thread_id = " . $extra_info;
  5461. $result = Database::query($sql_forum);
  5462. $row = Database :: fetch_array($result);
  5463. $item_title = $row['title'];
  5464. $item_description = '';
  5465. } else {
  5466. $item_title = '';
  5467. $item_description = '';
  5468. }
  5469. $return = '<div style="margin:3px 12px;">';
  5470. if ($id != 0 && is_array($extra_info))
  5471. $parent = $extra_info['parent_item_id'];
  5472. else
  5473. $parent = 0;
  5474. $sql = "
  5475. SELECT *
  5476. FROM " . $tbl_lp_item . "
  5477. WHERE
  5478. lp_id = " . $this->lp_id;
  5479. $result = Database::query($sql);
  5480. $arrLP = array ();
  5481. while ($row = Database :: fetch_array($result)) {
  5482. $arrLP[] = array (
  5483. 'id' => $row['id'],
  5484. 'item_type' => $row['item_type'],
  5485. 'title' => $row['title'],
  5486. 'path' => $row['path'],
  5487. 'description' => $row['description'],
  5488. 'parent_item_id' => $row['parent_item_id'],
  5489. 'previous_item_id' => $row['previous_item_id'],
  5490. 'next_item_id' => $row['next_item_id'],
  5491. 'display_order' => $row['display_order'],
  5492. 'max_score' => $row['max_score'],
  5493. 'min_score' => $row['min_score'],
  5494. 'mastery_score' => $row['mastery_score'],
  5495. 'prerequisite' => $row['prerequisite']
  5496. );
  5497. }
  5498. $this->tree_array($arrLP);
  5499. $arrLP = $this->arrMenu;
  5500. unset ($this->arrMenu);
  5501. if ($action == 'add')
  5502. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>';
  5503. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>';
  5504. else
  5505. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>';
  5506. $return .= '<form method="POST">';
  5507. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5508. $return .= '<tr>';
  5509. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>';
  5510. $return .= '<td class="input">';
  5511. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5512. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5513. $arrHide = array (
  5514. $id
  5515. );
  5516. for ($i = 0; $i < count($arrLP); $i++) {
  5517. if ($action != 'add') {
  5518. 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)) {
  5519. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5520. } else {
  5521. $arrHide[] = $arrLP[$i]['id'];
  5522. }
  5523. } else {
  5524. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5525. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  5526. }
  5527. }
  5528. if ($arrLP != null) {
  5529. reset($arrLP);
  5530. }
  5531. $return .= "\t\t\t\t" . '</select>';
  5532. $return .= '</td>';
  5533. $return .= '</tr>';
  5534. $return .= '<tr>';
  5535. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '&nbsp;:</label></td>';
  5536. $return .= '<td class="input">';
  5537. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5538. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5539. for ($i = 0; $i < count($arrLP); $i++) {
  5540. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5541. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5542. $selected = 'selected="selected" ';
  5543. elseif ($action == 'add') $selected = 'selected="selected" ';
  5544. else
  5545. $selected = '';
  5546. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5547. }
  5548. }
  5549. $return .= "\t\t\t\t" . '</select>';
  5550. $return .= '</td>';
  5551. $return .= '</tr>';
  5552. if ($action != 'move') {
  5553. $return .= '<tr>';
  5554. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>';
  5555. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5556. $return .= '</tr>';
  5557. $return .= '<tr>';
  5558. $return .= '</tr>';
  5559. $id_prerequisite = 0;
  5560. if ($arrLP != null) {
  5561. foreach ($arrLP as $key => $value) {
  5562. if ($value['id'] == $id) {
  5563. $id_prerequisite = $value['prerequisite'];
  5564. break;
  5565. }
  5566. }
  5567. }
  5568. $arrHide = array();
  5569. for ($i = 0; $i < count($arrLP); $i++) {
  5570. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5571. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5572. $s_selected_position = $arrLP[$i]['id'];
  5573. elseif ($action == 'add') $s_selected_position = 0;
  5574. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5575. }
  5576. }
  5577. $return .= '<tr>';
  5578. $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>';
  5579. $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5580. foreach ($arrHide as $key => $value) {
  5581. if ($key == $s_selected_position && $action == 'add') {
  5582. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5583. }
  5584. elseif ($key == $id_prerequisite && $action == 'edit') {
  5585. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5586. } else {
  5587. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5588. }
  5589. }
  5590. $return .= "</select></td>";
  5591. $return .= '</tr>';
  5592. }
  5593. $return .= '<tr>';
  5594. $return .= '<td colspan="2">
  5595. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
  5596. $return .= '</tr>';
  5597. $return .= '</table>';
  5598. if ($action == 'move') {
  5599. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5600. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5601. }
  5602. if (is_numeric($extra_info)) {
  5603. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5604. }
  5605. elseif (is_array($extra_info)) {
  5606. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5607. }
  5608. $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
  5609. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5610. $return .= '</form>';
  5611. $return .= '</div>';
  5612. return $return;
  5613. }
  5614. /**
  5615. * Return the HTML form to display an item (generally a section/module item)
  5616. * @param string Item type (module/dokeos_module)
  5617. * @param string Title (optional, only when creating)
  5618. * @param string Action ('add'/'edit')
  5619. * @param integer lp_item ID
  5620. * @param mixed Extra info
  5621. * @return string HTML form
  5622. */
  5623. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5624. global $_course;
  5625. global $charset;
  5626. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5627. if ($id != 0 && is_array($extra_info)) {
  5628. $item_title = $extra_info['title'];
  5629. $item_description = $extra_info['description'];
  5630. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5631. } else {
  5632. $item_title = '';
  5633. $item_description = '';
  5634. }
  5635. $return = ' <div class="row">
  5636. <div class="form_header">';
  5637. if ($id != 0 && is_array($extra_info))
  5638. $parent = $extra_info['parent_item_id'];
  5639. else
  5640. $parent = 0;
  5641. $sql = "
  5642. SELECT *
  5643. FROM " . $tbl_lp_item . "
  5644. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5645. if ($item_type == 'module')
  5646. $sql .= " AND parent_item_id = 0";
  5647. $result = Database::query($sql);
  5648. $arrLP = array ();
  5649. while ($row = Database :: fetch_array($result)) {
  5650. $arrLP[] = array (
  5651. 'id' => $row['id'],
  5652. 'item_type' => $row['item_type'],
  5653. 'title' => $row['title'],
  5654. 'path' => $row['path'],
  5655. 'description' => $row['description'],
  5656. 'parent_item_id' => $row['parent_item_id'],
  5657. 'previous_item_id' => $row['previous_item_id'],
  5658. 'next_item_id' => $row['next_item_id'],
  5659. 'max_score' => $row['max_score'],
  5660. 'min_score' => $row['min_score'],
  5661. 'mastery_score' => $row['mastery_score'],
  5662. 'prerequisite' => $row['prerequisite'],
  5663. 'display_order' => $row['display_order']
  5664. );
  5665. }
  5666. $this->tree_array($arrLP);
  5667. $arrLP = $this->arrMenu;
  5668. unset ($this->arrMenu);
  5669. $return .= $title;
  5670. $return .= ' </div>
  5671. </div>';
  5672. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5673. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5674. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5675. $defaults['description'] = $item_description;
  5676. $form->addElement('html', $return);
  5677. //$arrHide = array($id);
  5678. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5679. $arrHide[0]['padding'] = 3;
  5680. $charset = api_get_system_encoding();
  5681. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5682. for ($i = 0; $i < count($arrLP); $i++) {
  5683. if ($action != 'add') {
  5684. 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)) {
  5685. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5686. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5687. if ($parent == $arrLP[$i]['id']) {
  5688. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5689. }
  5690. }
  5691. } else {
  5692. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5693. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5694. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5695. if ($parent == $arrLP[$i]['id']) {
  5696. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5697. }
  5698. }
  5699. }
  5700. }
  5701. if ($action != 'move') {
  5702. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5703. $form->applyFilter('title', 'html_filter');
  5704. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5705. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5706. } else {
  5707. $form->addElement('hidden', 'title');
  5708. }
  5709. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5710. foreach ($arrHide as $key => $value) {
  5711. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5712. }
  5713. if (!empty($s_selected_parent)) {
  5714. $parent_select->setSelected($s_selected_parent);
  5715. }
  5716. }
  5717. if (is_array($arrLP)) {
  5718. reset($arrLP);
  5719. }
  5720. $arrHide = array ();
  5721. // POSITION
  5722. for ($i = 0; $i < count($arrLP); $i++) {
  5723. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5724. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5725. $s_selected_position = $arrLP[$i]['id'];
  5726. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5727. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5728. }
  5729. }
  5730. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
  5731. $padding = isset($value['padding']) ? $value['padding'] : 0;
  5732. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $padding . 'px;"');
  5733. foreach ($arrHide as $key => $value) {
  5734. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $padding . 'px;"');
  5735. }
  5736. if (!empty ($s_selected_position)) {
  5737. $position->setSelected($s_selected_position);
  5738. }
  5739. if (is_array($arrLP)) {
  5740. reset($arrLP);
  5741. }
  5742. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5743. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5744. $form->addElement('hidden', 'parent', '0');
  5745. }
  5746. $extension = null;
  5747. if (!empty($item_path)) {
  5748. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5749. }
  5750. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5751. if ($item_type == 'sco') {
  5752. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5753. }
  5754. $renderer = $form->defaultRenderer();
  5755. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5756. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5757. $defaults['content_lp'] = file_get_contents($item_path);
  5758. }
  5759. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5760. $form->addElement('hidden', 'post_time', time());
  5761. $form->setDefaults($defaults);
  5762. return $form->return_form();
  5763. }
  5764. /**
  5765. * Returns the form to update or create a document
  5766. * @param string Action (add/edit)
  5767. * @param integer ID of the lp_item (if already exists)
  5768. * @param mixed Integer if document ID, string if info ('new')
  5769. * @return string HTML form
  5770. */
  5771. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5772. global $charset;
  5773. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5774. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5775. $path_parts = pathinfo($extra_info['dir']);
  5776. $no_display_edit_textarea = false;
  5777. //If action==edit document
  5778. //We don't display the document form if it's not an editable document (html or txt file)
  5779. if ($action == "edit") {
  5780. if (is_array($extra_info)) {
  5781. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5782. $no_display_edit_textarea = true;
  5783. }
  5784. }
  5785. }
  5786. $no_display_add = false;
  5787. // If action==add an existing document
  5788. // We don't display the document form if it's not an editable document (html or txt file).
  5789. if ($action == "add") {
  5790. if (is_numeric($extra_info)) {
  5791. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5792. $result = Database::query($sql_doc);
  5793. $path_file = Database :: result($result, 0, 0);
  5794. $path_parts = pathinfo($path_file);
  5795. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5796. $no_display_add = true;
  5797. }
  5798. }
  5799. }
  5800. if ($id != 0 && is_array($extra_info)) {
  5801. $item_title = stripslashes($extra_info['title']);
  5802. $item_description = stripslashes($extra_info['description']);
  5803. $item_terms = stripslashes($extra_info['terms']);
  5804. if (empty ($item_title)) {
  5805. $path_parts = pathinfo($extra_info['path']);
  5806. $item_title = stripslashes($path_parts['filename']);
  5807. }
  5808. } elseif (is_numeric($extra_info)) {
  5809. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5810. WHERE id = " . Database :: escape_string($extra_info);
  5811. $result = Database::query($sql_doc);
  5812. $row = Database :: fetch_array($result);
  5813. $explode = explode('.', $row['title']);
  5814. if (count($explode) > 1) {
  5815. for ($i = 0; $i < count($explode) - 1; $i++)
  5816. $item_title .= $explode[$i];
  5817. } else {
  5818. $item_title = $row['title'];
  5819. }
  5820. $item_title = str_replace('_', ' ', $item_title);
  5821. if (empty ($item_title)) {
  5822. $path_parts = pathinfo($row['path']);
  5823. $item_title = stripslashes($path_parts['filename']);
  5824. }
  5825. } else {
  5826. $item_title = '';
  5827. $item_description = '';
  5828. }
  5829. $return = ' <div class="row">
  5830. <div class="form_header">';
  5831. if ($id != 0 && is_array($extra_info))
  5832. $parent = $extra_info['parent_item_id'];
  5833. else
  5834. $parent = 0;
  5835. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5836. WHERE lp_id = " . $this->lp_id;
  5837. $result = Database::query($sql);
  5838. $arrLP = array ();
  5839. while ($row = Database :: fetch_array($result)) {
  5840. $arrLP[] = array (
  5841. 'id' => $row['id'],
  5842. 'item_type' => $row['item_type'],
  5843. 'title' => $row['title'],
  5844. 'path' => $row['path'],
  5845. 'description' => $row['description'],
  5846. 'parent_item_id' => $row['parent_item_id'],
  5847. 'previous_item_id' => $row['previous_item_id'],
  5848. 'next_item_id' => $row['next_item_id'],
  5849. 'display_order' => $row['display_order'],
  5850. 'max_score' => $row['max_score'],
  5851. 'min_score' => $row['min_score'],
  5852. 'mastery_score' => $row['mastery_score'],
  5853. 'prerequisite' => $row['prerequisite']
  5854. );
  5855. }
  5856. $this->tree_array($arrLP);
  5857. $arrLP = $this->arrMenu;
  5858. unset ($this->arrMenu);
  5859. if ($action == 'add') {
  5860. $return .= get_lang('CreateTheDocument');
  5861. } elseif ($action == 'move') {
  5862. $return .= get_lang('MoveTheCurrentDocument');
  5863. } else {
  5864. $return .= get_lang('EditTheCurrentDocument');
  5865. }
  5866. $return .= '</div>
  5867. </div>';
  5868. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5869. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5870. }
  5871. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5872. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5873. $defaults['title'] = Security :: remove_XSS($item_title);
  5874. if (empty($item_title)) {
  5875. $defaults['title'] = Security::remove_XSS($item_title);
  5876. }
  5877. $defaults['description'] = $item_description;
  5878. $form->addElement('html', $return);
  5879. if ($action != 'move') {
  5880. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5881. $form->applyFilter('title', 'html_filter');
  5882. }
  5883. //$arrHide = array($id);
  5884. $arrHide[0]['value'] = $this->name;
  5885. $arrHide[0]['padding'] = 3;
  5886. for ($i = 0; $i < count($arrLP); $i++) {
  5887. if ($action != 'add') {
  5888. 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)) {
  5889. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5890. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5891. if ($parent == $arrLP[$i]['id']) {
  5892. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5893. }
  5894. }
  5895. } else {
  5896. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5897. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5898. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5899. if ($parent == $arrLP[$i]['id']) {
  5900. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5901. }
  5902. }
  5903. }
  5904. }
  5905. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5906. $my_count=0;
  5907. foreach ($arrHide as $key => $value) {
  5908. if ($my_count!=0) {
  5909. // The LP name is also the first section and is not in the same charset like the other sections.
  5910. $value['value'] = Security :: remove_XSS($value['value']);
  5911. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5912. } else {
  5913. $value['value'] = Security :: remove_XSS($value['value']);
  5914. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5915. }
  5916. $my_count++;
  5917. }
  5918. if (!empty($id)) {
  5919. $parent_select->setSelected($parent);
  5920. } else {
  5921. $parent_item_id = $_SESSION['parent_item_id'];
  5922. $parent_select->setSelected($parent_item_id);
  5923. }
  5924. if (is_array($arrLP)) {
  5925. reset($arrLP);
  5926. }
  5927. $arrHide = array ();
  5928. //POSITION
  5929. for ($i = 0; $i < count($arrLP); $i++) {
  5930. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5931. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5932. $s_selected_position = $arrLP[$i]['id'];
  5933. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5934. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5935. }
  5936. }
  5937. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
  5938. $position->addOption(get_lang('FirstPosition'), 0);
  5939. foreach ($arrHide as $key => $value) {
  5940. $padding = isset($value['padding']) ? $value['padding']: 0;
  5941. $position->addOption($value['value'], $key, 'style="padding-left:' . $padding . 'px;"');
  5942. }
  5943. $position->setSelected($s_selected_position);
  5944. if (is_array($arrLP)) {
  5945. reset($arrLP);
  5946. }
  5947. if ($action != 'move') {
  5948. $id_prerequisite = 0;
  5949. if (is_array($arrLP)) {
  5950. foreach ($arrLP as $key => $value) {
  5951. if ($value['id'] == $id) {
  5952. $id_prerequisite = $value['prerequisite'];
  5953. break;
  5954. }
  5955. }
  5956. }
  5957. // Commented the prerequisites, only visible in edit (new document).
  5958. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5959. //$select_prerequisites->addOption(get_lang('NoPrerequisites'), 0);
  5960. // Form element for uploading an mp3 file.
  5961. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5962. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5963. /* Code deprecated - moved to lp level (not lp-item).
  5964. if (api_get_setting('search_enabled') === 'true') {
  5965. //add terms field
  5966. $terms = $form->addElement('text', 'terms', get_lang('SearchFeatureTerms').'&nbsp;:', 'id="idTerms" class="learnpath_item_form"');
  5967. $terms->setValue($item_terms);
  5968. }
  5969. */
  5970. $arrHide = array ();
  5971. for ($i = 0; $i < count($arrLP); $i++) {
  5972. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5973. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5974. $s_selected_position = $arrLP[$i]['id'];
  5975. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5976. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5977. }
  5978. }
  5979. /* foreach ($arrHide as $key => $value) {
  5980. $select_prerequisites->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
  5981. if ($key == $s_selected_position && $action == 'add') {
  5982. $select_prerequisites -> setSelected(0);
  5983. }
  5984. elseif ($key == $id_prerequisite && $action == 'edit') {
  5985. $select_prerequisites -> setSelected($id_prerequisite);
  5986. }
  5987. }
  5988. */
  5989. if (!$no_display_add) {
  5990. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5991. if (isset ($_POST['content']))
  5992. $content = stripslashes($_POST['content']);
  5993. elseif (is_array($extra_info)) {
  5994. //If it's an html document or a text file
  5995. if (!$no_display_edit_textarea) {
  5996. $content = $this->display_document($extra_info['path'], false, false);
  5997. }
  5998. }
  5999. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  6000. else
  6001. $content = '';
  6002. if (!$no_display_edit_textarea) {
  6003. // We need to claculate here some specific settings for the online editor.
  6004. // The calculated settings work for documents in the Documents tool
  6005. // (on the root or in subfolders).
  6006. // For documents in native scorm packages it is unclear whether the
  6007. // online editor should be activated or not.
  6008. $relative_path = $extra_info['dir'];
  6009. if ($relative_path == 'n/') {
  6010. // A new document, it is in the root of the repository.
  6011. $relative_path = '';
  6012. $relative_prefix = '';
  6013. } else {
  6014. // The document already exists. Whe have to determine its relative path towards the repository root.
  6015. $relative_path = explode('/', $relative_path);
  6016. $cnt = count($relative_path) - 2;
  6017. if ($cnt < 0) {
  6018. $cnt = 0;
  6019. }
  6020. $relative_prefix = str_repeat('../', $cnt);
  6021. $relative_path = array_slice($relative_path, 1, $cnt);
  6022. $relative_path = implode('/', $relative_path);
  6023. if (strlen($relative_path) > 0) {
  6024. $relative_path = $relative_path . '/';
  6025. }
  6026. }
  6027. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  6028. 'CreateDocumentDir' => $relative_prefix,
  6029. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  6030. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  6031. );
  6032. if ($_GET['action'] == 'add_item') {
  6033. $class = 'add';
  6034. $text = get_lang('LPCreateDocument');
  6035. } else
  6036. if ($_GET['action'] == 'edit_item') {
  6037. $class = 'save';
  6038. $text = get_lang('SaveDocument');
  6039. }
  6040. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  6041. $renderer = $form->defaultRenderer();
  6042. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  6043. $form->addElement('html', '<div style="margin:3px 12px">');
  6044. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  6045. $form->addElement('html', '</div>');
  6046. $defaults['content_lp'] = $content;
  6047. }
  6048. }
  6049. elseif (is_numeric($extra_info)) {
  6050. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6051. $return = $this->display_document($extra_info, true, true, true);
  6052. $form->addElement('html', $return);
  6053. }
  6054. }
  6055. }
  6056. if ($action == 'move') {
  6057. $form->addElement('hidden', 'title', $item_title);
  6058. $form->addElement('hidden', 'description', $item_description);
  6059. }
  6060. if (is_numeric($extra_info)) {
  6061. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  6062. $form->addElement('hidden', 'path', $extra_info);
  6063. }
  6064. elseif (is_array($extra_info)) {
  6065. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6066. $form->addElement('hidden', 'path', $extra_info['path']);
  6067. }
  6068. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  6069. $form->addElement('hidden', 'post_time', time());
  6070. $form->setDefaults($defaults);
  6071. return $form->return_form();
  6072. }
  6073. /**
  6074. * Return HTML form to add/edit a link item
  6075. * @param string Action (add/edit)
  6076. * @param integer Item ID if exists
  6077. * @param mixed Extra info
  6078. * @return string HTML form
  6079. */
  6080. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  6081. global $charset;
  6082. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6083. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6084. if ($id != 0 && is_array($extra_info)) {
  6085. $item_title = stripslashes($extra_info['title']);
  6086. $item_description = stripslashes($extra_info['description']);
  6087. $item_url = stripslashes($extra_info['url']);
  6088. } elseif (is_numeric($extra_info)) {
  6089. $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE id = " . $extra_info;
  6090. $result = Database::query($sql_link);
  6091. $row = Database :: fetch_array($result);
  6092. $item_title = $row['title'];
  6093. $item_description = $row['description'];
  6094. $item_url = $row['url'];
  6095. } else {
  6096. $item_title = '';
  6097. $item_description = '';
  6098. $item_url = '';
  6099. }
  6100. $return = ' <div class="row">
  6101. <div class="form_header">';
  6102. if ($id != 0 && is_array($extra_info))
  6103. $parent = $extra_info['parent_item_id'];
  6104. else
  6105. $parent = 0;
  6106. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6107. $result = Database::query($sql);
  6108. $arrLP = array ();
  6109. while ($row = Database :: fetch_array($result)) {
  6110. $arrLP[] = array (
  6111. 'id' => $row['id'],
  6112. 'item_type' => $row['item_type'],
  6113. 'title' => $row['title'],
  6114. 'path' => $row['path'],
  6115. 'description' => $row['description'],
  6116. 'parent_item_id' => $row['parent_item_id'],
  6117. 'previous_item_id' => $row['previous_item_id'],
  6118. 'next_item_id' => $row['next_item_id'],
  6119. 'display_order' => $row['display_order'],
  6120. 'max_score' => $row['max_score'],
  6121. 'min_score' => $row['min_score'],
  6122. 'mastery_score' => $row['mastery_score'],
  6123. 'prerequisite' => $row['prerequisite']
  6124. );
  6125. }
  6126. $this->tree_array($arrLP);
  6127. $arrLP = $this->arrMenu;
  6128. unset ($this->arrMenu);
  6129. if ($action == 'add')
  6130. $return .= get_lang('CreateTheLink') . '&nbsp;:';
  6131. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:';
  6132. else
  6133. $return .= get_lang('EditCurrentLink') . '&nbsp;:';
  6134. $return .= ' </div>
  6135. </div>';
  6136. $return .= '<div class="sectioncomment">';
  6137. $return .= '<form method="POST">';
  6138. $return .= '<table>';
  6139. if ($action != 'move') {
  6140. $return .= '<tr>';
  6141. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6142. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
  6143. $return .= '</tr>';
  6144. }
  6145. $return .= '<tr>';
  6146. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6147. $return .= '<td class="input">';
  6148. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6149. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  6150. $arrHide = array (
  6151. $id
  6152. );
  6153. $parent_item_id = $_SESSION['parent_item_id'];
  6154. for ($i = 0; $i < count($arrLP); $i++) {
  6155. if ($action != 'add') {
  6156. 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)) {
  6157. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  6158. } else {
  6159. $arrHide[] = $arrLP[$i]['id'];
  6160. }
  6161. } else {
  6162. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6163. $return .= "\t\t\t\t\t" . '<option ' . (($parent_item_id == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  6164. }
  6165. }
  6166. if (is_array($arrLP)) {
  6167. reset($arrLP);
  6168. }
  6169. $return .= "\t\t\t\t" . '</select>';
  6170. $return .= '</td>';
  6171. $return .= '</tr>';
  6172. $return .= '<tr>';
  6173. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6174. $return .= '<td class="input">';
  6175. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6176. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6177. for ($i = 0; $i < count($arrLP); $i++) {
  6178. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6179. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6180. $selected = 'selected="selected" ';
  6181. elseif ($action == 'add')
  6182. $selected = 'selected="selected" ';
  6183. else
  6184. $selected = '';
  6185. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6186. }
  6187. }
  6188. $return .= '</select>';
  6189. $return .= '</td>';
  6190. $return .= '</tr>';
  6191. if ($action != 'move') {
  6192. $return .= '<tr>';
  6193. $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
  6194. $return .= '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>';
  6195. $return .= '</tr>';
  6196. $id_prerequisite = 0;
  6197. if (is_array($arrLP)) {
  6198. foreach ($arrLP as $key => $value) {
  6199. if ($value['id'] == $id) {
  6200. $id_prerequisite = $value['prerequisite'];
  6201. break;
  6202. }
  6203. }
  6204. }
  6205. $arrHide = array ();
  6206. for ($i = 0; $i < count($arrLP); $i++) {
  6207. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6208. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6209. $s_selected_position = $arrLP[$i]['id'];
  6210. elseif ($action == 'add') $s_selected_position = 0;
  6211. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6212. }
  6213. }
  6214. /*// Commented the prerequisites, only visible in edit (link).
  6215. $return .= '<tr>';
  6216. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6217. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6218. foreach($arrHide as $key => $value) {
  6219. if ($key == $s_selected_position && $action == 'add') {
  6220. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6221. }
  6222. elseif ($key == $id_prerequisite && $action == 'edit') {
  6223. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6224. }
  6225. else {
  6226. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6227. }
  6228. }
  6229. $return .= "</select></td>";
  6230. */
  6231. $return .= '</tr>';
  6232. }
  6233. $return .= '<tr>';
  6234. if ($action == 'add') {
  6235. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6236. } else {
  6237. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6238. }
  6239. $return .= '</tr>';
  6240. $return .= '</table>';
  6241. if ($action == 'move') {
  6242. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6243. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6244. }
  6245. if (is_numeric($extra_info)) {
  6246. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6247. }
  6248. elseif (is_array($extra_info)) {
  6249. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6250. }
  6251. $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
  6252. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6253. $return .= '</form>';
  6254. $return .= '</div>';
  6255. return $return;
  6256. }
  6257. /**
  6258. * Return HTML form to add/edit a student publication (work)
  6259. * @param string Action (add/edit)
  6260. * @param integer Item ID if already exists
  6261. * @param mixed Extra info (work ID if integer)
  6262. * @return string HTML form
  6263. */
  6264. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6265. global $charset;
  6266. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6267. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6268. if ($id != 0 && is_array($extra_info)) {
  6269. $item_title = stripslashes($extra_info['title']);
  6270. $item_description = stripslashes($extra_info['description']);
  6271. }
  6272. elseif (is_numeric($extra_info)) {
  6273. $sql_publication = "
  6274. SELECT
  6275. title,
  6276. description
  6277. FROM " . $tbl_publication . "
  6278. WHERE id = " . $extra_info;
  6279. $result = Database::query($sql_publication);
  6280. $row = Database :: fetch_array($result);
  6281. $item_title = $row['title'];
  6282. } else {
  6283. $item_title = get_lang('Student_publication');
  6284. }
  6285. $return = ' <div class="row">
  6286. <div class="form_header">';
  6287. if ($id != 0 && is_array($extra_info))
  6288. $parent = $extra_info['parent_item_id'];
  6289. else
  6290. $parent = 0;
  6291. $sql = "
  6292. SELECT *
  6293. FROM " . $tbl_lp_item . "
  6294. WHERE
  6295. lp_id = " . $this->lp_id;
  6296. $result = Database::query($sql);
  6297. $arrLP = array ();
  6298. while ($row = Database :: fetch_array($result)) {
  6299. $arrLP[] = array (
  6300. 'id' => $row['id'],
  6301. 'item_type' => $row['item_type'],
  6302. 'title' => $row['title'],
  6303. 'path' => $row['path'],
  6304. 'description' => $row['description'],
  6305. 'parent_item_id' => $row['parent_item_id'],
  6306. 'previous_item_id' => $row['previous_item_id'],
  6307. 'next_item_id' => $row['next_item_id'],
  6308. 'display_order' => $row['display_order'],
  6309. 'max_score' => $row['max_score'],
  6310. 'min_score' => $row['min_score'],
  6311. 'mastery_score' => $row['mastery_score'],
  6312. 'prerequisite' => $row['prerequisite']
  6313. );
  6314. }
  6315. $this->tree_array($arrLP);
  6316. $arrLP = $this->arrMenu;
  6317. unset ($this->arrMenu);
  6318. if ($action == 'add')
  6319. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6320. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6321. else
  6322. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6323. $return .= ' </div>
  6324. </div>';
  6325. $return .= '<div class="sectioncomment">';
  6326. $return .= '<form method="POST">';
  6327. $return .= '<table class="lp_form">';
  6328. if ($action != 'move') {
  6329. $return .= '<tr>';
  6330. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6331. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  6332. $return .= '</tr>';
  6333. }
  6334. $return .= '<tr>';
  6335. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6336. $return .= '<td class="input">';
  6337. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" style="width:100%;" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6338. //$parent_item_id = $_SESSION['parent_item_id'];
  6339. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6340. $arrHide = array (
  6341. $id
  6342. );
  6343. for ($i = 0; $i < count($arrLP); $i++) {
  6344. if ($action != 'add') {
  6345. 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)) {
  6346. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  6347. } else {
  6348. $arrHide[] = $arrLP[$i]['id'];
  6349. }
  6350. } else {
  6351. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6352. $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'] . '">' . $arrLP[$i]['title'] . '</option>';
  6353. }
  6354. }
  6355. if (is_array($arrLP)) {
  6356. reset($arrLP);
  6357. }
  6358. $return .= "\t\t\t\t" . '</select>';
  6359. $return .= '</td>';
  6360. $return .= '</tr>';
  6361. $return .= '<tr>';
  6362. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6363. $return .= '<td class="input">';
  6364. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6365. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6366. for ($i = 0; $i < count($arrLP); $i++) {
  6367. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6368. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6369. $selected = 'selected="selected" ';
  6370. elseif ($action == 'add') $selected = 'selected="selected" ';
  6371. else
  6372. $selected = '';
  6373. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6374. }
  6375. }
  6376. $return .= "\t\t\t\t" . '</select>';
  6377. $return .= '</td>';
  6378. $return .= '</tr>';
  6379. if ($action != 'move') {
  6380. $id_prerequisite = 0;
  6381. if (is_array($arrLP)) {
  6382. foreach ($arrLP as $key => $value) {
  6383. if ($value['id'] == $id) {
  6384. $id_prerequisite = $value['prerequisite'];
  6385. break;
  6386. }
  6387. }
  6388. }
  6389. $arrHide = array ();
  6390. for ($i = 0; $i < count($arrLP); $i++) {
  6391. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6392. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6393. $s_selected_position = $arrLP[$i]['id'];
  6394. elseif ($action == 'add') $s_selected_position = 0;
  6395. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6396. }
  6397. }
  6398. // Commented the prerequisites, only visible in edit (work).
  6399. /*
  6400. $return .= '<tr>';
  6401. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6402. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6403. foreach($arrHide as $key => $value) {
  6404. if ($key == $s_selected_position && $action == 'add') {
  6405. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6406. }
  6407. elseif ($key == $id_prerequisite && $action == 'edit') {
  6408. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6409. }
  6410. else {
  6411. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6412. }
  6413. }
  6414. $return .= "</select></td>";
  6415. */
  6416. $return .= '</tr>';
  6417. }
  6418. $return .= '<tr>';
  6419. if ($action == 'add') {
  6420. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6421. } else {
  6422. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6423. }
  6424. $return .= '</tr>';
  6425. $return .= '</table>';
  6426. if ($action == 'move') {
  6427. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6428. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6429. }
  6430. if (is_numeric($extra_info)) {
  6431. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6432. } elseif (is_array($extra_info)) {
  6433. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6434. }
  6435. $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
  6436. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6437. $return .= '</form>';
  6438. $return .= '</div>';
  6439. return $return;
  6440. }
  6441. /**
  6442. * Displays the menu for manipulating a step
  6443. * @return string html
  6444. */
  6445. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6446. global $charset, $_course;
  6447. $return = '<div class="actions">';
  6448. switch ($item_type) {
  6449. case 'dokeos_chapter' :
  6450. case 'chapter' :
  6451. // Commented the message cause should not show it.
  6452. //$lang = get_lang('TitleManipulateChapter');
  6453. break;
  6454. case 'dokeos_module' :
  6455. case 'module' :
  6456. // Commented the message cause should not show it.
  6457. //$lang = get_lang('TitleManipulateModule');
  6458. break;
  6459. case TOOL_DOCUMENT :
  6460. // Commented the message cause should not show it.
  6461. //$lang = get_lang('TitleManipulateDocument');
  6462. break;
  6463. case TOOL_LINK :
  6464. case 'link' :
  6465. // Commented the message cause should not show it.
  6466. //$lang = get_lang('TitleManipulateLink');
  6467. break;
  6468. case TOOL_QUIZ :
  6469. // Commented the message cause should not show it.
  6470. //$lang = get_lang('TitleManipulateQuiz');
  6471. break;
  6472. case TOOL_STUDENTPUBLICATION :
  6473. // Commented the message cause should not show it.
  6474. //$lang = get_lang('TitleManipulateStudentPublication');
  6475. break;
  6476. }
  6477. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6478. $item_id = intval($item_id);
  6479. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = " . $item_id;
  6480. $result = Database::query($sql);
  6481. $row = Database::fetch_assoc($result);
  6482. $s_title = $row['title'];
  6483. // We display an audio player if needed.
  6484. if (!empty ($row['audio'])) {
  6485. $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>';
  6486. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6487. $return .= '<script type="text/javascript">
  6488. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6489. s1.addParam("allowscriptaccess","always");
  6490. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6491. s1.write("container");
  6492. </script>';
  6493. }
  6494. // Commented ":" for message in step.
  6495. //$return .= $lang.': ';
  6496. $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
  6497. $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), $url.'&action=edit_item&path_item=' . $row['path']);
  6498. $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), 22), $url.'&action=move_item');
  6499. // Commented for now as prerequisites cannot be added to chapters.
  6500. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6501. $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), 22), $url.'&action=edit_item_prereq');
  6502. }
  6503. $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), $url.'&action=delete_item');
  6504. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6505. ob_start();
  6506. $audio_recorder_studentview = 'false';
  6507. $audio_recorder_item_id = $item_id;
  6508. if (api_get_setting('service_visio', 'active') == 'true') {
  6509. include 'audiorecorder.inc.php';
  6510. }
  6511. $return .= ob_get_contents();
  6512. ob_end_clean();
  6513. // End of audiorecorder include
  6514. $return .= '</div>';
  6515. return $return;
  6516. }
  6517. /**
  6518. * Creates the javascript needed for filling up the checkboxes without page reload
  6519. *
  6520. * @return string
  6521. */
  6522. public function get_js_dropdown_array() {
  6523. $return = 'var child_name = new Array();' . "\n";
  6524. $return .= 'var child_value = new Array();' . "\n\n";
  6525. $return .= 'child_name[0] = new Array();' . "\n";
  6526. $return .= 'child_value[0] = new Array();' . "\n\n";
  6527. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6528. $sql_zero = "
  6529. SELECT *
  6530. FROM " . $tbl_lp_item . "
  6531. WHERE
  6532. lp_id = " . $this->lp_id . " AND
  6533. parent_item_id = 0
  6534. ORDER BY display_order ASC";
  6535. $res_zero = Database::query($sql_zero);
  6536. global $charset;
  6537. $i = 0;
  6538. while ($row_zero = Database :: fetch_array($res_zero)) {
  6539. $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
  6540. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6541. }
  6542. $return .= "\n";
  6543. $sql = "
  6544. SELECT *
  6545. FROM " . $tbl_lp_item . "
  6546. WHERE
  6547. lp_id = " . $this->lp_id;
  6548. $res = Database::query($sql);
  6549. while ($row = Database :: fetch_array($res)) {
  6550. $sql_parent = "
  6551. SELECT *
  6552. FROM " . $tbl_lp_item . "
  6553. WHERE parent_item_id = " . $row['id'] . "
  6554. ORDER BY display_order ASC";
  6555. $res_parent = Database::query($sql_parent);
  6556. $i = 0;
  6557. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6558. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6559. while ($row_parent = Database :: fetch_array($res_parent)) {
  6560. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
  6561. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6562. }
  6563. $return .= "\n";
  6564. }
  6565. return $return;
  6566. }
  6567. /**
  6568. * Display the form to allow moving an item
  6569. * @param integer Item ID
  6570. * @return string HTML form
  6571. */
  6572. public function display_move_item($item_id) {
  6573. global $_course; //will disappear
  6574. global $charset;
  6575. $return = '';
  6576. if (is_numeric($item_id)) {
  6577. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6578. $sql = "SELECT *
  6579. FROM " . $tbl_lp_item . "
  6580. WHERE id = " . $item_id;
  6581. $res = Database::query($sql);
  6582. $row = Database :: fetch_array($res);
  6583. switch ($row['item_type']) {
  6584. case 'dokeos_chapter' :
  6585. case 'dir' :
  6586. case 'asset' :
  6587. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6588. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6589. break;
  6590. case 'dokeos_module' :
  6591. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6592. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6593. break;
  6594. case TOOL_DOCUMENT :
  6595. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6596. $return .= $this->display_document_form('move', $item_id, $row);
  6597. break;
  6598. case TOOL_LINK :
  6599. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6600. $return .= $this->display_link_form('move', $item_id, $row);
  6601. break;
  6602. case TOOL_HOTPOTATOES :
  6603. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6604. $return .= $this->display_link_form('move', $item_id, $row);
  6605. break;
  6606. case TOOL_QUIZ :
  6607. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6608. $return .= $this->display_quiz_form('move', $item_id, $row);
  6609. break;
  6610. case TOOL_STUDENTPUBLICATION :
  6611. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6612. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6613. break;
  6614. case TOOL_FORUM :
  6615. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6616. $return .= $this->display_forum_form('move', $item_id, $row);
  6617. break;
  6618. case TOOL_THREAD :
  6619. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6620. $return .= $this->display_forum_form('move', $item_id, $row);
  6621. break;
  6622. }
  6623. }
  6624. return $return;
  6625. }
  6626. /**
  6627. * Displays a basic form on the overview page for changing the item title and the item description.
  6628. * @param string $item_type
  6629. * @param string $title
  6630. * @param array $data
  6631. * @return string
  6632. */
  6633. public function display_item_small_form($item_type, $title = '', $data) {
  6634. global $charset;
  6635. $return = '<div class="lp_small_form">';
  6636. $return .= '<p class="lp_title">' . $title . '</p>';
  6637. $return .= '<form method="post">';
  6638. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6639. $return .= '<tr>';
  6640. $return .= '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>';
  6641. $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
  6642. $return .= '</tr>';
  6643. // It said these lines of code - see SVN#11724 and SVN#10770
  6644. //$return .= '<tr>';
  6645. //$return .= '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>';
  6646. //$return .= '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>';
  6647. //$return .= '</tr>';
  6648. $return .= '<tr>';
  6649. $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
  6650. $return .= '</tr>';
  6651. $return .= '</table>';
  6652. $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
  6653. $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
  6654. $return .= '</form>';
  6655. $return .= '</div>';
  6656. return $return;
  6657. }
  6658. /**
  6659. * Return HTML form to allow prerequisites selection
  6660. * @param integer Item ID
  6661. * @return string HTML form
  6662. */
  6663. public function display_item_prerequisites_form($item_id) {
  6664. global $charset;
  6665. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6666. $item_id = intval($item_id);
  6667. /* Current prerequisite */
  6668. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . $item_id;
  6669. $result = Database::query($sql);
  6670. $row = Database::fetch_array($result);
  6671. $preq_id = $row['prerequisite'];
  6672. //$preq_mastery = $row['mastery_score'];
  6673. //$preq_max = $row['max_score'];
  6674. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6675. $return = ' <div class="row">
  6676. <div class="form_header">';
  6677. $return .= get_lang('AddEditPrerequisites');
  6678. $return .= '</div></div>';
  6679. $return .= '<div class="sectioncomment">';
  6680. $return .= '<form method="POST">';
  6681. $return .= '<table class="data_table" style="width:650px">';
  6682. $return .= '<tr>';
  6683. $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
  6684. $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
  6685. $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
  6686. $return .= '</tr>';
  6687. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6688. $return .= '<tr >';
  6689. $return .= '<td colspan="3" class="radio">';
  6690. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
  6691. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6692. $return .= '</tr>';
  6693. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6694. $result = Database::query($sql);
  6695. $arrLP = array ();
  6696. while ($row = Database :: fetch_array($result)) {
  6697. $arrLP[] = array (
  6698. 'id' => $row['id'],
  6699. 'item_type' => $row['item_type'],
  6700. 'title' => $row['title'],
  6701. 'ref' => $row['ref'],
  6702. 'description' => $row['description'],
  6703. 'parent_item_id' => $row['parent_item_id'],
  6704. 'previous_item_id' => $row['previous_item_id'],
  6705. 'next_item_id' => $row['next_item_id'],
  6706. 'max_score' => $row['max_score'],
  6707. 'min_score' => $row['min_score'],
  6708. 'mastery_score' => $row['mastery_score'],
  6709. 'prerequisite' => $row['prerequisite'],
  6710. 'next_item_id' => $row['next_item_id'],
  6711. 'display_order' => $row['display_order']
  6712. );
  6713. if ($row['ref'] == $preq_id) {
  6714. $preq_mastery = $row['mastery_score'];
  6715. $preq_max = $row['max_score'];
  6716. }
  6717. }
  6718. $this->tree_array($arrLP);
  6719. $arrLP = $this->arrMenu;
  6720. unset ($this->arrMenu);
  6721. for ($i = 0; $i < count($arrLP); $i++) {
  6722. if ($arrLP[$i]['id'] == $item_id)
  6723. break;
  6724. $return .= '<tr>';
  6725. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6726. $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'] . '" />';
  6727. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6728. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6729. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6730. } else
  6731. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6732. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6733. } else {
  6734. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6735. }
  6736. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6737. $return .= '</td>';
  6738. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6739. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6740. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6741. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6742. $return .= '</td>';
  6743. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6744. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6745. $return .= '</td>';
  6746. }
  6747. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6748. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6749. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6750. $return .= '</td>';
  6751. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6752. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6753. $return .= '</td>';
  6754. }
  6755. $return .= '</tr>';
  6756. }
  6757. $return .= '<tr>';
  6758. $return .= '</tr>';
  6759. $return .= '</table>';
  6760. $return .= '<div style="padding-top:3px;">';
  6761. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
  6762. $return .= '</div>';
  6763. $return .= '</form>';
  6764. $return .= '</div>';
  6765. return $return;
  6766. }
  6767. /**
  6768. * Return HTML list to allow prerequisites selection for lp
  6769. * @param integer Item ID
  6770. * @return string HTML form
  6771. */
  6772. public function display_lp_prerequisites_list() {
  6773. global $charset;
  6774. $lp_id = $this->lp_id;
  6775. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6776. // get current prerequisite
  6777. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6778. $result = Database::query($sql);
  6779. $row = Database :: fetch_array($result);
  6780. $preq_id = $row['prerequisite'];
  6781. $session_id = api_get_session_id();
  6782. $session_condition = api_get_session_condition($session_id, false);
  6783. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6784. $rs = Database::query($sql);
  6785. $return = '';
  6786. $return .= '<select name="prerequisites" >';
  6787. $return .= '<option value="0">'.get_lang('None').'</option>';
  6788. if (Database::num_rows($rs) > 0) {
  6789. while ($row = Database::fetch_array($rs)) {
  6790. if ($row['id'] == $lp_id) {
  6791. continue;
  6792. }
  6793. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6794. }
  6795. }
  6796. $return .= '</select>';
  6797. return $return;
  6798. }
  6799. /**
  6800. * Creates a list with all the documents in it
  6801. * @return string
  6802. */
  6803. public function get_documents() {
  6804. global $_course;
  6805. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6806. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6807. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6808. $path = '/';
  6809. $path = Database::escape_string(str_replace('_', '\_', $path));
  6810. $added_slash = ($path == '/') ? '' : '/';
  6811. //condition for the session
  6812. $current_session_id = api_get_session_id();
  6813. $condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '".$_course['code']."' )))";
  6814. $sql_doc = "SELECT docs.*
  6815. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6816. WHERE docs.id = last.ref
  6817. AND docs.path LIKE '".$path.$added_slash."%'
  6818. AND docs.path NOT LIKE '%_DELETED_%'
  6819. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6820. $res_doc = Database::query($sql_doc);
  6821. //$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';}\"" . '>'.Display::return_icon('folder_document.gif',get_lang('Documents'),array('style'=>'margin-right:5px;', 'height' => '16px')).' '. get_lang('Documents') . '</div>';
  6822. $return = '<div class="lp_resource">';
  6823. $resources = Database::store_result($res_doc);
  6824. $resources_sorted = array();
  6825. $return .= '<div class="lp_resource_element">';
  6826. $return .= Display::return_icon('new_doc.gif', '', array(), 22);
  6827. $return .= Display::url(get_lang('NewDocument') , api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
  6828. $return .= '</div>';
  6829. // If you want to debug it, I advise you to do "echo" on the eval statements.
  6830. foreach ($resources as $resource) {
  6831. $resource_paths = explode('/', $resource['path']);
  6832. array_shift($resource_paths);
  6833. $path_to_eval = $last_path = '';
  6834. $is_file = false;
  6835. foreach ($resource_paths as $key => $resource_path) {
  6836. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // It's a folder.
  6837. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6838. } else
  6839. if (strpos($resource_path, '.') !== false)
  6840. $is_file = true;
  6841. $last_path = $resource_path;
  6842. }
  6843. if ($is_file) {
  6844. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6845. //for backward compatibility
  6846. if (empty($resource['title'])) {
  6847. $resource['title'] = basename($resource['path']);
  6848. }
  6849. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6850. } else {
  6851. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6852. }
  6853. }
  6854. $label = get_lang('Documents');
  6855. $new_array[$label] = array('id' => 0, 'files'=>$resources_sorted);
  6856. $return .= $this->write_resources_tree($new_array);
  6857. /*if (Database :: num_rows($res_doc) == 0) {
  6858. $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
  6859. }*/
  6860. $return .= '</div>';
  6861. return $return;
  6862. }
  6863. /**
  6864. * Generate and return an HTML list of resources based on a given array.
  6865. * This list is used to show the course creator a list of available resources to choose from
  6866. * when creating a learning path.
  6867. * @param array Array of elements to add to the list
  6868. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6869. * @return string The HTML list
  6870. */
  6871. public function write_resources_tree($resources_sorted, $num = 0) {
  6872. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6873. $return = '';
  6874. if (count($resources_sorted) > 0) {
  6875. foreach ($resources_sorted as $key => $resource) {
  6876. if (isset($resource['id']) && is_int($resource['id'])) {
  6877. // It's a folder.
  6878. //hide some folders
  6879. if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
  6880. continue;
  6881. } elseif(preg_match('/_groupdocs/', $key)){
  6882. continue;
  6883. } elseif(preg_match('/sf_user_/', $key)){
  6884. continue;
  6885. } elseif(preg_match('/shared_folder_session_/', $key)){
  6886. continue;
  6887. }
  6888. //trad some titles
  6889. if ($key=='images') {
  6890. $key=get_lang('Images');
  6891. } elseif($key=='gallery') {
  6892. $key=get_lang('Gallery');
  6893. } elseif($key=='flash') {
  6894. $key=get_lang('Flash');
  6895. } elseif($key=='audio'){
  6896. $key=get_lang('Audio');
  6897. } elseif($key=='video') {
  6898. $key=get_lang('Video');
  6899. }
  6900. $return .= '<div class="doc_resource">';
  6901. $return .= '<div style="margin-left:' . ($num * 18) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '" onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')"><img alt="" src="../img/lp_folder.gif" title="" align="absmiddle" />&nbsp;<span onClick="javascript: testResources(\'' . $resource['id'] . '\',\'img_' . $resource['id'] . '\')" style="cursor: pointer;" >' . $key . '</span></div><div style="display: none;" id="' . $resource['id'] . '">';
  6902. if (isset($resource['files'])) {
  6903. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6904. }
  6905. $return .= '</div></div>';
  6906. } else {
  6907. if (!is_array($resource)) {
  6908. // It's a file.
  6909. $icon = choose_image($resource);
  6910. $position = strrpos($icon, '.');
  6911. $icon = substr($icon, 0, $position) . '_small.gif';
  6912. $file_info = explode('/', $resource);
  6913. $my_file_title = $file_info[0];
  6914. $my_file_name = $file_info[1];
  6915. //$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>';
  6916. // Show the "image name" not the filename of the image.
  6917. $return .= '<div class="doc_resource"><div style="margin-left:' . (($num +1) * 18) . 'px;margin-right:5px;"><a href="' . api_get_self() . '?cidReq=' . Security::remove_XSS($_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;' . $my_file_title . "</a></div></div>\r\n"; }
  6918. }
  6919. }
  6920. }
  6921. return $return;
  6922. }
  6923. /**
  6924. * Creates a list with all the exercises (quiz) in it
  6925. * @return string
  6926. */
  6927. public function get_exercises() {
  6928. // New for hotpotatoes.
  6929. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6930. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6931. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6932. $session_id = api_get_session_id();
  6933. $condition_session = api_get_session_condition($session_id);
  6934. $sql_quiz = "SELECT * FROM $tbl_quiz WHERE active<>'-1' $condition_session ORDER BY title ASC";
  6935. $sql_hot = "SELECT * FROM $tbl_doc WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
  6936. $res_quiz = Database::query($sql_quiz);
  6937. $res_hot = Database::query($sql_hot);
  6938. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: 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>';
  6939. $return = '<div class="lp_resource">';
  6940. $return .= '<div class="lp_resource_element">';
  6941. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6942. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
  6943. $return .= '</div>';
  6944. while ($row_hot = Database :: fetch_array($res_hot)) {
  6945. $return .= '<div class="lp_resource_element">';
  6946. // Display quizhotpotatoes.
  6947. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6948. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_HOTPOTATOES . '&amp;file=' . $row_hot['id'] . '&amp;lp_id=' . $this->lp_id . '">' . ((!empty ($row_hot['comment'])) ? $row_hot['comment'] : Security :: remove_XSS($row_hot['title'])) . '</a>';
  6949. //$return .= $row_quiz['title'];
  6950. $return .= '</div>';
  6951. }
  6952. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6953. $return .= '<div class="lp_resource_element">';
  6954. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6955. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_QUIZ . '&amp;file=' . $row_quiz['id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($row_quiz['title']) . '</a>';
  6956. //$return .= $row_quiz['title'];
  6957. $return .= '</div>';
  6958. }
  6959. /*if (Database :: num_rows($res_quiz) == 0) {
  6960. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  6961. }*/
  6962. $return .= '</div>';
  6963. return $return;
  6964. }
  6965. /**
  6966. * Creates a list with all the links in it
  6967. * @return string
  6968. */
  6969. public function get_links() {
  6970. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6971. $session_id = api_get_session_id();
  6972. $condition_session = api_get_session_condition($session_id,false);
  6973. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6974. $res_link = Database::query($sql_link);
  6975. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: 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>';
  6976. $return = '<div class="lp_resource">';
  6977. $return .= '<div class="lp_resource_element">';
  6978. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6979. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  6980. $return .= '</div>';
  6981. while ($row_link = Database :: fetch_array($res_link)) {
  6982. $return .= '<div class="lp_resource_element">';
  6983. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6984. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_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>';
  6985. $return .= '</div>';
  6986. }
  6987. /*if (Database :: num_rows($res_link) == 0)
  6988. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  6989. */
  6990. $return .= '</div>';
  6991. return $return;
  6992. }
  6993. /**
  6994. * Creates a list with all the student publications in it
  6995. * @return unknown
  6996. */
  6997. public function get_student_publications() {
  6998. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6999. $session_id = api_get_session_id();
  7000. $condition_session = api_get_session_condition($session_id, false);
  7001. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  7002. $res_student = Database::query($sql_student);
  7003. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: 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>';
  7004. $return = '<div class="lp_resource" >';
  7005. $return .= '<div class="lp_resource_element">';
  7006. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  7007. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_STUDENTPUBLICATION . '&amp;lp_id=' . $this->lp_id . '">' . get_lang('AddAssignmentPage') . '</a>';
  7008. $return .= '</div>';
  7009. $return .= '</div>';
  7010. return $return;
  7011. }
  7012. /**
  7013. * Creates a list with all the forums in it
  7014. * @return string
  7015. */
  7016. public function get_forums() {
  7017. require_once '../forum/forumfunction.inc.php';
  7018. require_once '../forum/forumconfig.inc.php';
  7019. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  7020. $table_forums = Database :: get_course_table(TABLE_FORUM);
  7021. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  7022. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  7023. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  7024. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  7025. $a_forums = get_forums();
  7026. //$return .= '<div class="lp_resource_header"' . " onclick=\"javascript: 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>';
  7027. $return = '<div class="lp_resource">';
  7028. $return .= '<div class="lp_resource_element">';
  7029. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  7030. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&amp;content=forum&amp;origin=learnpath&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
  7031. $return .= '</div>';
  7032. foreach ($a_forums as $forum) {
  7033. $return .= '<div class="lp_resource_element_no_link">';
  7034. $return .= '<script type="text/javascript">
  7035. function toggle_forum(forum_id){
  7036. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  7037. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  7038. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  7039. }
  7040. else {
  7041. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  7042. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  7043. }
  7044. }
  7045. </script>';
  7046. if (!empty($forum['forum_id'])) {
  7047. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  7048. $return .= '<a style="cursor:hand" onclick="javascript: 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>
  7049. <a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_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">' . Security :: remove_XSS($forum['forum_title']) . '</a><ul style="display:none" id="forum_' . $forum['forum_id'] . '_content">';
  7050. }
  7051. $a_threads = get_threads($forum['forum_id']);
  7052. if (is_array($a_threads)) {
  7053. foreach ($a_threads as $thread) {
  7054. $return .= '<li><a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_THREAD . '&amp;thread_id=' . $thread['thread_id'] . '&amp;lp_id=' . $this->lp_id . '">' . Security :: remove_XSS($thread['thread_title']) . '</a></li>';
  7055. }
  7056. }
  7057. $return .= '</ul></div>';
  7058. }
  7059. return $return;
  7060. }
  7061. /**
  7062. * // TODO: The output encoding should be equal to the system encoding.
  7063. *
  7064. * Exports the learning path as a SCORM package. This is the main function that
  7065. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  7066. * whole thing and returns the zip.
  7067. *
  7068. * This method needs to be called in PHP5, as it will fail with non-adequate
  7069. * XML package (like the ones for PHP4), and it is *not* a static method, so
  7070. * you need to call it on a learnpath object.
  7071. * @TODO The method might be redefined later on in the scorm class itself to avoid
  7072. * creating a SCORM structure if there is one already. However, if the initial SCORM
  7073. * path has been modified, it should use the generic method here below.
  7074. * @TODO link this function with the export_lp() function in the same class
  7075. * @param string Optional name of zip file. If none, title of learnpath is
  7076. * domesticated and trailed with ".zip"
  7077. * @return string Returns the zip package string, or null if error
  7078. */
  7079. public function scorm_export() {
  7080. global $_course;
  7081. // Remove memory and time limits as much as possible as this might be a long process...
  7082. if (function_exists('ini_set')) {
  7083. $mem = ini_get('memory_limit');
  7084. if (substr($mem, -1, 1) == 'M') {
  7085. $mem_num = substr($mem, 0, -1);
  7086. if ($mem_num < 128) {
  7087. ini_set('memory_limit', '128M');
  7088. }
  7089. } else {
  7090. ini_set('memory_limit', '128M');
  7091. }
  7092. ini_set('max_execution_time', 600);
  7093. //} else {
  7094. //error_log('Scorm export: could not change memory and time limits', 0);
  7095. }
  7096. // Create the zip handler (this will remain available throughout the method).
  7097. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  7098. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7099. $temp_dir_short = uniqid();
  7100. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  7101. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  7102. $zip_folder = new PclZip($temp_zip_file);
  7103. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  7104. $root_path = $main_path = api_get_path(SYS_PATH);
  7105. $files_cleanup = array();
  7106. // Place to temporarily stash the zipfiles.
  7107. // create the temp dir if it doesn't exist
  7108. // or do a cleanup befor creating the zipfile.
  7109. if (!is_dir($temp_zip_dir)) {
  7110. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  7111. } else {
  7112. // Cleanup: Check the temp dir for old files and delete them.
  7113. $handle = opendir($temp_zip_dir);
  7114. while (false !== ($file = readdir($handle))) {
  7115. if ($file != '.' && $file != '..') {
  7116. unlink("$temp_zip_dir/$file");
  7117. }
  7118. }
  7119. closedir($handle);
  7120. }
  7121. $zip_files = $zip_files_abs = $zip_files_dist = array();
  7122. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  7123. // Remove the possible . at the end of the path.
  7124. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  7125. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  7126. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  7127. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  7128. }
  7129. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  7130. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  7131. // Aggregation Model official document, secion "2.3 Content Packaging".
  7132. $xmldoc = new DOMDocument('1.0'); // We are going to build a UTF-8 encoded manifest. Later we will recode it to the desired (and supported) encoding.
  7133. $root = $xmldoc->createElement('manifest');
  7134. $root->setAttribute('identifier', 'SingleCourseManifest');
  7135. $root->setAttribute('version', '1.1');
  7136. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  7137. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  7138. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  7139. $root->setAttribute('xsi:schemaLocation', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd');
  7140. // Build mandatory sub-root container elements.
  7141. $metadata = $xmldoc->createElement('metadata');
  7142. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  7143. $metadata->appendChild($md_schema);
  7144. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7145. $metadata->appendChild($md_schemaversion);
  7146. $root->appendChild($metadata);
  7147. $organizations = $xmldoc->createElement('organizations');
  7148. $resources = $xmldoc->createElement('resources');
  7149. // Build the only organization we will use in building our learnpaths.
  7150. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7151. $organization = $xmldoc->createElement('organization');
  7152. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7153. // To set the title of the SCORM entity (=organization), we take the name given
  7154. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7155. // learning path charset) as it is the encoding that defines how it is stored
  7156. // in the database. Then we convert it to HTML entities again as the "&" character
  7157. // alone is not authorized in XML (must be &amp;).
  7158. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7159. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7160. $organization->appendChild($org_title);
  7161. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7162. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7163. $link_updates = array();
  7164. foreach ($this->items as $index => $item) {
  7165. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7166. // Get included documents from this item.
  7167. if ($item->type == 'sco')
  7168. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7169. else
  7170. $inc_docs = $item->get_resources_from_source();
  7171. // Give a child element <item> to the <organization> element.
  7172. $my_item_id = $item->get_id();
  7173. $my_item = $xmldoc->createElement('item');
  7174. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7175. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7176. $my_item->setAttribute('isvisible', 'true');
  7177. // Give a child element <title> to the <item> element.
  7178. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7179. $my_item->appendChild($my_title);
  7180. // Give a child element <adlcp:prerequisites> to the <item> element.
  7181. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7182. $my_prereqs->setAttribute('type', 'aicc_script');
  7183. $my_item->appendChild($my_prereqs);
  7184. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7185. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7186. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7187. //$xmldoc->createElement('adlcp:timelimitaction','');
  7188. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7189. //$xmldoc->createElement('adlcp:datafromlms','');
  7190. // Give a child element <adlcp:masteryscore> to the <item> element.
  7191. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7192. $my_item->appendChild($my_masteryscore);
  7193. // Attach this item to the organization element or hits parent if there is one.
  7194. if (!empty($item->parent) && $item->parent != 0) {
  7195. $children = $organization->childNodes;
  7196. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7197. if (is_object($possible_parent)) {
  7198. $possible_parent->appendChild($my_item);
  7199. } else {
  7200. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7201. }
  7202. } else {
  7203. if ($this->debug > 0) { error_log('No parent'); }
  7204. $organization->appendChild($my_item);
  7205. }
  7206. // Get the path of the file(s) from the course directory root.
  7207. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7208. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7209. $my_xml_file_path = $my_file_path;
  7210. $my_sub_dir = dirname($my_file_path);
  7211. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7212. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7213. $my_xml_sub_dir = $my_sub_dir;
  7214. // Give a <resource> child to the <resources> element
  7215. $my_resource = $xmldoc->createElement('resource');
  7216. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7217. $my_resource->setAttribute('type', 'webcontent');
  7218. $my_resource->setAttribute('href', $my_xml_file_path);
  7219. // adlcp:scormtype can be either 'sco' or 'asset'.
  7220. if ($item->type == 'sco') {
  7221. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7222. } else {
  7223. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7224. }
  7225. // xml:base is the base directory to find the files declared in this resource.
  7226. $my_resource->setAttribute('xml:base', '');
  7227. // Give a <file> child to the <resource> element.
  7228. $my_file = $xmldoc->createElement('file');
  7229. $my_file->setAttribute('href', $my_xml_file_path);
  7230. $my_resource->appendChild($my_file);
  7231. // Dependency to other files - not yet supported.
  7232. $i = 1;
  7233. foreach ($inc_docs as $doc_info) {
  7234. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7235. $my_dep = $xmldoc->createElement('resource');
  7236. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7237. $my_dep->setAttribute('identifier', $res_id);
  7238. $my_dep->setAttribute('type', 'webcontent');
  7239. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7240. $my_dep_file = $xmldoc->createElement('file');
  7241. // Check type of URL.
  7242. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7243. if ($doc_info[1] == 'remote') {
  7244. // Remote file. Save url as is.
  7245. $my_dep_file->setAttribute('href', $doc_info[0]);
  7246. $my_dep->setAttribute('xml:base', '');
  7247. } elseif ($doc_info[1] == 'local') {
  7248. switch ($doc_info[2]) {
  7249. case 'url': // Local URL - save path as url for now, don't zip file.
  7250. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7251. $current_dir = dirname($abs_path);
  7252. $current_dir = str_replace('\\', '/', $current_dir);
  7253. $file_path = realpath($abs_path);
  7254. $file_path = str_replace('\\', '/', $file_path);
  7255. $my_dep_file->setAttribute('href', $file_path);
  7256. $my_dep->setAttribute('xml:base', '');
  7257. if (strstr($file_path, $main_path) !== false) {
  7258. // The calculated real path is really inside Chamilo's root path.
  7259. // Reduce file path to what's under the DocumentRoot.
  7260. $file_path = substr($file_path, strlen($root_path) - 1);
  7261. //echo $file_path;echo '<br /><br />';
  7262. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7263. $zip_files_abs[] = $file_path;
  7264. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7265. $my_dep_file->setAttribute('href', $file_path);
  7266. $my_dep->setAttribute('xml:base', '');
  7267. }
  7268. elseif (empty($file_path)) {
  7269. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7270. if (strpos($document_root, -1) == '/') {
  7271. $document_root = substr(0, -1, $document_root);
  7272. }*/
  7273. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7274. $file_path = str_replace('//', '/', $file_path);
  7275. if (file_exists($file_path)) {
  7276. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7277. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7278. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7279. $my_dep_file->setAttribute('href', $file_path);
  7280. $my_dep->setAttribute('xml:base', '');
  7281. }
  7282. }
  7283. break;
  7284. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7285. $my_dep_file->setAttribute('href', $doc_info[0]);
  7286. $my_dep->setAttribute('xml:base', '');
  7287. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7288. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7289. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7290. $abs_img_path_without_subdir = $doc_info[0];
  7291. $relp = api_get_path(REL_PATH); // The url-append config param.
  7292. $pos = strpos($abs_img_path_without_subdir, $relp);
  7293. if ($pos === 0) {
  7294. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7295. }
  7296. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7297. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7298. $file_path = str_replace('\\', '/', $file_path);
  7299. $file_path = str_replace('//', '/', $file_path);
  7300. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7301. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7302. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7303. // Check if the current document is in that path.
  7304. if (strstr($file_path, $cur_path) !== false) {
  7305. // The document is in that path, now get the relative path
  7306. // to the containing document.
  7307. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7308. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7309. $relative_path = '';
  7310. if (strstr($file_path, $cur_path) !== false) {
  7311. $relative_path = substr($file_path, strlen($orig_file_path));
  7312. $file_path = substr($file_path, strlen($cur_path));
  7313. } else {
  7314. // This case is still a problem as it's difficult to calculate a relative path easily
  7315. // might still generate wrong links.
  7316. //$file_path = substr($file_path,strlen($cur_path));
  7317. // Calculate the directory path to the current file (without trailing slash).
  7318. $my_relative_path = dirname($file_path);
  7319. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7320. $my_relative_file = basename($file_path);
  7321. // Calculate the directory path to the containing file (without trailing slash).
  7322. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7323. $dotdot = '';
  7324. $subdir = '';
  7325. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7326. $my_relative_path2 = dirname($my_relative_path);
  7327. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7328. $my_orig_file_path = dirname($my_orig_file_path);
  7329. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7330. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7331. $dotdot += '../';
  7332. $my_relative_path = $my_relative_path2;
  7333. }
  7334. $relative_path = $dotdot.$subdir.$my_relative_file;
  7335. }
  7336. // Put the current document in the zip (this array is the array
  7337. // that will manage documents already in the course folder - relative).
  7338. $zip_files[] = $file_path;
  7339. // Update the links to the current document in the containing document (make them relative).
  7340. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7341. $my_dep_file->setAttribute('href', $file_path);
  7342. $my_dep->setAttribute('xml:base', '');
  7343. }
  7344. elseif (strstr($file_path,$main_path) !== false) {
  7345. // The calculated real path is really inside Chamilo's root path.
  7346. // Reduce file path to what's under the DocumentRoot.
  7347. $file_path = substr($file_path, strlen($root_path));
  7348. //echo $file_path;echo '<br /><br />';
  7349. //error_log('Reduced path: '.$file_path, 0);
  7350. $zip_files_abs[] = $file_path;
  7351. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7352. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7353. $my_dep->setAttribute('xml:base', '');
  7354. }
  7355. elseif (empty($file_path)) {
  7356. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7357. if(strpos($document_root,-1) == '/') {
  7358. $document_root = substr(0, -1, $document_root);
  7359. }*/
  7360. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7361. $file_path = str_replace('//', '/', $file_path);
  7362. if (file_exists($file_path)) {
  7363. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7364. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7365. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7366. $my_dep_file->setAttribute('href','document/'.$file_path);
  7367. $my_dep->setAttribute('xml:base', '');
  7368. }
  7369. }
  7370. break;
  7371. 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
  7372. if (substr($doc_info[0], 0, 2) == '..') {
  7373. // Relative path going up.
  7374. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7375. $current_dir = str_replace('\\', '/', $current_dir);
  7376. $file_path = realpath($current_dir.$doc_info[0]);
  7377. $file_path = str_replace('\\', '/', $file_path);
  7378. //error_log($file_path.' <-> '.$main_path,0);
  7379. if (strstr($file_path, $main_path) !== false) {
  7380. // The calculated real path is really inside Chamilo's root path.
  7381. // Reduce file path to what's under the DocumentRoot.
  7382. $file_path = substr($file_path, strlen($root_path));
  7383. //error_log('Reduced path: '.$file_path, 0);
  7384. $zip_files_abs[] = $file_path;
  7385. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7386. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7387. $my_dep->setAttribute('xml:base', '');
  7388. }
  7389. } else {
  7390. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7391. $my_dep_file->setAttribute('href', $doc_info[0]);
  7392. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7393. }
  7394. break;
  7395. default:
  7396. $my_dep_file->setAttribute('href', $doc_info[0]);
  7397. $my_dep->setAttribute('xml:base', '');
  7398. break;
  7399. }
  7400. }
  7401. $my_dep->appendChild($my_dep_file);
  7402. $resources->appendChild($my_dep);
  7403. $dependency = $xmldoc->createElement('dependency');
  7404. $dependency->setAttribute('identifierref', $res_id);
  7405. $my_resource->appendChild($dependency);
  7406. $i++;
  7407. }
  7408. //$my_dependency = $xmldoc->createElement('dependency');
  7409. //$my_dependency->setAttribute('identifierref', '');
  7410. $resources->appendChild($my_resource);
  7411. $zip_files[] = $my_file_path;
  7412. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7413. } else {
  7414. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7415. if ($item->type == TOOL_LINK) {
  7416. $my_item = $xmldoc->createElement('item');
  7417. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7418. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7419. $my_item->setAttribute('isvisible', 'true');
  7420. // Give a child element <title> to the <item> element.
  7421. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7422. $my_item->appendChild($my_title);
  7423. // Give a child element <adlcp:prerequisites> to the <item> element.
  7424. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7425. $my_prereqs->setAttribute('type', 'aicc_script');
  7426. $my_item->appendChild($my_prereqs);
  7427. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7428. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7429. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7430. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7431. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7432. //$xmldoc->createElement('adlcp:datafromlms', '');
  7433. // Give a child element <adlcp:masteryscore> to the <item> element.
  7434. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7435. $my_item->appendChild($my_masteryscore);
  7436. // Attach this item to the organization element or its parent if there is one.
  7437. if (!empty($item->parent) && $item->parent != 0) {
  7438. $children = $organization->childNodes;
  7439. for ($i = 0; $i < $children->length; $i++) {
  7440. $item_temp = $children->item($i);
  7441. if ($item_temp -> nodeName == 'item') {
  7442. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7443. $item_temp -> appendChild($my_item);
  7444. }
  7445. }
  7446. }
  7447. } else {
  7448. $organization->appendChild($my_item);
  7449. }
  7450. $my_file_path = 'link_'.$item->get_id().'.html';
  7451. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7452. $rs = Database::query($sql);
  7453. if ($link = Database :: fetch_array($rs)) {
  7454. $url = $link['url'];
  7455. $title = stripslashes($link['title']);
  7456. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7457. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7458. $my_xml_file_path = $my_file_path;
  7459. $my_sub_dir = dirname($my_file_path);
  7460. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7461. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7462. $my_xml_sub_dir = $my_sub_dir;
  7463. // Give a <resource> child to the <resources> element.
  7464. $my_resource = $xmldoc->createElement('resource');
  7465. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7466. $my_resource->setAttribute('type', 'webcontent');
  7467. $my_resource->setAttribute('href', $my_xml_file_path);
  7468. // adlcp:scormtype can be either 'sco' or 'asset'.
  7469. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7470. // xml:base is the base directory to find the files declared in this resource.
  7471. $my_resource->setAttribute('xml:base', '');
  7472. // give a <file> child to the <resource> element.
  7473. $my_file = $xmldoc->createElement('file');
  7474. $my_file->setAttribute('href', $my_xml_file_path);
  7475. $my_resource->appendChild($my_file);
  7476. $resources->appendChild($my_resource);
  7477. }
  7478. }
  7479. elseif ($item->type == TOOL_QUIZ) {
  7480. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7481. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7482. $exe = new Exercise();
  7483. $exe->read($exe_id);
  7484. $my_item = $xmldoc->createElement('item');
  7485. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7486. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7487. $my_item->setAttribute('isvisible', 'true');
  7488. // Give a child element <title> to the <item> element.
  7489. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7490. $my_item->appendChild($my_title);
  7491. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7492. //$my_item->appendChild($my_max_score);
  7493. // Give a child element <adlcp:prerequisites> to the <item> element.
  7494. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7495. $my_prereqs->setAttribute('type','aicc_script');
  7496. $my_item->appendChild($my_prereqs);
  7497. // Give a child element <adlcp:masteryscore> to the <item> element.
  7498. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7499. $my_item->appendChild($my_masteryscore);
  7500. // Attach this item to the organization element or hits parent if there is one.
  7501. if (!empty($item->parent) && $item->parent != 0) {
  7502. $children = $organization->childNodes;
  7503. for ($i = 0; $i < $children->length; $i++) {
  7504. $item_temp = $children->item($i);
  7505. if ($item_temp -> nodeName == 'item') {
  7506. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7507. $item_temp -> appendChild($my_item);
  7508. }
  7509. }
  7510. }
  7511. } else {
  7512. $organization->appendChild($my_item);
  7513. }
  7514. // Include export scripts.
  7515. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7516. // Get the path of the file(s) from the course directory root
  7517. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7518. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7519. // Write the contents of the exported exercise into a (big) html file
  7520. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7521. $contents = export_exercise($exe_id,true);
  7522. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7523. $res = file_put_contents($tmp_file_path, $contents);
  7524. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7525. $files_cleanup[] = $tmp_file_path;
  7526. //error_log($tmp_path); die();
  7527. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7528. $my_xml_file_path = $my_file_path;
  7529. $my_sub_dir = dirname($my_file_path);
  7530. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7531. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7532. $my_xml_sub_dir = $my_sub_dir;
  7533. // Give a <resource> child to the <resources> element.
  7534. $my_resource = $xmldoc->createElement('resource');
  7535. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7536. $my_resource->setAttribute('type', 'webcontent');
  7537. $my_resource->setAttribute('href', $my_xml_file_path);
  7538. // adlcp:scormtype can be either 'sco' or 'asset'.
  7539. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7540. // xml:base is the base directory to find the files declared in this resource.
  7541. $my_resource->setAttribute('xml:base', '');
  7542. // Give a <file> child to the <resource> element.
  7543. $my_file = $xmldoc->createElement('file');
  7544. $my_file->setAttribute('href', $my_xml_file_path);
  7545. $my_resource->appendChild($my_file);
  7546. // Get included docs.
  7547. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7548. // Dependency to other files - not yet supported.
  7549. $i = 1;
  7550. foreach ($inc_docs as $doc_info) {
  7551. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7552. $my_dep = $xmldoc->createElement('resource');
  7553. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7554. $my_dep->setAttribute('identifier', $res_id);
  7555. $my_dep->setAttribute('type', 'webcontent');
  7556. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7557. $my_dep_file = $xmldoc->createElement('file');
  7558. // Check type of URL.
  7559. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7560. if ($doc_info[1] == 'remote') {
  7561. // Remote file. Save url as is.
  7562. $my_dep_file->setAttribute('href', $doc_info[0]);
  7563. $my_dep->setAttribute('xml:base', '');
  7564. } elseif ($doc_info[1] == 'local') {
  7565. switch ($doc_info[2]) {
  7566. case 'url': // Local URL - save path as url for now, don't zip file.
  7567. // Save file but as local file (retrieve from URL).
  7568. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7569. $current_dir = dirname($abs_path);
  7570. $current_dir = str_replace('\\', '/', $current_dir);
  7571. $file_path = realpath($abs_path);
  7572. $file_path = str_replace('\\', '/', $file_path);
  7573. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7574. $my_dep->setAttribute('xml:base', '');
  7575. if (strstr($file_path, $main_path) !== false) {
  7576. // The calculated real path is really inside the chamilo root path.
  7577. // Reduce file path to what's under the DocumentRoot.
  7578. $file_path = substr($file_path, strlen($root_path));
  7579. //echo $file_path;echo '<br /><br />';
  7580. //error_log('Reduced path: '.$file_path, 0);
  7581. $zip_files_abs[] = $file_path;
  7582. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7583. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7584. $my_dep->setAttribute('xml:base', '');
  7585. }
  7586. elseif (empty($file_path)) {
  7587. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7588. if (strpos($document_root,-1) == '/') {
  7589. $document_root = substr(0, -1, $document_root);
  7590. }*/
  7591. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7592. $file_path = str_replace('//', '/', $file_path);
  7593. if (file_exists($file_path)) {
  7594. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7595. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7596. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7597. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7598. $my_dep->setAttribute('xml:base', '');
  7599. }
  7600. }
  7601. break;
  7602. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7603. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7604. $current_dir = str_replace('\\', '/', $current_dir);
  7605. $file_path = realpath($doc_info[0]);
  7606. $file_path = str_replace('\\', '/', $file_path);
  7607. $my_dep_file->setAttribute('href', $file_path);
  7608. $my_dep->setAttribute('xml:base', '');
  7609. if (strstr($file_path,$main_path) !== false) {
  7610. // The calculated real path is really inside the chamilo root path.
  7611. // Reduce file path to what's under the DocumentRoot.
  7612. $file_path = substr($file_path, strlen($root_path));
  7613. //echo $file_path;echo '<br /><br />';
  7614. //error_log('Reduced path: '.$file_path, 0);
  7615. $zip_files_abs[] = $file_path;
  7616. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7617. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7618. $my_dep->setAttribute('xml:base', '');
  7619. }
  7620. elseif (empty($file_path)) {
  7621. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7622. if (strpos($document_root,-1) == '/') {
  7623. $document_root = substr(0, -1, $document_root);
  7624. }*/
  7625. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7626. $file_path = str_replace('//', '/', $file_path);
  7627. if (file_exists($file_path)) {
  7628. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7629. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7630. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7631. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7632. $my_dep->setAttribute('xml:base', '');
  7633. }
  7634. }
  7635. break;
  7636. 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
  7637. if (substr($doc_info[0], 0, 2) == '..') {
  7638. // Relative path going up.
  7639. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7640. $current_dir = str_replace('\\', '/', $current_dir);
  7641. $file_path = realpath($current_dir.$doc_info[0]);
  7642. $file_path = str_replace('\\', '/', $file_path);
  7643. //error_log($file_path.' <-> '.$main_path, 0);
  7644. if (strstr($file_path, $main_path) !== false) {
  7645. // The calculated real path is really inside Chamilo's root path.
  7646. // Reduce file path to what's under the DocumentRoot.
  7647. $file_path = substr($file_path, strlen($root_path));
  7648. $file_path_dest = $file_path;
  7649. // File path is courses/CHAMILO/document/....
  7650. $info_file_path = explode('/', $file_path);
  7651. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7652. $file_path_dest = 'document/'.$file_path;
  7653. }
  7654. //error_log('Reduced path: '.$file_path, 0);
  7655. $zip_files_abs[] = $file_path;
  7656. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7657. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7658. $my_dep->setAttribute('xml:base', '');
  7659. }
  7660. } else {
  7661. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7662. $my_dep_file->setAttribute('href', $doc_info[0]);
  7663. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7664. }
  7665. break;
  7666. default:
  7667. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7668. $my_dep->setAttribute('xml:base', '');
  7669. break;
  7670. }
  7671. }
  7672. $my_dep->appendChild($my_dep_file);
  7673. $resources->appendChild($my_dep);
  7674. $dependency = $xmldoc->createElement('dependency');
  7675. $dependency->setAttribute('identifierref', $res_id);
  7676. $my_resource->appendChild($dependency);
  7677. $i++;
  7678. }
  7679. $resources->appendChild($my_resource);
  7680. $zip_files[] = $my_file_path;
  7681. } else {
  7682. // Get the path of the file(s) from the course directory root
  7683. $my_file_path = 'non_exportable.html';
  7684. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7685. $my_xml_file_path = $my_file_path;
  7686. $my_sub_dir = dirname($my_file_path);
  7687. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7688. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7689. $my_xml_sub_dir = $my_sub_dir;
  7690. // Give a <resource> child to the <resources> element.
  7691. $my_resource = $xmldoc->createElement('resource');
  7692. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7693. $my_resource->setAttribute('type', 'webcontent');
  7694. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7695. // adlcp:scormtype can be either 'sco' or 'asset'.
  7696. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7697. // xml:base is the base directory to find the files declared in this resource.
  7698. $my_resource->setAttribute('xml:base', '');
  7699. // Give a <file> child to the <resource> element.
  7700. $my_file = $xmldoc->createElement('file');
  7701. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7702. $my_resource->appendChild($my_file);
  7703. $resources->appendChild($my_resource);
  7704. }
  7705. }
  7706. }
  7707. $organizations->appendChild($organization);
  7708. $root->appendChild($organizations);
  7709. $root->appendChild($resources);
  7710. $xmldoc->appendChild($root);
  7711. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7712. // then add the file to the zip, then destroy the file (this is done automatically).
  7713. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7714. //error_log(print_r($zip_files,true), 0);
  7715. foreach ($zip_files as $file_path) {
  7716. if (empty($file_path)) { continue; }
  7717. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7718. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7719. $this->create_path($dest_file);
  7720. //error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path,0);
  7721. //echo $main_path.$file_path.'<br />';
  7722. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7723. // Check if the file needs a link update.
  7724. if (in_array($file_path, array_keys($link_updates))) {
  7725. $string = file_get_contents($dest_file);
  7726. unlink($dest_file);
  7727. foreach ($link_updates[$file_path] as $old_new) {
  7728. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7729. // This is an ugly hack that allows .flv files to be found by the flv player that
  7730. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7731. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7732. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7733. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7734. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7735. }
  7736. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7737. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7738. }
  7739. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7740. }
  7741. file_put_contents($dest_file, $string);
  7742. }
  7743. }
  7744. foreach ($zip_files_abs as $file_path) {
  7745. if (empty($file_path)) { continue; }
  7746. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7747. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7748. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7749. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7750. $this->create_path($dest_file);
  7751. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7752. //error_log('copy '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/'.$file_path.' to '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/'.$file_path, 0);
  7753. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7754. copy($main_path.$file_path, $dest_file);
  7755. // Check if the file needs a link update.
  7756. if (in_array($file_path, array_keys($link_updates))) {
  7757. $string = file_get_contents($dest_file);
  7758. unlink($dest_file);
  7759. foreach ($link_updates[$file_path] as $old_new) {
  7760. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7761. // This is an ugly hack that allows .flv files to be found by the flv player that
  7762. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7763. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7764. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7765. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7766. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7767. }
  7768. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7769. }
  7770. file_put_contents($dest_file, $string);
  7771. }
  7772. }
  7773. if (is_array($links_to_create)) {
  7774. foreach ($links_to_create as $file => $link) {
  7775. $file_content = '<!DOCTYPE html
  7776. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7777. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7778. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7779. <head>
  7780. <title>'.$link['title'].'</title>
  7781. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7782. </head>
  7783. <body dir="'.api_get_text_direction().'">
  7784. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7785. </body>
  7786. </html>';
  7787. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7788. }
  7789. }
  7790. // Add non exportable message explanation.
  7791. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7792. $file_content = '<!DOCTYPE html
  7793. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7794. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7795. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7796. <head>
  7797. <title>'.$lang_not_exportable.'</title>
  7798. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7799. </head>
  7800. <body dir="'.api_get_text_direction().'">
  7801. ';
  7802. $file_content .=
  7803. <<<EOD
  7804. <style>
  7805. .error-message {
  7806. font-family: arial, verdana, helvetica, sans-serif;
  7807. border-width: 1px;
  7808. border-style: solid;
  7809. left: 50%;
  7810. margin: 10px auto;
  7811. min-height: 30px;
  7812. padding: 5px;
  7813. right: 50%;
  7814. width: 500px;
  7815. background-color: #FFD1D1;
  7816. border-color: #FF0000;
  7817. color: #000;
  7818. }
  7819. </style>
  7820. <body>
  7821. <div class="error-message">
  7822. $lang_not_exportable
  7823. </div>
  7824. </body>
  7825. </html>
  7826. EOD;
  7827. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7828. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7829. }
  7830. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7831. // Add the extra files that go along with a SCORM package.
  7832. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7833. $extra_files = scandir($main_code_path);
  7834. foreach ($extra_files as $extra_file) {
  7835. if (strpos($extra_file, '.') === 0)
  7836. continue;
  7837. else {
  7838. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7839. $this->create_path($dest_file);
  7840. copy($main_code_path.$extra_file, $dest_file);
  7841. }
  7842. }
  7843. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7844. $manifest = @$xmldoc->saveXML();
  7845. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7846. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7847. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7848. // Clean possible temporary files.
  7849. foreach ($files_cleanup as $file) {
  7850. $res = unlink($file);
  7851. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7852. }
  7853. // Send file to client.
  7854. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7855. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7856. $name = replace_dangerous_char($this->get_name()).'.zip';
  7857. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7858. }
  7859. public function scorm_export_to_pdf($lp_id) {
  7860. $lp_id = intval($lp_id);
  7861. $files_to_export = array();
  7862. $course_data = api_get_course_info($this->cc);
  7863. if (!empty($course_data)) {
  7864. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7865. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7866. $list = $this->get_flat_ordered_items_list($lp_id);
  7867. foreach($list as $item_id) {
  7868. $item = $this->items[$item_id];
  7869. //Getting documents from a LP with chamilo documents
  7870. switch ($item->type) {
  7871. case 'document':
  7872. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7873. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7874. if (file_exists($file_path)) {
  7875. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7876. }
  7877. break;
  7878. case 'sco':
  7879. $file_path = $scorm_path.'/'.$item->path;
  7880. if (file_exists($file_path)) {
  7881. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7882. }
  7883. break;
  7884. case 'dokeos_chapter':
  7885. case 'dir':
  7886. case 'chapter':
  7887. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7888. break;
  7889. }
  7890. }
  7891. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7892. $pdf = new PDF();
  7893. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7894. return $result;
  7895. }
  7896. return false;
  7897. }
  7898. /**
  7899. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7900. * if it doesn't exist
  7901. */
  7902. public function create_path($path) {
  7903. $path_bits = split('/', dirname($path));
  7904. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7905. $path_built = IS_WINDOWS_OS ? '' : '/';
  7906. foreach ($path_bits as $bit) {
  7907. if (!empty ($bit)) {
  7908. $new_path = $path_built . $bit;
  7909. if (is_dir($new_path)) {
  7910. $path_built = $new_path . '/';
  7911. } else {
  7912. mkdir($new_path, api_get_permissions_for_new_directories());
  7913. $path_built = $new_path . '/';
  7914. }
  7915. }
  7916. }
  7917. }
  7918. /**
  7919. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7920. * @return boolean The results of the unlink function, or false if there was no image to start with
  7921. */
  7922. public function delete_lp_image() {
  7923. $img = $this->get_preview_image();
  7924. if ($img != '') {
  7925. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7926. $this->set_preview_image('');
  7927. return @ unlink($del_file);
  7928. } else {
  7929. return false;
  7930. }
  7931. }
  7932. /**
  7933. * Uploads an author image to the upload/learning_path/images directory
  7934. * @param array The image array, coming from the $_FILES superglobal
  7935. * @return boolean True on success, false on error
  7936. */
  7937. public function upload_image($image_array) {
  7938. $image_moved = false;
  7939. if (!empty ($image_array['name'])) {
  7940. $upload_ok = process_uploaded_file($image_array);
  7941. $has_attachment = true;
  7942. } else {
  7943. $image_moved = true;
  7944. }
  7945. if ($upload_ok) {
  7946. if ($has_attachment) {
  7947. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7948. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7949. $updir = $sys_course_path . $courseDir;
  7950. // Try to add an extension to the file if it hasn't one.
  7951. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7952. if (!filter_extension($new_file_name)) {
  7953. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7954. $image_moved = false;
  7955. } else {
  7956. $file_extension = explode('.', $image_array['name']);
  7957. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7958. $new_file_name = uniqid('') . '.' . $file_extension;
  7959. $new_path = $updir . '/' . $new_file_name;
  7960. // Resize the image.
  7961. $temp = new Image($image_array['tmp_name']);
  7962. $picture_infos = $temp->get_image_info();
  7963. if ($picture_infos['width'] > 104) {
  7964. $thumbwidth = 104;
  7965. } else {
  7966. $thumbwidth = $picture_infos['width'];
  7967. }
  7968. if ($picture_infos['height'] > 96) {
  7969. $new_height = 96;
  7970. } else {
  7971. $new_height = $picture_infos['height'];
  7972. }
  7973. $temp->resize($thumbwidth, $new_height, 0);
  7974. $result = $temp->send_image($new_path);
  7975. // Storing the image filename.
  7976. if ($result) {
  7977. $image_moved = true;
  7978. $this->set_preview_image($new_file_name);
  7979. return true;
  7980. }
  7981. }
  7982. }
  7983. }
  7984. return false;
  7985. }
  7986. public function set_autolunch($lp_id, $status) {
  7987. $lp_id = intval($lp_id);
  7988. $status = intval($status);
  7989. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  7990. //Setting everything to autolunch = 0
  7991. $attributes['autolunch'] = 0;
  7992. $where = array('session_id = ? '=> api_get_session_id());
  7993. Database::update($lp_table, $attributes,$where);
  7994. if ($status == 1) {
  7995. //Setting my lp_id to autolunch = 1
  7996. $attributes['autolunch'] = 1;
  7997. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  7998. Database::update($lp_table, $attributes, $where );
  7999. }
  8000. }
  8001. }
  8002. if (!function_exists('trim_value')) {
  8003. function trim_value(& $value) {
  8004. $value = trim($value);
  8005. }
  8006. }