learnpath.class.php 420 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906
  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> Improvements
  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 $seriousgame_mode = 0;
  47. public $progress_bar_mode = '%';
  48. // Percentage progress as saved in the db.
  49. public $progress_db = '0';
  50. public $proximity; // Wether the content is distant or local or unknown.
  51. public $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  52. // !!!This array (refs_list) is built differently depending on the nature of the LP.
  53. // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
  54. public $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  55. // TODO: Check if this type variable is useful here (instead of just in the controller script).
  56. public $user_id; //ID of the user that is viewing/using the course
  57. public $update_queue = array();
  58. public $scorm_debug = 0;
  59. public $arrMenu = array(); // Array for the menu items.
  60. public $debug = 0; // Logging level.
  61. public $lp_session_id =0;
  62. public $lp_view_session_id =0; // The specific view might be bound to a session.
  63. public $prerequisite = 0;
  64. public $use_max_score = 1; // 1 or 0
  65. public $created_on = '';
  66. public $modified_on = '';
  67. public $publicated_on = '';
  68. public $expired_on = '';
  69. /**
  70. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  71. * Also builds the list of items into $this->items.
  72. * @param string Course code
  73. * @param integer Learnpath ID
  74. * @param integer User ID
  75. * @return boolean True on success, false on error
  76. */
  77. public function __construct($course, $lp_id, $user_id) {
  78. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  79. // Check params.
  80. // Check course code.
  81. $course_db = '';
  82. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  83. if (empty($course)) {
  84. $this->error = 'Course code is empty';
  85. return false;
  86. } else {
  87. $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
  88. //$course = Database::escape_string($course);
  89. $course = $this->escape_string($course);
  90. $sql = "SELECT * FROM $main_table WHERE code = '$course'";
  91. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying course: '.$sql, 0); }
  92. $res = Database::query($sql);
  93. if (Database::num_rows($res) > 0) {
  94. $this->cc = $course;
  95. $row_course = Database::fetch_array($res);
  96. $course_db = $row_course['db_name'];
  97. } else {
  98. $this->error = 'Course code does not exist in database ('.$sql.')';
  99. return false;
  100. }
  101. }
  102. // Check learnpath ID.
  103. if (empty($lp_id)) {
  104. $this->error = 'Learnpath ID is empty';
  105. return false;
  106. } else {
  107. // TODO: Make it flexible to use any course_code (still using env course code here).
  108. $lp_table = Database::get_course_table(TABLE_LP_MAIN, $course_db);
  109. //$id = Database::escape_integer($id);
  110. $lp_id = $this->escape_string($lp_id);
  111. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
  112. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  113. $res = Database::query($sql);
  114. if (Database::num_rows($res) > 0) {
  115. $this->lp_id = $lp_id;
  116. $row = Database::fetch_array($res);
  117. $this->type = $row['lp_type'];
  118. $this->name = stripslashes($row['name']);
  119. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  120. $this->proximity = $row['content_local'];
  121. $this->theme = $row['theme'];
  122. $this->maker = $row['content_maker'];
  123. $this->prevent_reinit = $row['prevent_reinit'];
  124. $this->seriousgame_mode = $row['seriousgame_mode'];
  125. $this->license = $row['content_license'];
  126. $this->scorm_debug = $row['debug'];
  127. $this->js_lib = $row['js_lib'];
  128. $this->path = $row['path'];
  129. $this->preview_image = $row['preview_image'];
  130. $this->author = $row['author'];
  131. $this->hide_toc_frame = $row['hide_toc_frame'];
  132. $this->lp_session_id = $row['session_id'];
  133. $this->use_max_score = $row['use_max_score'];
  134. $this->created_on = $row['created_on'];
  135. $this->modified_on = $row['modified_on'];
  136. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  137. $this->publicated_on = $row['publicated_on'];
  138. }
  139. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  140. $this->expired_on = $row['expired_on'];
  141. }
  142. if ($this->type == 2) {
  143. if ($row['force_commit'] == 1) {
  144. $this->force_commit = true;
  145. }
  146. }
  147. $this->mode = $row['default_view_mod'];
  148. } else {
  149. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  150. return false;
  151. }
  152. }
  153. // Check user ID.
  154. if (empty($user_id)) {
  155. $this->error = 'User ID is empty';
  156. return false;
  157. } else {
  158. //$main_table = Database::get_main_user_table();
  159. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  160. //$user_id = Database::escape_integer($user_id);
  161. $user_id = $this->escape_string($user_id);
  162. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  163. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  164. $res = Database::query($sql);
  165. if (Database::num_rows($res) > 0) {
  166. $this->user_id = $user_id;
  167. } else {
  168. $this->error = 'User ID does not exist in database ('.$sql.')';
  169. return false;
  170. }
  171. }
  172. // End of variables checking.
  173. $session_id = api_get_session_id();
  174. // Get the session condition for learning paths of the base + session.
  175. $session = api_get_session_condition($session_id);
  176. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  177. $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
  178. // Selecting by view_count descending allows to get the highest view_count first.
  179. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  180. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  181. $res = Database::query($sql);
  182. $view_id = 0; // Used later to query lp_item_view.
  183. if (Database :: num_rows($res) > 0) {
  184. if ($this->debug > 2) {
  185. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  186. }
  187. $row = Database :: fetch_array($res);
  188. $this->attempt = $row['view_count'];
  189. $this->lp_view_id = $row['id'];
  190. $this->last_item_seen = $row['last_item'];
  191. $this->progress_db = $row['progress'];
  192. $this->lp_view_session_id = $row['session_id'];
  193. } else {
  194. if ($this->debug > 2) {
  195. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  196. }
  197. $this->attempt = 1;
  198. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  199. $res_ins = Database::query($sql_ins);
  200. $this->lp_view_id = Database :: insert_id();
  201. if ($this->debug > 2) {
  202. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  203. }
  204. }
  205. // Initialise items.
  206. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
  207. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  208. $res = Database::query($sql);
  209. while ($row = Database::fetch_array($res)) {
  210. $oItem = '';
  211. //$this->ordered_items[] = $row['id'];
  212. switch ($this->type) {
  213. case 3: //aicc
  214. $oItem = new aiccItem('db', $row['id'], $course_db);
  215. if (is_object($oItem)) {
  216. $my_item_id = $oItem->get_id();
  217. $oItem->set_lp_view($this->lp_view_id, $course_db);
  218. $oItem->set_prevent_reinit($this->prevent_reinit);
  219. // Don't use reference here as the next loop will make the pointed object change.
  220. $this->items[$my_item_id] = $oItem;
  221. $this->refs_list[$oItem->ref] = $my_item_id;
  222. if ($this->debug > 2) {
  223. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  224. }
  225. }
  226. break;
  227. case 2:
  228. require_once 'scorm.class.php';
  229. require_once 'scormItem.class.php';
  230. $oItem = new scormItem('db', $row['id'], $course_db);
  231. if (is_object($oItem)) {
  232. $my_item_id = $oItem->get_id();
  233. $oItem->set_lp_view($this->lp_view_id, $course_db);
  234. $oItem->set_prevent_reinit($this->prevent_reinit);
  235. // Don't use reference here as the next loop will make the pointed object change.
  236. error_log('my_item_id->'.$my_item_id);
  237. $this->items[$my_item_id] = $oItem;
  238. $this->refs_list[$oItem->ref] = $my_item_id;
  239. if ($this->debug > 2) {
  240. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  241. }
  242. }
  243. break;
  244. case 1:
  245. default:
  246. require_once 'learnpathItem.class.php';
  247. $oItem = new learnpathItem($row['id'], $user_id, $course_db);
  248. if (is_object($oItem)) {
  249. $my_item_id = $oItem->get_id();
  250. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  251. $oItem->set_prevent_reinit($this->prevent_reinit);
  252. // Don't use reference here as the next loop will make the pointed object change.
  253. $this->items[$my_item_id] = $oItem;
  254. $this->refs_list[$my_item_id] = $my_item_id;
  255. if ($this->debug > 2) {
  256. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  257. }
  258. }
  259. break;
  260. }
  261. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  262. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  263. if (is_object($this->items[$row['id']])) {
  264. $this->items[$row['id']]->set_level(0);
  265. }
  266. } else {
  267. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  268. $this->items[$row['id']]->set_level($level);
  269. if (is_object($this->items[$row['parent_item_id']])) {
  270. // Items is a list of pointers from item DB ids to item objects.
  271. $this->items[$row['parent_item_id']]->add_child($row['id']);
  272. } else {
  273. if ($this->debug > 2) {
  274. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  275. }
  276. }
  277. }
  278. // Get last viewing vars.
  279. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  280. // This query should only return one or zero result.
  281. $sql = "SELECT * " .
  282. "FROM $lp_item_view_table " .
  283. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  284. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  285. if ($this->debug > 2) {
  286. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  287. }
  288. // Get the item status.
  289. $res2 = Database::query($sql);
  290. if (Database :: num_rows($res2) > 0) {
  291. // If this learnpath has already been used by this user, get his last attempt count and
  292. // the last item seen back into this object.
  293. //$max = 0;
  294. $row2 = Database :: fetch_array($res2);
  295. if ($this->debug > 2) {
  296. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  297. }
  298. if (is_object($this->items[$row['id']])) {
  299. $this->items[$row['id']]->set_status($row2['status']);
  300. if (empty ($row2['status'])) {
  301. $this->items[$row['id']]->set_status($this->default_status);
  302. }
  303. }
  304. //$this->attempt = $row['view_count'];
  305. //$this->last_item = $row['id'];
  306. } else { // No item has been found in lp_item_view for this view.
  307. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  308. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  309. //$this->attempt = 1;
  310. //$this->last_item = 0;
  311. if (is_object($this->items[$row['id']])) {
  312. $this->items[$row['id']]->set_status($this->default_status);
  313. }
  314. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  315. $sql_ins = "INSERT INTO $lp_item_view_table " .
  316. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  317. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  318. if ($this->debug > 2) {
  319. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  320. }
  321. $res_ins = Database::query($sql_ins);
  322. }
  323. // Setting the view in the item object.
  324. if (is_object($this->items[$row['id']])) {
  325. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
  326. }
  327. }
  328. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
  329. $this->max_ordered_items = 0;
  330. foreach ($this->ordered_items as $index => $dummy) {
  331. if ($index > $this->max_ordered_items && !empty($dummy)) {
  332. $this->max_ordered_items = $index;
  333. }
  334. }
  335. // TODO: Define the current item better.
  336. $this->first();
  337. if ($this->debug > 2) {
  338. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  339. }
  340. }
  341. /**
  342. * 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
  343. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  344. *
  345. * @param int $parent
  346. * @param int $previous
  347. * @param string $type
  348. * @param int resource ID (ref)
  349. * @param string $title
  350. * @param string $description
  351. * @return int
  352. */
  353. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  354. if ($this->debug > 0) {
  355. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  356. }
  357. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  358. $parent = intval($parent);
  359. $previous = intval($previous);
  360. $type = $this->escape_string($type);
  361. $id = intval($id);
  362. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  363. if (empty ($max_time_allowed)) {
  364. $max_time_allowed = 0;
  365. }
  366. $title = $this->escape_string($title);
  367. $description = $this->escape_string($description);
  368. $sql_count = " SELECT COUNT(id) AS num
  369. FROM " . $tbl_lp_item . "
  370. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  371. $res_count = Database::query($sql_count);
  372. $row = Database :: fetch_array($res_count);
  373. $num = $row['num'];
  374. if ($num > 0) {
  375. if ($previous == 0) {
  376. $sql = "SELECT id, next_item_id, display_order
  377. FROM " . $tbl_lp_item . "
  378. WHERE
  379. lp_id = " . $this->get_id() . " AND
  380. parent_item_id = " . $parent . " AND
  381. previous_item_id = 0 OR previous_item_id=" . $parent;
  382. $result = Database::query($sql);
  383. $row = Database :: fetch_array($result);
  384. $tmp_previous = 0;
  385. $next = $row['id'];
  386. $display_order = 0;
  387. } else {
  388. $previous = (int) $previous;
  389. $sql = "
  390. SELECT
  391. id,
  392. previous_item_id,
  393. next_item_id,
  394. display_order
  395. FROM " . $tbl_lp_item . "
  396. WHERE
  397. lp_id = " . $this->get_id() . " AND
  398. id = " . $previous;
  399. $result = Database::query($sql);
  400. $row = Database :: fetch_array($result);
  401. $tmp_previous = $row['id'];
  402. $next = $row['next_item_id'];
  403. $display_order = $row['display_order'];
  404. }
  405. } else {
  406. $tmp_previous = 0;
  407. $next = 0;
  408. $display_order = 0;
  409. }
  410. $new_item_id = -1;
  411. $id = $this->escape_string($id);
  412. if ($type == 'quiz') {
  413. $sql = 'SELECT SUM(ponderation)
  414. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  415. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  416. ON quiz_question.id = quiz_rel_question.question_id
  417. AND quiz_rel_question.exercice_id = ' . $id;
  418. $rsQuiz = Database::query($sql);
  419. $max_score = Database :: result($rsQuiz, 0, 0);
  420. } else {
  421. $max_score = 100;
  422. }
  423. if ($prerequisites != 0) {
  424. $sql_ins = "
  425. INSERT INTO " . $tbl_lp_item . " ( ".
  426. "lp_id, ".
  427. "item_type, ".
  428. "ref, ".
  429. "title, ".
  430. "description, ".
  431. "path, ".
  432. "max_score, ".
  433. "parent_item_id, ".
  434. "previous_item_id, ".
  435. "next_item_id, ".
  436. "display_order, ".
  437. "prerequisite, ".
  438. "max_time_allowed ".
  439. ") VALUES ( ".
  440. $this->get_id() . ", ".
  441. "'" . $type . "', ".
  442. "'', ".
  443. "'" . $title . "', ".
  444. "'" . $description . "', ".
  445. "'" . $id . "', ".
  446. "'" . $max_score . "', ".
  447. $parent . ", ".
  448. $previous . ", ".
  449. $next . ", ".
  450. ($display_order +1) . ", ".
  451. $prerequisites . ", ".
  452. $max_time_allowed .
  453. ")";
  454. } else {
  455. // Insert new item.
  456. $sql_ins = "
  457. INSERT INTO " . $tbl_lp_item . " ( ".
  458. "lp_id, ".
  459. "item_type, ".
  460. "ref, ".
  461. "title, ".
  462. "description, ".
  463. "path, ".
  464. "max_score, ".
  465. "parent_item_id, ".
  466. "previous_item_id, ".
  467. "next_item_id, ".
  468. "display_order, ".
  469. "max_time_allowed ".
  470. ") VALUES (".
  471. $this->get_id() . ",".
  472. "'" . $type . "',".
  473. "'',".
  474. "'" . $title . "',".
  475. "'" . $description . "',".
  476. "'" . $id . "',".
  477. "'" . $max_score . "',".
  478. $parent . ",".
  479. $previous . ",".
  480. $next . ",".
  481. ($display_order +1) . ",".
  482. $max_time_allowed .
  483. ")";
  484. }
  485. if ($this->debug > 2) {
  486. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  487. }
  488. $res_ins = Database::query($sql_ins);
  489. if ($res_ins > 0) {
  490. $new_item_id = Database :: insert_id($res_ins);
  491. // Update the item that should come after the new item.
  492. $sql_update_next = "
  493. UPDATE " . $tbl_lp_item . "
  494. SET previous_item_id = " . $new_item_id . "
  495. WHERE id = " . $next;
  496. $res_update_next = Database::query($sql_update_next);
  497. // Update the item that should be before the new item.
  498. $sql_update_previous = "
  499. UPDATE " . $tbl_lp_item . "
  500. SET next_item_id = " . $new_item_id . "
  501. WHERE id = " . $tmp_previous;
  502. $res_update_previous = Database::query($sql_update_previous);
  503. // Update all the items after the new item.
  504. $sql_update_order = "
  505. UPDATE " . $tbl_lp_item . "
  506. SET display_order = display_order + 1
  507. WHERE
  508. lp_id = " . $this->get_id() . " AND
  509. id <> " . $new_item_id . " AND
  510. parent_item_id = " . $parent . " AND
  511. display_order > " . $display_order;
  512. $res_update_previous = Database::query($sql_update_order);
  513. // Update the item that should come after the new item.
  514. $sql_update_ref = "
  515. UPDATE " . $tbl_lp_item . "
  516. SET ref = " . $new_item_id . "
  517. WHERE id = " . $new_item_id;
  518. Database::query($sql_update_ref);
  519. }
  520. // Upload audio.
  521. if (!empty ($_FILES['mp3']['name'])) {
  522. // Create the audio folder if it does not exist yet.
  523. global $_course;
  524. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  525. if (!is_dir($filepath . 'audio')) {
  526. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  527. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  528. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  529. }
  530. // Upload the file in the documents tool.
  531. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  532. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  533. // Getting the filename only.
  534. $file_components = explode('/', $file_path);
  535. $file = $file_components[count($file_components) - 1];
  536. // Store the mp3 file in the lp_item table.
  537. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  538. Database::query($sql_insert_audio);
  539. }
  540. return $new_item_id;
  541. }
  542. /**
  543. * Static admin function allowing addition of a learnpath to a course.
  544. * @param string Course code
  545. * @param string Learnpath name
  546. * @param string Learnpath description string, if provided
  547. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  548. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  549. * @param string Zip file containing the learnpath or directory containing the learnpath
  550. * @return integer The new learnpath ID on success, 0 on failure
  551. */
  552. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  553. global $charset;
  554. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  555. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  556. // Check course code exists.
  557. // Check lp_name doesn't exist, otherwise append something.
  558. $i = 0;
  559. $name = learnpath :: escape_string($name);
  560. // Session id.
  561. $session_id = api_get_session_id();
  562. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  563. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  564. $res_name = Database::query($check_name);
  565. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  566. //by default the publication date is the same that the creation date
  567. $publicated_on = api_get_utc_datetime();
  568. } else {
  569. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  570. }
  571. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  572. $expired_on = '';
  573. } else {
  574. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  575. }
  576. while (Database :: num_rows($res_name)) {
  577. // There is already one such name, update the current one a bit.
  578. $i++;
  579. $name = $name . ' - ' . $i;
  580. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  581. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  582. $res_name = Database::query($check_name);
  583. }
  584. // New name does not exist yet; keep it.
  585. // Escape description.
  586. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  587. $type = 1;
  588. switch ($learnpath) {
  589. case 'guess':
  590. break;
  591. case 'dokeos':
  592. case 'chamilo':
  593. $type = 1;
  594. break;
  595. case 'aicc':
  596. break;
  597. }
  598. switch ($origin) {
  599. case 'zip':
  600. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  601. break;
  602. case 'manual':
  603. default:
  604. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  605. $res_max = Database::query($get_max);
  606. if (Database :: num_rows($res_max) < 1) {
  607. $dsp = 1;
  608. } else {
  609. $row = Database :: fetch_array($res_max);
  610. $dsp = $row[0] + 1;
  611. }
  612. $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) " .
  613. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  614. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  615. $res_insert = Database::query($sql_insert);
  616. $id = Database :: insert_id();
  617. if ($id > 0) {
  618. // Insert into item_property.
  619. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  620. return $id;
  621. }
  622. break;
  623. }
  624. }
  625. /**
  626. * Appends a message to the message attribute
  627. * @param string Message to append.
  628. */
  629. public function append_message($string) {
  630. if ($this->debug > 0) {
  631. error_log('New LP - In learnpath::append_message()', 0);
  632. }
  633. $this->message .= $string;
  634. }
  635. /**
  636. * Autocompletes the parents of an item in case it's been completed or passed
  637. * @param integer Optional ID of the item from which to look for parents
  638. */
  639. public function autocomplete_parents($item) {
  640. if ($this->debug > 0) {
  641. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  642. }
  643. if (empty ($item)) {
  644. $item = $this->current;
  645. }
  646. $parent_id = $this->items[$item]->get_parent();
  647. if ($this->debug > 2) {
  648. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  649. }
  650. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  651. // if $item points to an object and there is a parent.
  652. if ($this->debug > 2) {
  653. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  654. }
  655. $current_item = & $this->items[$item];
  656. $parent = & $this->items[$parent_id]; // Get the parent.
  657. // New experiment including failed and browsed in completed status.
  658. $current_status = $current_item->get_status();
  659. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  660. // If the current item is completed or passes or succeeded.
  661. $completed = true;
  662. if ($this->debug > 2) {
  663. error_log('New LP - Status of current item is alright', 0);
  664. }
  665. foreach ($parent->get_children() as $child) {
  666. // Check all his brothers (his parent's children) for completion status.
  667. if ($child != $item) {
  668. if ($this->debug > 2) {
  669. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  670. }
  671. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  672. // Trying completing parents of failed and browsed items as well.
  673. if ($this->items[$child]->status_is(array (
  674. 'completed',
  675. 'passed',
  676. 'succeeded',
  677. 'browsed',
  678. 'failed'
  679. ))) {
  680. // Keep completion status to true.
  681. } else {
  682. if ($this->debug > 2) {
  683. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  684. }
  685. $completed = false;
  686. }
  687. }
  688. }
  689. if ($completed) { // If all the children were completed:
  690. $parent->set_status('completed');
  691. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  692. $this->update_queue[$parent->get_id()] = $parent->get_status();
  693. if ($this->debug > 2) {
  694. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  695. }
  696. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  697. }
  698. } else {
  699. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  700. }
  701. }
  702. }
  703. /**
  704. * Autosaves the current results into the database for the whole learnpath
  705. */
  706. public function autosave() {
  707. if ($this->debug > 0) {
  708. error_log('New LP - In learnpath::autosave()', 0);
  709. }
  710. // TODO: Add save operations for the learnpath itself.
  711. }
  712. /**
  713. * Clears the message attribute
  714. */
  715. public function clear_message() {
  716. if ($this->debug > 0) {
  717. error_log('New LP - In learnpath::clear_message()', 0);
  718. }
  719. $this->message = '';
  720. }
  721. /**
  722. * Closes the current resource
  723. *
  724. * Stops the timer
  725. * Saves into the database if required
  726. * Clears the current resource data from this object
  727. * @return boolean True on success, false on failure
  728. */
  729. public function close() {
  730. if ($this->debug > 0) {
  731. error_log('New LP - In learnpath::close()', 0);
  732. }
  733. if (empty ($this->lp_id)) {
  734. $this->error = 'Trying to close this learnpath but no ID is set';
  735. return false;
  736. }
  737. $this->current_time_stop = time();
  738. if ($this->save) {
  739. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  740. /*
  741. $sql = "UPDATE $learnpath_view_table " .
  742. "SET " .
  743. "stop_time = ".$this->current_time_stop.", " .
  744. "score = ".$this->current_score.", ".
  745. "WHERE learnpath_id = '".$this->lp_id."'";
  746. //$res = Database::query($sql);
  747. $res = Database::query($res);
  748. if (Database::affected_rows($res) < 1) {
  749. $this->error = 'Could not update learnpath_view table while closing learnpath';
  750. return false;
  751. }
  752. */
  753. }
  754. $this->ordered_items = array ();
  755. $this->index = 0;
  756. unset ($this->lp_id);
  757. //unset other stuff
  758. return true;
  759. }
  760. /**
  761. * Static admin function allowing removal of a learnpath
  762. * @param string Course code
  763. * @param integer Learnpath ID
  764. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  765. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  766. */
  767. public function delete($course = null, $id = null, $delete = 'keep') {
  768. // TODO: Implement a way of getting this to work when the current object is not set.
  769. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  770. //if (empty($course)) { $course = api_get_course_id(); }
  771. //if (empty($id)) { $id = $this->get_id(); }
  772. // If an ID is specifically given and the current LP is not the same, prevent delete.
  773. if (!empty ($id) && ($id != $this->lp_id)) {
  774. return false;
  775. }
  776. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  777. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  778. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  779. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  780. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  781. // Delete lp item id.
  782. foreach ($this->items as $id => $dummy) {
  783. //$this->items[$id]->delete();
  784. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  785. $res_del_item_view = Database::query($sql_del_view);
  786. }
  787. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  788. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  789. $res_del_item = Database::query($sql_del_item);
  790. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  791. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  792. $res_del_view = Database::query($sql_del_view);
  793. $this->toggle_publish($this->lp_id, 'i');
  794. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  795. if ($this->type == 2 || $this->type == 3) {
  796. // This is a scorm learning path, delete the files as well.
  797. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  798. $res = Database::query($sql);
  799. if (Database :: num_rows($res) > 0) {
  800. $row = Database :: fetch_array($res);
  801. $path = $row['path'];
  802. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  803. $res = Database::query($sql);
  804. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  805. if ($this->debug > 2) {
  806. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  807. }
  808. } else {
  809. // No other LP uses that directory, delete it.
  810. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  811. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  812. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  813. if ($this->debug > 2) {
  814. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  815. }
  816. // Proposed by Christophe (clefevre).
  817. if (strcmp(substr($path, -2), "/.") == 0) {
  818. $path = substr($path, 0, -1); // Remove "." at the end.
  819. }
  820. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  821. rmdirr($course_scorm_dir . $path);
  822. }
  823. }
  824. }
  825. }
  826. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  827. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  828. $res_del_lp = Database::query($sql_del_lp);
  829. $this->update_display_order(); // Updates the display order of all lps.
  830. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  831. require_once '../gradebook/lib/be.inc.php';
  832. // Delete link of gradebook tool
  833. //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  834. /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  835. $result = Database::query($sql);
  836. $row = Database :: fetch_array($result, 'ASSOC');*/
  837. // Fixing gradebook link deleted see #5229.
  838. /*
  839. if (!empty($row['id'])) {
  840. $link = LinkFactory :: load($row['id']);
  841. if ($link[0] != null) {
  842. $link[0]->delete();
  843. }
  844. }*/
  845. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  846. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
  847. if ($link_id !== false) {
  848. remove_resource_from_course_gradebook($link_id);
  849. }
  850. if (api_get_setting('search_enabled') == 'true') {
  851. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  852. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  853. }
  854. }
  855. /**
  856. * Removes all the children of one item - dangerous!
  857. * @param integer Element ID of which children have to be removed
  858. * @return integer Total number of children removed
  859. */
  860. public function delete_children_items($id) {
  861. if ($this->debug > 0) {
  862. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  863. }
  864. $num = 0;
  865. if (empty ($id) || $id != strval(intval($id))) {
  866. return false;
  867. }
  868. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  869. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  870. $res = Database::query($sql);
  871. while ($row = Database :: fetch_array($res)) {
  872. $num += $this->delete_children_items($row['id']);
  873. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  874. $res_del = Database::query($sql_del);
  875. $num++;
  876. }
  877. return $num;
  878. }
  879. /**
  880. * Removes an item from the current learnpath
  881. * @param integer Elem ID (0 if first)
  882. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  883. * @return integer Number of elements moved
  884. * @todo implement resource removal
  885. */
  886. public function delete_item($id, $remove = 'keep') {
  887. if ($this->debug > 0) {
  888. error_log('New LP - In learnpath::delete_item()', 0);
  889. }
  890. // TODO: Implement the resource removal.
  891. if (empty ($id) || $id != strval(intval($id))) {
  892. return false;
  893. }
  894. // First select item to get previous, next, and display order.
  895. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  896. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  897. $res_sel = Database::query($sql_sel);
  898. if (Database :: num_rows($res_sel) < 1) {
  899. return false;
  900. }
  901. $row = Database :: fetch_array($res_sel);
  902. $previous = $row['previous_item_id'];
  903. $next = $row['next_item_id'];
  904. $display = $row['display_order'];
  905. $parent = $row['parent_item_id'];
  906. $lp = $row['lp_id'];
  907. // Delete children items.
  908. $num = $this->delete_children_items($id);
  909. if ($this->debug > 2) {
  910. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  911. }
  912. // Now delete the item.
  913. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  914. if ($this->debug > 2) {
  915. error_log('New LP - Deleting item: ' . $sql_del, 0);
  916. }
  917. $res_del = Database::query($sql_del);
  918. // Now update surrounding items.
  919. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  920. $res_upd = Database::query($sql_upd);
  921. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  922. $res_upd = Database::query($sql_upd);
  923. // Now update all following items with new display order.
  924. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  925. $res_all = Database::query($sql_all);
  926. //Removing prerequisites since the item will not longer exist
  927. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  928. $res_all = Database::query($sql_all);
  929. // Remove from search engine if enabled.
  930. if (api_get_setting('search_enabled') == 'true') {
  931. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  932. $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';
  933. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  934. $res = Database::query($sql);
  935. if (Database :: num_rows($res) > 0) {
  936. $row2 = Database :: fetch_array($res);
  937. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  938. $di = new DokeosIndexer();
  939. $di->remove_document((int) $row2['search_did']);
  940. }
  941. $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';
  942. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  943. Database::query($sql);
  944. }
  945. }
  946. /**
  947. * Updates an item's content in place
  948. * @param integer Element ID
  949. * @param integer Parent item ID
  950. * @param integer Previous item ID
  951. * @param string Item title
  952. * @param string Item description
  953. * @param string Prerequisites (optional)
  954. * @param string Indexing terms (optional)
  955. * @param array The array resulting of the $_FILES[mp3] element
  956. * @return boolean True on success, false on error
  957. */
  958. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  959. if ($this->debug > 0) {
  960. error_log('New LP - In learnpath::edit_item()', 0);
  961. }
  962. if (empty ($max_time_allowed)) {
  963. $max_time_allowed = 0;
  964. }
  965. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  966. return false;
  967. }
  968. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  969. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  970. $res_select = Database::query($sql_select);
  971. $row_select = Database :: fetch_array($res_select);
  972. $audio_update_sql = '';
  973. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  974. // Create the audio folder if it does not exist yet.
  975. global $_course;
  976. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  977. if (!is_dir($filepath . 'audio')) {
  978. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  979. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  980. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  981. }
  982. // Upload file in documents.
  983. $pi = pathinfo($audio['name']);
  984. if ($pi['extension'] == 'mp3') {
  985. $c_det = api_get_course_info($this->cc);
  986. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  987. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  988. $path = substr($path, 7);
  989. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  990. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  991. }
  992. }
  993. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  994. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  995. // TODO: htmlspecialchars to be checked for encoding related problems.
  996. if ($same_parent && $same_previous) {
  997. // Only update title and description.
  998. $sql_update = " UPDATE " . $tbl_lp_item . "
  999. SET title = '" . $this->escape_string($title) . "',
  1000. prerequisite = '" . $prerequisites . "',
  1001. description = '" . $this->escape_string($description) . "'
  1002. " . $audio_update_sql . ",
  1003. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  1004. WHERE id = " . $id;
  1005. $res_update = Database::query($sql_update);
  1006. } else {
  1007. $old_parent = $row_select['parent_item_id'];
  1008. $old_previous = $row_select['previous_item_id'];
  1009. $old_next = $row_select['next_item_id'];
  1010. $old_order = $row_select['display_order'];
  1011. $old_prerequisite = $row_select['prerequisite'];
  1012. $old_max_time_allowed = $row_select['max_time_allowed'];
  1013. /* BEGIN -- virtually remove the current item id */
  1014. /* for the next and previous item it is like the current item doesn't exist anymore */
  1015. if ($old_previous != 0) {
  1016. $sql_update_next = "
  1017. UPDATE " . $tbl_lp_item . "
  1018. SET next_item_id = " . $old_next . "
  1019. WHERE id = " . $old_previous;
  1020. $res_update_next = Database::query($sql_update_next);
  1021. //echo '<p>' . $sql_update_next . '</p>';
  1022. }
  1023. if ($old_next != 0) {
  1024. $sql_update_previous = "
  1025. UPDATE " . $tbl_lp_item . "
  1026. SET previous_item_id = " . $old_previous . "
  1027. WHERE id = " . $old_next;
  1028. $res_update_previous = Database::query($sql_update_previous);
  1029. //echo '<p>' . $sql_update_previous . '</p>';
  1030. }
  1031. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1032. $sql_update_order = "
  1033. UPDATE " . $tbl_lp_item . "
  1034. SET display_order = display_order - 1
  1035. WHERE
  1036. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1037. parent_item_id = " . $old_parent;
  1038. $res_update_order = Database::query($sql_update_order);
  1039. //echo '<p>' . $sql_update_order . '</p>';
  1040. /* END -- virtually remove the current item id */
  1041. /* BEGIN -- update the current item id to his new location */
  1042. if ($previous == 0) {
  1043. // Select the data of the item that should come after the current item.
  1044. $sql_select_old = "
  1045. SELECT
  1046. id,
  1047. display_order
  1048. FROM " . $tbl_lp_item . "
  1049. WHERE
  1050. lp_id = " . $this->lp_id . " AND
  1051. parent_item_id = " . $parent . " AND
  1052. previous_item_id = " . $previous;
  1053. $res_select_old = Database::query($sql_select_old);
  1054. $row_select_old = Database :: fetch_array($res_select_old);
  1055. //echo '<p>' . $sql_select_old . '</p>';
  1056. // If the new parent didn't have children before.
  1057. if (Database :: num_rows($res_select_old) == 0) {
  1058. $new_next = 0;
  1059. $new_order = 1;
  1060. } else {
  1061. $new_next = $row_select_old['id'];
  1062. $new_order = $row_select_old['display_order'];
  1063. }
  1064. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1065. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1066. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1067. } else {
  1068. // Select the data of the item that should come before the current item.
  1069. $sql_select_old = "
  1070. SELECT
  1071. next_item_id,
  1072. display_order
  1073. FROM " . $tbl_lp_item . "
  1074. WHERE id = " . $previous;
  1075. $res_select_old = Database::query($sql_select_old);
  1076. $row_select_old = Database :: fetch_array($res_select_old);
  1077. //echo '<p>' . $sql_select_old . '</p>';
  1078. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1079. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1080. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1081. $new_next = $row_select_old['next_item_id'];
  1082. $new_order = $row_select_old['display_order'] + 1;
  1083. }
  1084. // TODO: htmlspecialchars to be checked for encoding related problems.
  1085. // Update the current item with the new data.
  1086. $sql_update = "
  1087. UPDATE " . $tbl_lp_item . "
  1088. SET
  1089. title = '" . $this->escape_string($title) . "',
  1090. description = '" . $this->escape_string($description) . "',
  1091. parent_item_id = " . $parent . ",
  1092. previous_item_id = " . $previous . ",
  1093. next_item_id = " . $new_next . ",
  1094. display_order = " . $new_order . "
  1095. " . $audio_update_sql . "
  1096. WHERE id = " . $id;
  1097. $res_update_next = Database::query($sql_update);
  1098. //echo '<p>' . $sql_update . '</p>';
  1099. if ($previous != 0) {
  1100. // Update the previous item's next_item_id.
  1101. $sql_update_previous = "
  1102. UPDATE " . $tbl_lp_item . "
  1103. SET next_item_id = " . $id . "
  1104. WHERE id = " . $previous;
  1105. $res_update_next = Database::query($sql_update_previous);
  1106. //echo '<p>' . $sql_update_previous . '</p>';
  1107. }
  1108. if ($new_next != 0) {
  1109. // Update the next item's previous_item_id.
  1110. $sql_update_next = "
  1111. UPDATE " . $tbl_lp_item . "
  1112. SET previous_item_id = " . $id . "
  1113. WHERE id = " . $new_next;
  1114. $res_update_next = Database::query($sql_update_next);
  1115. //echo '<p>' . $sql_update_next . '</p>';
  1116. }
  1117. if ($old_prerequisite != $prerequisites) {
  1118. $sql_update_next = "
  1119. UPDATE " . $tbl_lp_item . "
  1120. SET prerequisite = " . $prerequisites . "
  1121. WHERE id = " . $id;
  1122. $res_update_next = Database::query($sql_update_next);
  1123. }
  1124. if ($old_max_time_allowed != $max_time_allowed) {
  1125. $sql_update_max_time_allowed = "
  1126. UPDATE " . $tbl_lp_item . "
  1127. SET max_time_allowed = " . $max_time_allowed . "
  1128. WHERE id = " . $id;
  1129. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1130. }
  1131. // Update all the items with the same or a bigger display_order than the current item.
  1132. $sql_update_order = "
  1133. UPDATE " . $tbl_lp_item . "
  1134. SET display_order = display_order + 1
  1135. WHERE
  1136. lp_id = " . $this->get_id() . " AND
  1137. id <> " . $id . " AND
  1138. parent_item_id = " . $parent . " AND
  1139. display_order >= " . $new_order;
  1140. $res_update_next = Database::query($sql_update_order);
  1141. }
  1142. }
  1143. /**
  1144. * Updates an item's prereq in place
  1145. * @param integer Element ID
  1146. * @param string Prerequisite Element ID
  1147. * @param string Prerequisite item type
  1148. * @param string Prerequisite min score
  1149. * @param string Prerequisite max score
  1150. * @return boolean True on success, false on error
  1151. */
  1152. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1153. if ($this->debug > 0) {
  1154. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1155. }
  1156. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1157. return false;
  1158. }
  1159. $prerequisite_id = $this->escape_string($prerequisite_id);
  1160. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1161. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1162. $mastery_score = 0;
  1163. if (!is_numeric($max_score) || $max_score < 0)
  1164. $max_score = 100;
  1165. if ($mastery_score > $max_score)
  1166. $max_score = $mastery_score;
  1167. if (!is_numeric($prerequisite_id))
  1168. $prerequisite_id = 'NULL';
  1169. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1170. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1171. $res_upd = Database::query($sql_upd);
  1172. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1173. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1174. mastery_score = " . $mastery_score .
  1175. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1176. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1177. $res_upd = Database::query($sql_upd);
  1178. }
  1179. // TODO: Update the item object (can be ignored for now because refreshed).
  1180. return true;
  1181. }
  1182. /**
  1183. * Escapes a string with the available database escape function
  1184. * @param string String to escape
  1185. * @return string String escaped
  1186. */
  1187. public function escape_string($string) {
  1188. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1189. return Database :: escape_string($string);
  1190. }
  1191. /**
  1192. * Static admin function exporting a learnpath into a zip file
  1193. * @param string Export type (scorm, zip, cd)
  1194. * @param string Course code
  1195. * @param integer Learnpath ID
  1196. * @param string Zip file name
  1197. * @return string Zip file path (or false on error)
  1198. */
  1199. public function export_lp($type, $course, $id, $zipname) {
  1200. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1201. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1202. return false;
  1203. }
  1204. $url = '';
  1205. switch ($type) {
  1206. case 'scorm':
  1207. break;
  1208. case 'zip':
  1209. break;
  1210. case 'cdrom':
  1211. break;
  1212. }
  1213. return $url;
  1214. }
  1215. /**
  1216. * Gets all the chapters belonging to the same parent as the item/chapter given
  1217. * Can also be called as abstract method
  1218. * @param integer Item ID
  1219. * @return array A list of all the "brother items" (or an empty array on failure)
  1220. */
  1221. public function get_brother_chapters($id) {
  1222. if ($this->debug > 0) {
  1223. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1224. }
  1225. if (empty ($id) OR $id != strval(intval($id))) {
  1226. return array ();
  1227. }
  1228. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1229. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1230. $res_parent = Database::query($sql_parent);
  1231. if (Database :: num_rows($res_parent) > 0) {
  1232. $row_parent = Database :: fetch_array($res_parent);
  1233. $parent = $row_parent['parent_item_id'];
  1234. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1235. $res_bros = Database::query($sql_bros);
  1236. $list = array ();
  1237. while ($row_bro = Database :: fetch_array($res_bros)) {
  1238. $list[] = $row_bro;
  1239. }
  1240. return $list;
  1241. }
  1242. return array ();
  1243. }
  1244. /**
  1245. * Gets all the items belonging to the same parent as the item given
  1246. * Can also be called as abstract method
  1247. * @param integer Item ID
  1248. * @return array A list of all the "brother items" (or an empty array on failure)
  1249. */
  1250. public function get_brother_items($id) {
  1251. if ($this->debug > 0) {
  1252. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1253. }
  1254. if (empty ($id) OR $id != strval(intval($id))) {
  1255. return array ();
  1256. }
  1257. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1258. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1259. $res_parent = Database::query($sql_parent);
  1260. if (Database :: num_rows($res_parent) > 0) {
  1261. $row_parent = Database :: fetch_array($res_parent);
  1262. $parent = $row_parent['parent_item_id'];
  1263. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1264. $res_bros = Database::query($sql_bros);
  1265. $list = array ();
  1266. while ($row_bro = Database :: fetch_array($res_bros)) {
  1267. $list[] = $row_bro;
  1268. }
  1269. return $list;
  1270. }
  1271. return array ();
  1272. }
  1273. /**
  1274. * Get the specific prefix index terms of this learning path
  1275. * @return array Array of terms
  1276. */
  1277. public function get_common_index_terms_by_prefix($prefix) {
  1278. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1279. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1280. $prefix_terms = array();
  1281. if (!empty($terms)) {
  1282. foreach ($terms as $term) {
  1283. $prefix_terms[] = $term['value'];
  1284. }
  1285. }
  1286. return $prefix_terms;
  1287. }
  1288. /**
  1289. * Gets the number of items currently completed
  1290. * @return integer The number of items currently completed
  1291. */
  1292. public function get_complete_items_count() {
  1293. if ($this->debug > 0) {
  1294. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1295. }
  1296. $i = 0;
  1297. foreach ($this->items as $id => $dummy) {
  1298. // Trying failed and browsed considered "progressed" as well.
  1299. if ($this->items[$id]->status_is(array (
  1300. 'completed',
  1301. 'passed',
  1302. 'succeeded',
  1303. 'browsed',
  1304. 'failed'
  1305. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1306. $i++;
  1307. }
  1308. }
  1309. return $i;
  1310. }
  1311. /**
  1312. * Gets the current item ID
  1313. * @return integer The current learnpath item id
  1314. */
  1315. public function get_current_item_id() {
  1316. $current = 0;
  1317. if ($this->debug > 0) {
  1318. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1319. }
  1320. if (!empty ($this->current)) {
  1321. $current = $this->current;
  1322. }
  1323. if ($this->debug > 2) {
  1324. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1325. }
  1326. return $current;
  1327. }
  1328. /**
  1329. * Force to get the first learnpath item id
  1330. * @return integer The current learnpath item id
  1331. */
  1332. public function get_first_item_id() {
  1333. $current = 0;
  1334. if (is_array($this->ordered_items)) {
  1335. $current = $this->ordered_items[0];
  1336. }
  1337. return $current;
  1338. }
  1339. /**
  1340. * Gets the total number of items available for viewing in this SCORM
  1341. * @return integer The total number of items
  1342. */
  1343. public function get_total_items_count() {
  1344. if ($this->debug > 0) {
  1345. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1346. }
  1347. return count($this->items);
  1348. }
  1349. /**
  1350. * Gets the total number of items available for viewing in this SCORM but without chapters
  1351. * @return integer The total no-chapters number of items
  1352. */
  1353. public function get_total_items_count_without_chapters() {
  1354. if ($this->debug > 0) {
  1355. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1356. }
  1357. $total = 0;
  1358. foreach ($this->items as $temp => $temp2) {
  1359. if (!in_array($temp2->get_type(), array (
  1360. 'dokeos_chapter',
  1361. 'chapter',
  1362. 'dir'
  1363. )))
  1364. $total++;
  1365. }
  1366. return $total;
  1367. }
  1368. /**
  1369. * Gets the first element URL.
  1370. * @return string URL to load into the viewer
  1371. */
  1372. public function first() {
  1373. if ($this->debug > 0) {
  1374. error_log('New LP - In learnpath::first()', 0);
  1375. }
  1376. // Test if the last_item_seen exists and is not a dir.
  1377. if (count($this->ordered_items) == 0) {
  1378. $this->index = 0;
  1379. }
  1380. 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()) {
  1381. if ($this->debug > 2) {
  1382. 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);
  1383. }
  1384. $index = -1;
  1385. foreach ($this->ordered_items as $myindex => $item_id) {
  1386. if ($item_id == $this->last_item_seen) {
  1387. $index = $myindex;
  1388. break;
  1389. }
  1390. }
  1391. if ($index == -1) {
  1392. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1393. if ($this->debug > 2) {
  1394. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1395. }
  1396. return false;
  1397. } else {
  1398. $this->last = $this->last_item_seen;
  1399. $this->current = $this->last_item_seen;
  1400. $this->index = $index;
  1401. }
  1402. } else {
  1403. if ($this->debug > 2) {
  1404. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1405. }
  1406. $index = 0;
  1407. // Loop through all ordered items and stop at the first item that is
  1408. // not a directory *and* that has not been completed yet.
  1409. 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) {
  1410. $index++;
  1411. }
  1412. $this->last = $this->current;
  1413. // current is
  1414. $this->current = $this->ordered_items[$index];
  1415. $this->index = $index;
  1416. if ($this->debug > 2) {
  1417. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1418. }
  1419. }
  1420. if ($this->debug > 2) {
  1421. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1422. }
  1423. }
  1424. /**
  1425. * Gets the information about an item in a format usable as JavaScript to update
  1426. * the JS API by just printing this content into the <head> section of the message frame
  1427. * @param integer Item ID
  1428. * @return string
  1429. */
  1430. public function get_js_info($item_id = '') {
  1431. if ($this->debug > 0) {
  1432. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1433. }
  1434. $info = '';
  1435. $item_id = $this->escape_string($item_id);
  1436. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1437. //if item is defined, return values from DB
  1438. $oItem = $this->items[$item_id];
  1439. $info .= '<script language="javascript">';
  1440. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1441. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1442. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1443. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1444. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1445. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1446. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1447. $info .= "top.set_flag_synchronized();";
  1448. $info .= '</script>';
  1449. if ($this->debug > 2) {
  1450. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1451. }
  1452. return $info;
  1453. } else {
  1454. // If item_id is empty, just update to default SCORM data.
  1455. $info .= '<script language="javascript">';
  1456. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1457. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1458. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1459. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1460. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1461. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1462. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1463. $info .= "top.set_flag_synchronized();";
  1464. $info .= '</script>';
  1465. if ($this->debug > 2) {
  1466. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1467. }
  1468. return $info;
  1469. }
  1470. }
  1471. /**
  1472. * Gets the js library from the database
  1473. * @return string The name of the javascript library to be used
  1474. */
  1475. public function get_js_lib() {
  1476. $lib = '';
  1477. if (!empty ($this->js_lib)) {
  1478. $lib = $this->js_lib;
  1479. }
  1480. return $lib;
  1481. }
  1482. /**
  1483. * Gets the learnpath database ID
  1484. * @return integer Learnpath ID in the lp table
  1485. */
  1486. public function get_id() {
  1487. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1488. if (!empty ($this->lp_id)) {
  1489. return $this->lp_id;
  1490. } else {
  1491. return 0;
  1492. }
  1493. }
  1494. /**
  1495. * Gets the last element URL.
  1496. * @return string URL to load into the viewer
  1497. */
  1498. public function get_last() {
  1499. if ($this->debug > 0) {
  1500. error_log('New LP - In learnpath::get_last()', 0);
  1501. }
  1502. $this->index = count($this->ordered_items) - 1;
  1503. return $this->ordered_items[$this->index];
  1504. }
  1505. /**
  1506. * Gets the navigation bar for the learnpath display screen
  1507. * @return string The HTML string to use as a navigation bar
  1508. */
  1509. public function get_navigation_bar() {
  1510. if ($this->debug > 0) {
  1511. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1512. }
  1513. // TODO: Find a good value for the following variables.
  1514. $file = '';
  1515. $openDir = '';
  1516. $edoceo = '';
  1517. $time = 0;
  1518. $navbar = '';
  1519. $RequestUri = '';
  1520. $mycurrentitemid = $this->get_current_item_id();
  1521. if ($this->mode == 'fullscreen') {
  1522. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1523. ' <tr> ' . "\n" .
  1524. ' <td>' . "\n" .
  1525. ' <div class="buttons">' . "\n" .
  1526. ' <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" .
  1527. ' <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" .
  1528. ' <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" .
  1529. //' <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" .
  1530. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1531. ' </div>' . "\n" .
  1532. ' </td>' . "\n" .
  1533. ' </tr>' . "\n" .
  1534. '</table>';
  1535. } else {
  1536. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1537. ' <tr> ' . "\n" .
  1538. ' <td>' . "\n" .
  1539. ' <div class="buttons">' . "\n" .
  1540. ' <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" .
  1541. ' <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" .
  1542. ' <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" .
  1543. // ' <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" .
  1544. ' </div>' . "\n" .
  1545. ' </td>' . "\n" .
  1546. ' </tr>' . "\n" .
  1547. '</table>';
  1548. }
  1549. return $navbar;
  1550. }
  1551. /**
  1552. * Gets the next resource in queue (url).
  1553. * @return string URL to load into the viewer
  1554. */
  1555. public function get_next_index() {
  1556. if ($this->debug > 0) {
  1557. error_log('New LP - In learnpath::get_next_index()', 0);
  1558. }
  1559. // TODO
  1560. $index = $this->index;
  1561. $index++;
  1562. if ($this->debug > 2) {
  1563. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1564. }
  1565. 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) {
  1566. $index++;
  1567. if ($index == $this->max_ordered_items){
  1568. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1569. return $this->index;
  1570. } else {
  1571. return $index;
  1572. }
  1573. }
  1574. }
  1575. if (empty ($this->ordered_items[$index])) {
  1576. return $this->index;
  1577. }
  1578. if ($this->debug > 2) {
  1579. error_log('New LP - index is now ' . $index, 0);
  1580. }
  1581. return $index;
  1582. }
  1583. /**
  1584. * Gets item_id for the next element
  1585. * @return integer Next item (DB) ID
  1586. */
  1587. public function get_next_item_id() {
  1588. if ($this->debug > 0) {
  1589. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1590. }
  1591. $new_index = $this->get_next_index();
  1592. if (!empty ($new_index)) {
  1593. if (isset ($this->ordered_items[$new_index])) {
  1594. if ($this->debug > 2) {
  1595. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1596. }
  1597. return $this->ordered_items[$new_index];
  1598. }
  1599. }
  1600. if ($this->debug > 2) {
  1601. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1602. }
  1603. return 0;
  1604. }
  1605. /**
  1606. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1607. *
  1608. * Generally, the package provided is in the form of a zip file, so the function
  1609. * has been written to test a zip file. If not a zip, the function will return the
  1610. * default return value: ''
  1611. * @param string the path to the file
  1612. * @param string the original name of the file
  1613. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1614. */
  1615. public function get_package_type($file_path, $file_name) {
  1616. // Get name of the zip file without the extension.
  1617. $file_info = pathinfo($file_name);
  1618. $filename = $file_info['basename']; // Name including extension.
  1619. $extension = $file_info['extension']; // Extension only.
  1620. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1621. 'dll',
  1622. 'exe'
  1623. ))) {
  1624. return 'oogie';
  1625. }
  1626. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1627. 'dll',
  1628. 'exe'
  1629. ))) {
  1630. return 'woogie';
  1631. }
  1632. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1633. $zipFile = new pclZip($file_path);
  1634. // Check the zip content (real size and file extension).
  1635. $zipContentArray = $zipFile->listContent();
  1636. $package_type = '';
  1637. $at_root = false;
  1638. $manifest = '';
  1639. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1640. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1641. foreach ($zipContentArray as $thisContent) {
  1642. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1643. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1644. }
  1645. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1646. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1647. $package_type = 'scorm';
  1648. break; // Exit the foreach loop.
  1649. }
  1650. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1651. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1652. $package_type = 'aicc';
  1653. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1654. } else {
  1655. $package_type = '';
  1656. }
  1657. }
  1658. }
  1659. return $package_type;
  1660. }
  1661. /**
  1662. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1663. * @return string URL to load into the viewer
  1664. */
  1665. public function get_previous_index() {
  1666. if ($this->debug > 0) {
  1667. error_log('New LP - In learnpath::get_previous_index()', 0);
  1668. }
  1669. $index = $this->index;
  1670. if (isset ($this->ordered_items[$index -1])) {
  1671. $index--;
  1672. 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')) {
  1673. $index--;
  1674. if ($index < 0) {
  1675. return $this->index;
  1676. }
  1677. }
  1678. } else {
  1679. if ($this->debug > 2) {
  1680. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1681. }
  1682. // There is no previous item.
  1683. }
  1684. return $index;
  1685. }
  1686. /**
  1687. * Gets item_id for the next element
  1688. * @return integer Previous item (DB) ID
  1689. */
  1690. public function get_previous_item_id() {
  1691. if ($this->debug > 0) {
  1692. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1693. }
  1694. $new_index = $this->get_previous_index();
  1695. return $this->ordered_items[$new_index];
  1696. }
  1697. /**
  1698. * Gets the progress value from the progress_db attribute
  1699. * @return integer Current progress value
  1700. */
  1701. public function get_progress() {
  1702. if ($this->debug > 0) {
  1703. error_log('New LP - In learnpath::get_progress()', 0);
  1704. }
  1705. if (!empty ($this->progress_db)) {
  1706. return $this->progress_db;
  1707. }
  1708. return 0;
  1709. }
  1710. /**
  1711. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1712. * @param integer Learnpath ID
  1713. * @param integer User ID
  1714. * @param string Mode of display ('%','abs' or 'both')
  1715. * @param string Course database name (optional, defaults to '')
  1716. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1717. * @return integer Current progress value as found in the database
  1718. */
  1719. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1720. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1721. $session_id = intval($session_id);
  1722. $session_condition = api_get_session_condition($session_id);
  1723. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1724. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1725. $res = Database::query($sql);
  1726. $view_id = 0;
  1727. if (Database :: num_rows($res) > 0) {
  1728. $row = Database :: fetch_array($res);
  1729. $progress = $row['progress'];
  1730. $view_id = $row['id'];
  1731. } else {
  1732. if ($sincere) {
  1733. return null;
  1734. }
  1735. }
  1736. if (empty ($progress)) {
  1737. $progress = '0';
  1738. }
  1739. if ($mode == '%') {
  1740. return $progress . '%';
  1741. } else {
  1742. // Get the number of items completed and the number of items total.
  1743. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1744. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1745. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1746. $res = Database::query($sql);
  1747. $row = Database :: fetch_array($res);
  1748. $total = $row[0];
  1749. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1750. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1751. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1752. // Trying as also counting browsed and failed items.
  1753. $sql = "SELECT count(distinct(lp_item_id))
  1754. FROM $tbl_item_view as item_view
  1755. INNER JOIN $tbl_item as item
  1756. ON item.id = item_view.lp_item_id
  1757. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1758. WHERE lp_view_id = " . $view_id . "
  1759. AND status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1760. $res = Database::query($sql);
  1761. $row = Database :: fetch_array($res);
  1762. $completed = $row[0];
  1763. if ($mode == 'abs') {
  1764. return $completed . '/' . $total;
  1765. }
  1766. elseif ($mode == 'both') {
  1767. if ($progress < ($completed / ($total ? $total : 1))) {
  1768. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1769. }
  1770. return $progress . '% (' . $completed . '/' . $total . ')';
  1771. }
  1772. }
  1773. return $progress;
  1774. }
  1775. /**
  1776. * Returns the HTML necessary to print a mediaplayer block inside a page
  1777. * @return string The mediaplayer HTML
  1778. */
  1779. public function get_mediaplayer($autostart='true') {
  1780. global $_course;
  1781. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1782. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1783. // Getting all the information about the item.
  1784. $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 " .
  1785. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1786. $result = Database::query($sql);
  1787. $row = Database::fetch_assoc($result);
  1788. $output = '';
  1789. if (!empty ($row['audio'])) {
  1790. $list = $_SESSION['oLP']->get_toc();
  1791. $type_quiz = false;
  1792. foreach($list as $toc) {
  1793. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1794. $type_quiz = true;
  1795. }
  1796. }
  1797. if ($type_quiz) {
  1798. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1799. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1800. } else {
  1801. $autostart_audio = $autostart;
  1802. }
  1803. } else {
  1804. $autostart_audio = 'true';
  1805. }
  1806. // The mp3 player.
  1807. $output = '<div id="container">';
  1808. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1809. $output .= '<script type="text/javascript">
  1810. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1811. s1.addParam("allowscriptaccess","always");
  1812. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1813. s1.write("container");
  1814. </script></div>';
  1815. }
  1816. return $output;
  1817. }
  1818. /**
  1819. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1820. * @param int Learnpath id
  1821. * @param int Student id
  1822. * @param string Course code (optional)
  1823. * @return bool True if
  1824. */
  1825. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1826. $lp_id = (int)$lp_id;
  1827. $course = api_get_course_info($course);
  1828. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
  1829. // Get current prerequisite
  1830. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
  1831. $rs = Database::query($sql);
  1832. if (Database::num_rows($rs)>0) {
  1833. $row = Database::fetch_array($rs);
  1834. $prerequisite = $row['prerequisite'];
  1835. $find = array(' ','-',':');
  1836. $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
  1837. $to = str_replace($find,'',api_get_local_time($row['expired_on']));
  1838. $is_visible = true;
  1839. $progress = 0;
  1840. if (!empty($prerequisite)) {
  1841. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1842. $progress = intval($progress);
  1843. if ($progress < 100) {
  1844. $is_visible = false;
  1845. }
  1846. }
  1847. // Also check the time availability of the learning path
  1848. if ($is_visible) {
  1849. $now = str_replace($find,'',api_get_local_time());
  1850. if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
  1851. $is_visible = false;
  1852. }
  1853. }
  1854. return $is_visible;
  1855. }
  1856. return false;
  1857. }
  1858. /**
  1859. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1860. * completed so far.
  1861. * @param string Mode in which we want the values
  1862. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1863. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1864. * @param boolean true if it comes from a Diplay LP view
  1865. * @return string HTML string containing the progress bar
  1866. */
  1867. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1868. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1869. global $lp_theme_css;
  1870. // Setting up the CSS path of the current style if exists.
  1871. if (!empty ($lp_theme_css)) {
  1872. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1873. } else {
  1874. $css_path = '../img/';
  1875. }
  1876. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1877. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1878. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1879. }
  1880. $text = $percentage . $text_add;
  1881. // Default progress bar config
  1882. // times that will be greater or shorter
  1883. $factor = 1.2;
  1884. if ($from_lp)
  1885. $progress_height = '26';
  1886. else
  1887. $progress_height = '16';
  1888. $size = str_replace('%', '', $percentage);
  1889. $output ='<div style="width:135px">' .
  1890. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1891. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1892. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1893. if ($percentage <= 98) {
  1894. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1895. } else {
  1896. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1897. }
  1898. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1899. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1900. return $output;
  1901. }
  1902. /**
  1903. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1904. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1905. * @param integer Additional steps to fake as completed
  1906. * @return list Percentage or number and symbol (% or /xx)
  1907. */
  1908. public function get_progress_bar_text($mode = '', $add = 0) {
  1909. if ($this->debug > 0) {
  1910. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1911. }
  1912. if (empty ($mode)) {
  1913. $mode = $this->progress_bar_mode;
  1914. }
  1915. $total_items = $this->get_total_items_count_without_chapters();
  1916. if ($this->debug > 2) {
  1917. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1918. }
  1919. $i = $this->get_complete_items_count();
  1920. if ($this->debug > 2) {
  1921. error_log('New LP - Items completed so far: ' . $i, 0);
  1922. }
  1923. if ($add != 0) {
  1924. $i += $add;
  1925. if ($this->debug > 2) {
  1926. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1927. }
  1928. }
  1929. $text = '';
  1930. if ($i > $total_items) {
  1931. $i = $total_items;
  1932. }
  1933. if ($mode == '%') {
  1934. if ($total_items > 0) {
  1935. $percentage = ((float) $i / (float) $total_items) * 100;
  1936. } else {
  1937. $percentage = 0;
  1938. }
  1939. $percentage = number_format($percentage, 0);
  1940. $text = '%';
  1941. }
  1942. elseif ($mode == 'abs') {
  1943. $percentage = $i;
  1944. $text = '/' . $total_items;
  1945. }
  1946. return array (
  1947. $percentage,
  1948. $text
  1949. );
  1950. }
  1951. /**
  1952. * Gets the progress bar mode
  1953. * @return string The progress bar mode attribute
  1954. */
  1955. public function get_progress_bar_mode() {
  1956. if ($this->debug > 0) {
  1957. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1958. }
  1959. if (!empty ($this->progress_bar_mode)) {
  1960. return $this->progress_bar_mode;
  1961. } else {
  1962. return '%';
  1963. }
  1964. }
  1965. /**
  1966. * Gets the learnpath proximity (remote or local)
  1967. * @return string Learnpath proximity
  1968. */
  1969. public function get_proximity() {
  1970. if ($this->debug > 0) {
  1971. error_log('New LP - In learnpath::get_proximity()', 0);
  1972. }
  1973. if (!empty ($this->proximity)) {
  1974. return $this->proximity;
  1975. } else {
  1976. return '';
  1977. }
  1978. }
  1979. /**
  1980. * Gets the learnpath theme (remote or local)
  1981. * @return string Learnpath theme
  1982. */
  1983. public function get_theme() {
  1984. if ($this->debug > 0) {
  1985. error_log('New LP - In learnpath::get_theme()', 0);
  1986. }
  1987. if (!empty ($this->theme)) {
  1988. return $this->theme;
  1989. } else {
  1990. return '';
  1991. }
  1992. }
  1993. /**
  1994. * Gets the learnpath session id
  1995. * @return string Learnpath theme
  1996. */
  1997. public function get_lp_session_id() {
  1998. if ($this->debug > 0) {
  1999. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  2000. }
  2001. if (!empty ($this->lp_session_id)) {
  2002. return $this->lp_session_id;
  2003. } else {
  2004. return 0;
  2005. }
  2006. }
  2007. /**
  2008. * Gets the learnpath image
  2009. * @return string Web URL of the LP image
  2010. */
  2011. public function get_preview_image() {
  2012. if ($this->debug > 0) {
  2013. error_log('New LP - In learnpath::get_preview_image()', 0);
  2014. }
  2015. if (!empty ($this->preview_image)) {
  2016. return $this->preview_image;
  2017. } else {
  2018. return '';
  2019. }
  2020. }
  2021. /**
  2022. * Gets the learnpath author
  2023. * @return string LP's author
  2024. */
  2025. public function get_author() {
  2026. if ($this->debug > 0) {
  2027. error_log('New LP - In learnpath::get_author()', 0);
  2028. }
  2029. if (!empty ($this->author)) {
  2030. return $this->author;
  2031. } else {
  2032. return '';
  2033. }
  2034. }
  2035. /**
  2036. * Gets the learnpath author
  2037. * @return string LP's author
  2038. */
  2039. public function get_hide_toc_frame() {
  2040. if ($this->debug > 0) {
  2041. error_log('New LP - In learnpath::get_author()', 0);
  2042. }
  2043. if (!empty ($this->hide_toc_frame)) {
  2044. return $this->hide_toc_frame;
  2045. } else {
  2046. return '';
  2047. }
  2048. }
  2049. /**
  2050. * Generate a new prerequisites string for a given item. If this item was a sco and
  2051. * its prerequisites were strings (instead of IDs), then transform those strings into
  2052. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2053. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2054. * same rule as the scorm_export() method
  2055. * @param integer Item ID
  2056. * @return string Prerequisites string ready for the export as SCORM
  2057. */
  2058. public function get_scorm_prereq_string($item_id) {
  2059. if ($this->debug > 0) {
  2060. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2061. }
  2062. if (!is_object($this->items[$item_id])) {
  2063. return false;
  2064. }
  2065. $oItem = $this->items[$item_id];
  2066. $prereq = $oItem->get_prereq_string();
  2067. if (empty ($prereq)) {
  2068. return '';
  2069. }
  2070. 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,
  2071. // then simply return it (with the ITEM_ prefix).
  2072. return 'ITEM_' . $prereq;
  2073. } else {
  2074. if (isset ($this->refs_list[$prereq])) {
  2075. // It's a simple string item from which the ID can be found in the refs list,
  2076. // so we can transform it directly to an ID for export.
  2077. return 'ITEM_' . $this->refs_list[$prereq];
  2078. } else {
  2079. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2080. // and replace them, one by one, by the internal IDs (chamilo db)
  2081. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2082. // by a space as well.
  2083. $find = array (
  2084. '&',
  2085. '|',
  2086. '~',
  2087. '=',
  2088. '<>',
  2089. '{',
  2090. '}',
  2091. '*',
  2092. '(',
  2093. ')'
  2094. );
  2095. $replace = array (
  2096. ' ',
  2097. ' ',
  2098. ' ',
  2099. ' ',
  2100. ' ',
  2101. ' ',
  2102. ' ',
  2103. ' ',
  2104. ' ',
  2105. ' '
  2106. );
  2107. $prereq_mod = str_replace($find, $replace, $prereq);
  2108. $ids = split(' ', $prereq_mod);
  2109. foreach ($ids as $id) {
  2110. $id = trim($id);
  2111. if (isset ($this->refs_list[$id])) {
  2112. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2113. }
  2114. }
  2115. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2116. return $prereq;
  2117. }
  2118. }
  2119. }
  2120. /**
  2121. * Returns the XML DOM document's node
  2122. * @param resource Reference to a list of objects to search for the given ITEM_*
  2123. * @param string The identifier to look for
  2124. * @return mixed The reference to the element found with that identifier. False if not found
  2125. */
  2126. public function get_scorm_xml_node(& $children, $id) {
  2127. for ($i = 0; $i < $children->length; $i++) {
  2128. $item_temp = $children->item($i);
  2129. if ($item_temp->nodeName == 'item') {
  2130. if ($item_temp->getAttribute('identifier') == $id) {
  2131. return $item_temp;
  2132. }
  2133. }
  2134. $subchildren = $item_temp->childNodes;
  2135. if ($subchildren->length > 0) {
  2136. $val = $this->get_scorm_xml_node($subchildren, $id);
  2137. if (is_object($val)) {
  2138. return $val;
  2139. }
  2140. }
  2141. }
  2142. return false;
  2143. }
  2144. /**
  2145. * Returns a usable array of stats related to the current learnpath and user
  2146. * @return array Well-formatted array containing status for the current learnpath
  2147. */
  2148. public function get_stats() {
  2149. if ($this->debug > 0) {
  2150. error_log('New LP - In learnpath::get_stats()', 0);
  2151. }
  2152. // TODO
  2153. }
  2154. /**
  2155. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2156. * the given course (for all learnpaths and all users)
  2157. * @param string Course code
  2158. * @return array Well-formatted array containing status for the course's learnpaths
  2159. */
  2160. public function get_stats_course($course) {
  2161. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2162. // TODO
  2163. }
  2164. /**
  2165. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2166. * the given course and learnpath (for all users)
  2167. * @param string Course code
  2168. * @param integer Learnpath ID
  2169. * @return array Well-formatted array containing status for the specified learnpath
  2170. */
  2171. public function get_stats_lp($course, $lp) {
  2172. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2173. // TODO
  2174. }
  2175. /**
  2176. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2177. * the given course, learnpath and user.
  2178. * @param string Course code
  2179. * @param integer Learnpath ID
  2180. * @param integer User ID
  2181. * @return array Well-formatted array containing status for the specified learnpath and user
  2182. */
  2183. public function get_stats_lp_user($course, $lp, $user) {
  2184. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2185. // TODO
  2186. }
  2187. /**
  2188. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2189. * the given course and learnpath (for all users)
  2190. * @param string Course code
  2191. * @param integer User ID
  2192. * @return array Well-formatted array containing status for the user's learnpaths
  2193. */
  2194. public function get_stats_user($course, $user) {
  2195. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2196. // TODO
  2197. }
  2198. /**
  2199. * Gets the status list for all LP's items
  2200. * @return array Array of [index] => [item ID => current status]
  2201. */
  2202. public function get_items_status_list() {
  2203. if ($this->debug > 0) {
  2204. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2205. }
  2206. $list = array ();
  2207. foreach ($this->ordered_items as $item_id) {
  2208. $list[] = array (
  2209. $item_id => $this->items[$item_id]->get_status()
  2210. );
  2211. }
  2212. return $list;
  2213. }
  2214. /**
  2215. * Return the number of interactions for the given learnpath Item View ID.
  2216. * This method can be used as static.
  2217. * @param integer Item View ID
  2218. * @return integer Number of interactions
  2219. */
  2220. public function get_interactions_count_from_db($lp_iv_id = 0, $course_code = null) {
  2221. if (empty ($lp_iv_id)) {
  2222. return -1;
  2223. }
  2224. $course_info = api_get_course_info($course_code);
  2225. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION, $course_info['db_name']);
  2226. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2227. $res = Database::query($sql);
  2228. $row = Database :: fetch_array($res);
  2229. $num = $row[0];
  2230. return $num;
  2231. }
  2232. /**
  2233. * Return the interactions as an array for the given lp_iv_id.
  2234. * This method can be used as static.
  2235. * @param integer Learnpath Item View ID
  2236. * @return array
  2237. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2238. */
  2239. public function get_iv_interactions_array($lp_iv_id = 0) {
  2240. $list = array ();
  2241. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2242. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2243. $res = Database::query($sql);
  2244. $num = Database :: num_rows($res);
  2245. if ($num > 0) {
  2246. $list[] = array (
  2247. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2248. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2249. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2250. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2251. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2252. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2253. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2254. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2255. );
  2256. while ($row = Database :: fetch_array($res)) {
  2257. $list[] = array (
  2258. 'order_id' => ($row['order_id'] + 1),
  2259. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2260. 'type' => $row['interaction_type'],
  2261. 'time' => $row['completion_time'],
  2262. //'correct_responses' => $row['correct_responses'],
  2263. 'correct_responses' => '', // Hide correct responses from students.
  2264. 'student_response' => $row['student_response'],
  2265. 'result' => $row['result'],
  2266. 'latency' => $row['latency']
  2267. );
  2268. }
  2269. }
  2270. return $list;
  2271. }
  2272. /**
  2273. * Return the number of objectives for the given learnpath Item View ID.
  2274. * This method can be used as static.
  2275. * @param integer Item View ID
  2276. * @return integer Number of objectives
  2277. */
  2278. public function get_objectives_count_from_db($lp_iv_id = 0, $course_code = null) {
  2279. if (empty ($lp_iv_id)) {
  2280. return -1;
  2281. }
  2282. $course_info = api_get_course_info($course_code);
  2283. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE, $course_info['db_name']);
  2284. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2285. $res = Database::query($sql);
  2286. $row = Database :: fetch_array($res);
  2287. $num = $row[0];
  2288. return $num;
  2289. }
  2290. /**
  2291. * Return the objectives as an array for the given lp_iv_id.
  2292. * This method can be used as static.
  2293. * @param integer Learnpath Item View ID
  2294. * @return array
  2295. * @todo Translate labels
  2296. */
  2297. public function get_iv_objectives_array($lp_iv_id = 0) {
  2298. $list = array();
  2299. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2300. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2301. $res = Database::query($sql);
  2302. $num = Database :: num_rows($res);
  2303. if ($num > 0) {
  2304. $list[] = array (
  2305. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2306. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2307. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2308. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2309. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2310. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2311. );
  2312. while ($row = Database :: fetch_array($res)) {
  2313. $list[] = array (
  2314. 'order_id' => ($row['order_id'] + 1),
  2315. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2316. 'score_raw' => $row['score_raw'],
  2317. 'score_max' => $row['score_max'],
  2318. 'score_min' => $row['score_min'],
  2319. 'status' => $row['status']
  2320. );
  2321. }
  2322. }
  2323. return $list;
  2324. }
  2325. /**
  2326. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2327. * used by get_html_toc() to be ready to display
  2328. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2329. */
  2330. public function get_toc() {
  2331. if ($this->debug > 0) {
  2332. error_log('New LP - In learnpath::get_toc()', 0);
  2333. }
  2334. $toc = array ();
  2335. //echo "<pre>".print_r($this->items,true)."</pre>";
  2336. foreach ($this->ordered_items as $item_id) {
  2337. if ($this->debug > 2) {
  2338. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2339. }
  2340. // TODO: Change this link generation and use new function instead.
  2341. $toc[] = array (
  2342. 'id' => $item_id,
  2343. 'title' => $this->items[$item_id]->get_title(),
  2344. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2345. 'status' => $this->items[$item_id]->get_status(),
  2346. 'level' => $this->items[$item_id]->get_level(),
  2347. 'type' => $this->items[$item_id]->get_type(),
  2348. 'description' => $this->items[$item_id]->get_description(),
  2349. 'path' => $this->items[$item_id]->get_path(),
  2350. );
  2351. }
  2352. if ($this->debug > 2) {
  2353. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2354. }
  2355. return $toc;
  2356. }
  2357. /**
  2358. * Generate and return the table of contents for this learnpath. The JS
  2359. * table returned is used inside of scorm_api.php
  2360. * @return string A JS array vairiable construction
  2361. */
  2362. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2363. if ($this->debug > 0) {
  2364. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2365. }
  2366. $toc = $varname.' = new Array();';
  2367. //echo "<pre>".print_r($this->items,true)."</pre>";
  2368. foreach ($this->ordered_items as $item_id) {
  2369. if ($this->debug > 2) {
  2370. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2371. }
  2372. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2373. }
  2374. if ($this->debug > 2) {
  2375. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2376. }
  2377. return $toc;
  2378. }
  2379. /**
  2380. * Gets the learning path type
  2381. * @param boolean Return the name? If false, return the ID. Default is false.
  2382. * @return mixed Type ID or name, depending on the parameter
  2383. */
  2384. public function get_type($get_name = false) {
  2385. $res = false;
  2386. if ($this->debug > 0) {
  2387. error_log('New LP - In learnpath::get_type()', 0);
  2388. }
  2389. if (!empty ($this->type)) {
  2390. if ($get_name) {
  2391. // Get it from the lp_type table in main db.
  2392. } else {
  2393. $res = $this->type;
  2394. }
  2395. }
  2396. if ($this->debug > 2) {
  2397. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2398. }
  2399. return $res;
  2400. }
  2401. /**
  2402. * Gets the learning path type as static method
  2403. * @param boolean Return the name? If false, return the ID. Default is false.
  2404. * @return mixed Type ID or name, depending on the parameter
  2405. */
  2406. public function get_type_static($lp_id = 0) {
  2407. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2408. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2409. $res = Database::query($sql);
  2410. if ($res === false) {
  2411. return null;
  2412. }
  2413. if (Database :: num_rows($res) <= 0) {
  2414. return null;
  2415. }
  2416. $row = Database :: fetch_array($res);
  2417. return $row['lp_type'];
  2418. }
  2419. /**
  2420. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2421. * This method can be used as abstract and is recursive
  2422. * @param integer Learnpath ID
  2423. * @param integer Parent ID of the items to look for
  2424. * @return mixed Ordered list of item IDs or false on error
  2425. */
  2426. public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
  2427. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2428. $list = array();
  2429. if (empty ($lp)) {
  2430. return false;
  2431. }
  2432. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  2433. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2434. $res = Database::query($sql);
  2435. while ($row = Database :: fetch_array($res)) {
  2436. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
  2437. $list[] = $row['id'];
  2438. foreach ($sublist as $item) {
  2439. $list[] = $item;
  2440. }
  2441. }
  2442. return $list;
  2443. }
  2444. /**
  2445. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2446. * @return string HTML TOC ready to display
  2447. */
  2448. public function get_html_toc() {
  2449. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2450. $charset = api_get_system_encoding();
  2451. $display_action_links_with_icons = false;
  2452. if ($this->debug > 0) {
  2453. error_log('New LP - In learnpath::get_html_toc()', 0);
  2454. }
  2455. $list = $this->get_toc();
  2456. //echo $this->current;
  2457. //$parent = $this->items[$this->current]->get_parent();
  2458. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2459. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2460. // Build, display.
  2461. if ($is_allowed_to_edit) {
  2462. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2463. //var_dump($this->get_lp_session_id());
  2464. if ($this->get_lp_session_id() == api_get_session_id()) {
  2465. $html .= '<div id="actions_lp" class="actions_lp">';
  2466. if ($display_action_links_with_icons) {
  2467. $html .= '<div style = "text-align:center;">';
  2468. $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>";
  2469. $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>";
  2470. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2471. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2472. $html .= '</div>';
  2473. } else {
  2474. $html .= '<div style = "text-align:center;">';
  2475. $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>";
  2476. $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>";
  2477. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2478. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2479. $html .= '</div>';
  2480. }
  2481. $html .= '</div>';
  2482. }
  2483. }
  2484. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2485. require_once 'resourcelinker.inc.php';
  2486. // Temporary variables.
  2487. $mycurrentitemid = $this->get_current_item_id();
  2488. $color_counter = 0;
  2489. $i = 0;
  2490. foreach ($list as $item) {
  2491. if ($this->debug > 2) {
  2492. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2493. }
  2494. // TODO: Complete this.
  2495. $icon_name = array (
  2496. 'not attempted' => '../img/notattempted.gif',
  2497. 'incomplete' => '../img/incomplete.png',
  2498. 'failed' => '../img/delete.png',
  2499. 'completed' => '../img/completed.png',
  2500. 'passed' => '../img/passed.png',
  2501. 'succeeded' => '../img/succeeded.png',
  2502. 'browsed' => '../img/completed.png',
  2503. );
  2504. $style = 'scorm_item';
  2505. $scorm_color_background = 'scorm_item';
  2506. $style_item = 'scorm_item';
  2507. $current = false;
  2508. if ($item['id'] == $this->current) {
  2509. $style = 'scorm_item_highlight';
  2510. $scorm_color_background = 'scorm_item_highlight';
  2511. } else
  2512. if ($color_counter % 2 == 0) {
  2513. $scorm_color_background = 'scorm_item_1';
  2514. } else {
  2515. $scorm_color_background = 'scorm_item_2';
  2516. }
  2517. if ($scorm_color_background != '') {
  2518. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2519. }
  2520. // The anchor will let us center the TOC on the currently viewed item &^D
  2521. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2522. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2523. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2524. } else {
  2525. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2526. }
  2527. $title = $item['title'];
  2528. if (empty ($title)) {
  2529. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2530. }
  2531. $title = Security::remove_XSS($title);
  2532. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2533. //$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>" ;
  2534. $url = $this->get_link('http', $item['id']);
  2535. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2536. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2537. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2538. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2539. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2540. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2541. } elseif ($item['type'] == 'dir') {
  2542. $html .= stripslashes($title);
  2543. }
  2544. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2545. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2546. $user_id = api_get_user_id();
  2547. $course_id = api_get_course_id();
  2548. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2549. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2550. $result = Database::query($sql);
  2551. $count = Database :: num_rows($result);
  2552. if ($item['type'] == 'quiz') {
  2553. if ($item['status'] == 'completed') {
  2554. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2555. }
  2556. } else {
  2557. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2558. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2559. }
  2560. }
  2561. $html .= "</div>";
  2562. if ($scorm_color_background != '') {
  2563. $html .= '</div>';
  2564. }
  2565. $color_counter++;
  2566. }
  2567. $html .= "</div>";
  2568. return $html;
  2569. }
  2570. /**
  2571. * Gets the learnpath maker name - generally the editor's name
  2572. * @return string Learnpath maker name
  2573. */
  2574. public function get_maker() {
  2575. if ($this->debug > 0) {
  2576. error_log('New LP - In learnpath::get_maker()', 0);
  2577. }
  2578. if (!empty ($this->maker)) {
  2579. return $this->maker;
  2580. } else {
  2581. return '';
  2582. }
  2583. }
  2584. /**
  2585. * Gets the user-friendly message stored in $this->message
  2586. * @return string Message
  2587. */
  2588. public function get_message() {
  2589. if ($this->debug > 0) {
  2590. error_log('New LP - In learnpath::get_message()', 0);
  2591. }
  2592. return $this->message;
  2593. }
  2594. /**
  2595. * Gets the learnpath name/title
  2596. * @return string Learnpath name/title
  2597. */
  2598. public function get_name() {
  2599. if ($this->debug > 0) {
  2600. error_log('New LP - In learnpath::get_name()', 0);
  2601. }
  2602. if (!empty ($this->name)) {
  2603. return $this->name;
  2604. } else {
  2605. return 'N/A';
  2606. }
  2607. }
  2608. /**
  2609. * Gets a link to the resource from the present location, depending on item ID.
  2610. * @param string Type of link expected
  2611. * @param integer Learnpath item ID
  2612. * @return string Link to the lp_item resource
  2613. */
  2614. public function get_link($type = 'http', $item_id = null) {
  2615. if ($this->debug > 0) {
  2616. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2617. }
  2618. if (empty($item_id)) {
  2619. if ($this->debug > 2) {
  2620. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2621. }
  2622. $item_id = $this->get_current_item_id();
  2623. }
  2624. if (empty ($item_id)) {
  2625. if ($this->debug > 2) {
  2626. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2627. }
  2628. //still empty, this means there was no item_id given and we are not in an object context or
  2629. //the object property is empty, return empty link
  2630. $item_id = $this->first();
  2631. return '';
  2632. }
  2633. $file = '';
  2634. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2635. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2636. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2637. $item_id = Database::escape_string($item_id);
  2638. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2639. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2640. if ($this->debug > 2) {
  2641. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2642. }
  2643. $res = Database::query($sel);
  2644. if (Database :: num_rows($res) > 0) {
  2645. $row = Database :: fetch_array($res);
  2646. //var_dump($row);
  2647. $lp_type = $row['ltype'];
  2648. $lp_path = $row['lpath'];
  2649. $lp_item_type = $row['litype'];
  2650. $lp_item_path = $row['lipath'];
  2651. $lp_item_params = $row['liparams'];
  2652. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2653. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2654. }
  2655. //$lp_item_params = '?'.$lp_item_params;
  2656. //add ? if none - left commented to give freedom to scorm implementation
  2657. //if(substr($lp_item_params,0,1)!='?'){
  2658. // $lp_item_params = '?'.$lp_item_params;
  2659. //}
  2660. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2661. if ($type == 'http') {
  2662. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2663. } else {
  2664. $course_path = $sys_course_path; //system path
  2665. }
  2666. // 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.
  2667. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2668. $lp_type = 1;
  2669. }
  2670. // Now go through the specific cases to get the end of the path.
  2671. // @todo Use constants instead of int values.
  2672. switch ($lp_type) {
  2673. case 1 :
  2674. if ($lp_item_type == 'dokeos_chapter') {
  2675. $file = 'lp_content.php?type=dir';
  2676. } else {
  2677. require_once 'resourcelinker.inc.php';
  2678. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2679. //CEV CHANGE
  2680. if ($lp_item_type == 'link') {
  2681. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2682. if (is_youtube_link($file)) {
  2683. $src = get_youtube_video_id($file);
  2684. $file = 'embed.php?type=youtube&src='.$src;
  2685. }
  2686. } else {
  2687. // check how much attempts of a exercise exits in lp
  2688. $lp_item_id = $this->get_current_item_id();
  2689. $lp_view_id = $this->get_view_id();
  2690. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2691. $list = $this->get_toc();
  2692. $type_quiz = false;
  2693. foreach ($list as $toc) {
  2694. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2695. $type_quiz = true;
  2696. }
  2697. }
  2698. if ($type_quiz) {
  2699. $lp_item_id = Database :: escape_string($lp_item_id);
  2700. $lp_view_id = Database :: escape_string($lp_view_id);
  2701. $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'";
  2702. $result = Database::query($sql);
  2703. $row_count = Database :: fetch_row($result);
  2704. $count_item_view = (int) $row_count[0];
  2705. $not_multiple_attempt = 0;
  2706. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2707. $not_multiple_attempt = 1;
  2708. }
  2709. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2710. }
  2711. $tmp_array = explode('/', $file);
  2712. $document_name = $tmp_array[count($tmp_array) - 1];
  2713. if (strpos($document_name, '_DELETED_')) {
  2714. $file = 'blank.php?error=document_deleted';
  2715. }
  2716. }
  2717. }
  2718. break;
  2719. case 2 :
  2720. if ($this->debug > 2) {
  2721. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2722. }
  2723. if ($lp_item_type != 'dir') {
  2724. // Quite complex here:
  2725. // We want to make sure 'http://' (and similar) links can
  2726. // be loaded as is (withouth the Chamilo path in front) but
  2727. // some contents use this form: resource.htm?resource=http://blablabla
  2728. // which means we have to find a protocol at the path's start, otherwise
  2729. // it should not be considered as an external URL.
  2730. //if ($this->prerequisites_match($item_id)) {
  2731. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2732. if ($this->debug > 2) {
  2733. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2734. }
  2735. // Distant url, return as is.
  2736. $file = $lp_item_path;
  2737. } else {
  2738. if ($this->debug > 2) {
  2739. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2740. }
  2741. // Prevent getting untranslatable urls.
  2742. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2743. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2744. // Prepare the path.
  2745. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2746. // TODO: Fix this for urls with protocol header.
  2747. $file = str_replace('//', '/', $file);
  2748. $file = str_replace(':/', '://', $file);
  2749. if (substr($lp_path, -1) == '/') {
  2750. $lp_path = substr($lp_path, 0, -1);
  2751. }
  2752. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2753. // if file not found.
  2754. $decoded = html_entity_decode($lp_item_path);
  2755. list ($decoded) = explode('?', $decoded);
  2756. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2757. require_once 'resourcelinker.inc.php';
  2758. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2759. if (empty($file)) {
  2760. $file = 'blank.php?error=document_not_found';
  2761. } else {
  2762. $tmp_array = explode('/', $file);
  2763. $document_name = $tmp_array[count($tmp_array) - 1];
  2764. if (strpos($document_name, '_DELETED_')) {
  2765. $file = 'blank.php?error=document_deleted';
  2766. } else {
  2767. $file = 'blank.php?error=document_not_found';
  2768. }
  2769. }
  2770. } else {
  2771. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2772. }
  2773. }
  2774. }
  2775. //}else{
  2776. //prerequisites did not match
  2777. //$file = 'blank.php';
  2778. //}
  2779. // We want to use parameters if they were defined in the imsmanifest.
  2780. if ($file != 'blank.php') {
  2781. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2782. }
  2783. } else {
  2784. $file = 'lp_content.php?type=dir';
  2785. }
  2786. break;
  2787. case 3 :
  2788. if ($this->debug > 2) {
  2789. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2790. }
  2791. // Formatting AICC HACP append URL.
  2792. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2793. if ($lp_item_type != 'dir') {
  2794. // Quite complex here:
  2795. // We want to make sure 'http://' (and similar) links can
  2796. // be loaded as is (withouth the Chamilo path in front) but
  2797. // some contents use this form: resource.htm?resource=http://blablabla
  2798. // which means we have to find a protocol at the path's start, otherwise
  2799. // it should not be considered as an external URL.
  2800. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2801. if ($this->debug > 2) {
  2802. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2803. }
  2804. // Distant url, return as is.
  2805. $file = $lp_item_path;
  2806. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2807. /*
  2808. if (stristr($file,'<servername>') !== false) {
  2809. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2810. }
  2811. */
  2812. if (stripos($file, '<servername>') !== false) {
  2813. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2814. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2815. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2816. }
  2817. //
  2818. $file .= $aicc_append;
  2819. } else {
  2820. if ($this->debug > 2) {
  2821. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2822. }
  2823. // Prevent getting untranslatable urls.
  2824. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2825. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2826. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2827. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2828. // TODO: Fix this for urls with protocol header.
  2829. $file = str_replace('//', '/', $file);
  2830. $file = str_replace(':/', '://', $file);
  2831. $file .= $aicc_append;
  2832. }
  2833. } else {
  2834. $file = 'lp_content.php?type=dir';
  2835. }
  2836. break;
  2837. case 4 :
  2838. break;
  2839. default :
  2840. break;
  2841. }
  2842. }
  2843. if ($this->debug > 2) {
  2844. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2845. }
  2846. return $file;
  2847. }
  2848. /**
  2849. * Gets the latest usable view or generate a new one
  2850. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2851. * @return integer DB lp_view id
  2852. */
  2853. public function get_view($attempt_num = 0) {
  2854. if ($this->debug > 0) {
  2855. error_log('New LP - In learnpath::get_view()', 0);
  2856. }
  2857. $search = '';
  2858. // Use $attempt_num to enable multi-views management (disabled so far).
  2859. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2860. $search = 'AND view_count = ' . $attempt_num;
  2861. }
  2862. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2863. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2864. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2865. "WHERE lp_id = " . $this->get_id() . " " .
  2866. "AND user_id = " . $this->get_user_id() . " " .
  2867. $search .
  2868. " ORDER BY view_count DESC";
  2869. $res = Database::query($sql);
  2870. if (Database :: num_rows($res) > 0) {
  2871. $row = Database :: fetch_array($res);
  2872. $this->lp_view_id = $row['id'];
  2873. } else {
  2874. // There is no database record, create one.
  2875. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2876. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2877. $res = Database::query($sql);
  2878. $id = Database :: insert_id();
  2879. $this->lp_view_id = $id;
  2880. }
  2881. return $this->lp_view_id;
  2882. }
  2883. /**
  2884. * Gets the current view id
  2885. * @return integer View ID (from lp_view)
  2886. */
  2887. public function get_view_id() {
  2888. if ($this->debug > 0) {
  2889. error_log('New LP - In learnpath::get_view_id()', 0);
  2890. }
  2891. if (!empty ($this->lp_view_id)) {
  2892. return $this->lp_view_id;
  2893. } else {
  2894. return 0;
  2895. }
  2896. }
  2897. /**
  2898. * Gets the update queue
  2899. * @return array Array containing IDs of items to be updated by JavaScript
  2900. */
  2901. public function get_update_queue() {
  2902. if ($this->debug > 0) {
  2903. error_log('New LP - In learnpath::get_update_queue()', 0);
  2904. }
  2905. return $this->update_queue;
  2906. }
  2907. /**
  2908. * Gets the user ID
  2909. * @return integer User ID
  2910. */
  2911. public function get_user_id() {
  2912. if ($this->debug > 0) {
  2913. error_log('New LP - In learnpath::get_user_id()', 0);
  2914. }
  2915. if (!empty ($this->user_id)) {
  2916. return $this->user_id;
  2917. } else {
  2918. return false;
  2919. }
  2920. }
  2921. /**
  2922. * Checks if any of the items has an audio element attached
  2923. * @return bool True or false
  2924. */
  2925. public function has_audio() {
  2926. if ($this->debug > 1) {
  2927. error_log('New LP - In learnpath::has_audio()', 0);
  2928. }
  2929. $has = false;
  2930. foreach ($this->items as $i => $item) {
  2931. if (!empty ($this->items[$i]->audio)) {
  2932. $has = true;
  2933. break;
  2934. }
  2935. }
  2936. return $has;
  2937. }
  2938. /**
  2939. * Logs a message into a file
  2940. * @param string Message to log
  2941. * @return boolean True on success, false on error or if msg empty
  2942. */
  2943. public function log($msg) {
  2944. if ($this->debug > 0) {
  2945. error_log('New LP - In learnpath::log()', 0);
  2946. }
  2947. // TODO
  2948. $this->error .= $msg;
  2949. return true;
  2950. }
  2951. /**
  2952. * Moves an item up and down at its level
  2953. * @param integer Item to move up and down
  2954. * @param string Direction 'up' or 'down'
  2955. * @return integer New display order, or false on error
  2956. */
  2957. public function move_item($id, $direction) {
  2958. if ($this->debug > 0) {
  2959. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2960. }
  2961. if (empty ($id) or empty ($direction)) {
  2962. return false;
  2963. }
  2964. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2965. $sql_sel = "
  2966. SELECT *
  2967. FROM " . $tbl_lp_item . "
  2968. WHERE id = " . $id;
  2969. $res_sel = Database::query($sql_sel);
  2970. // Check if elem exists.
  2971. if (Database :: num_rows($res_sel) < 1) {
  2972. return false;
  2973. }
  2974. // Gather data.
  2975. $row = Database :: fetch_array($res_sel);
  2976. $previous = $row['previous_item_id'];
  2977. $next = $row['next_item_id'];
  2978. $display = $row['display_order'];
  2979. $parent = $row['parent_item_id'];
  2980. $lp = $row['lp_id'];
  2981. // Update the item (switch with previous/next one).
  2982. switch ($direction) {
  2983. case 'up' :
  2984. if ($this->debug > 2) {
  2985. error_log('Movement up detected', 0);
  2986. }
  2987. if ($display <= 1) { /*do nothing*/
  2988. } else {
  2989. $sql_sel2 = "SELECT *
  2990. FROM $tbl_lp_item
  2991. WHERE id = $previous";
  2992. if ($this->debug > 2) {
  2993. error_log('Selecting previous: ' . $sql_sel2, 0);
  2994. }
  2995. $res_sel2 = Database::query($sql_sel2);
  2996. if (Database :: num_rows($res_sel2) < 1) {
  2997. $previous_previous = 0;
  2998. }
  2999. // Gather data.
  3000. $row2 = Database :: fetch_array($res_sel2);
  3001. $previous_previous = $row2['previous_item_id'];
  3002. // Update previous_previous item (switch "next" with current).
  3003. if ($previous_previous != 0) {
  3004. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  3005. if ($this->debug > 2) {
  3006. error_log($sql_upd2, 0);
  3007. }
  3008. $res_upd2 = Database::query($sql_upd2);
  3009. }
  3010. // Update previous item (switch with current).
  3011. if ($previous != 0) {
  3012. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  3013. if ($this->debug > 2) {
  3014. error_log($sql_upd2, 0);
  3015. }
  3016. $res_upd2 = Database::query($sql_upd2);
  3017. }
  3018. // Update current item (switch with previous).
  3019. if ($id != 0) {
  3020. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  3021. if ($this->debug > 2) {
  3022. error_log($sql_upd2, 0);
  3023. }
  3024. $res_upd2 = Database::query($sql_upd2);
  3025. }
  3026. // Update next item (new previous item).
  3027. if ($next != 0) {
  3028. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  3029. if ($this->debug > 2) {
  3030. error_log($sql_upd2, 0);
  3031. }
  3032. $res_upd2 = Database::query($sql_upd2);
  3033. }
  3034. $display = $display -1;
  3035. }
  3036. break;
  3037. case 'down' :
  3038. if ($this->debug > 2) {
  3039. error_log('Movement down detected', 0);
  3040. }
  3041. if ($next == 0) { /* Do nothing. */
  3042. } else {
  3043. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  3044. if ($this->debug > 2) {
  3045. error_log('Selecting next: ' . $sql_sel2, 0);
  3046. }
  3047. $res_sel2 = Database::query($sql_sel2);
  3048. if (Database :: num_rows($res_sel2) < 1) {
  3049. $next_next = 0;
  3050. }
  3051. // Gather data.
  3052. $row2 = Database :: fetch_array($res_sel2);
  3053. $next_next = $row2['next_item_id'];
  3054. // Update previous item (switch with current).
  3055. if ($previous != 0) {
  3056. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3057. $res_upd2 = Database::query($sql_upd2);
  3058. }
  3059. // Update current item (switch with previous).
  3060. if ($id != 0) {
  3061. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3062. $res_upd2 = Database::query($sql_upd2);
  3063. }
  3064. // Update next item (new previous item).
  3065. if ($next != 0) {
  3066. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3067. $res_upd2 = Database::query($sql_upd2);
  3068. }
  3069. // Update next_next item (switch "previous" with current).
  3070. if ($next_next != 0) {
  3071. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3072. $res_upd2 = Database::query($sql_upd2);
  3073. }
  3074. $display = $display +1;
  3075. }
  3076. break;
  3077. default :
  3078. return false;
  3079. }
  3080. return $display;
  3081. }
  3082. /**
  3083. * Move a learnpath up (display_order)
  3084. * @param integer Learnpath ID
  3085. */
  3086. public function move_up($lp_id) {
  3087. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3088. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3089. $res = Database::query($sql);
  3090. if ($res === false)
  3091. return false;
  3092. $lps = array ();
  3093. $lp_order = array ();
  3094. $num = Database :: num_rows($res);
  3095. // First check the order is correct, globally (might be wrong because
  3096. // of versions < 1.8.4)
  3097. if ($num > 0) {
  3098. $i = 1;
  3099. while ($row = Database :: fetch_array($res)) {
  3100. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3101. $need_fix = true;
  3102. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3103. $res_u = Database::query($sql_u);
  3104. }
  3105. $row['display_order'] = $i;
  3106. $lps[$row['id']] = $row;
  3107. $lp_order[$i] = $row['id'];
  3108. $i++;
  3109. }
  3110. }
  3111. if ($num > 1) { // If there's only one element, no need to sort.
  3112. $order = $lps[$lp_id]['display_order'];
  3113. if ($order > 1) { // If it's the first element, no need to move up.
  3114. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3115. $res_u1 = Database::query($sql_u1);
  3116. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3117. $res_u2 = Database::query($sql_u2);
  3118. }
  3119. }
  3120. }
  3121. /**
  3122. * Move a learnpath down (display_order)
  3123. * @param integer Learnpath ID
  3124. */
  3125. public function move_down($lp_id) {
  3126. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3127. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3128. $res = Database::query($sql);
  3129. if ($res === false)
  3130. return false;
  3131. $lps = array ();
  3132. $lp_order = array ();
  3133. $num = Database :: num_rows($res);
  3134. $max = 0;
  3135. // First check the order is correct, globally (might be wrong because
  3136. // of versions < 1.8.4).
  3137. if ($num > 0) {
  3138. $i = 1;
  3139. while ($row = Database :: fetch_array($res)) {
  3140. $max = $i;
  3141. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3142. $need_fix = true;
  3143. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3144. $res_u = Database::query($sql_u);
  3145. }
  3146. $row['display_order'] = $i;
  3147. $lps[$row['id']] = $row;
  3148. $lp_order[$i] = $row['id'];
  3149. $i++;
  3150. }
  3151. }
  3152. if ($num > 1) { // If there's only one element, no need to sort.
  3153. $order = $lps[$lp_id]['display_order'];
  3154. if ($order < $max) { // If it's the first element, no need to move up.
  3155. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3156. $res_u1 = Database::query($sql_u1);
  3157. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3158. $res_u2 = Database::query($sql_u2);
  3159. }
  3160. }
  3161. }
  3162. /**
  3163. * Updates learnpath attributes to point to the next element
  3164. * The last part is similar to set_current_item but processing the other way around
  3165. */
  3166. public function next() {
  3167. if ($this->debug > 0) {
  3168. error_log('New LP - In learnpath::next()', 0);
  3169. }
  3170. $this->last = $this->get_current_item_id();
  3171. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3172. $this->autocomplete_parents($this->last);
  3173. $new_index = $this->get_next_index();
  3174. if ($this->debug > 2) {
  3175. error_log('New LP - New index: ' . $new_index, 0);
  3176. }
  3177. $this->index = $new_index;
  3178. if ($this->debug > 2) {
  3179. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3180. }
  3181. $this->current = $this->ordered_items[$new_index];
  3182. if ($this->debug > 2) {
  3183. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3184. }
  3185. }
  3186. /**
  3187. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3188. * class, this might be redefined to allow several behaviours depending on the document type.
  3189. * @param integer Resource ID
  3190. * @return boolean True on success, false otherwise
  3191. */
  3192. public function open($id) {
  3193. if ($this->debug > 0) {
  3194. error_log('New LP - In learnpath::open()', 0);
  3195. }
  3196. // TODO:
  3197. // set the current resource attribute to this resource
  3198. // switch on element type (redefine in child class?)
  3199. // set status for this item to "opened"
  3200. // start timer
  3201. // initialise score
  3202. $this->index = 0; //or = the last item seen (see $this->last)
  3203. }
  3204. /**
  3205. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3206. * and the prerequisite string on error.
  3207. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3208. * @param integer Optional item ID. If none given, uses the current open item.
  3209. * @return boolean True if prerequisites are matched, false otherwise
  3210. * @return string Empty string if true returned, prerequisites string otherwise.
  3211. */
  3212. public function prerequisites_match($item = null) {
  3213. if ($this->debug > 0) {
  3214. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3215. }
  3216. if (empty ($item)) {
  3217. $item = $this->current;
  3218. }
  3219. if (is_object($this->items[$item])) {
  3220. $prereq_string = $this->items[$item]->get_prereq_string();
  3221. if (empty ($prereq_string)) {
  3222. return true;
  3223. }
  3224. // Clean spaces.
  3225. $prereq_string = str_replace(' ', '', $prereq_string);
  3226. if ($this->debug > 0) {
  3227. error_log('Found prereq_string: ' . $prereq_string, 0);
  3228. }
  3229. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3230. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3231. if ($result === false) {
  3232. $this->set_error_msg($this->items[$item]->prereq_alert);
  3233. }
  3234. } else {
  3235. $result = true;
  3236. if ($this->debug > 1) {
  3237. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3238. }
  3239. }
  3240. if ($this->debug > 1) {
  3241. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3242. }
  3243. return $result;
  3244. }
  3245. /**
  3246. * Updates learnpath attributes to point to the previous element
  3247. * The last part is similar to set_current_item but processing the other way around
  3248. */
  3249. public function previous() {
  3250. if ($this->debug > 0) {
  3251. error_log('New LP - In learnpath::previous()', 0);
  3252. }
  3253. $this->last = $this->get_current_item_id();
  3254. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3255. $this->autocomplete_parents($this->last);
  3256. $new_index = $this->get_previous_index();
  3257. $this->index = $new_index;
  3258. $this->current = $this->ordered_items[$new_index];
  3259. }
  3260. /**
  3261. * Publishes a learnpath. This basically means show or hide the learnpath
  3262. * to normal users.
  3263. * Can be used as abstract
  3264. * @param integer Learnpath ID
  3265. * @param string New visibility
  3266. */
  3267. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3268. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3269. $action = 'visible';
  3270. if ($set_visibility != 1) {
  3271. $action = 'invisible';
  3272. }
  3273. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3274. }
  3275. /**
  3276. * Publishes a learnpath. This basically means show or hide the learnpath
  3277. * on the course homepage
  3278. * Can be used as abstract
  3279. * @param integer Learnpath id
  3280. * @param string New visibility (v/s - visible/invisible)
  3281. */
  3282. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3283. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3284. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3285. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3286. $result = Database::query($sql);
  3287. $row = Database :: fetch_array($result);
  3288. $name = domesticate($row['name']);
  3289. if ($set_visibility == 'i') {
  3290. $s = $name . " " . get_lang('_no_published');
  3291. $dialogBox = $s;
  3292. $v = 0;
  3293. }
  3294. if ($set_visibility == 'v') {
  3295. $s = $name . " " . get_lang('_published');
  3296. $dialogBox = $s;
  3297. $v = 1;
  3298. }
  3299. $session_id = api_get_session_id();
  3300. $session_condition = api_get_session_condition($session_id);
  3301. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3302. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3303. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3304. $result = Database::query($sql);
  3305. $num = Database :: num_rows($result);
  3306. $row2 = Database :: fetch_array($result);
  3307. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3308. if (($set_visibility == 'i') && ($num > 0)) {
  3309. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3310. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3311. $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)";
  3312. } else {
  3313. // Parameter and database incompatible, do nothing.
  3314. }
  3315. $result = Database::query($sql);
  3316. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3317. }
  3318. /**
  3319. * Restart the whole learnpath. Return the URL of the first element.
  3320. * Make sure the results are saved with anoter method. This method should probably be
  3321. * redefined in children classes.
  3322. * To use a similar method statically, use the create_new_attempt() method
  3323. * @return string URL to load in the viewer
  3324. */
  3325. public function restart() {
  3326. if ($this->debug > 0) {
  3327. error_log('New LP - In learnpath::restart()', 0);
  3328. }
  3329. // TODO
  3330. // Call autosave method to save the current progress.
  3331. //$this->index = 0;
  3332. $session_id = api_get_session_id();
  3333. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3334. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3335. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3336. if ($this->debug > 2) {
  3337. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3338. }
  3339. $res = Database::query($sql);
  3340. if ($view_id = Database :: insert_id($res)) {
  3341. $this->lp_view_id = $view_id;
  3342. $this->attempt = $this->attempt + 1;
  3343. } else {
  3344. $this->error = 'Could not insert into item_view table...';
  3345. return false;
  3346. }
  3347. $this->autocomplete_parents($this->current);
  3348. foreach ($this->items as $index => $dummy) {
  3349. $this->items[$index]->restart();
  3350. $this->items[$index]->set_lp_view($this->lp_view_id);
  3351. }
  3352. $this->first();
  3353. return true;
  3354. }
  3355. /**
  3356. * Saves the current item
  3357. * @return boolean
  3358. */
  3359. public function save_current() {
  3360. if ($this->debug > 0) {
  3361. error_log('New LP - In learnpath::save_current()', 0);
  3362. }
  3363. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3364. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3365. if ($this->debug > 2) {
  3366. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3367. }
  3368. if ($this->debug > 2) {
  3369. error_log('' . print_r($this->items, true), 0);
  3370. }
  3371. if (is_object($this->items[$this->current])) {
  3372. //$res = $this->items[$this->current]->save(false);
  3373. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3374. $this->autocomplete_parents($this->current);
  3375. $status = $this->items[$this->current]->get_status();
  3376. $this->append_message('new_item_status: ' . $status);
  3377. $this->update_queue[$this->current] = $status;
  3378. return $res;
  3379. }
  3380. return false;
  3381. }
  3382. /**
  3383. * Saves the given item
  3384. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3385. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3386. * @return boolean
  3387. */
  3388. public function save_item($item_id = null, $from_outside = true) {
  3389. if ($this->debug > 0) {
  3390. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3391. }
  3392. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3393. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3394. if (empty ($item_id)) {
  3395. $item_id = $this->escape_string($_REQUEST['id']);
  3396. }
  3397. if (empty ($item_id)) {
  3398. $item_id = $this->get_current_item_id();
  3399. }
  3400. if ($this->debug > 2) {
  3401. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3402. }
  3403. if (is_object($this->items[$item_id])) {
  3404. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3405. //$res = $this->items[$item_id]->save($from_outside);
  3406. $this->autocomplete_parents($item_id);
  3407. $status = $this->items[$item_id]->get_status();
  3408. $this->append_message('new_item_status: ' . $status);
  3409. $this->update_queue[$item_id] = $status;
  3410. return $res;
  3411. }
  3412. return false;
  3413. }
  3414. /**
  3415. * Saves the last item seen's ID only in case
  3416. */
  3417. public function save_last() {
  3418. if ($this->debug > 0) {
  3419. error_log('New LP - In learnpath::save_last()', 0);
  3420. }
  3421. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3422. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3423. if (isset ($this->current)) {
  3424. if ($this->debug > 2) {
  3425. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3426. }
  3427. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3428. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3429. if ($this->debug > 2) {
  3430. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3431. }
  3432. $res = Database::query($sql);
  3433. }
  3434. // Save progress.
  3435. list($progress, $text) = $this->get_progress_bar_text('%');
  3436. if ($progress >= 0 && $progress <= 100) {
  3437. $progress = (int) $progress;
  3438. $sql = "UPDATE $table SET progress = $progress " .
  3439. "WHERE lp_id = " . $this->get_id() . " AND " .
  3440. "user_id = " . $this->get_user_id().' '.$session_condition;
  3441. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3442. $this->progress_db = $progress;
  3443. }
  3444. }
  3445. /**
  3446. * Sets the current item ID (checks if valid and authorized first)
  3447. * @param integer New item ID. If not given or not authorized, defaults to current
  3448. */
  3449. public function set_current_item($item_id = null) {
  3450. if ($this->debug > 0) {
  3451. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3452. }
  3453. if (empty ($item_id)) {
  3454. if ($this->debug > 2) {
  3455. error_log('New LP - No new current item given, ignore...', 0);
  3456. }
  3457. // Do nothing.
  3458. } else {
  3459. if ($this->debug > 2) {
  3460. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3461. }
  3462. if (is_numeric($item_id)) {
  3463. $item_id = $this->escape_string($item_id);
  3464. // TODO: Check in database here.
  3465. $this->last = $this->current;
  3466. $this->current = $item_id;
  3467. // TODO: Update $this->index as well.
  3468. foreach ($this->ordered_items as $index => $item) {
  3469. if ($item == $this->current) {
  3470. $this->index = $index;
  3471. break;
  3472. }
  3473. }
  3474. if ($this->debug > 2) {
  3475. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3476. }
  3477. } else {
  3478. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3479. }
  3480. }
  3481. }
  3482. /**
  3483. * Sets the encoding
  3484. * @param string New encoding
  3485. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3486. */
  3487. public function set_encoding($enc = 'UTF-8') {
  3488. if ($this->debug > 0) {
  3489. error_log('New LP - In learnpath::set_encoding()', 0);
  3490. }
  3491. /* // Deprecated code (Chamilo 1.8.8).
  3492. $enc = strtoupper($enc);
  3493. $encodings = array (
  3494. 'UTF-8',
  3495. 'ISO-8859-1',
  3496. 'ISO-8859-15',
  3497. 'cp1251',
  3498. 'cp1252',
  3499. 'KOI8-R',
  3500. 'BIG5',
  3501. 'GB2312',
  3502. 'Shift_JIS',
  3503. 'EUC-JP',
  3504. ''
  3505. );
  3506. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3507. $lp = $this->get_id();
  3508. if ($lp != 0) {
  3509. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3510. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3511. $res = Database::query($sql);
  3512. return $res;
  3513. }
  3514. }
  3515. return false;
  3516. */
  3517. $enc = api_refine_encoding_id($enc);
  3518. if (empty($enc)) {
  3519. $enc = api_get_system_encoding();
  3520. }
  3521. if (api_is_encoding_supported($enc)) {
  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 default_encoding = '$enc' WHERE id = " . $lp;
  3526. $res = Database::query($sql);
  3527. return $res;
  3528. }
  3529. }
  3530. return false;
  3531. }
  3532. /**
  3533. * Sets the JS lib setting in the database directly.
  3534. * This is the JavaScript library file this lp needs to load on startup
  3535. * @param string Proximity setting
  3536. * @return boolean True on update success. False otherwise.
  3537. */
  3538. public function set_jslib($lib = '') {
  3539. if ($this->debug > 0) {
  3540. error_log('New LP - In learnpath::set_jslib()', 0);
  3541. }
  3542. $lp = $this->get_id();
  3543. if ($lp != 0) {
  3544. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3545. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3546. $res = Database::query($sql);
  3547. return $res;
  3548. } else {
  3549. return false;
  3550. }
  3551. }
  3552. /**
  3553. * Sets the name of the LP maker (publisher) (and save)
  3554. * @param string Optional string giving the new content_maker of this learnpath
  3555. * @return boolean True
  3556. */
  3557. public function set_maker($name = '') {
  3558. if ($this->debug > 0) {
  3559. error_log('New LP - In learnpath::set_maker()', 0);
  3560. }
  3561. if (empty ($name))
  3562. return false;
  3563. $this->maker = $this->escape_string($name);
  3564. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3565. $lp_id = $this->get_id();
  3566. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3567. if ($this->debug > 2) {
  3568. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3569. }
  3570. $res = Database::query($sql);
  3571. return true;
  3572. }
  3573. /**
  3574. * Sets the name of the current learnpath (and save)
  3575. * @param string Optional string giving the new name of this learnpath
  3576. * @return boolean True/False
  3577. */
  3578. public function set_name($name = '') {
  3579. if ($this->debug > 0) {
  3580. error_log('New LP - In learnpath::set_name()', 0);
  3581. }
  3582. if (empty ($name))
  3583. return false;
  3584. $this->name = $this->escape_string($name);
  3585. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3586. $lp_id = $this->get_id();
  3587. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3588. if ($this->debug > 2) {
  3589. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3590. }
  3591. $res = Database::query($sql);
  3592. // If the lp is visible on the homepage, change his name there.
  3593. if (Database::affected_rows()) {
  3594. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3595. $sql = 'UPDATE ' . $table . ' SET
  3596. name = "' . $this->name . '"
  3597. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3598. Database::query($sql);
  3599. }
  3600. return true;
  3601. }
  3602. /**
  3603. * Set index specified prefix terms for all items in this path
  3604. * @param string Comma-separated list of terms
  3605. * @param char Xapian term prefix
  3606. * @return boolean False on error, true otherwise
  3607. */
  3608. public function set_terms_by_prefix($terms_string, $prefix) {
  3609. if (api_get_setting('search_enabled') !== 'true')
  3610. return false;
  3611. if (!extension_loaded('xapian')) {
  3612. return false;
  3613. }
  3614. $terms_string = trim($terms_string);
  3615. $terms = explode(',', $terms_string);
  3616. array_walk($terms, 'trim_value');
  3617. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3618. //var_dump($stored_terms);
  3619. //var_dump($terms);
  3620. // Don't do anything if no change, verify only at DB, not the search engine.
  3621. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3622. return false;
  3623. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3624. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3625. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3626. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3627. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3628. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3629. $lp_id = intval($_POST['lp_id']);
  3630. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3631. $result = Database::query($sql);
  3632. $di = new DokeosIndexer();
  3633. while ($lp_item = Database :: fetch_array($result)) {
  3634. // Get search_did.
  3635. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3636. $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';
  3637. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3638. //echo $sql; echo '<br>';
  3639. $res = Database::query($sql);
  3640. if (Database::num_rows($res) > 0) {
  3641. $se_ref = Database :: fetch_array($res);
  3642. // Compare terms.
  3643. $doc = $di->get_document($se_ref['search_did']);
  3644. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3645. $xterms = array ();
  3646. foreach ($xapian_terms as $xapian_term) {
  3647. $xterms[] = substr($xapian_term['name'], 1);
  3648. }
  3649. $dterms = $terms;
  3650. $missing_terms = array_diff($dterms, $xterms);
  3651. $deprecated_terms = array_diff($xterms, $dterms);
  3652. // Save it to search engine.
  3653. foreach ($missing_terms as $term) {
  3654. $doc->add_term($prefix . $term, 1);
  3655. }
  3656. foreach ($deprecated_terms as $term) {
  3657. $doc->remove_term($prefix . $term);
  3658. }
  3659. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3660. $di->getDb()->flush();
  3661. } else {
  3662. //@todo What we should do here?
  3663. }
  3664. }
  3665. return true;
  3666. }
  3667. /**
  3668. * Sets the theme of the LP (local/remote) (and save)
  3669. * @param string Optional string giving the new theme of this learnpath
  3670. * @return bool Returns true if theme name is not empty
  3671. */
  3672. public function set_theme($name = '') {
  3673. if ($this->debug > 0) {
  3674. error_log('New LP - In learnpath::set_theme()', 0);
  3675. }
  3676. $this->theme = $this->escape_string($name);
  3677. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3678. $lp_id = $this->get_id();
  3679. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3680. if ($this->debug > 2) {
  3681. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3682. }
  3683. //$res = Database::query($sql);
  3684. $res = Database::query($sql);
  3685. return true;
  3686. }
  3687. /**
  3688. * Sets the image of an LP (and save)
  3689. * @param string Optional string giving the new image of this learnpath
  3690. * @return bool Returns true if theme name is not empty
  3691. */
  3692. public function set_preview_image($name = '') {
  3693. if ($this->debug > 0) {
  3694. error_log('New LP - In learnpath::set_preview_image()', 0);
  3695. }
  3696. $this->preview_image = $this->escape_string($name);
  3697. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3698. $lp_id = $this->get_id();
  3699. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3700. if ($this->debug > 2) {
  3701. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3702. }
  3703. $res = Database::query($sql);
  3704. return true;
  3705. }
  3706. /**
  3707. * Sets the author of a LP (and save)
  3708. * @param string Optional string giving the new author of this learnpath
  3709. * @return bool Returns true if author's name is not empty
  3710. */
  3711. public function set_author($name = '') {
  3712. if ($this->debug > 0) {
  3713. error_log('New LP - In learnpath::set_author()', 0);
  3714. }
  3715. $this->author = $this->escape_string($name);
  3716. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3717. $lp_id = $this->get_id();
  3718. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3719. if ($this->debug > 2) {
  3720. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3721. }
  3722. $res = Database::query($sql);
  3723. return true;
  3724. }
  3725. /**
  3726. * Sets the hide_toc_frame parameter of a LP (and save)
  3727. * @param int 1 if frame is hiddent 0 thenelse
  3728. * @return bool Returns true if author's name is not empty
  3729. */
  3730. public function set_hide_toc_frame($hide) {
  3731. if ($this->debug > 0) {
  3732. error_log('New LP - In learnpath::set_hide_toc_frame()', 0);
  3733. }
  3734. if (intval($hide) == $hide){
  3735. $this->hide_toc_frame = $hide;
  3736. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3737. $lp_id = $this->get_id();
  3738. $sql = "UPDATE $lp_table SET hide_toc_frame = '" . $this->hide_toc_frame . "' WHERE id = '$lp_id'";
  3739. if ($this->debug > 2) {
  3740. error_log('New LP - lp updated with new preview hide_toc_frame : ' . $this->author, 0);
  3741. }
  3742. $res = Database::query($sql);
  3743. return true;
  3744. }
  3745. else {
  3746. return false;
  3747. }
  3748. }
  3749. /**
  3750. * Sets the prerequisite of a LP (and save)
  3751. * @param int integer giving the new prerequisite of this learnpath
  3752. * @return bool returns true if prerequisite is not empty
  3753. */
  3754. public function set_prerequisite($prerequisite) {
  3755. if ($this->debug > 0) {
  3756. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3757. }
  3758. $this->prerequisite = intval($prerequisite);
  3759. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3760. $lp_id = $this->get_id();
  3761. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3762. if ($this->debug > 2) {
  3763. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3764. }
  3765. $res = Database::query($sql);
  3766. return true;
  3767. }
  3768. /**
  3769. * Sets the location/proximity of the LP (local/remote) (and save)
  3770. * @param string Optional string giving the new location of this learnpath
  3771. * @return boolean True on success / False on error
  3772. */
  3773. public function set_proximity($name = '') {
  3774. if ($this->debug > 0) {
  3775. error_log('New LP - In learnpath::set_proximity()', 0);
  3776. }
  3777. if (empty ($name))
  3778. return false;
  3779. $this->proximity = $this->escape_string($name);
  3780. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3781. $lp_id = $this->get_id();
  3782. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3783. if ($this->debug > 2) {
  3784. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3785. }
  3786. $res = Database::query($sql);
  3787. return true;
  3788. }
  3789. /**
  3790. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3791. * @param integer DB ID of the item
  3792. */
  3793. public function set_previous_item($id) {
  3794. if ($this->debug > 0) {
  3795. error_log('New LP - In learnpath::set_previous_item()', 0);
  3796. }
  3797. $this->last = $id;
  3798. }
  3799. /**
  3800. * Sets use_max_score
  3801. * @param string Optional string giving the new location of this learnpath
  3802. * @return boolean True on success / False on error
  3803. */
  3804. public function set_use_max_score($use_max_score = 1) {
  3805. if ($this->debug > 0) {
  3806. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3807. }
  3808. $use_max_score = intval($use_max_score);
  3809. $this->use_max_score = $use_max_score;
  3810. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3811. $lp_id = $this->get_id();
  3812. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3813. if ($this->debug > 2) {
  3814. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 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_expired_on($expired_on) {
  3825. if ($this->debug > 0) {
  3826. error_log('New LP - In learnpath::set_expired_on()', 0);
  3827. }
  3828. if (!empty($expired_on)) {
  3829. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3830. } else {
  3831. $this->expired_on = '';
  3832. }
  3833. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3834. $lp_id = $this->get_id();
  3835. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3836. if ($this->debug > 2) {
  3837. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3838. }
  3839. $res = Database::query($sql);
  3840. return true;
  3841. }
  3842. /**
  3843. * Sets and saves the publicated_on date
  3844. * @param string Optional string giving the new author of this learnpath
  3845. * @return bool Returns true if author's name is not empty
  3846. */
  3847. public function set_publicated_on($publicated_on) {
  3848. if ($this->debug > 0) {
  3849. error_log('New LP - In learnpath::set_expired_on()', 0);
  3850. }
  3851. if (!empty($publicated_on)) {
  3852. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3853. } else {
  3854. $this->publicated_on = '';
  3855. }
  3856. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3857. $lp_id = $this->get_id();
  3858. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3859. if ($this->debug > 2) {
  3860. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3861. }
  3862. $res = Database::query($sql);
  3863. return true;
  3864. }
  3865. /**
  3866. * Sets and saves the expired_on date
  3867. * @param string Optional string giving the new author of this learnpath
  3868. * @return bool Returns true if author's name is not empty
  3869. */
  3870. public function set_modified_on() {
  3871. if ($this->debug > 0) {
  3872. error_log('New LP - In learnpath::set_expired_on()', 0);
  3873. }
  3874. $this->modified_on = api_get_utc_datetime();
  3875. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3876. $lp_id = $this->get_id();
  3877. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3878. if ($this->debug > 2) {
  3879. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3880. }
  3881. $res = Database::query($sql);
  3882. return true;
  3883. }
  3884. /**
  3885. * Sets the object's error message
  3886. * @param string Error message. If empty, reinits the error string
  3887. * @return void
  3888. */
  3889. public function set_error_msg($error = '') {
  3890. if ($this->debug > 0) {
  3891. error_log('New LP - In learnpath::set_error_msg()', 0);
  3892. }
  3893. if (empty ($error)) {
  3894. $this->error = '';
  3895. } else {
  3896. $this->error .= $error;
  3897. }
  3898. }
  3899. /**
  3900. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3901. * @param boolean Whether to allow a new attempt or not
  3902. * @return boolean True
  3903. */
  3904. public function start_current_item($allow_new_attempt = false) {
  3905. if ($this->debug > 0) {
  3906. error_log('New LP - In learnpath::start_current_item()', 0);
  3907. }
  3908. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3909. $type = $this->get_type();
  3910. $item_type = $this->items[$this->current]->get_type();
  3911. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3912. $this->items[$this->current]->open($allow_new_attempt);
  3913. $this->autocomplete_parents($this->current);
  3914. $prereq_check = $this->prerequisites_match($this->current);
  3915. $this->items[$this->current]->save(false, $prereq_check);
  3916. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3917. } else {
  3918. // If sco, then it is supposed to have been updated by some other call.
  3919. }
  3920. if ($item_type == 'sco') {
  3921. $this->items[$this->current]->restart();
  3922. }
  3923. }
  3924. if ($this->debug > 0) {
  3925. error_log('New LP - End of learnpath::start_current_item()', 0);
  3926. }
  3927. return true;
  3928. }
  3929. /**
  3930. * Stops the processing and counters for the old item (as held in $this->last)
  3931. * @return boolean True/False
  3932. */
  3933. public function stop_previous_item() {
  3934. if ($this->debug > 0) {
  3935. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3936. }
  3937. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3938. if ($this->debug > 2) {
  3939. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3940. }
  3941. switch ($this->get_type()) {
  3942. case '3' :
  3943. if ($this->items[$this->last]->get_type() != 'au') {
  3944. if ($this->debug > 2) {
  3945. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3946. }
  3947. $this->items[$this->last]->close();
  3948. //$this->autocomplete_parents($this->last);
  3949. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3950. } else {
  3951. if ($this->debug > 2) {
  3952. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3953. }
  3954. }
  3955. case '2' :
  3956. if ($this->items[$this->last]->get_type() != 'sco') {
  3957. if ($this->debug > 2) {
  3958. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3959. }
  3960. $this->items[$this->last]->close();
  3961. //$this->autocomplete_parents($this->last);
  3962. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3963. } else {
  3964. if ($this->debug > 2) {
  3965. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3966. }
  3967. }
  3968. break;
  3969. case '1' :
  3970. default :
  3971. if ($this->debug > 2) {
  3972. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3973. }
  3974. $this->items[$this->last]->close();
  3975. break;
  3976. }
  3977. } else {
  3978. if ($this->debug > 2) {
  3979. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3980. }
  3981. return false;
  3982. }
  3983. return true;
  3984. }
  3985. /**
  3986. * Updates the default view mode from fullscreen to embedded and inversely
  3987. * @return string The current default view mode ('fullscreen' or 'embedded')
  3988. */
  3989. public function update_default_view_mode() {
  3990. if ($this->debug > 0) {
  3991. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3992. }
  3993. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3994. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3995. $res = Database::query($sql);
  3996. if (Database :: num_rows($res) > 0) {
  3997. $row = Database :: fetch_array($res);
  3998. $view_mode = $row['default_view_mod'];
  3999. if ($view_mode == 'fullscreen') {
  4000. $view_mode = 'embedded';
  4001. } elseif ($view_mode == 'embedded') {
  4002. $view_mode = 'embedframe';
  4003. } elseif ($view_mode == 'embedframe') {
  4004. $view_mode = 'fullscreen';
  4005. }
  4006. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  4007. $res = Database::query($sql);
  4008. $this->mode = $view_mode;
  4009. return $view_mode;
  4010. } else {
  4011. if ($this->debug > 2) {
  4012. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4013. }
  4014. }
  4015. return -1;
  4016. }
  4017. /**
  4018. * Updates the default behaviour about auto-commiting SCORM updates
  4019. * @return boolean True if auto-commit has been set to 'on', false otherwise
  4020. */
  4021. public function update_default_scorm_commit() {
  4022. if ($this->debug > 0) {
  4023. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  4024. }
  4025. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4026. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4027. $res = Database::query($sql);
  4028. if (Database :: num_rows($res) > 0) {
  4029. $row = Database :: fetch_array($res);
  4030. $force = $row['force_commit'];
  4031. if ($force == 1) {
  4032. $force = 0;
  4033. $force_return = false;
  4034. } elseif ($force == 0) {
  4035. $force = 1;
  4036. $force_return = true;
  4037. }
  4038. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  4039. $res = Database::query($sql);
  4040. $this->force_commit = $force_return;
  4041. return $force_return;
  4042. } else {
  4043. if ($this->debug > 2) {
  4044. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4045. }
  4046. }
  4047. return -1;
  4048. }
  4049. /**
  4050. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4051. * @return bool True on success, false on failure
  4052. */
  4053. public function update_display_order() {
  4054. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4055. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  4056. $res = Database::query($sql);
  4057. if ($res === false)
  4058. return false;
  4059. $lps = array ();
  4060. $lp_order = array ();
  4061. $num = Database :: num_rows($res);
  4062. // First check the order is correct, globally (might be wrong because
  4063. // of versions < 1.8.4).
  4064. if ($num > 0) {
  4065. $i = 1;
  4066. while ($row = Database :: fetch_array($res)) {
  4067. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4068. $need_fix = true;
  4069. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  4070. $res_u = Database::query($sql_u);
  4071. }
  4072. $i++;
  4073. }
  4074. }
  4075. return true;
  4076. }
  4077. /**
  4078. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4079. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4080. */
  4081. public function update_reinit() {
  4082. if ($this->debug > 0) {
  4083. error_log('New LP - In learnpath::update_reinit()', 0);
  4084. }
  4085. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4086. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4087. $res = Database::query($sql);
  4088. if (Database :: num_rows($res) > 0) {
  4089. $row = Database :: fetch_array($res);
  4090. $force = $row['prevent_reinit'];
  4091. if ($force == 1) {
  4092. $force = 0;
  4093. } elseif ($force == 0) {
  4094. $force = 1;
  4095. }
  4096. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4097. $res = Database::query($sql);
  4098. $this->prevent_reinit = $force;
  4099. return $force;
  4100. } else {
  4101. if ($this->debug > 2) {
  4102. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4103. }
  4104. }
  4105. return -1;
  4106. }
  4107. /**
  4108. * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag
  4109. *
  4110. * @return string 'single', 'multi' or 'seriousgame'
  4111. * @author ndiechburg <noel@cblue.be>
  4112. **/
  4113. public function get_attempt_mode()
  4114. {
  4115. if (!isset($this->seriousgame_mode)) { //Set default value for seriousgame_mode
  4116. $this->seriousgame_mode=0;
  4117. }
  4118. if (!isset($this->prevent_reinit)) { // Set default value for prevent_reinit
  4119. $this->prevent_reinit =1;
  4120. }
  4121. if ($this->seriousgame_mode == 1 && $this->prevent_reinit == 1) {
  4122. return 'seriousgame';
  4123. }
  4124. if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 1) {
  4125. return 'single';
  4126. }
  4127. if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 0) {
  4128. return 'multiple';
  4129. }
  4130. return 'single';
  4131. }
  4132. /**
  4133. * Register the attempt mode into db thanks to flags prevent_reinit and seriousgame_mode flags
  4134. *
  4135. * @param string 'seriousgame', 'single' or 'multiple'
  4136. * @return boolean
  4137. * @author ndiechburg <noel@cblue.be>
  4138. **/
  4139. public function set_attempt_mode($mode)
  4140. {
  4141. switch ($mode) {
  4142. case 'seriousgame' :
  4143. $sg_mode = 1;
  4144. $prevent_reinit = 1;
  4145. break;
  4146. case 'single' :
  4147. $sg_mode = 0;
  4148. $prevent_reinit = 1;
  4149. break;
  4150. case 'multiple' :
  4151. $sg_mode = 0;
  4152. $prevent_reinit = 0;
  4153. break;
  4154. default :
  4155. $sg_mode = 0;
  4156. $prevent_reinit = 0;
  4157. break;
  4158. }
  4159. $this->prevent_reinit = $prevent_reinit;
  4160. $this->seriousgame_mode = $sg_mode;
  4161. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4162. $sql = "UPDATE $lp_table SET prevent_reinit = $prevent_reinit , seriousgame_mode = $sg_mode WHERE id = " . $this->get_id();
  4163. $res = Database::query($sql);
  4164. if ($res) {
  4165. return true;
  4166. }
  4167. else {
  4168. return false;
  4169. }
  4170. }
  4171. /**
  4172. * switch between multiple attempt, single attempt or serious_game mode (only for scorm)
  4173. *
  4174. * @return boolean
  4175. * @author ndiechburg <noel@cblue.be>
  4176. **/
  4177. public function switch_attempt_mode()
  4178. {
  4179. if ($this->debug > 0) {
  4180. error_log('New LP - In learnpath::switch_attempt_mode()', 0);
  4181. }
  4182. $mode = $this->get_attempt_mode();
  4183. switch ($mode) {
  4184. case 'single' :
  4185. $next_mode = 'multiple';
  4186. break;
  4187. case 'multiple' :
  4188. $next_mode = 'seriousgame';
  4189. break;
  4190. case 'seriousgame' :
  4191. $next_mode = 'single';
  4192. break;
  4193. default :
  4194. $next_mode = 'single';
  4195. break;
  4196. }
  4197. $this->set_attempt_mode($next_mode);
  4198. }
  4199. /**
  4200. * Swithc the lp in ktm mode. This is a special scorm mode with unique attempt but possibility to do again a completed item.
  4201. *
  4202. * @return boolean true if seriousgame_mode has been set to 1, false otherwise
  4203. * @author ndiechburg <noel@cblue.be>
  4204. **/
  4205. public function set_seriousgame_mode()
  4206. {
  4207. if ($this->debug > 0) {
  4208. error_log('New LP - In learnpath::set_seriousgame_mode()', 0);
  4209. }
  4210. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4211. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4212. $res = Database::query($sql);
  4213. if (Database :: num_rows($res) > 0) {
  4214. $row = Database :: fetch_array($res);
  4215. $force = $row['seriousgame_mode'];
  4216. if ($force == 1) {
  4217. $force = 0;
  4218. } elseif ($force == 0) {
  4219. $force = 1;
  4220. }
  4221. $sql = "UPDATE $lp_table SET seriousgame_mode = $force WHERE id = " . $this->get_id();
  4222. $res = Database::query($sql);
  4223. $this->seriousgame_mode = $force;
  4224. return $force;
  4225. } else {
  4226. if ($this->debug > 2) {
  4227. error_log('New LP - Problem in set_seriousgame_mode() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4228. }
  4229. }
  4230. return -1;
  4231. }
  4232. /**
  4233. * Updates the "scorm_debug" value that shows or hide the debug window
  4234. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4235. */
  4236. public function update_scorm_debug() {
  4237. if ($this->debug > 0) {
  4238. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4239. }
  4240. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4241. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4242. $res = Database::query($sql);
  4243. if (Database :: num_rows($res) > 0) {
  4244. $row = Database :: fetch_array($res);
  4245. $force = $row['debug'];
  4246. if ($force == 1) {
  4247. $force = 0;
  4248. } elseif ($force == 0) {
  4249. $force = 1;
  4250. }
  4251. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4252. $res = Database::query($sql);
  4253. $this->scorm_debug = $force;
  4254. return $force;
  4255. } else {
  4256. if ($this->debug > 2) {
  4257. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4258. }
  4259. }
  4260. return -1;
  4261. }
  4262. /**
  4263. * Function that makes a call to the function sort_tree_array and create_tree_array
  4264. * @author Kevin Van Den Haute
  4265. * @param array
  4266. */
  4267. public function tree_array($array) {
  4268. if ($this->debug > 1) {
  4269. error_log('New LP - In learnpath::tree_array()', 0);
  4270. }
  4271. $array = $this->sort_tree_array($array);
  4272. $this->create_tree_array($array);
  4273. }
  4274. /**
  4275. * Creates an array with the elements of the learning path tree in it
  4276. *
  4277. * @author Kevin Van Den Haute
  4278. * @param array $array
  4279. * @param int $parent
  4280. * @param int $depth
  4281. * @param array $tmp
  4282. */
  4283. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4284. if ($this->debug > 1) {
  4285. error_log('New LP - In learnpath::create_tree_array())', 0);
  4286. }
  4287. if (is_array($array)) {
  4288. for ($i = 0; $i < count($array); $i++) {
  4289. if ($array[$i]['parent_item_id'] == $parent) {
  4290. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4291. $tmp[] = $array[$i]['parent_item_id'];
  4292. $depth++;
  4293. }
  4294. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4295. $this->arrMenu[] = array (
  4296. 'id' => $array[$i]['id'],
  4297. 'item_type' => $array[$i]['item_type'],
  4298. 'title' => $array[$i]['title'],
  4299. 'path' => $array[$i]['path'],
  4300. 'description' => $array[$i]['description'],
  4301. 'parent_item_id' => $array[$i]['parent_item_id'],
  4302. 'previous_item_id' => $array[$i]['previous_item_id'],
  4303. 'next_item_id' => $array[$i]['next_item_id'],
  4304. 'min_score' => $array[$i]['min_score'],
  4305. 'max_score' => $array[$i]['max_score'],
  4306. 'mastery_score' => $array[$i]['mastery_score'],
  4307. 'display_order' => $array[$i]['display_order'],
  4308. 'prerequisite' => $preq,
  4309. 'depth' => $depth,
  4310. 'audio' => $array[$i]['audio']
  4311. );
  4312. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4313. }
  4314. }
  4315. }
  4316. }
  4317. /**
  4318. * Sorts a multi dimensional array by parent id and display order
  4319. * @author Kevin Van Den Haute
  4320. *
  4321. * @param array $array (array with al the learning path items in it)
  4322. *
  4323. * @return array
  4324. */
  4325. public function sort_tree_array($array) {
  4326. foreach ($array as $key => $row) {
  4327. $parent[$key] = $row['parent_item_id'];
  4328. $position[$key] = $row['display_order'];
  4329. }
  4330. if (count($array) > 0)
  4331. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4332. return $array;
  4333. }
  4334. /**
  4335. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4336. * Also the actions for the modules, chapters and documents are in this table.
  4337. * @author Kevin Van Den Haute
  4338. * @param int $lp_id
  4339. * @return string
  4340. */
  4341. public function overview() {
  4342. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4343. if ($this->debug > 0) {
  4344. error_log('New LP - In learnpath::overview()', 0);
  4345. }
  4346. global $charset, $_course;
  4347. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4348. $return = '';
  4349. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4350. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4351. WHERE lp_id = " . $this->lp_id;
  4352. $result = Database::query($sql);
  4353. $arrLP = array ();
  4354. while ($row = Database :: fetch_array($result)) {
  4355. $row['title'] = Security :: remove_XSS($row['title']);
  4356. $row['description'] = Security :: remove_XSS($row['description']);
  4357. $arrLP[] = array (
  4358. 'id' => $row['id'],
  4359. 'item_type' => $row['item_type'],
  4360. 'title' => $row['title'],
  4361. 'path' => $row['path'],
  4362. 'description' => $row['description'],
  4363. 'parent_item_id' => $row['parent_item_id'],
  4364. 'previous_item_id' => $row['previous_item_id'],
  4365. 'next_item_id' => $row['next_item_id'],
  4366. 'max_score' => $row['max_score'],
  4367. 'min_score' => $row['min_score'],
  4368. 'mastery_score' => $row['mastery_score'],
  4369. 'prerequisite' => $row['prerequisite'],
  4370. 'display_order' => $row['display_order'],
  4371. 'audio' => $row['audio']
  4372. );
  4373. }
  4374. $this->tree_array($arrLP);
  4375. $arrLP = $this->arrMenu;
  4376. unset ($this->arrMenu);
  4377. if ($is_allowed_to_edit) {
  4378. $token = Security::get_token();
  4379. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4380. $return .= '<div class="actions">';
  4381. $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>';
  4382. if ($_GET['updateaudio'] == 'true') {
  4383. $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>';
  4384. } else {
  4385. $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
  4386. }
  4387. $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>';
  4388. $return .= ' '.Display :: return_icon('i.gif');
  4389. $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') . '">
  4390. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4391. $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') . '">
  4392. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4393. if ($_GET['updateaudio'] == 'true') {
  4394. $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'','32'),'#');
  4395. } else {
  4396. $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>';
  4397. }
  4398. $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>';
  4399. $return .= '</div>';
  4400. }
  4401. // we need to start a form when we want to update all the mp3 files
  4402. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4403. $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">';
  4404. $return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
  4405. }
  4406. $return .= '<table class="data_table">';
  4407. $return .= '<tr>';
  4408. $return .= '<th width="60%">' . get_lang('Title') . '</th>';
  4409. //$return .= '<th>'.get_lang('Description').'</th>';
  4410. $return .= '<th>' . get_lang('Audio') . '</th>';
  4411. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4412. $return .= '<th>' . get_lang('Move') . '</th>';
  4413. }
  4414. $return .= '<th>' . get_lang('Actions') . '</th>';
  4415. $return .= '</tr>';
  4416. for ($i = 0; $i < count($arrLP); $i++) {
  4417. $title = $arrLP[$i]['title'];
  4418. if ($arrLP[$i]['description'] == '')
  4419. $arrLP[$i]['description'] = '&nbsp;';
  4420. if (($i % 2) == 0) {
  4421. $oddclass = 'row_odd';
  4422. } else {
  4423. $oddclass = 'row_even';
  4424. }
  4425. $return .= '<tr class="' . $oddclass . '">';
  4426. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4427. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4428. $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>';
  4429. } else {
  4430. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4431. $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>';
  4432. } else {
  4433. //$return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>';
  4434. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
  4435. }
  4436. }
  4437. //$return .= '<td>' . stripslashes($arrLP[$i]['description']) . '</td>';
  4438. // The audio column.
  4439. $return .= '<td align="center">';
  4440. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4441. if (!empty ($arrLP[$i]['audio'])) {
  4442. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4443. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4444. $return .= '<script type="text/javascript">
  4445. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4446. s1.addParam("allowscriptaccess","always");
  4447. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4448. s1.write("container' . $i . '");
  4449. </script>';
  4450. } else {
  4451. $return .= ' - ';
  4452. }
  4453. } else {
  4454. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4455. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4456. if (!empty ($arrLP[$i]['audio'])) {
  4457. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4458. }
  4459. }
  4460. }
  4461. $return .= '</td>';
  4462. if ($is_allowed_to_edit) {
  4463. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4464. $return .= '<td align="center">';
  4465. if ($arrLP[$i]['previous_item_id'] != 0) {
  4466. $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.'">';
  4467. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4468. $return .= '</a>';
  4469. } else {
  4470. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4471. }
  4472. if ($arrLP[$i]['next_item_id'] != 0) {
  4473. $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.'">';
  4474. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4475. $return .= '</a>';
  4476. } else
  4477. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4478. $return .= '</td>';
  4479. }
  4480. $return .= '<td align="center">';
  4481. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4482. $return .= '<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'] . '">';
  4483. $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4484. $return .= '</a>';
  4485. } else {
  4486. $return .= '<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'] . '">';
  4487. $return .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4488. $return .= '</a>';
  4489. }
  4490. $return .= '<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) . '\');">';
  4491. $return .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
  4492. $return .= '</a>';
  4493. $return .= '</td>';
  4494. }
  4495. $return .= '</tr>';
  4496. }
  4497. if (count($arrLP) == 0) {
  4498. $return .= '<tr>';
  4499. $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
  4500. $return .= '</tr>';
  4501. }
  4502. $return .= '</table>';
  4503. // We need to close the form when we are updating the mp3 files.
  4504. if ($_GET['updateaudio'] == 'true') {
  4505. $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?
  4506. }
  4507. // We need to close the form when we are updating the mp3 files.
  4508. if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
  4509. $return .= '</form>';
  4510. }
  4511. return $return;
  4512. }
  4513. /**
  4514. * This function builds the action menu
  4515. * @return void
  4516. */
  4517. public function build_action_menu() {
  4518. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4519. echo '<div class="actions">';
  4520. //echo '<span>'.Display::return_icon('build_learnpath.png','-','','32').' '.get_lang('Build').'</span>';
  4521. echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
  4522. 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>';
  4523. 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> ';
  4524. Display :: display_icon('i.gif');
  4525. 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>';
  4526. 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>';
  4527. 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>';
  4528. 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>';
  4529. echo '</div>';
  4530. }
  4531. /**
  4532. * This functions builds the LP tree based on data from the database.
  4533. * @return string
  4534. * @uses dtree.js :: necessary javascript for building this tree
  4535. */
  4536. public function build_tree() {
  4537. $return = "<script type=\"text/javascript\">\n";
  4538. $return .= "\tm = new dTree('m');\n\n";
  4539. $return .= "\tm.config.folderLinks = true;\n";
  4540. $return .= "\tm.config.useCookies = true;\n";
  4541. $return .= "\tm.config.useIcons = true;\n";
  4542. $return .= "\tm.config.useLines = true;\n";
  4543. $return .= "\tm.config.useSelection = true;\n";
  4544. $return .= "\tm.config.useStatustext = false;\n\n";
  4545. $menu = 0;
  4546. $parent = '';
  4547. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4548. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4549. $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
  4550. FROM $tbl_lp_item
  4551. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4552. $result = Database::query($sql);
  4553. $arrLP = array ();
  4554. while ($row = Database :: fetch_array($result)) {
  4555. $row['title'] = Security :: remove_XSS($row['title']);
  4556. $row['description'] = Security :: remove_XSS($row['description']);
  4557. $arrLP[] = array (
  4558. 'id' => $row['id'],
  4559. 'item_type' => $row['item_type'],
  4560. 'title' => $row['title'],
  4561. 'path' => $row['path'],
  4562. 'description' => $row['description'],
  4563. 'parent_item_id' => $row['parent_item_id'],
  4564. 'previous_item_id' => $row['previous_item_id'],
  4565. 'next_item_id' => $row['next_item_id'],
  4566. 'max_score' => $row['max_score'],
  4567. 'min_score' => $row['min_score'],
  4568. 'mastery_score' => $row['mastery_score'],
  4569. 'display_order' => $row['display_order']
  4570. );
  4571. }
  4572. $this->tree_array($arrLP);
  4573. $arrLP = $this->arrMenu;
  4574. unset ($this->arrMenu);
  4575. $title = '';
  4576. for ($i = 0; $i < count($arrLP); $i++) {
  4577. $title = addslashes($arrLP[$i]['title']);
  4578. $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;
  4579. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4580. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4581. $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";
  4582. } else
  4583. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4584. $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";
  4585. } else {
  4586. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4587. }
  4588. if ($menu < $arrLP[$i]['id'])
  4589. $menu = $arrLP[$i]['id'];
  4590. }
  4591. $return .= "\n\tdocument.write(m);\n";
  4592. $return .= "\t if(!m.selectedNode) m.s(1);";
  4593. $return .= "</script>\n";
  4594. return $return;
  4595. }
  4596. /**
  4597. * Create a new document //still needs some finetuning
  4598. * @param array $_course
  4599. * @return string
  4600. */
  4601. public function create_document($_course) {
  4602. global $charset;
  4603. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4604. if (strstr($dir, '..'))
  4605. $dir = '/';
  4606. if ($dir[0] == '.')
  4607. $dir = substr($dir, 1);
  4608. if ($dir[0] != '/')
  4609. $dir = '/' . $dir;
  4610. if ($dir[strlen($dir) - 1] != '/')
  4611. $dir .= '/';
  4612. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4613. if (empty($_POST['dir']) && empty($_GET['dir'])) {
  4614. //Creating learning_path folder
  4615. $dir = '/learning_path';
  4616. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  4617. $folder = null;
  4618. if (!is_dir($filepath.'/'.$dir)) {
  4619. $folder = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'));
  4620. } else {
  4621. $folder = true;
  4622. }
  4623. $dir = '/learning_path/';
  4624. //Creating LP folder
  4625. if ($folder) {
  4626. $title = replace_dangerous_char($this->name);
  4627. $dir = $dir.$title;
  4628. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
  4629. if (!is_dir($filepath.'/'.$dir)) {
  4630. $folder = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $this->name);
  4631. } else {
  4632. $folder = true;
  4633. }
  4634. $dir = $dir.'/';
  4635. if ($folder) {
  4636. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document'.$dir;
  4637. }
  4638. }
  4639. }
  4640. if (!is_dir($filepath)) {
  4641. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4642. $dir = '/';
  4643. }
  4644. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4645. // is already escaped twice when it gets here.
  4646. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4647. $title = disable_dangerous_file($title);
  4648. $filename = $title;
  4649. $content = $_POST['content_lp'];
  4650. $tmp_filename = $filename;
  4651. $i = 0;
  4652. while (file_exists($filepath . $tmp_filename . '.html'))
  4653. $tmp_filename = $filename . '_' . ++ $i;
  4654. $filename = $tmp_filename . '.html';
  4655. $content = stripslashes(text_filter($content));
  4656. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4657. // Change the path of mp3 to absolute.
  4658. // The first regexp deals with ../../../ urls.
  4659. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4660. // The second regexp deals with audio/ urls.
  4661. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4662. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4663. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4664. if (!file_exists($filepath . $filename)) {
  4665. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4666. fputs($fp, $content);
  4667. fclose($fp);
  4668. $file_size = filesize($filepath . $filename);
  4669. $save_file_path = $dir . $filename;
  4670. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4671. if ($document_id) {
  4672. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4673. // Update parent folders.
  4674. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4675. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4676. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4677. if ($new_comment || $new_title) {
  4678. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4679. $ct = '';
  4680. if ($new_comment)
  4681. $ct .= ", comment='" . $new_comment . "'";
  4682. if ($new_title)
  4683. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4684. $sql_update = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." WHERE id = " . $document_id;
  4685. Database::query($sql_update);
  4686. }
  4687. }
  4688. return $document_id;
  4689. }
  4690. }
  4691. }
  4692. /**
  4693. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4694. * @param array $_course array
  4695. * @return void
  4696. */
  4697. public function edit_document($_course) {
  4698. global $_configuration;
  4699. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4700. if (strstr($dir, '..'))
  4701. $dir = '/';
  4702. if ($dir[0] == '.')
  4703. $dir = substr($dir, 1);
  4704. if ($dir[0] != '/')
  4705. $dir = '/' . $dir;
  4706. if ($dir[strlen($dir) - 1] != '/')
  4707. $dir .= '/';
  4708. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4709. if (!is_dir($filepath)) {
  4710. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4711. $dir = '/';
  4712. }
  4713. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4714. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4715. $sql = "SELECT path
  4716. FROM " . $table_doc . "
  4717. WHERE id = " . Database::escape_string($_POST['path']);
  4718. $res = Database::query($sql);
  4719. $row = Database :: fetch_array($res);
  4720. $content = stripslashes($_POST['content_lp']);
  4721. $file = $filepath . $row['path'];
  4722. if ($fp = @ fopen($file, 'w')) {
  4723. $content = text_filter($content);
  4724. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4725. // Change the path of mp3 to absolute.
  4726. // The first regexp deals with ../../../ urls.
  4727. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4728. // The second regexp deals with audio/ urls.
  4729. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4730. fputs($fp, $content);
  4731. fclose($fp);
  4732. }
  4733. }
  4734. }
  4735. /**
  4736. * Displays the selected item, with a panel for manipulating the item
  4737. * @param int $item_id
  4738. * @param string $msg
  4739. * @return string
  4740. */
  4741. public function display_item($item_id, $iframe = true, $msg = '') {
  4742. global $_course; // It will disappear.
  4743. $return = '';
  4744. if (is_numeric($item_id)) {
  4745. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4746. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4747. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4748. WHERE lp.id = " . Database :: escape_string($item_id);
  4749. $result = Database::query($sql);
  4750. while ($row = Database :: fetch_array($result)) {
  4751. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4752. // Prevents wrong parent selection for document, see Bug#1251.
  4753. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4754. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4755. }
  4756. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4757. $return .= '<div style="padding:10px;">';
  4758. if ($msg != '')
  4759. $return .= $msg;
  4760. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4761. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4762. //$return .= '<hr />';
  4763. switch ($row['item_type']) {
  4764. case TOOL_QUIZ:
  4765. if (!empty($row['path'])) {
  4766. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4767. $exercise = new Exercise();
  4768. $exercise->read($row['path']);
  4769. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4770. $return .=$exercise->description.'<br />';
  4771. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4772. }
  4773. break;
  4774. case TOOL_DOCUMENT:
  4775. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4776. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4777. $result = Database::query($sql_doc);
  4778. $path_file = Database :: result($result, 0, 0);
  4779. $path_parts = pathinfo($path_file);
  4780. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4781. if (in_array($path_parts['extension'], array (
  4782. 'html',
  4783. 'txt',
  4784. 'png',
  4785. 'jpg',
  4786. 'JPG',
  4787. 'jpeg',
  4788. 'JPEG',
  4789. 'gif',
  4790. 'swf'
  4791. ))) {
  4792. $return .= $this->display_document($row['path'], true, true);
  4793. }
  4794. break;
  4795. }
  4796. $return .= '</div>';
  4797. }
  4798. }
  4799. return $return;
  4800. }
  4801. /**
  4802. * Shows the needed forms for editing a specific item
  4803. * @param int $item_id
  4804. * @return string
  4805. */
  4806. public function display_edit_item($item_id) {
  4807. global $_course; // It will disappear.
  4808. $return = '';
  4809. if (is_numeric($item_id)) {
  4810. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4811. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . Database :: escape_string($item_id);
  4812. $res = Database::query($sql);
  4813. $row = Database::fetch_array($res);
  4814. switch ($row['item_type']) {
  4815. case 'dokeos_chapter' :
  4816. case 'dir' :
  4817. case 'asset' :
  4818. case 'sco' :
  4819. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4820. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4821. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4822. } else {
  4823. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4824. }
  4825. break;
  4826. case TOOL_DOCUMENT :
  4827. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4828. $sql_step = " SELECT lp.*, doc.path as dir
  4829. FROM " . $tbl_lp_item . " as lp
  4830. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4831. WHERE lp.id = " . Database :: escape_string($item_id);
  4832. $res_step = Database::query($sql_step);
  4833. $row_step = Database :: fetch_array($res_step);
  4834. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4835. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4836. break;
  4837. case TOOL_LINK :
  4838. $link_id = (string) $row['path'];
  4839. if (ctype_digit($link_id)) {
  4840. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4841. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4842. $res_link = Database::query($sql_select);
  4843. $row_link = Database :: fetch_array($res_link);
  4844. if (is_array($row_link)) {
  4845. $row['url'] = $row_link['url'];
  4846. }
  4847. }
  4848. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4849. $return .= $this->display_link_form('edit', $item_id, $row);
  4850. break;
  4851. case 'dokeos_module' :
  4852. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4853. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4854. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4855. } else {
  4856. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4857. }
  4858. break;
  4859. case TOOL_QUIZ :
  4860. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4861. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4862. break;
  4863. case TOOL_HOTPOTATOES :
  4864. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4865. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4866. break;
  4867. case TOOL_STUDENTPUBLICATION :
  4868. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4869. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4870. break;
  4871. case TOOL_FORUM :
  4872. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4873. $return .= $this->display_forum_form('edit', $item_id, $row);
  4874. break;
  4875. case TOOL_THREAD :
  4876. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4877. $return .= $this->display_thread_form('edit', $item_id, $row);
  4878. break;
  4879. }
  4880. }
  4881. return $return;
  4882. }
  4883. /**
  4884. * Function that displays a list with al the resources that could be added to the learning path
  4885. * @return string
  4886. */
  4887. public function display_resources() {
  4888. global $_course; // TODO: Don't use globals.
  4889. /*$return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4890. $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>';
  4891. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';*/
  4892. //Get all the docs
  4893. $documents = $this->get_documents();
  4894. //Get all the exercises
  4895. $exercises = $this->get_exercises();
  4896. // Get all the links
  4897. $links = $this->get_links();
  4898. //Get al the student publications
  4899. $works = $this->get_student_publications();
  4900. //Get al the forums
  4901. $forums = $this->get_forums();
  4902. $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
  4903. Display::return_icon('quiz.png', get_lang('Quiz'), array(), 64),
  4904. Display::return_icon('links.png', get_lang('Links'), array(), 64),
  4905. Display::return_icon('works.png', get_lang('Works'), array(), 64),
  4906. Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
  4907. );
  4908. echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums), 'resource_tab');
  4909. return true;
  4910. }
  4911. /**
  4912. * Returns the extension of a document
  4913. * @param string filename
  4914. * @return string Extension (part after the last dot)
  4915. */
  4916. public function get_extension($filename) {
  4917. $explode = explode('.', $filename);
  4918. return $explode[count($explode) - 1];
  4919. }
  4920. /**
  4921. * Displays a document by id
  4922. *
  4923. * @param unknown_type $id
  4924. * @return unknown
  4925. */
  4926. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4927. global $_course; // It is temporary.
  4928. $return = '';
  4929. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4930. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4931. WHERE id = " . $id;
  4932. $res_doc = Database::query($sql_doc);
  4933. $row_doc = Database :: fetch_array($res_doc);
  4934. //if ($show_title)
  4935. //$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>';
  4936. // TODO: Add a path filter.
  4937. if ($iframe) {
  4938. $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>';
  4939. } else {
  4940. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4941. }
  4942. return $return;
  4943. }
  4944. /**
  4945. * Return HTML form to add/edit a quiz
  4946. * @param string Action (add/edit)
  4947. * @param integer Item ID if already exists
  4948. * @param mixed Extra information (quiz ID if integer)
  4949. * @return string HTML form
  4950. */
  4951. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4952. global $charset;
  4953. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4954. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4955. if ($id != 0 && is_array($extra_info)) {
  4956. $item_title = stripslashes($extra_info['title']);
  4957. $item_description = stripslashes($extra_info['description']);
  4958. }
  4959. elseif (is_numeric($extra_info)) {
  4960. $sql_quiz = "
  4961. SELECT
  4962. title,
  4963. description
  4964. FROM " . $tbl_quiz . "
  4965. WHERE id = " . $extra_info;
  4966. $result = Database::query($sql_quiz);
  4967. $row = Database :: fetch_array($result);
  4968. $item_title = $row['title'];
  4969. $item_description = $row['description'];
  4970. } else {
  4971. $item_title = '';
  4972. $item_description = '';
  4973. }
  4974. $return = ' <div class="row">
  4975. <div class="form_header">';
  4976. if ($id != 0 && is_array($extra_info))
  4977. $parent = $extra_info['parent_item_id'];
  4978. else
  4979. $parent = 0;
  4980. $sql = "
  4981. SELECT *
  4982. FROM " . $tbl_lp_item . "
  4983. WHERE
  4984. lp_id = " . $this->lp_id;
  4985. $result = Database::query($sql);
  4986. $arrLP = array ();
  4987. while ($row = Database :: fetch_array($result)) {
  4988. $arrLP[] = array (
  4989. 'id' => $row['id'],
  4990. 'item_type' => $row['item_type'],
  4991. 'title' => $row['title'],
  4992. 'path' => $row['path'],
  4993. 'description' => $row['description'],
  4994. 'parent_item_id' => $row['parent_item_id'],
  4995. 'previous_item_id' => $row['previous_item_id'],
  4996. 'next_item_id' => $row['next_item_id'],
  4997. 'display_order' => $row['display_order'],
  4998. 'max_score' => $row['max_score'],
  4999. 'min_score' => $row['min_score'],
  5000. 'mastery_score' => $row['mastery_score'],
  5001. 'prerequisite' => $row['prerequisite'],
  5002. 'max_time_allowed' => $row['max_time_allowed']
  5003. );
  5004. }
  5005. $this->tree_array($arrLP);
  5006. $arrLP = $this->arrMenu;
  5007. unset ($this->arrMenu);
  5008. if ($action == 'add')
  5009. $return .= get_lang('CreateTheExercise') . '&nbsp;:';
  5010. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:';
  5011. else
  5012. $return .= get_lang('EditCurrentExecice') . '&nbsp;:';
  5013. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5014. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5015. }
  5016. $return .= ' </div>
  5017. </div>';
  5018. $return .= '<div class="sectioncomment">';
  5019. $return .= '<form method="POST">';
  5020. $return .= '<table class="lp_form">';
  5021. if ($action != 'move') {
  5022. $return .= '<tr>';
  5023. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5024. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
  5025. $return .= '</tr>';
  5026. }
  5027. $return .= '<tr>';
  5028. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5029. $return .= '<td class="input">';
  5030. $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">';
  5031. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5032. $arrHide = array (
  5033. $id
  5034. );
  5035. //$parent_item_id = $_SESSION['parent_item_id'];
  5036. for ($i = 0; $i < count($arrLP); $i++) {
  5037. if ($action != 'add') {
  5038. 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)) {
  5039. $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>';
  5040. } else {
  5041. $arrHide[] = $arrLP[$i]['id'];
  5042. }
  5043. } else {
  5044. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5045. $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>';
  5046. }
  5047. }
  5048. if (is_array($arrLP)) {
  5049. reset($arrLP);
  5050. }
  5051. $return .= '</select>';
  5052. $return .= '</td>';
  5053. $return .= '</tr>';
  5054. $return .= '<tr>';
  5055. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5056. $return .= '<td class="input">';
  5057. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
  5058. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5059. for ($i = 0; $i < count($arrLP); $i++) {
  5060. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5061. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5062. $selected = 'selected="selected" ';
  5063. elseif ($action == 'add') $selected = 'selected="selected" ';
  5064. else
  5065. $selected = '';
  5066. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5067. }
  5068. }
  5069. $return .= "\t\t\t\t" . '</select>';
  5070. $return .= '</td>';
  5071. $return .= '</tr>';
  5072. if ($action != 'move') {
  5073. $id_prerequisite = 0;
  5074. if (is_array($arrLP)) {
  5075. foreach ($arrLP as $key => $value) {
  5076. if ($value['id'] == $id) {
  5077. $id_prerequisite = $value['prerequisite'];
  5078. break;
  5079. }
  5080. }
  5081. }
  5082. $arrHide = array ();
  5083. for ($i = 0; $i < count($arrLP); $i++) {
  5084. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5085. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5086. $s_selected_position = $arrLP[$i]['id'];
  5087. elseif ($action == 'add') $s_selected_position = 0;
  5088. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5089. }
  5090. }
  5091. /*// Commented the prerequisites, only visible in edit (exercise).
  5092. $return .= '<tr>';
  5093. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  5094. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5095. foreach($arrHide as $key => $value){
  5096. if($key==$s_selected_position && $action == 'add'){
  5097. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5098. }
  5099. elseif($key==$id_prerequisite && $action == 'edit'){
  5100. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5101. }
  5102. else{
  5103. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5104. }
  5105. }
  5106. $return .= "</select></td>";
  5107. */
  5108. $return .= '</tr>';
  5109. /*$return .= '<tr>';
  5110. $return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
  5111. $return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  5112. // Remove temporarily the test description.
  5113. //$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
  5114. //$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
  5115. $return .= '</tr>'; */
  5116. }
  5117. $return .= '<tr>';
  5118. if ($action == 'add') {
  5119. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  5120. } else {
  5121. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  5122. }
  5123. $return .= '</tr>';
  5124. $return .= '</table>';
  5125. if ($action == 'move') {
  5126. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5127. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5128. }
  5129. if (is_numeric($extra_info)) {
  5130. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5131. }
  5132. elseif (is_array($extra_info)) {
  5133. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5134. }
  5135. $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
  5136. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5137. $return .= '</form>';
  5138. $return .= '</div>';
  5139. return $return;
  5140. }
  5141. /**
  5142. * Addition of Hotpotatoes tests
  5143. * @param string Action
  5144. * @param integer Internal ID of the item
  5145. * @param mixed Extra information - can be an array with title and description indexes
  5146. * @return string HTML structure to display the hotpotatoes addition formular
  5147. */
  5148. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  5149. global $charset;
  5150. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5151. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5152. if ($id != 0 && is_array($extra_info)) {
  5153. $item_title = stripslashes($extra_info['title']);
  5154. $item_description = stripslashes($extra_info['description']);
  5155. } elseif (is_numeric($extra_info)) {
  5156. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  5157. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  5158. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  5159. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  5160. $res_hot = Database::query($sql_hot);
  5161. $row = Database::fetch_array($res_hot);
  5162. $item_title = $row['title'];
  5163. $item_description = $row['description'];
  5164. if (!empty ($row['comment'])) {
  5165. $item_title = $row['comment'];
  5166. }
  5167. } else {
  5168. $item_title = '';
  5169. $item_description = '';
  5170. }
  5171. if ($id != 0 && is_array($extra_info))
  5172. $parent = $extra_info['parent_item_id'];
  5173. else
  5174. $parent = 0;
  5175. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = " . $this->lp_id;
  5176. $result = Database::query($sql);
  5177. $arrLP = array ();
  5178. while ($row = Database :: fetch_array($result)) {
  5179. $arrLP[] = array (
  5180. 'id' => $row['id'],
  5181. 'item_type' => $row['item_type'],
  5182. 'title' => $row['title'],
  5183. 'path' => $row['path'],
  5184. 'description' => $row['description'],
  5185. 'parent_item_id' => $row['parent_item_id'],
  5186. 'previous_item_id' => $row['previous_item_id'],
  5187. 'next_item_id' => $row['next_item_id'],
  5188. 'display_order' => $row['display_order'],
  5189. 'max_score' => $row['max_score'],
  5190. 'min_score' => $row['min_score'],
  5191. 'mastery_score' => $row['mastery_score'],
  5192. 'prerequisite' => $row['prerequisite'],
  5193. 'max_time_allowed' => $row['max_time_allowed']
  5194. );
  5195. }
  5196. /*
  5197. $this->tree_array($arrLP);
  5198. $arrLP = $this->arrMenu;
  5199. unset ($this->arrMenu);*/
  5200. if ($action == 'add')
  5201. $return .= '<div class="row"><div class="form_header">' . get_lang('CreateTheExercise') . '&nbsp;:</div></div>';
  5202. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>';
  5203. else
  5204. //$return .= '<p class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>';
  5205. $return .= '<div class="row"><div class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</div></div>';
  5206. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5207. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5208. }
  5209. $return .= '<form method="POST">';
  5210. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5211. $return .= '<tr>';
  5212. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
  5213. $return .= '<td class="input">';
  5214. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5215. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5216. $arrHide = array (
  5217. $id
  5218. );
  5219. if (count($arrLP) > 0) {
  5220. for ($i = 0; $i < count($arrLP); $i++) {
  5221. if ($action != 'add') {
  5222. 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)) {
  5223. $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>';
  5224. } else {
  5225. $arrHide[] = $arrLP[$i]['id'];
  5226. }
  5227. } else {
  5228. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5229. $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>';
  5230. }
  5231. }
  5232. reset($arrLP);
  5233. }
  5234. $return .= "\t\t\t\t" . '</select>';
  5235. $return .= '</td>';
  5236. $return .= '</tr>';
  5237. $return .= '<tr>';
  5238. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
  5239. $return .= '<td class="input">';
  5240. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5241. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5242. for ($i = 0; $i < count($arrLP); $i++) {
  5243. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5244. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5245. $selected = 'selected="selected" ';
  5246. elseif ($action == 'add') $selected = 'selected="selected" ';
  5247. else
  5248. $selected = '';
  5249. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5250. }
  5251. }
  5252. $return .= "\t\t\t\t" . '</select>';
  5253. $return .= '</td>';
  5254. $return .= '</tr>';
  5255. if ($action != 'move') {
  5256. $return .= '<tr>';
  5257. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
  5258. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5259. $return .= '</tr>';
  5260. $id_prerequisite = 0;
  5261. if (is_array($arrLP) && count($arrLP) > 0) {
  5262. foreach ($arrLP as $key => $value) {
  5263. if ($value['id'] == $id) {
  5264. $id_prerequisite = $value['prerequisite'];
  5265. break;
  5266. }
  5267. }
  5268. $arrHide = array ();
  5269. for ($i = 0; $i < count($arrLP); $i++) {
  5270. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5271. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5272. $s_selected_position = $arrLP[$i]['id'];
  5273. elseif ($action == 'add') $s_selected_position = 0;
  5274. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5275. }
  5276. }
  5277. }
  5278. //$return .= '<tr>';
  5279. //$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>';
  5280. //$return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5281. /*
  5282. foreach ($arrHide as $key => $value) {
  5283. if ($key == $s_selected_position && $action == 'add') {
  5284. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5285. }
  5286. elseif ($key == $id_prerequisite && $action == 'edit') {
  5287. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5288. } else {
  5289. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5290. }
  5291. }
  5292. */
  5293. //$return .= "</select></td>";
  5294. //$return .= '</tr>';
  5295. //$return .= '<tr>';
  5296. //$return .= '</tr>';
  5297. }
  5298. $return .= '<tr>';
  5299. $return .= '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
  5300. $return .= '</tr>';
  5301. $return .= '</table>';
  5302. if ($action == 'move') {
  5303. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5304. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5305. }
  5306. if (is_numeric($extra_info)) {
  5307. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5308. }
  5309. elseif (is_array($extra_info)) {
  5310. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5311. }
  5312. $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
  5313. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5314. $return .= '</form>';
  5315. return $return;
  5316. }
  5317. /**
  5318. * Return the form to display the forum edit/add option
  5319. * @param string Action (add/edit)
  5320. * @param integer ID of the lp_item if already exists
  5321. * @param mixed Forum ID or title
  5322. * @return string HTML form
  5323. */
  5324. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5325. global $charset;
  5326. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5327. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5328. if ($id != 0 && is_array($extra_info)) {
  5329. $item_title = stripslashes($extra_info['title']);
  5330. }
  5331. elseif (is_numeric($extra_info)) {
  5332. $sql_forum = "
  5333. SELECT
  5334. forum_title as title, forum_comment as comment
  5335. FROM " . $tbl_forum . "
  5336. WHERE forum_id = " . $extra_info;
  5337. $result = Database::query($sql_forum);
  5338. $row = Database :: fetch_array($result);
  5339. $item_title = $row['title'];
  5340. $item_description = $row['comment'];
  5341. } else {
  5342. $item_title = '';
  5343. $item_description = '';
  5344. }
  5345. $return = ' <div class="row">
  5346. <div class="form_header">';
  5347. if ($id != 0 && is_array($extra_info))
  5348. $parent = $extra_info['parent_item_id'];
  5349. else
  5350. $parent = 0;
  5351. $sql = "
  5352. SELECT *
  5353. FROM " . $tbl_lp_item . "
  5354. WHERE
  5355. lp_id = " . $this->lp_id;
  5356. $result = Database::query($sql);
  5357. $arrLP = array ();
  5358. while ($row = Database :: fetch_array($result)) {
  5359. $arrLP[] = array (
  5360. 'id' => $row['id'],
  5361. 'item_type' => $row['item_type'],
  5362. 'title' => $row['title'],
  5363. 'path' => $row['path'],
  5364. 'description' => $row['description'],
  5365. 'parent_item_id' => $row['parent_item_id'],
  5366. 'previous_item_id' => $row['previous_item_id'],
  5367. 'next_item_id' => $row['next_item_id'],
  5368. 'display_order' => $row['display_order'],
  5369. 'max_score' => $row['max_score'],
  5370. 'min_score' => $row['min_score'],
  5371. 'mastery_score' => $row['mastery_score'],
  5372. 'prerequisite' => $row['prerequisite']
  5373. );
  5374. }
  5375. $this->tree_array($arrLP);
  5376. $arrLP = $this->arrMenu;
  5377. unset ($this->arrMenu);
  5378. if ($action == 'add')
  5379. $return .= get_lang('CreateTheForum') . '&nbsp;:';
  5380. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:';
  5381. else
  5382. $return .= get_lang('EditCurrentForum') . '&nbsp;:';
  5383. $return .= ' </div>
  5384. </div>';
  5385. $return .= '<div class="sectioncomment">';
  5386. $return .= '<form method="POST">';
  5387. $return .= '<table class="lp_form">';
  5388. if ($action != 'move') {
  5389. $return .= '<tr>';
  5390. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5391. $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  5392. $return .= '</tr>';
  5393. }
  5394. $return .= '<tr>';
  5395. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5396. $return .= '<td class="input">';
  5397. $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">';
  5398. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5399. $arrHide = array (
  5400. $id
  5401. );
  5402. //$parent_item_id = $_SESSION['parent_item_id'];
  5403. for ($i = 0; $i < count($arrLP); $i++) {
  5404. if ($action != 'add') {
  5405. 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)) {
  5406. $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>';
  5407. } else {
  5408. $arrHide[] = $arrLP[$i]['id'];
  5409. }
  5410. } else {
  5411. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5412. $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>';
  5413. }
  5414. }
  5415. if (is_array($arrLP)) {
  5416. reset($arrLP);
  5417. }
  5418. $return .= "\t\t\t\t" . '</select>';
  5419. $return .= '</td>';
  5420. $return .= '</tr>';
  5421. $return .= '<tr>';
  5422. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5423. $return .= '<td class="input">';
  5424. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5425. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5426. for ($i = 0; $i < count($arrLP); $i++) {
  5427. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5428. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5429. $selected = 'selected="selected" ';
  5430. elseif ($action == 'add') $selected = 'selected="selected" ';
  5431. else
  5432. $selected = '';
  5433. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5434. }
  5435. }
  5436. $return .= "\t\t\t\t" . '</select>';
  5437. $return .= '</td>';
  5438. $return .= '</tr>';
  5439. if ($action != 'move') {
  5440. $return .= '<tr>';
  5441. $return .= '</tr>';
  5442. $id_prerequisite = 0;
  5443. if (is_array($arrLP)) {
  5444. foreach ($arrLP as $key => $value) {
  5445. if ($value['id'] == $id) {
  5446. $id_prerequisite = $value['prerequisite'];
  5447. break;
  5448. }
  5449. }
  5450. }
  5451. $arrHide = array ();
  5452. for ($i = 0; $i < count($arrLP); $i++) {
  5453. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5454. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5455. $s_selected_position = $arrLP[$i]['id'];
  5456. elseif ($action == 'add') $s_selected_position = 0;
  5457. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5458. }
  5459. }
  5460. $return .= '</tr>';
  5461. }
  5462. $return .= '<tr>';
  5463. if ($action == 'add') {
  5464. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5465. } else {
  5466. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5467. }
  5468. $return .= '</tr>';
  5469. $return .= '</table>';
  5470. if ($action == 'move') {
  5471. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5472. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5473. }
  5474. if (is_numeric($extra_info)) {
  5475. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5476. }
  5477. elseif (is_array($extra_info)) {
  5478. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5479. }
  5480. $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
  5481. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5482. $return .= '</form>';
  5483. $return .= '</div>';
  5484. return $return;
  5485. }
  5486. /**
  5487. * Return HTML form to add/edit forum threads
  5488. * @param string Action (add/edit)
  5489. * @param integer Item ID if already exists in learning path
  5490. * @param mixed Extra information (thread ID if integer)
  5491. * @return string HTML form
  5492. */
  5493. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5494. global $charset;
  5495. echo '
  5496. <style>
  5497. div.row div.label {
  5498. width:110px;
  5499. }
  5500. div.row div.formw {
  5501. width: 82%;
  5502. }
  5503. </style>';
  5504. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5505. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5506. if ($id != 0 && is_array($extra_info)) {
  5507. $item_title = stripslashes($extra_info['title']);
  5508. }
  5509. elseif (is_numeric($extra_info)) {
  5510. $sql_forum = "
  5511. SELECT
  5512. thread_title as title
  5513. FROM " . $tbl_forum . "
  5514. WHERE thread_id = " . $extra_info;
  5515. $result = Database::query($sql_forum);
  5516. $row = Database :: fetch_array($result);
  5517. $item_title = $row['title'];
  5518. $item_description = '';
  5519. } else {
  5520. $item_title = '';
  5521. $item_description = '';
  5522. }
  5523. $return = '<div style="margin:3px 12px;">';
  5524. if ($id != 0 && is_array($extra_info))
  5525. $parent = $extra_info['parent_item_id'];
  5526. else
  5527. $parent = 0;
  5528. $sql = "
  5529. SELECT *
  5530. FROM " . $tbl_lp_item . "
  5531. WHERE
  5532. lp_id = " . $this->lp_id;
  5533. $result = Database::query($sql);
  5534. $arrLP = array ();
  5535. while ($row = Database :: fetch_array($result)) {
  5536. $arrLP[] = array (
  5537. 'id' => $row['id'],
  5538. 'item_type' => $row['item_type'],
  5539. 'title' => $row['title'],
  5540. 'path' => $row['path'],
  5541. 'description' => $row['description'],
  5542. 'parent_item_id' => $row['parent_item_id'],
  5543. 'previous_item_id' => $row['previous_item_id'],
  5544. 'next_item_id' => $row['next_item_id'],
  5545. 'display_order' => $row['display_order'],
  5546. 'max_score' => $row['max_score'],
  5547. 'min_score' => $row['min_score'],
  5548. 'mastery_score' => $row['mastery_score'],
  5549. 'prerequisite' => $row['prerequisite']
  5550. );
  5551. }
  5552. $this->tree_array($arrLP);
  5553. $arrLP = $this->arrMenu;
  5554. unset ($this->arrMenu);
  5555. if ($action == 'add')
  5556. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>';
  5557. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>';
  5558. else
  5559. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>';
  5560. $return .= '<form method="POST">';
  5561. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5562. $return .= '<tr>';
  5563. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>';
  5564. $return .= '<td class="input">';
  5565. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5566. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5567. $arrHide = array (
  5568. $id
  5569. );
  5570. for ($i = 0; $i < count($arrLP); $i++) {
  5571. if ($action != 'add') {
  5572. 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)) {
  5573. $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>';
  5574. } else {
  5575. $arrHide[] = $arrLP[$i]['id'];
  5576. }
  5577. } else {
  5578. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5579. $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>';
  5580. }
  5581. }
  5582. if ($arrLP != null) {
  5583. reset($arrLP);
  5584. }
  5585. $return .= "\t\t\t\t" . '</select>';
  5586. $return .= '</td>';
  5587. $return .= '</tr>';
  5588. $return .= '<tr>';
  5589. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '&nbsp;:</label></td>';
  5590. $return .= '<td class="input">';
  5591. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5592. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5593. for ($i = 0; $i < count($arrLP); $i++) {
  5594. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5595. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5596. $selected = 'selected="selected" ';
  5597. elseif ($action == 'add') $selected = 'selected="selected" ';
  5598. else
  5599. $selected = '';
  5600. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5601. }
  5602. }
  5603. $return .= "\t\t\t\t" . '</select>';
  5604. $return .= '</td>';
  5605. $return .= '</tr>';
  5606. if ($action != 'move') {
  5607. $return .= '<tr>';
  5608. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>';
  5609. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5610. $return .= '</tr>';
  5611. $return .= '<tr>';
  5612. $return .= '</tr>';
  5613. $id_prerequisite = 0;
  5614. if ($arrLP != null) {
  5615. foreach ($arrLP as $key => $value) {
  5616. if ($value['id'] == $id) {
  5617. $id_prerequisite = $value['prerequisite'];
  5618. break;
  5619. }
  5620. }
  5621. }
  5622. $arrHide = array();
  5623. for ($i = 0; $i < count($arrLP); $i++) {
  5624. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5625. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5626. $s_selected_position = $arrLP[$i]['id'];
  5627. elseif ($action == 'add') $s_selected_position = 0;
  5628. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5629. }
  5630. }
  5631. $return .= '<tr>';
  5632. $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>';
  5633. $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5634. foreach ($arrHide as $key => $value) {
  5635. if ($key == $s_selected_position && $action == 'add') {
  5636. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5637. }
  5638. elseif ($key == $id_prerequisite && $action == 'edit') {
  5639. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5640. } else {
  5641. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5642. }
  5643. }
  5644. $return .= "</select></td>";
  5645. $return .= '</tr>';
  5646. }
  5647. $return .= '<tr>';
  5648. $return .= '<td colspan="2">
  5649. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
  5650. $return .= '</tr>';
  5651. $return .= '</table>';
  5652. if ($action == 'move') {
  5653. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5654. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5655. }
  5656. if (is_numeric($extra_info)) {
  5657. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5658. }
  5659. elseif (is_array($extra_info)) {
  5660. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5661. }
  5662. $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
  5663. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5664. $return .= '</form>';
  5665. $return .= '</div>';
  5666. return $return;
  5667. }
  5668. /**
  5669. * Return the HTML form to display an item (generally a section/module item)
  5670. * @param string Item type (module/dokeos_module)
  5671. * @param string Title (optional, only when creating)
  5672. * @param string Action ('add'/'edit')
  5673. * @param integer lp_item ID
  5674. * @param mixed Extra info
  5675. * @return string HTML form
  5676. */
  5677. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5678. global $_course;
  5679. global $charset;
  5680. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5681. if ($id != 0 && is_array($extra_info)) {
  5682. $item_title = $extra_info['title'];
  5683. $item_description = $extra_info['description'];
  5684. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5685. } else {
  5686. $item_title = '';
  5687. $item_description = '';
  5688. }
  5689. $return = ' <div class="row">
  5690. <div class="form_header">';
  5691. if ($id != 0 && is_array($extra_info))
  5692. $parent = $extra_info['parent_item_id'];
  5693. else
  5694. $parent = 0;
  5695. $sql = "
  5696. SELECT *
  5697. FROM " . $tbl_lp_item . "
  5698. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5699. if ($item_type == 'module')
  5700. $sql .= " AND parent_item_id = 0";
  5701. $result = Database::query($sql);
  5702. $arrLP = array ();
  5703. while ($row = Database :: fetch_array($result)) {
  5704. $arrLP[] = array (
  5705. 'id' => $row['id'],
  5706. 'item_type' => $row['item_type'],
  5707. 'title' => $row['title'],
  5708. 'path' => $row['path'],
  5709. 'description' => $row['description'],
  5710. 'parent_item_id' => $row['parent_item_id'],
  5711. 'previous_item_id' => $row['previous_item_id'],
  5712. 'next_item_id' => $row['next_item_id'],
  5713. 'max_score' => $row['max_score'],
  5714. 'min_score' => $row['min_score'],
  5715. 'mastery_score' => $row['mastery_score'],
  5716. 'prerequisite' => $row['prerequisite'],
  5717. 'display_order' => $row['display_order']
  5718. );
  5719. }
  5720. $this->tree_array($arrLP);
  5721. $arrLP = $this->arrMenu;
  5722. unset ($this->arrMenu);
  5723. $return .= $title;
  5724. $return .= ' </div>
  5725. </div>';
  5726. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5727. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5728. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5729. $defaults['description'] = $item_description;
  5730. $form->addElement('html', $return);
  5731. //$arrHide = array($id);
  5732. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5733. $arrHide[0]['padding'] = 3;
  5734. $charset = api_get_system_encoding();
  5735. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5736. for ($i = 0; $i < count($arrLP); $i++) {
  5737. if ($action != 'add') {
  5738. 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)) {
  5739. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5740. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5741. if ($parent == $arrLP[$i]['id']) {
  5742. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5743. }
  5744. }
  5745. } else {
  5746. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5747. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5748. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5749. if ($parent == $arrLP[$i]['id']) {
  5750. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5751. }
  5752. }
  5753. }
  5754. }
  5755. if ($action != 'move') {
  5756. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5757. $form->applyFilter('title', 'html_filter');
  5758. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5759. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5760. } else {
  5761. $form->addElement('hidden', 'title');
  5762. }
  5763. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5764. foreach ($arrHide as $key => $value) {
  5765. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5766. }
  5767. $parent_select->setSelected($s_selected_parent);
  5768. }
  5769. if (is_array($arrLP)) {
  5770. reset($arrLP);
  5771. }
  5772. $arrHide = array ();
  5773. // POSITION
  5774. for ($i = 0; $i < count($arrLP); $i++) {
  5775. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5776. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5777. $s_selected_position = $arrLP[$i]['id'];
  5778. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5779. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5780. }
  5781. }
  5782. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
  5783. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5784. foreach ($arrHide as $key => $value) {
  5785. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5786. }
  5787. if (!empty ($s_selected_position)) {
  5788. $position->setSelected($s_selected_position);
  5789. }
  5790. if (is_array($arrLP)) {
  5791. reset($arrLP);
  5792. }
  5793. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5794. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5795. $form->addElement('hidden', 'parent', '0');
  5796. }
  5797. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5798. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5799. if ($item_type == 'sco') {
  5800. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5801. }
  5802. $renderer = $form->defaultRenderer();
  5803. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5804. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5805. $defaults['content_lp'] = file_get_contents($item_path);
  5806. }
  5807. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5808. $form->addElement('hidden', 'post_time', time());
  5809. $form->setDefaults($defaults);
  5810. return $form->return_form();
  5811. }
  5812. /**
  5813. * Returns the form to update or create a document
  5814. * @param string Action (add/edit)
  5815. * @param integer ID of the lp_item (if already exists)
  5816. * @param mixed Integer if document ID, string if info ('new')
  5817. * @return string HTML form
  5818. */
  5819. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5820. global $charset;
  5821. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5822. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5823. $path_parts = pathinfo($extra_info['dir']);
  5824. $no_display_edit_textarea = false;
  5825. //If action==edit document
  5826. //We don't display the document form if it's not an editable document (html or txt file)
  5827. if ($action == "edit") {
  5828. if (is_array($extra_info)) {
  5829. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5830. $no_display_edit_textarea = true;
  5831. }
  5832. }
  5833. }
  5834. $no_display_add = false;
  5835. // If action==add an existing document
  5836. // We don't display the document form if it's not an editable document (html or txt file).
  5837. if ($action == "add") {
  5838. if (is_numeric($extra_info)) {
  5839. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5840. $result = Database::query($sql_doc);
  5841. $path_file = Database :: result($result, 0, 0);
  5842. $path_parts = pathinfo($path_file);
  5843. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5844. $no_display_add = true;
  5845. }
  5846. }
  5847. }
  5848. if ($id != 0 && is_array($extra_info)) {
  5849. $item_title = stripslashes($extra_info['title']);
  5850. $item_description = stripslashes($extra_info['description']);
  5851. $item_terms = stripslashes($extra_info['terms']);
  5852. if (empty ($item_title)) {
  5853. $path_parts = pathinfo($extra_info['path']);
  5854. $item_title = stripslashes($path_parts['filename']);
  5855. }
  5856. } elseif (is_numeric($extra_info)) {
  5857. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5858. WHERE id = " . Database :: escape_string($extra_info);
  5859. $result = Database::query($sql_doc);
  5860. $row = Database :: fetch_array($result);
  5861. $explode = explode('.', $row['title']);
  5862. if (count($explode) > 1) {
  5863. for ($i = 0; $i < count($explode) - 1; $i++)
  5864. $item_title .= $explode[$i];
  5865. } else {
  5866. $item_title = $row['title'];
  5867. }
  5868. $item_title = str_replace('_', ' ', $item_title);
  5869. if (empty ($item_title)) {
  5870. $path_parts = pathinfo($row['path']);
  5871. $item_title = stripslashes($path_parts['filename']);
  5872. }
  5873. } else {
  5874. $item_title = '';
  5875. $item_description = '';
  5876. }
  5877. $return = ' <div class="row">
  5878. <div class="form_header">';
  5879. if ($id != 0 && is_array($extra_info))
  5880. $parent = $extra_info['parent_item_id'];
  5881. else
  5882. $parent = 0;
  5883. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5884. WHERE lp_id = " . $this->lp_id;
  5885. $result = Database::query($sql);
  5886. $arrLP = array ();
  5887. while ($row = Database :: fetch_array($result)) {
  5888. $arrLP[] = array (
  5889. 'id' => $row['id'],
  5890. 'item_type' => $row['item_type'],
  5891. 'title' => $row['title'],
  5892. 'path' => $row['path'],
  5893. 'description' => $row['description'],
  5894. 'parent_item_id' => $row['parent_item_id'],
  5895. 'previous_item_id' => $row['previous_item_id'],
  5896. 'next_item_id' => $row['next_item_id'],
  5897. 'display_order' => $row['display_order'],
  5898. 'max_score' => $row['max_score'],
  5899. 'min_score' => $row['min_score'],
  5900. 'mastery_score' => $row['mastery_score'],
  5901. 'prerequisite' => $row['prerequisite']
  5902. );
  5903. }
  5904. $this->tree_array($arrLP);
  5905. $arrLP = $this->arrMenu;
  5906. unset ($this->arrMenu);
  5907. if ($action == 'add') {
  5908. $return .= get_lang('CreateTheDocument');
  5909. } elseif ($action == 'move') {
  5910. $return .= get_lang('MoveTheCurrentDocument');
  5911. } else {
  5912. $return .= get_lang('EditTheCurrentDocument');
  5913. }
  5914. $return .= '</div>
  5915. </div>';
  5916. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5917. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5918. }
  5919. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5920. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5921. $defaults['title'] = Security :: remove_XSS($item_title);
  5922. if (empty($item_title)) {
  5923. $defaults['title'] = Security::remove_XSS($item_title);
  5924. }
  5925. $defaults['description'] = $item_description;
  5926. $form->addElement('html', $return);
  5927. if ($action != 'move') {
  5928. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5929. $form->applyFilter('title', 'html_filter');
  5930. }
  5931. //$arrHide = array($id);
  5932. $arrHide[0]['value'] = $this->name;
  5933. $arrHide[0]['padding'] = 3;
  5934. for ($i = 0; $i < count($arrLP); $i++) {
  5935. if ($action != 'add') {
  5936. 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)) {
  5937. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5938. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5939. if ($parent == $arrLP[$i]['id']) {
  5940. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5941. }
  5942. }
  5943. } else {
  5944. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5945. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5946. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5947. if ($parent == $arrLP[$i]['id']) {
  5948. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5949. }
  5950. }
  5951. }
  5952. }
  5953. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5954. $my_count=0;
  5955. foreach ($arrHide as $key => $value) {
  5956. if ($my_count!=0) {
  5957. // The LP name is also the first section and is not in the same charset like the other sections.
  5958. $value['value'] = Security :: remove_XSS($value['value']);
  5959. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5960. } else {
  5961. $value['value'] = Security :: remove_XSS($value['value']);
  5962. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5963. }
  5964. $my_count++;
  5965. }
  5966. if (!empty($id)) {
  5967. $parent_select->setSelected($parent);
  5968. } else {
  5969. $parent_item_id = $_SESSION['parent_item_id'];
  5970. $parent_select->setSelected($parent_item_id);
  5971. }
  5972. if (is_array($arrLP)) {
  5973. reset($arrLP);
  5974. }
  5975. $arrHide = array ();
  5976. //POSITION
  5977. for ($i = 0; $i < count($arrLP); $i++) {
  5978. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5979. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5980. $s_selected_position = $arrLP[$i]['id'];
  5981. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5982. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5983. }
  5984. }
  5985. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
  5986. $position->addOption(get_lang('FirstPosition'), 0);
  5987. foreach ($arrHide as $key => $value) {
  5988. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5989. }
  5990. $position->setSelected($s_selected_position);
  5991. if (is_array($arrLP)) {
  5992. reset($arrLP);
  5993. }
  5994. if ($action != 'move') {
  5995. $id_prerequisite = 0;
  5996. if (is_array($arrLP)) {
  5997. foreach ($arrLP as $key => $value) {
  5998. if ($value['id'] == $id) {
  5999. $id_prerequisite = $value['prerequisite'];
  6000. break;
  6001. }
  6002. }
  6003. }
  6004. // Commented the prerequisites, only visible in edit (new document).
  6005. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  6006. //$select_prerequisites->addOption(get_lang('NoPrerequisites'), 0);
  6007. // Form element for uploading an mp3 file.
  6008. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  6009. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  6010. /* Code deprecated - moved to lp level (not lp-item).
  6011. if (api_get_setting('search_enabled') === 'true') {
  6012. //add terms field
  6013. $terms = $form->addElement('text', 'terms', get_lang('SearchFeatureTerms').'&nbsp;:', 'id="idTerms" class="learnpath_item_form"');
  6014. $terms->setValue($item_terms);
  6015. }
  6016. */
  6017. $arrHide = array ();
  6018. for ($i = 0; $i < count($arrLP); $i++) {
  6019. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6020. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6021. $s_selected_position = $arrLP[$i]['id'];
  6022. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  6023. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6024. }
  6025. }
  6026. /* foreach ($arrHide as $key => $value) {
  6027. $select_prerequisites->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
  6028. if ($key == $s_selected_position && $action == 'add') {
  6029. $select_prerequisites -> setSelected(0);
  6030. }
  6031. elseif ($key == $id_prerequisite && $action == 'edit') {
  6032. $select_prerequisites -> setSelected($id_prerequisite);
  6033. }
  6034. }
  6035. */
  6036. if (!$no_display_add) {
  6037. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  6038. if (isset ($_POST['content']))
  6039. $content = stripslashes($_POST['content']);
  6040. elseif (is_array($extra_info)) {
  6041. //If it's an html document or a text file
  6042. if (!$no_display_edit_textarea) {
  6043. $content = $this->display_document($extra_info['path'], false, false);
  6044. }
  6045. }
  6046. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  6047. else
  6048. $content = '';
  6049. if (!$no_display_edit_textarea) {
  6050. // We need to claculate here some specific settings for the online editor.
  6051. // The calculated settings work for documents in the Documents tool
  6052. // (on the root or in subfolders).
  6053. // For documents in native scorm packages it is unclear whether the
  6054. // online editor should be activated or not.
  6055. $relative_path = $extra_info['dir'];
  6056. if ($relative_path == 'n/') {
  6057. // A new document, it is in the root of the repository.
  6058. $relative_path = '';
  6059. $relative_prefix = '';
  6060. } else {
  6061. // The document already exists. Whe have to determine its relative path towards the repository root.
  6062. $relative_path = explode('/', $relative_path);
  6063. $cnt = count($relative_path) - 2;
  6064. if ($cnt < 0) {
  6065. $cnt = 0;
  6066. }
  6067. $relative_prefix = str_repeat('../', $cnt);
  6068. $relative_path = array_slice($relative_path, 1, $cnt);
  6069. $relative_path = implode('/', $relative_path);
  6070. if (strlen($relative_path) > 0) {
  6071. $relative_path = $relative_path . '/';
  6072. }
  6073. }
  6074. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  6075. 'CreateDocumentDir' => $relative_prefix,
  6076. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  6077. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  6078. );
  6079. if ($_GET['action'] == 'add_item') {
  6080. $class = 'add';
  6081. $text = get_lang('LPCreateDocument');
  6082. } else
  6083. if ($_GET['action'] == 'edit_item') {
  6084. $class = 'save';
  6085. $text = get_lang('SaveDocument');
  6086. }
  6087. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  6088. $renderer = $form->defaultRenderer();
  6089. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  6090. $form->addElement('html', '<div style="margin:3px 12px">');
  6091. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  6092. $form->addElement('html', '</div>');
  6093. $defaults['content_lp'] = $content;
  6094. }
  6095. }
  6096. elseif (is_numeric($extra_info)) {
  6097. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6098. $return = $this->display_document($extra_info, true, true, true);
  6099. $form->addElement('html', $return);
  6100. }
  6101. }
  6102. }
  6103. if ($action == 'move') {
  6104. $form->addElement('hidden', 'title', $item_title);
  6105. $form->addElement('hidden', 'description', $item_description);
  6106. }
  6107. if (is_numeric($extra_info)) {
  6108. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  6109. $form->addElement('hidden', 'path', $extra_info);
  6110. }
  6111. elseif (is_array($extra_info)) {
  6112. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6113. $form->addElement('hidden', 'path', $extra_info['path']);
  6114. }
  6115. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  6116. $form->addElement('hidden', 'post_time', time());
  6117. $form->setDefaults($defaults);
  6118. return $form->return_form();
  6119. }
  6120. /**
  6121. * Return HTML form to add/edit a link item
  6122. * @param string Action (add/edit)
  6123. * @param integer Item ID if exists
  6124. * @param mixed Extra info
  6125. * @return string HTML form
  6126. */
  6127. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  6128. global $charset;
  6129. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6130. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6131. if ($id != 0 && is_array($extra_info)) {
  6132. $item_title = stripslashes($extra_info['title']);
  6133. $item_description = stripslashes($extra_info['description']);
  6134. $item_url = stripslashes($extra_info['url']);
  6135. } elseif (is_numeric($extra_info)) {
  6136. $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE id = " . $extra_info;
  6137. $result = Database::query($sql_link);
  6138. $row = Database :: fetch_array($result);
  6139. $item_title = $row['title'];
  6140. $item_description = $row['description'];
  6141. $item_url = $row['url'];
  6142. } else {
  6143. $item_title = '';
  6144. $item_description = '';
  6145. $item_url = '';
  6146. }
  6147. $return = ' <div class="row">
  6148. <div class="form_header">';
  6149. if ($id != 0 && is_array($extra_info))
  6150. $parent = $extra_info['parent_item_id'];
  6151. else
  6152. $parent = 0;
  6153. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6154. $result = Database::query($sql);
  6155. $arrLP = array ();
  6156. while ($row = Database :: fetch_array($result)) {
  6157. $arrLP[] = array (
  6158. 'id' => $row['id'],
  6159. 'item_type' => $row['item_type'],
  6160. 'title' => $row['title'],
  6161. 'path' => $row['path'],
  6162. 'description' => $row['description'],
  6163. 'parent_item_id' => $row['parent_item_id'],
  6164. 'previous_item_id' => $row['previous_item_id'],
  6165. 'next_item_id' => $row['next_item_id'],
  6166. 'display_order' => $row['display_order'],
  6167. 'max_score' => $row['max_score'],
  6168. 'min_score' => $row['min_score'],
  6169. 'mastery_score' => $row['mastery_score'],
  6170. 'prerequisite' => $row['prerequisite']
  6171. );
  6172. }
  6173. $this->tree_array($arrLP);
  6174. $arrLP = $this->arrMenu;
  6175. unset ($this->arrMenu);
  6176. if ($action == 'add')
  6177. $return .= get_lang('CreateTheLink') . '&nbsp;:';
  6178. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:';
  6179. else
  6180. $return .= get_lang('EditCurrentLink') . '&nbsp;:';
  6181. $return .= ' </div>
  6182. </div>';
  6183. $return .= '<div class="sectioncomment">';
  6184. $return .= '<form method="POST">';
  6185. $return .= '<table>';
  6186. if ($action != 'move') {
  6187. $return .= '<tr>';
  6188. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6189. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
  6190. $return .= '</tr>';
  6191. }
  6192. $return .= '<tr>';
  6193. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6194. $return .= '<td class="input">';
  6195. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6196. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  6197. $arrHide = array (
  6198. $id
  6199. );
  6200. $parent_item_id = $_SESSION['parent_item_id'];
  6201. for ($i = 0; $i < count($arrLP); $i++) {
  6202. if ($action != 'add') {
  6203. 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)) {
  6204. $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>';
  6205. } else {
  6206. $arrHide[] = $arrLP[$i]['id'];
  6207. }
  6208. } else {
  6209. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6210. $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>';
  6211. }
  6212. }
  6213. if (is_array($arrLP)) {
  6214. reset($arrLP);
  6215. }
  6216. $return .= "\t\t\t\t" . '</select>';
  6217. $return .= '</td>';
  6218. $return .= '</tr>';
  6219. $return .= '<tr>';
  6220. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6221. $return .= '<td class="input">';
  6222. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6223. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6224. for ($i = 0; $i < count($arrLP); $i++) {
  6225. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6226. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6227. $selected = 'selected="selected" ';
  6228. elseif ($action == 'add')
  6229. $selected = 'selected="selected" ';
  6230. else
  6231. $selected = '';
  6232. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6233. }
  6234. }
  6235. $return .= '</select>';
  6236. $return .= '</td>';
  6237. $return .= '</tr>';
  6238. if ($action != 'move') {
  6239. $return .= '<tr>';
  6240. $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
  6241. $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>';
  6242. $return .= '</tr>';
  6243. $id_prerequisite = 0;
  6244. if (is_array($arrLP)) {
  6245. foreach ($arrLP as $key => $value) {
  6246. if ($value['id'] == $id) {
  6247. $id_prerequisite = $value['prerequisite'];
  6248. break;
  6249. }
  6250. }
  6251. }
  6252. $arrHide = array ();
  6253. for ($i = 0; $i < count($arrLP); $i++) {
  6254. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6255. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6256. $s_selected_position = $arrLP[$i]['id'];
  6257. elseif ($action == 'add') $s_selected_position = 0;
  6258. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6259. }
  6260. }
  6261. /*// Commented the prerequisites, only visible in edit (link).
  6262. $return .= '<tr>';
  6263. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6264. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6265. foreach($arrHide as $key => $value) {
  6266. if ($key == $s_selected_position && $action == 'add') {
  6267. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6268. }
  6269. elseif ($key == $id_prerequisite && $action == 'edit') {
  6270. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6271. }
  6272. else {
  6273. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6274. }
  6275. }
  6276. $return .= "</select></td>";
  6277. */
  6278. $return .= '</tr>';
  6279. }
  6280. $return .= '<tr>';
  6281. if ($action == 'add') {
  6282. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6283. } else {
  6284. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6285. }
  6286. $return .= '</tr>';
  6287. $return .= '</table>';
  6288. if ($action == 'move') {
  6289. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6290. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6291. }
  6292. if (is_numeric($extra_info)) {
  6293. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6294. }
  6295. elseif (is_array($extra_info)) {
  6296. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6297. }
  6298. $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
  6299. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6300. $return .= '</form>';
  6301. $return .= '</div>';
  6302. return $return;
  6303. }
  6304. /**
  6305. * Return HTML form to add/edit a student publication (work)
  6306. * @param string Action (add/edit)
  6307. * @param integer Item ID if already exists
  6308. * @param mixed Extra info (work ID if integer)
  6309. * @return string HTML form
  6310. */
  6311. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6312. global $charset;
  6313. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6314. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6315. if ($id != 0 && is_array($extra_info)) {
  6316. $item_title = stripslashes($extra_info['title']);
  6317. $item_description = stripslashes($extra_info['description']);
  6318. }
  6319. elseif (is_numeric($extra_info)) {
  6320. $sql_publication = "
  6321. SELECT
  6322. title,
  6323. description
  6324. FROM " . $tbl_publication . "
  6325. WHERE id = " . $extra_info;
  6326. $result = Database::query($sql_publication);
  6327. $row = Database :: fetch_array($result);
  6328. $item_title = $row['title'];
  6329. } else {
  6330. $item_title = get_lang('Student_publication');
  6331. }
  6332. $return = ' <div class="row">
  6333. <div class="form_header">';
  6334. if ($id != 0 && is_array($extra_info))
  6335. $parent = $extra_info['parent_item_id'];
  6336. else
  6337. $parent = 0;
  6338. $sql = "
  6339. SELECT *
  6340. FROM " . $tbl_lp_item . "
  6341. WHERE
  6342. lp_id = " . $this->lp_id;
  6343. $result = Database::query($sql);
  6344. $arrLP = array ();
  6345. while ($row = Database :: fetch_array($result)) {
  6346. $arrLP[] = array (
  6347. 'id' => $row['id'],
  6348. 'item_type' => $row['item_type'],
  6349. 'title' => $row['title'],
  6350. 'path' => $row['path'],
  6351. 'description' => $row['description'],
  6352. 'parent_item_id' => $row['parent_item_id'],
  6353. 'previous_item_id' => $row['previous_item_id'],
  6354. 'next_item_id' => $row['next_item_id'],
  6355. 'display_order' => $row['display_order'],
  6356. 'max_score' => $row['max_score'],
  6357. 'min_score' => $row['min_score'],
  6358. 'mastery_score' => $row['mastery_score'],
  6359. 'prerequisite' => $row['prerequisite']
  6360. );
  6361. }
  6362. $this->tree_array($arrLP);
  6363. $arrLP = $this->arrMenu;
  6364. unset ($this->arrMenu);
  6365. if ($action == 'add')
  6366. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6367. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6368. else
  6369. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6370. $return .= ' </div>
  6371. </div>';
  6372. $return .= '<div class="sectioncomment">';
  6373. $return .= '<form method="POST">';
  6374. $return .= '<table class="lp_form">';
  6375. if ($action != 'move') {
  6376. $return .= '<tr>';
  6377. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6378. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  6379. $return .= '</tr>';
  6380. }
  6381. $return .= '<tr>';
  6382. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6383. $return .= '<td class="input">';
  6384. $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">';
  6385. //$parent_item_id = $_SESSION['parent_item_id'];
  6386. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6387. $arrHide = array (
  6388. $id
  6389. );
  6390. for ($i = 0; $i < count($arrLP); $i++) {
  6391. if ($action != 'add') {
  6392. 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)) {
  6393. $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>';
  6394. } else {
  6395. $arrHide[] = $arrLP[$i]['id'];
  6396. }
  6397. } else {
  6398. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6399. $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>';
  6400. }
  6401. }
  6402. if (is_array($arrLP)) {
  6403. reset($arrLP);
  6404. }
  6405. $return .= "\t\t\t\t" . '</select>';
  6406. $return .= '</td>';
  6407. $return .= '</tr>';
  6408. $return .= '<tr>';
  6409. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6410. $return .= '<td class="input">';
  6411. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6412. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6413. for ($i = 0; $i < count($arrLP); $i++) {
  6414. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6415. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6416. $selected = 'selected="selected" ';
  6417. elseif ($action == 'add') $selected = 'selected="selected" ';
  6418. else
  6419. $selected = '';
  6420. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6421. }
  6422. }
  6423. $return .= "\t\t\t\t" . '</select>';
  6424. $return .= '</td>';
  6425. $return .= '</tr>';
  6426. if ($action != 'move') {
  6427. $id_prerequisite = 0;
  6428. if (is_array($arrLP)) {
  6429. foreach ($arrLP as $key => $value) {
  6430. if ($value['id'] == $id) {
  6431. $id_prerequisite = $value['prerequisite'];
  6432. break;
  6433. }
  6434. }
  6435. }
  6436. $arrHide = array ();
  6437. for ($i = 0; $i < count($arrLP); $i++) {
  6438. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6439. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6440. $s_selected_position = $arrLP[$i]['id'];
  6441. elseif ($action == 'add') $s_selected_position = 0;
  6442. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6443. }
  6444. }
  6445. // Commented the prerequisites, only visible in edit (work).
  6446. /*
  6447. $return .= '<tr>';
  6448. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6449. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6450. foreach($arrHide as $key => $value) {
  6451. if ($key == $s_selected_position && $action == 'add') {
  6452. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6453. }
  6454. elseif ($key == $id_prerequisite && $action == 'edit') {
  6455. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6456. }
  6457. else {
  6458. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6459. }
  6460. }
  6461. $return .= "</select></td>";
  6462. */
  6463. $return .= '</tr>';
  6464. }
  6465. $return .= '<tr>';
  6466. if ($action == 'add') {
  6467. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6468. } else {
  6469. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6470. }
  6471. $return .= '</tr>';
  6472. $return .= '</table>';
  6473. if ($action == 'move') {
  6474. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6475. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6476. }
  6477. if (is_numeric($extra_info)) {
  6478. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6479. } elseif (is_array($extra_info)) {
  6480. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6481. }
  6482. $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
  6483. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6484. $return .= '</form>';
  6485. $return .= '</div>';
  6486. return $return;
  6487. }
  6488. /**
  6489. * Displays the menu for manipulating a step
  6490. * @return string html
  6491. */
  6492. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6493. global $charset, $_course;
  6494. $return = '<div class="actions">';
  6495. switch ($item_type) {
  6496. case 'dokeos_chapter' :
  6497. case 'chapter' :
  6498. // Commented the message cause should not show it.
  6499. //$lang = get_lang('TitleManipulateChapter');
  6500. break;
  6501. case 'dokeos_module' :
  6502. case 'module' :
  6503. // Commented the message cause should not show it.
  6504. //$lang = get_lang('TitleManipulateModule');
  6505. break;
  6506. case TOOL_DOCUMENT :
  6507. // Commented the message cause should not show it.
  6508. //$lang = get_lang('TitleManipulateDocument');
  6509. break;
  6510. case TOOL_LINK :
  6511. case 'link' :
  6512. // Commented the message cause should not show it.
  6513. //$lang = get_lang('TitleManipulateLink');
  6514. break;
  6515. case TOOL_QUIZ :
  6516. // Commented the message cause should not show it.
  6517. //$lang = get_lang('TitleManipulateQuiz');
  6518. break;
  6519. case TOOL_STUDENTPUBLICATION :
  6520. // Commented the message cause should not show it.
  6521. //$lang = get_lang('TitleManipulateStudentPublication');
  6522. break;
  6523. }
  6524. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6525. $item_id = intval($item_id);
  6526. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.id = " . $item_id;
  6527. $result = Database::query($sql);
  6528. $row = Database::fetch_assoc($result);
  6529. $s_title = $row['title'];
  6530. // We display an audio player if needed.
  6531. if (!empty ($row['audio'])) {
  6532. $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>';
  6533. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6534. $return .= '<script type="text/javascript">
  6535. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6536. s1.addParam("allowscriptaccess","always");
  6537. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6538. s1.write("container");
  6539. </script>';
  6540. }
  6541. // Commented ":" for message in step.
  6542. //$return .= $lang.': ';
  6543. $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
  6544. $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), $url.'&action=edit_item&path_item=' . $row['path']);
  6545. $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), 22), $url.'&action=move_item');
  6546. // Commented for now as prerequisites cannot be added to chapters.
  6547. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6548. $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), 22), $url.'&action=edit_item_prereq');
  6549. }
  6550. $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), $url.'&action=delete_item');
  6551. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6552. ob_start();
  6553. $audio_recorder_studentview = 'false';
  6554. $audio_recorder_item_id = $item_id;
  6555. if (api_get_setting('service_visio', 'active') == 'true') {
  6556. include 'audiorecorder.inc.php';
  6557. }
  6558. $return .= ob_get_contents();
  6559. ob_end_clean();
  6560. // End of audiorecorder include
  6561. $return .= '</div>';
  6562. return $return;
  6563. }
  6564. /**
  6565. * Creates the javascript needed for filling up the checkboxes without page reload
  6566. *
  6567. * @return string
  6568. */
  6569. public function get_js_dropdown_array() {
  6570. $return = 'var child_name = new Array();' . "\n";
  6571. $return .= 'var child_value = new Array();' . "\n\n";
  6572. $return .= 'child_name[0] = new Array();' . "\n";
  6573. $return .= 'child_value[0] = new Array();' . "\n\n";
  6574. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6575. $sql_zero = "
  6576. SELECT *
  6577. FROM " . $tbl_lp_item . "
  6578. WHERE
  6579. lp_id = " . $this->lp_id . " AND
  6580. parent_item_id = 0
  6581. ORDER BY display_order ASC";
  6582. $res_zero = Database::query($sql_zero);
  6583. global $charset;
  6584. $i = 0;
  6585. while ($row_zero = Database :: fetch_array($res_zero)) {
  6586. $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
  6587. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6588. }
  6589. $return .= "\n";
  6590. $sql = "
  6591. SELECT *
  6592. FROM " . $tbl_lp_item . "
  6593. WHERE
  6594. lp_id = " . $this->lp_id;
  6595. $res = Database::query($sql);
  6596. while ($row = Database :: fetch_array($res)) {
  6597. $sql_parent = "
  6598. SELECT *
  6599. FROM " . $tbl_lp_item . "
  6600. WHERE parent_item_id = " . $row['id'] . "
  6601. ORDER BY display_order ASC";
  6602. $res_parent = Database::query($sql_parent);
  6603. $i = 0;
  6604. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6605. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6606. while ($row_parent = Database :: fetch_array($res_parent)) {
  6607. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
  6608. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6609. }
  6610. $return .= "\n";
  6611. }
  6612. return $return;
  6613. }
  6614. /**
  6615. * Display the form to allow moving an item
  6616. * @param integer Item ID
  6617. * @return string HTML form
  6618. */
  6619. public function display_move_item($item_id) {
  6620. global $_course; //will disappear
  6621. global $charset;
  6622. $return = '';
  6623. if (is_numeric($item_id)) {
  6624. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6625. $sql = "SELECT *
  6626. FROM " . $tbl_lp_item . "
  6627. WHERE id = " . $item_id;
  6628. $res = Database::query($sql);
  6629. $row = Database :: fetch_array($res);
  6630. switch ($row['item_type']) {
  6631. case 'dokeos_chapter' :
  6632. case 'dir' :
  6633. case 'asset' :
  6634. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6635. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6636. break;
  6637. case 'dokeos_module' :
  6638. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6639. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6640. break;
  6641. case TOOL_DOCUMENT :
  6642. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6643. $return .= $this->display_document_form('move', $item_id, $row);
  6644. break;
  6645. case TOOL_LINK :
  6646. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6647. $return .= $this->display_link_form('move', $item_id, $row);
  6648. break;
  6649. case TOOL_HOTPOTATOES :
  6650. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6651. $return .= $this->display_link_form('move', $item_id, $row);
  6652. break;
  6653. case TOOL_QUIZ :
  6654. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6655. $return .= $this->display_quiz_form('move', $item_id, $row);
  6656. break;
  6657. case TOOL_STUDENTPUBLICATION :
  6658. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6659. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6660. break;
  6661. case TOOL_FORUM :
  6662. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6663. $return .= $this->display_forum_form('move', $item_id, $row);
  6664. break;
  6665. case TOOL_THREAD :
  6666. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6667. $return .= $this->display_forum_form('move', $item_id, $row);
  6668. break;
  6669. }
  6670. }
  6671. return $return;
  6672. }
  6673. /**
  6674. * Displays a basic form on the overview page for changing the item title and the item description.
  6675. * @param string $item_type
  6676. * @param string $title
  6677. * @param array $data
  6678. * @return string
  6679. */
  6680. public function display_item_small_form($item_type, $title = '', $data) {
  6681. global $charset;
  6682. $return .= '<div class="lp_small_form">';
  6683. $return .= '<p class="lp_title">' . $title . '</p>';
  6684. $return .= '<form method="post">';
  6685. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6686. $return .= '<tr>';
  6687. $return .= '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>';
  6688. $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
  6689. $return .= '</tr>';
  6690. // It said these lines of code - see SVN#11724 and SVN#10770
  6691. //$return .= '<tr>';
  6692. //$return .= '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>';
  6693. //$return .= '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>';
  6694. //$return .= '</tr>';
  6695. $return .= '<tr>';
  6696. $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
  6697. $return .= '</tr>';
  6698. $return .= '</table>';
  6699. $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
  6700. $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
  6701. $return .= '</form>';
  6702. $return .= '</div>';
  6703. return $return;
  6704. }
  6705. /**
  6706. * Return HTML form to allow prerequisites selection
  6707. * @param integer Item ID
  6708. * @return string HTML form
  6709. */
  6710. public function display_item_prerequisites_form($item_id) {
  6711. global $charset;
  6712. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6713. $item_id = intval($item_id);
  6714. /* Current prerequisite */
  6715. $sql = "SELECT * FROM $tbl_lp_item WHERE id = " . $item_id;
  6716. $result = Database::query($sql);
  6717. $row = Database::fetch_array($result);
  6718. $preq_id = $row['prerequisite'];
  6719. //$preq_mastery = $row['mastery_score'];
  6720. //$preq_max = $row['max_score'];
  6721. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6722. $return = ' <div class="row">
  6723. <div class="form_header">';
  6724. $return .= get_lang('AddEditPrerequisites');
  6725. $return .= '</div></div>';
  6726. $return .= '<div class="sectioncomment">';
  6727. $return .= '<form method="POST">';
  6728. $return .= '<table class="data_table" style="width:650px">';
  6729. $return .= '<tr>';
  6730. $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
  6731. $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
  6732. $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
  6733. $return .= '</tr>';
  6734. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6735. $return .= '<tr >';
  6736. $return .= '<td colspan="3" class="radio">';
  6737. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
  6738. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6739. $return .= '</tr>';
  6740. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6741. $result = Database::query($sql);
  6742. $arrLP = array ();
  6743. while ($row = Database :: fetch_array($result)) {
  6744. $arrLP[] = array (
  6745. 'id' => $row['id'],
  6746. 'item_type' => $row['item_type'],
  6747. 'title' => $row['title'],
  6748. 'ref' => $row['ref'],
  6749. 'description' => $row['description'],
  6750. 'parent_item_id' => $row['parent_item_id'],
  6751. 'previous_item_id' => $row['previous_item_id'],
  6752. 'next_item_id' => $row['next_item_id'],
  6753. 'max_score' => $row['max_score'],
  6754. 'min_score' => $row['min_score'],
  6755. 'mastery_score' => $row['mastery_score'],
  6756. 'prerequisite' => $row['prerequisite'],
  6757. 'next_item_id' => $row['next_item_id'],
  6758. 'display_order' => $row['display_order']
  6759. );
  6760. if ($row['ref'] == $preq_id) {
  6761. $preq_mastery = $row['mastery_score'];
  6762. $preq_max = $row['max_score'];
  6763. }
  6764. }
  6765. $this->tree_array($arrLP);
  6766. $arrLP = $this->arrMenu;
  6767. unset ($this->arrMenu);
  6768. for ($i = 0; $i < count($arrLP); $i++) {
  6769. if ($arrLP[$i]['id'] == $item_id)
  6770. break;
  6771. $return .= '<tr>';
  6772. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6773. $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'] . '" />';
  6774. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6775. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6776. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6777. } else
  6778. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6779. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6780. } else {
  6781. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6782. }
  6783. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6784. $return .= '</td>';
  6785. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6786. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6787. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6788. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6789. $return .= '</td>';
  6790. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6791. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6792. $return .= '</td>';
  6793. }
  6794. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6795. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6796. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6797. $return .= '</td>';
  6798. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6799. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6800. $return .= '</td>';
  6801. }
  6802. $return .= '</tr>';
  6803. }
  6804. $return .= '<tr>';
  6805. $return .= '</tr>';
  6806. $return .= '</table>';
  6807. $return .= '<div style="padding-top:3px;">';
  6808. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
  6809. $return .= '</div>';
  6810. $return .= '</form>';
  6811. $return .= '</div>';
  6812. return $return;
  6813. }
  6814. /**
  6815. * Return HTML list to allow prerequisites selection for lp
  6816. * @param integer Item ID
  6817. * @return string HTML form
  6818. */
  6819. public function display_lp_prerequisites_list() {
  6820. global $charset;
  6821. $lp_id = $this->lp_id;
  6822. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6823. // get current prerequisite
  6824. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6825. $result = Database::query($sql);
  6826. $row = Database :: fetch_array($result);
  6827. $preq_id = $row['prerequisite'];
  6828. $session_id = api_get_session_id();
  6829. $session_condition = api_get_session_condition($session_id, false);
  6830. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6831. $rs = Database::query($sql);
  6832. $return = '';
  6833. $return .= '<select name="prerequisites" >';
  6834. $return .= '<option value="0">'.get_lang('None').'</option>';
  6835. if (Database::num_rows($rs) > 0) {
  6836. while ($row = Database::fetch_array($rs)) {
  6837. if ($row['id'] == $lp_id) {
  6838. continue;
  6839. }
  6840. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6841. }
  6842. }
  6843. $return .= '</select>';
  6844. return $return;
  6845. }
  6846. /**
  6847. * Creates a list with all the documents in it
  6848. * @return string
  6849. */
  6850. public function get_documents() {
  6851. global $_course;
  6852. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6853. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6854. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6855. $path = '/';
  6856. $path = Database::escape_string(str_replace('_', '\_', $path));
  6857. $added_slash = ($path == '/') ? '' : '/';
  6858. //condition for the session
  6859. $current_session_id = api_get_session_id();
  6860. $condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '{$_course[id]}')))";
  6861. $sql_doc = "SELECT docs.*
  6862. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6863. WHERE docs.id = last.ref
  6864. AND docs.path LIKE '".$path.$added_slash."%'
  6865. AND docs.path NOT LIKE '%_DELETED_%'
  6866. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6867. $res_doc = Database::query($sql_doc);
  6868. //$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>';
  6869. $return = '<div class="lp_resource">';
  6870. $resources = Database::store_result($res_doc);
  6871. $resources_sorted = array();
  6872. $return .= '<div class="lp_resource_element">';
  6873. $return .= Display::return_icon('new_doc.gif', '', array(), 22);
  6874. $return .= Display::url(get_lang('NewDocument') , api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
  6875. $return .= '</div>';
  6876. // If you want to debug it, I advise you to do "echo" on the eval statements.
  6877. foreach ($resources as $resource) {
  6878. $resource_paths = explode('/', $resource['path']);
  6879. array_shift($resource_paths);
  6880. $path_to_eval = $last_path = '';
  6881. $is_file = false;
  6882. foreach ($resource_paths as $key => $resource_path) {
  6883. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // It's a folder.
  6884. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6885. } else
  6886. if (strpos($resource_path, '.') !== false)
  6887. $is_file = true;
  6888. $last_path = $resource_path;
  6889. }
  6890. if ($is_file) {
  6891. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6892. //for backward compatibility
  6893. if (empty($resource['title'])) {
  6894. $resource['title'] = basename($resource['path']);
  6895. }
  6896. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6897. } else {
  6898. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6899. }
  6900. }
  6901. $label = get_lang('Documents');
  6902. $new_array[$label] = array('id' => 0, 'files'=>$resources_sorted);
  6903. $return .= $this->write_resources_tree($new_array);
  6904. /*if (Database :: num_rows($res_doc) == 0) {
  6905. $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
  6906. }*/
  6907. $return .= '</div>';
  6908. return $return;
  6909. }
  6910. /**
  6911. * Generate and return an HTML list of resources based on a given array.
  6912. * This list is used to show the course creator a list of available resources to choose from
  6913. * when creating a learning path.
  6914. * @param array Array of elements to add to the list
  6915. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6916. * @return string The HTML list
  6917. */
  6918. public function write_resources_tree($resources_sorted, $num = 0) {
  6919. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6920. if (count($resources_sorted) > 0) {
  6921. foreach ($resources_sorted as $key => $resource) {
  6922. if (is_int($resource['id'])) {
  6923. // It's a folder.
  6924. //hide some folders
  6925. if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
  6926. continue;
  6927. } elseif(preg_match('/_groupdocs/', $key)){
  6928. continue;
  6929. } elseif(preg_match('/sf_user_/', $key)){
  6930. continue;
  6931. } elseif(preg_match('/shared_folder_session_/', $key)){
  6932. continue;
  6933. }
  6934. //trad some titles
  6935. if ($key=='images') {
  6936. $key=get_lang('Images');
  6937. } elseif($key=='gallery') {
  6938. $key=get_lang('Gallery');
  6939. } elseif($key=='flash') {
  6940. $key=get_lang('Flash');
  6941. } elseif($key=='audio'){
  6942. $key=get_lang('Audio');
  6943. } elseif($key=='video') {
  6944. $key=get_lang('Video');
  6945. }
  6946. $return .= '<div class="doc_resource"><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'] . '">';
  6947. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6948. $return .= '</div></div>';
  6949. } else {
  6950. if (!is_array($resource)) {
  6951. // It's a file.
  6952. $icon = choose_image($resource);
  6953. $position = strrpos($icon, '.');
  6954. $icon = substr($icon, 0, $position) . '_small.gif';
  6955. $file_info = explode('/', $resource);
  6956. $my_file_title = $file_info[0];
  6957. $my_file_name = $file_info[1];
  6958. //$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>';
  6959. // Show the "image name" not the filename of the image.
  6960. $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"; }
  6961. }
  6962. }
  6963. }
  6964. return $return;
  6965. }
  6966. /**
  6967. * Creates a list with all the exercises (quiz) in it
  6968. * @return string
  6969. */
  6970. public function get_exercises() {
  6971. // New for hotpotatoes.
  6972. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6973. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6974. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6975. $session_id = api_get_session_id();
  6976. $condition_session = api_get_session_condition($session_id);
  6977. $sql_quiz = "SELECT * FROM $tbl_quiz WHERE active<>'-1' $condition_session ORDER BY title ASC";
  6978. $sql_hot = "SELECT * FROM $tbl_doc WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
  6979. $res_quiz = Database::query($sql_quiz);
  6980. $res_hot = Database::query($sql_hot);
  6981. //$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>';
  6982. $return .= '<div class="lp_resource">';
  6983. $return .= '<div class="lp_resource_element">';
  6984. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6985. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
  6986. $return .= '</div>';
  6987. while ($row_hot = Database :: fetch_array($res_hot)) {
  6988. $return .= '<div class="lp_resource_element">';
  6989. // Display quizhotpotatoes.
  6990. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6991. $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>';
  6992. //$return .= $row_quiz['title'];
  6993. $return .= '</div>';
  6994. }
  6995. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6996. $return .= '<div class="lp_resource_element">';
  6997. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6998. $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>';
  6999. //$return .= $row_quiz['title'];
  7000. $return .= '</div>';
  7001. }
  7002. /*if (Database :: num_rows($res_quiz) == 0) {
  7003. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  7004. }*/
  7005. $return .= '</div>';
  7006. return $return;
  7007. }
  7008. /**
  7009. * Creates a list with all the links in it
  7010. * @return string
  7011. */
  7012. public function get_links() {
  7013. $tbl_link = Database :: get_course_table(TABLE_LINK);
  7014. $session_id = api_get_session_id();
  7015. $condition_session = api_get_session_condition($session_id,false);
  7016. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  7017. $res_link = Database::query($sql_link);
  7018. //$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>';
  7019. $return .= '<div class="lp_resource">';
  7020. $return .= '<div class="lp_resource_element">';
  7021. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  7022. $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>';
  7023. $return .= '</div>';
  7024. while ($row_link = Database :: fetch_array($res_link)) {
  7025. $return .= '<div class="lp_resource_element">';
  7026. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  7027. $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>';
  7028. $return .= '</div>';
  7029. }
  7030. /*if (Database :: num_rows($res_link) == 0)
  7031. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  7032. */
  7033. $return .= '</div>';
  7034. return $return;
  7035. }
  7036. /**
  7037. * Creates a list with all the student publications in it
  7038. * @return unknown
  7039. */
  7040. public function get_student_publications() {
  7041. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  7042. $session_id = api_get_session_id();
  7043. $condition_session = api_get_session_condition($session_id, false);
  7044. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  7045. $res_student = Database::query($sql_student);
  7046. //$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>';
  7047. $return .= '<div class="lp_resource" >';
  7048. $return .= '<div class="lp_resource_element">';
  7049. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  7050. $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>';
  7051. $return .= '</div>';
  7052. $return .= '</div>';
  7053. return $return;
  7054. }
  7055. /**
  7056. * Creates a list with all the forums in it
  7057. * @return string
  7058. */
  7059. public function get_forums() {
  7060. require_once '../forum/forumfunction.inc.php';
  7061. require_once '../forum/forumconfig.inc.php';
  7062. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  7063. $table_forums = Database :: get_course_table(TABLE_FORUM);
  7064. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  7065. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  7066. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  7067. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  7068. $a_forums = get_forums();
  7069. //$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>';
  7070. $return .= '<div class="lp_resource">';
  7071. $return .= '<div class="lp_resource_element">';
  7072. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  7073. $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>';
  7074. $return .= '</div>';
  7075. foreach ($a_forums as $forum) {
  7076. $return .= '<div class="lp_resource_element_no_link">';
  7077. $return .= '<script type="text/javascript">
  7078. function toggle_forum(forum_id){
  7079. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  7080. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  7081. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  7082. }
  7083. else {
  7084. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  7085. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  7086. }
  7087. }
  7088. </script>';
  7089. if (!empty($forum['forum_id'])) {
  7090. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  7091. $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>
  7092. <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">';
  7093. }
  7094. $a_threads = get_threads($forum['forum_id']);
  7095. if (is_array($a_threads)) {
  7096. foreach ($a_threads as $thread) {
  7097. $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>';
  7098. }
  7099. }
  7100. $return .= '</ul></div>';
  7101. }
  7102. return $return;
  7103. }
  7104. /**
  7105. * // TODO: The output encoding should be equal to the system encoding.
  7106. *
  7107. * Exports the learning path as a SCORM package. This is the main function that
  7108. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  7109. * whole thing and returns the zip.
  7110. *
  7111. * This method needs to be called in PHP5, as it will fail with non-adequate
  7112. * XML package (like the ones for PHP4), and it is *not* a static method, so
  7113. * you need to call it on a learnpath object.
  7114. * @TODO The method might be redefined later on in the scorm class itself to avoid
  7115. * creating a SCORM structure if there is one already. However, if the initial SCORM
  7116. * path has been modified, it should use the generic method here below.
  7117. * @TODO link this function with the export_lp() function in the same class
  7118. * @param string Optional name of zip file. If none, title of learnpath is
  7119. * domesticated and trailed with ".zip"
  7120. * @return string Returns the zip package string, or null if error
  7121. */
  7122. public function scorm_export() {
  7123. global $_course;
  7124. // Remove memory and time limits as much as possible as this might be a long process...
  7125. if (function_exists('ini_set')) {
  7126. $mem = ini_get('memory_limit');
  7127. if (substr($mem, -1, 1) == 'M') {
  7128. $mem_num = substr($mem, 0, -1);
  7129. if ($mem_num < 128) {
  7130. ini_set('memory_limit', '128M');
  7131. }
  7132. } else {
  7133. ini_set('memory_limit', '128M');
  7134. }
  7135. ini_set('max_execution_time', 600);
  7136. //} else {
  7137. //error_log('Scorm export: could not change memory and time limits', 0);
  7138. }
  7139. // Create the zip handler (this will remain available throughout the method).
  7140. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  7141. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7142. $temp_dir_short = uniqid();
  7143. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  7144. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  7145. $zip_folder = new PclZip($temp_zip_file);
  7146. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  7147. $root_path = $main_path = api_get_path(SYS_PATH);
  7148. $files_cleanup = array();
  7149. // Place to temporarily stash the zipfiles.
  7150. // create the temp dir if it doesn't exist
  7151. // or do a cleanup befor creating the zipfile.
  7152. if (!is_dir($temp_zip_dir)) {
  7153. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  7154. } else {
  7155. // Cleanup: Check the temp dir for old files and delete them.
  7156. $handle = opendir($temp_zip_dir);
  7157. while (false !== ($file = readdir($handle))) {
  7158. if ($file != '.' && $file != '..') {
  7159. unlink("$temp_zip_dir/$file");
  7160. }
  7161. }
  7162. closedir($handle);
  7163. }
  7164. $zip_files = $zip_files_abs = $zip_files_dist = array();
  7165. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  7166. // Remove the possible . at the end of the path.
  7167. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  7168. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  7169. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  7170. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  7171. }
  7172. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  7173. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  7174. // Aggregation Model official document, secion "2.3 Content Packaging".
  7175. $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.
  7176. $root = $xmldoc->createElement('manifest');
  7177. $root->setAttribute('identifier', 'SingleCourseManifest');
  7178. $root->setAttribute('version', '1.1');
  7179. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  7180. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  7181. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  7182. $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');
  7183. // Build mandatory sub-root container elements.
  7184. $metadata = $xmldoc->createElement('metadata');
  7185. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  7186. $metadata->appendChild($md_schema);
  7187. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7188. $metadata->appendChild($md_schemaversion);
  7189. $root->appendChild($metadata);
  7190. $organizations = $xmldoc->createElement('organizations');
  7191. $resources = $xmldoc->createElement('resources');
  7192. // Build the only organization we will use in building our learnpaths.
  7193. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7194. $organization = $xmldoc->createElement('organization');
  7195. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7196. // To set the title of the SCORM entity (=organization), we take the name given
  7197. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7198. // learning path charset) as it is the encoding that defines how it is stored
  7199. // in the database. Then we convert it to HTML entities again as the "&" character
  7200. // alone is not authorized in XML (must be &amp;).
  7201. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7202. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7203. $organization->appendChild($org_title);
  7204. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7205. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7206. $link_updates = array();
  7207. foreach ($this->items as $index => $item) {
  7208. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7209. // Get included documents from this item.
  7210. if ($item->type == 'sco')
  7211. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7212. else
  7213. $inc_docs = $item->get_resources_from_source();
  7214. // Give a child element <item> to the <organization> element.
  7215. $my_item_id = $item->get_id();
  7216. $my_item = $xmldoc->createElement('item');
  7217. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7218. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7219. $my_item->setAttribute('isvisible', 'true');
  7220. // Give a child element <title> to the <item> element.
  7221. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7222. $my_item->appendChild($my_title);
  7223. // Give a child element <adlcp:prerequisites> to the <item> element.
  7224. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7225. $my_prereqs->setAttribute('type', 'aicc_script');
  7226. $my_item->appendChild($my_prereqs);
  7227. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7228. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7229. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7230. //$xmldoc->createElement('adlcp:timelimitaction','');
  7231. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7232. //$xmldoc->createElement('adlcp:datafromlms','');
  7233. // Give a child element <adlcp:masteryscore> to the <item> element.
  7234. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7235. $my_item->appendChild($my_masteryscore);
  7236. // Attach this item to the organization element or hits parent if there is one.
  7237. if (!empty($item->parent) && $item->parent != 0) {
  7238. $children = $organization->childNodes;
  7239. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7240. if (is_object($possible_parent)) {
  7241. $possible_parent->appendChild($my_item);
  7242. } else {
  7243. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7244. }
  7245. } else {
  7246. if ($this->debug > 0) { error_log('No parent'); }
  7247. $organization->appendChild($my_item);
  7248. }
  7249. // Get the path of the file(s) from the course directory root.
  7250. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7251. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7252. $my_xml_file_path = $my_file_path;
  7253. $my_sub_dir = dirname($my_file_path);
  7254. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7255. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7256. $my_xml_sub_dir = $my_sub_dir;
  7257. // Give a <resource> child to the <resources> element
  7258. $my_resource = $xmldoc->createElement('resource');
  7259. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7260. $my_resource->setAttribute('type', 'webcontent');
  7261. $my_resource->setAttribute('href', $my_xml_file_path);
  7262. // adlcp:scormtype can be either 'sco' or 'asset'.
  7263. if ($item->type == 'sco') {
  7264. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7265. } else {
  7266. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7267. }
  7268. // xml:base is the base directory to find the files declared in this resource.
  7269. $my_resource->setAttribute('xml:base', '');
  7270. // Give a <file> child to the <resource> element.
  7271. $my_file = $xmldoc->createElement('file');
  7272. $my_file->setAttribute('href', $my_xml_file_path);
  7273. $my_resource->appendChild($my_file);
  7274. // Dependency to other files - not yet supported.
  7275. $i = 1;
  7276. foreach ($inc_docs as $doc_info) {
  7277. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7278. $my_dep = $xmldoc->createElement('resource');
  7279. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7280. $my_dep->setAttribute('identifier', $res_id);
  7281. $my_dep->setAttribute('type', 'webcontent');
  7282. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7283. $my_dep_file = $xmldoc->createElement('file');
  7284. // Check type of URL.
  7285. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7286. if ($doc_info[1] == 'remote') {
  7287. // Remote file. Save url as is.
  7288. $my_dep_file->setAttribute('href', $doc_info[0]);
  7289. $my_dep->setAttribute('xml:base', '');
  7290. } elseif ($doc_info[1] == 'local') {
  7291. switch ($doc_info[2]) {
  7292. case 'url': // Local URL - save path as url for now, don't zip file.
  7293. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7294. $current_dir = dirname($abs_path);
  7295. $current_dir = str_replace('\\', '/', $current_dir);
  7296. $file_path = realpath($abs_path);
  7297. $file_path = str_replace('\\', '/', $file_path);
  7298. $my_dep_file->setAttribute('href', $file_path);
  7299. $my_dep->setAttribute('xml:base', '');
  7300. if (strstr($file_path, $main_path) !== false) {
  7301. // The calculated real path is really inside Chamilo's root path.
  7302. // Reduce file path to what's under the DocumentRoot.
  7303. $file_path = substr($file_path, strlen($root_path) - 1);
  7304. //echo $file_path;echo '<br /><br />';
  7305. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7306. $zip_files_abs[] = $file_path;
  7307. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7308. $my_dep_file->setAttribute('href', $file_path);
  7309. $my_dep->setAttribute('xml:base', '');
  7310. }
  7311. elseif (empty($file_path)) {
  7312. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7313. if (strpos($document_root, -1) == '/') {
  7314. $document_root = substr(0, -1, $document_root);
  7315. }*/
  7316. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7317. $file_path = str_replace('//', '/', $file_path);
  7318. if (file_exists($file_path)) {
  7319. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7320. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7321. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7322. $my_dep_file->setAttribute('href', $file_path);
  7323. $my_dep->setAttribute('xml:base', '');
  7324. }
  7325. }
  7326. break;
  7327. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7328. $my_dep_file->setAttribute('href', $doc_info[0]);
  7329. $my_dep->setAttribute('xml:base', '');
  7330. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7331. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7332. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7333. $abs_img_path_without_subdir = $doc_info[0];
  7334. $relp = api_get_path(REL_PATH); // The url-append config param.
  7335. $pos = strpos($abs_img_path_without_subdir, $relp);
  7336. if ($pos === 0) {
  7337. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7338. }
  7339. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7340. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7341. $file_path = str_replace('\\', '/', $file_path);
  7342. $file_path = str_replace('//', '/', $file_path);
  7343. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7344. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7345. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7346. // Check if the current document is in that path.
  7347. if (strstr($file_path, $cur_path) !== false) {
  7348. // The document is in that path, now get the relative path
  7349. // to the containing document.
  7350. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7351. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7352. $relative_path = '';
  7353. if (strstr($file_path, $cur_path) !== false) {
  7354. $relative_path = substr($file_path, strlen($orig_file_path));
  7355. $file_path = substr($file_path, strlen($cur_path));
  7356. } else {
  7357. // This case is still a problem as it's difficult to calculate a relative path easily
  7358. // might still generate wrong links.
  7359. //$file_path = substr($file_path,strlen($cur_path));
  7360. // Calculate the directory path to the current file (without trailing slash).
  7361. $my_relative_path = dirname($file_path);
  7362. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7363. $my_relative_file = basename($file_path);
  7364. // Calculate the directory path to the containing file (without trailing slash).
  7365. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7366. $dotdot = '';
  7367. $subdir = '';
  7368. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7369. $my_relative_path2 = dirname($my_relative_path);
  7370. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7371. $my_orig_file_path = dirname($my_orig_file_path);
  7372. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7373. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7374. $dotdot += '../';
  7375. $my_relative_path = $my_relative_path2;
  7376. }
  7377. $relative_path = $dotdot.$subdir.$my_relative_file;
  7378. }
  7379. // Put the current document in the zip (this array is the array
  7380. // that will manage documents already in the course folder - relative).
  7381. $zip_files[] = $file_path;
  7382. // Update the links to the current document in the containing document (make them relative).
  7383. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7384. $my_dep_file->setAttribute('href', $file_path);
  7385. $my_dep->setAttribute('xml:base', '');
  7386. }
  7387. elseif (strstr($file_path,$main_path) !== false) {
  7388. // The calculated real path is really inside Chamilo's root path.
  7389. // Reduce file path to what's under the DocumentRoot.
  7390. $file_path = substr($file_path, strlen($root_path));
  7391. //echo $file_path;echo '<br /><br />';
  7392. //error_log('Reduced path: '.$file_path, 0);
  7393. $zip_files_abs[] = $file_path;
  7394. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7395. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7396. $my_dep->setAttribute('xml:base', '');
  7397. }
  7398. elseif (empty($file_path)) {
  7399. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7400. if(strpos($document_root,-1) == '/') {
  7401. $document_root = substr(0, -1, $document_root);
  7402. }*/
  7403. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7404. $file_path = str_replace('//', '/', $file_path);
  7405. if (file_exists($file_path)) {
  7406. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7407. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7408. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7409. $my_dep_file->setAttribute('href','document/'.$file_path);
  7410. $my_dep->setAttribute('xml:base', '');
  7411. }
  7412. }
  7413. break;
  7414. 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
  7415. if (substr($doc_info[0], 0, 2) == '..') {
  7416. // Relative path going up.
  7417. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7418. $current_dir = str_replace('\\', '/', $current_dir);
  7419. $file_path = realpath($current_dir.$doc_info[0]);
  7420. $file_path = str_replace('\\', '/', $file_path);
  7421. //error_log($file_path.' <-> '.$main_path,0);
  7422. if (strstr($file_path, $main_path) !== false) {
  7423. // The calculated real path is really inside Chamilo's root path.
  7424. // Reduce file path to what's under the DocumentRoot.
  7425. $file_path = substr($file_path, strlen($root_path));
  7426. //error_log('Reduced path: '.$file_path, 0);
  7427. $zip_files_abs[] = $file_path;
  7428. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7429. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7430. $my_dep->setAttribute('xml:base', '');
  7431. }
  7432. } else {
  7433. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7434. $my_dep_file->setAttribute('href', $doc_info[0]);
  7435. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7436. }
  7437. break;
  7438. default:
  7439. $my_dep_file->setAttribute('href', $doc_info[0]);
  7440. $my_dep->setAttribute('xml:base', '');
  7441. break;
  7442. }
  7443. }
  7444. $my_dep->appendChild($my_dep_file);
  7445. $resources->appendChild($my_dep);
  7446. $dependency = $xmldoc->createElement('dependency');
  7447. $dependency->setAttribute('identifierref', $res_id);
  7448. $my_resource->appendChild($dependency);
  7449. $i++;
  7450. }
  7451. //$my_dependency = $xmldoc->createElement('dependency');
  7452. //$my_dependency->setAttribute('identifierref', '');
  7453. $resources->appendChild($my_resource);
  7454. $zip_files[] = $my_file_path;
  7455. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7456. } else {
  7457. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7458. if ($item->type == TOOL_LINK) {
  7459. $my_item = $xmldoc->createElement('item');
  7460. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7461. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7462. $my_item->setAttribute('isvisible', 'true');
  7463. // Give a child element <title> to the <item> element.
  7464. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7465. $my_item->appendChild($my_title);
  7466. // Give a child element <adlcp:prerequisites> to the <item> element.
  7467. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7468. $my_prereqs->setAttribute('type', 'aicc_script');
  7469. $my_item->appendChild($my_prereqs);
  7470. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7471. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7472. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7473. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7474. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7475. //$xmldoc->createElement('adlcp:datafromlms', '');
  7476. // Give a child element <adlcp:masteryscore> to the <item> element.
  7477. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7478. $my_item->appendChild($my_masteryscore);
  7479. // Attach this item to the organization element or its parent if there is one.
  7480. if (!empty($item->parent) && $item->parent != 0) {
  7481. $children = $organization->childNodes;
  7482. for ($i = 0; $i < $children->length; $i++) {
  7483. $item_temp = $children->item($i);
  7484. if ($item_temp -> nodeName == 'item') {
  7485. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7486. $item_temp -> appendChild($my_item);
  7487. }
  7488. }
  7489. }
  7490. } else {
  7491. $organization->appendChild($my_item);
  7492. }
  7493. $my_file_path = 'link_'.$item->get_id().'.html';
  7494. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7495. $rs = Database::query($sql);
  7496. if ($link = Database :: fetch_array($rs)) {
  7497. $url = $link['url'];
  7498. $title = stripslashes($link['title']);
  7499. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7500. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7501. $my_xml_file_path = $my_file_path;
  7502. $my_sub_dir = dirname($my_file_path);
  7503. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7504. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7505. $my_xml_sub_dir = $my_sub_dir;
  7506. // Give a <resource> child to the <resources> element.
  7507. $my_resource = $xmldoc->createElement('resource');
  7508. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7509. $my_resource->setAttribute('type', 'webcontent');
  7510. $my_resource->setAttribute('href', $my_xml_file_path);
  7511. // adlcp:scormtype can be either 'sco' or 'asset'.
  7512. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7513. // xml:base is the base directory to find the files declared in this resource.
  7514. $my_resource->setAttribute('xml:base', '');
  7515. // give a <file> child to the <resource> element.
  7516. $my_file = $xmldoc->createElement('file');
  7517. $my_file->setAttribute('href', $my_xml_file_path);
  7518. $my_resource->appendChild($my_file);
  7519. $resources->appendChild($my_resource);
  7520. }
  7521. }
  7522. elseif ($item->type == TOOL_QUIZ) {
  7523. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7524. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7525. $exe = new Exercise();
  7526. $exe->read($exe_id);
  7527. $my_item = $xmldoc->createElement('item');
  7528. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7529. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7530. $my_item->setAttribute('isvisible', 'true');
  7531. // Give a child element <title> to the <item> element.
  7532. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7533. $my_item->appendChild($my_title);
  7534. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7535. //$my_item->appendChild($my_max_score);
  7536. // Give a child element <adlcp:prerequisites> to the <item> element.
  7537. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7538. $my_prereqs->setAttribute('type','aicc_script');
  7539. $my_item->appendChild($my_prereqs);
  7540. // Give a child element <adlcp:masteryscore> to the <item> element.
  7541. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7542. $my_item->appendChild($my_masteryscore);
  7543. // Attach this item to the organization element or hits parent if there is one.
  7544. if (!empty($item->parent) && $item->parent != 0) {
  7545. $children = $organization->childNodes;
  7546. for ($i = 0; $i < $children->length; $i++) {
  7547. $item_temp = $children->item($i);
  7548. if ($item_temp -> nodeName == 'item') {
  7549. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7550. $item_temp -> appendChild($my_item);
  7551. }
  7552. }
  7553. }
  7554. } else {
  7555. $organization->appendChild($my_item);
  7556. }
  7557. // Include export scripts.
  7558. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7559. // Get the path of the file(s) from the course directory root
  7560. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7561. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7562. // Write the contents of the exported exercise into a (big) html file
  7563. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7564. $contents = export_exercise($exe_id,true);
  7565. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7566. $res = file_put_contents($tmp_file_path, $contents);
  7567. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7568. $files_cleanup[] = $tmp_file_path;
  7569. //error_log($tmp_path); die();
  7570. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7571. $my_xml_file_path = $my_file_path;
  7572. $my_sub_dir = dirname($my_file_path);
  7573. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7574. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7575. $my_xml_sub_dir = $my_sub_dir;
  7576. // Give a <resource> child to the <resources> element.
  7577. $my_resource = $xmldoc->createElement('resource');
  7578. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7579. $my_resource->setAttribute('type', 'webcontent');
  7580. $my_resource->setAttribute('href', $my_xml_file_path);
  7581. // adlcp:scormtype can be either 'sco' or 'asset'.
  7582. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7583. // xml:base is the base directory to find the files declared in this resource.
  7584. $my_resource->setAttribute('xml:base', '');
  7585. // Give a <file> child to the <resource> element.
  7586. $my_file = $xmldoc->createElement('file');
  7587. $my_file->setAttribute('href', $my_xml_file_path);
  7588. $my_resource->appendChild($my_file);
  7589. // Get included docs.
  7590. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7591. // Dependency to other files - not yet supported.
  7592. $i = 1;
  7593. foreach ($inc_docs as $doc_info) {
  7594. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7595. $my_dep = $xmldoc->createElement('resource');
  7596. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7597. $my_dep->setAttribute('identifier', $res_id);
  7598. $my_dep->setAttribute('type', 'webcontent');
  7599. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7600. $my_dep_file = $xmldoc->createElement('file');
  7601. // Check type of URL.
  7602. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7603. if ($doc_info[1] == 'remote') {
  7604. // Remote file. Save url as is.
  7605. $my_dep_file->setAttribute('href', $doc_info[0]);
  7606. $my_dep->setAttribute('xml:base', '');
  7607. } elseif ($doc_info[1] == 'local') {
  7608. switch ($doc_info[2]) {
  7609. case 'url': // Local URL - save path as url for now, don't zip file.
  7610. // Save file but as local file (retrieve from URL).
  7611. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7612. $current_dir = dirname($abs_path);
  7613. $current_dir = str_replace('\\', '/', $current_dir);
  7614. $file_path = realpath($abs_path);
  7615. $file_path = str_replace('\\', '/', $file_path);
  7616. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7617. $my_dep->setAttribute('xml:base', '');
  7618. if (strstr($file_path, $main_path) !== false) {
  7619. // The calculated real path is really inside the chamilo root path.
  7620. // Reduce file path to what's under the DocumentRoot.
  7621. $file_path = substr($file_path, strlen($root_path));
  7622. //echo $file_path;echo '<br /><br />';
  7623. //error_log('Reduced path: '.$file_path, 0);
  7624. $zip_files_abs[] = $file_path;
  7625. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7626. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7627. $my_dep->setAttribute('xml:base', '');
  7628. }
  7629. elseif (empty($file_path)) {
  7630. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7631. if (strpos($document_root,-1) == '/') {
  7632. $document_root = substr(0, -1, $document_root);
  7633. }*/
  7634. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7635. $file_path = str_replace('//', '/', $file_path);
  7636. if (file_exists($file_path)) {
  7637. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7638. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7639. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7640. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7641. $my_dep->setAttribute('xml:base', '');
  7642. }
  7643. }
  7644. break;
  7645. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7646. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7647. $current_dir = str_replace('\\', '/', $current_dir);
  7648. $file_path = realpath($doc_info[0]);
  7649. $file_path = str_replace('\\', '/', $file_path);
  7650. $my_dep_file->setAttribute('href', $file_path);
  7651. $my_dep->setAttribute('xml:base', '');
  7652. if (strstr($file_path,$main_path) !== false) {
  7653. // The calculated real path is really inside the chamilo root path.
  7654. // Reduce file path to what's under the DocumentRoot.
  7655. $file_path = substr($file_path, strlen($root_path));
  7656. //echo $file_path;echo '<br /><br />';
  7657. //error_log('Reduced path: '.$file_path, 0);
  7658. $zip_files_abs[] = $file_path;
  7659. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7660. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7661. $my_dep->setAttribute('xml:base', '');
  7662. }
  7663. elseif (empty($file_path)) {
  7664. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7665. if (strpos($document_root,-1) == '/') {
  7666. $document_root = substr(0, -1, $document_root);
  7667. }*/
  7668. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7669. $file_path = str_replace('//', '/', $file_path);
  7670. if (file_exists($file_path)) {
  7671. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7672. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7673. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7674. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7675. $my_dep->setAttribute('xml:base', '');
  7676. }
  7677. }
  7678. break;
  7679. 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
  7680. if (substr($doc_info[0], 0, 2) == '..') {
  7681. // Relative path going up.
  7682. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7683. $current_dir = str_replace('\\', '/', $current_dir);
  7684. $file_path = realpath($current_dir.$doc_info[0]);
  7685. $file_path = str_replace('\\', '/', $file_path);
  7686. //error_log($file_path.' <-> '.$main_path, 0);
  7687. if (strstr($file_path, $main_path) !== false) {
  7688. // The calculated real path is really inside Chamilo's root path.
  7689. // Reduce file path to what's under the DocumentRoot.
  7690. $file_path = substr($file_path, strlen($root_path));
  7691. $file_path_dest = $file_path;
  7692. // File path is courses/CHAMILO/document/....
  7693. $info_file_path = explode('/', $file_path);
  7694. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7695. $file_path_dest = 'document/'.$file_path;
  7696. }
  7697. //error_log('Reduced path: '.$file_path, 0);
  7698. $zip_files_abs[] = $file_path;
  7699. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7700. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7701. $my_dep->setAttribute('xml:base', '');
  7702. }
  7703. } else {
  7704. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7705. $my_dep_file->setAttribute('href', $doc_info[0]);
  7706. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7707. }
  7708. break;
  7709. default:
  7710. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7711. $my_dep->setAttribute('xml:base', '');
  7712. break;
  7713. }
  7714. }
  7715. $my_dep->appendChild($my_dep_file);
  7716. $resources->appendChild($my_dep);
  7717. $dependency = $xmldoc->createElement('dependency');
  7718. $dependency->setAttribute('identifierref', $res_id);
  7719. $my_resource->appendChild($dependency);
  7720. $i++;
  7721. }
  7722. $resources->appendChild($my_resource);
  7723. $zip_files[] = $my_file_path;
  7724. } else {
  7725. // Get the path of the file(s) from the course directory root
  7726. $my_file_path = 'non_exportable.html';
  7727. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7728. $my_xml_file_path = $my_file_path;
  7729. $my_sub_dir = dirname($my_file_path);
  7730. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7731. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7732. $my_xml_sub_dir = $my_sub_dir;
  7733. // Give a <resource> child to the <resources> element.
  7734. $my_resource = $xmldoc->createElement('resource');
  7735. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7736. $my_resource->setAttribute('type', 'webcontent');
  7737. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7738. // adlcp:scormtype can be either 'sco' or 'asset'.
  7739. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7740. // xml:base is the base directory to find the files declared in this resource.
  7741. $my_resource->setAttribute('xml:base', '');
  7742. // Give a <file> child to the <resource> element.
  7743. $my_file = $xmldoc->createElement('file');
  7744. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7745. $my_resource->appendChild($my_file);
  7746. $resources->appendChild($my_resource);
  7747. }
  7748. }
  7749. }
  7750. $organizations->appendChild($organization);
  7751. $root->appendChild($organizations);
  7752. $root->appendChild($resources);
  7753. $xmldoc->appendChild($root);
  7754. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7755. // then add the file to the zip, then destroy the file (this is done automatically).
  7756. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7757. //error_log(print_r($zip_files,true), 0);
  7758. foreach ($zip_files as $file_path) {
  7759. if (empty($file_path)) { continue; }
  7760. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7761. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7762. $this->create_path($dest_file);
  7763. //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);
  7764. //echo $main_path.$file_path.'<br />';
  7765. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7766. // Check if the file needs a link update.
  7767. if (in_array($file_path, array_keys($link_updates))) {
  7768. $string = file_get_contents($dest_file);
  7769. unlink($dest_file);
  7770. foreach ($link_updates[$file_path] as $old_new) {
  7771. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7772. // This is an ugly hack that allows .flv files to be found by the flv player that
  7773. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7774. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7775. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7776. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7777. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7778. }
  7779. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7780. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7781. }
  7782. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7783. }
  7784. file_put_contents($dest_file, $string);
  7785. }
  7786. }
  7787. foreach ($zip_files_abs as $file_path) {
  7788. if (empty($file_path)) { continue; }
  7789. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7790. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7791. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7792. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7793. $this->create_path($dest_file);
  7794. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7795. //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);
  7796. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7797. copy($main_path.$file_path, $dest_file);
  7798. // Check if the file needs a link update.
  7799. if (in_array($file_path, array_keys($link_updates))) {
  7800. $string = file_get_contents($dest_file);
  7801. unlink($dest_file);
  7802. foreach ($link_updates[$file_path] as $old_new) {
  7803. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7804. // This is an ugly hack that allows .flv files to be found by the flv player that
  7805. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7806. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7807. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7808. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7809. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7810. }
  7811. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7812. }
  7813. file_put_contents($dest_file, $string);
  7814. }
  7815. }
  7816. if (is_array($links_to_create)) {
  7817. foreach ($links_to_create as $file => $link) {
  7818. $file_content = '<!DOCTYPE html
  7819. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7820. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7821. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7822. <head>
  7823. <title>'.$link['title'].'</title>
  7824. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7825. </head>
  7826. <body dir="'.api_get_text_direction().'">
  7827. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7828. </body>
  7829. </html>';
  7830. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7831. }
  7832. }
  7833. // Add non exportable message explanation.
  7834. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7835. $file_content = '<!DOCTYPE html
  7836. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7837. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7838. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7839. <head>
  7840. <title>'.$lang_not_exportable.'</title>
  7841. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7842. </head>
  7843. <body dir="'.api_get_text_direction().'">
  7844. ';
  7845. $file_content .=
  7846. <<<EOD
  7847. <style>
  7848. .error-message {
  7849. font-family: arial, verdana, helvetica, sans-serif;
  7850. border-width: 1px;
  7851. border-style: solid;
  7852. left: 50%;
  7853. margin: 10px auto;
  7854. min-height: 30px;
  7855. padding: 5px;
  7856. right: 50%;
  7857. width: 500px;
  7858. background-color: #FFD1D1;
  7859. border-color: #FF0000;
  7860. color: #000;
  7861. }
  7862. </style>
  7863. <body>
  7864. <div class="error-message">
  7865. $lang_not_exportable
  7866. </div>
  7867. </body>
  7868. </html>
  7869. EOD;
  7870. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7871. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7872. }
  7873. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7874. // Add the extra files that go along with a SCORM package.
  7875. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7876. $extra_files = scandir($main_code_path);
  7877. foreach ($extra_files as $extra_file) {
  7878. if (strpos($extra_file, '.') === 0)
  7879. continue;
  7880. else {
  7881. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7882. $this->create_path($dest_file);
  7883. copy($main_code_path.$extra_file, $dest_file);
  7884. }
  7885. }
  7886. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7887. $manifest = @$xmldoc->saveXML();
  7888. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7889. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7890. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7891. // Clean possible temporary files.
  7892. foreach ($files_cleanup as $file) {
  7893. $res = unlink($file);
  7894. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7895. }
  7896. // Send file to client.
  7897. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7898. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7899. $name = replace_dangerous_char($this->get_name()).'.zip';
  7900. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7901. }
  7902. public function scorm_export_to_pdf($lp_id) {
  7903. $lp_id = intval($lp_id);
  7904. $files_to_export = array();
  7905. $course_data = api_get_course_info($this->cc);
  7906. if (!empty($course_data)) {
  7907. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7908. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7909. $list = $this->get_flat_ordered_items_list($lp_id);
  7910. foreach($list as $item_id) {
  7911. $item = $this->items[$item_id];
  7912. //Getting documents from a LP with chamilo documents
  7913. switch ($item->type) {
  7914. case 'document':
  7915. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7916. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7917. if (file_exists($file_path)) {
  7918. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7919. }
  7920. break;
  7921. case 'sco':
  7922. $file_path = $scorm_path.'/'.$item->path;
  7923. if (file_exists($file_path)) {
  7924. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7925. }
  7926. break;
  7927. case 'dokeos_chapter':
  7928. case 'dir':
  7929. case 'chapter':
  7930. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7931. break;
  7932. }
  7933. }
  7934. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7935. $pdf = new PDF();
  7936. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7937. return $result;
  7938. }
  7939. return false;
  7940. }
  7941. /**
  7942. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7943. * if it doesn't exist
  7944. */
  7945. public function create_path($path) {
  7946. $path_bits = split('/', dirname($path));
  7947. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7948. $path_built = IS_WINDOWS_OS ? '' : '/';
  7949. foreach ($path_bits as $bit) {
  7950. if (!empty ($bit)) {
  7951. $new_path = $path_built . $bit;
  7952. if (is_dir($new_path)) {
  7953. $path_built = $new_path . '/';
  7954. } else {
  7955. mkdir($new_path, api_get_permissions_for_new_directories());
  7956. $path_built = $new_path . '/';
  7957. }
  7958. }
  7959. }
  7960. }
  7961. /**
  7962. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7963. * @return boolean The results of the unlink function, or false if there was no image to start with
  7964. */
  7965. public function delete_lp_image() {
  7966. $img = $this->get_preview_image();
  7967. if ($img != '') {
  7968. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7969. $this->set_preview_image('');
  7970. return @ unlink($del_file);
  7971. } else {
  7972. return false;
  7973. }
  7974. }
  7975. /**
  7976. * Uploads an author image to the upload/learning_path/images directory
  7977. * @param array The image array, coming from the $_FILES superglobal
  7978. * @return boolean True on success, false on error
  7979. */
  7980. public function upload_image($image_array) {
  7981. $image_moved = false;
  7982. if (!empty ($image_array['name'])) {
  7983. $upload_ok = process_uploaded_file($image_array);
  7984. $has_attachment = true;
  7985. } else {
  7986. $image_moved = true;
  7987. }
  7988. if ($upload_ok) {
  7989. if ($has_attachment) {
  7990. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7991. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7992. $updir = $sys_course_path . $courseDir;
  7993. // Try to add an extension to the file if it hasn't one.
  7994. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7995. if (!filter_extension($new_file_name)) {
  7996. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7997. $image_moved = false;
  7998. } else {
  7999. $file_extension = explode('.', $image_array['name']);
  8000. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  8001. $new_file_name = uniqid('') . '.' . $file_extension;
  8002. $new_path = $updir . '/' . $new_file_name;
  8003. //$result = @move_uploaded_file($image_array['tmp_name'], $new_path);
  8004. // Resize the image.
  8005. include_once api_get_path(LIBRARY_PATH).'image.lib.php';
  8006. $temp = new image($image_array['tmp_name']);
  8007. $picture_infos = @getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  8008. if ($picture_infos[0] > 104) {
  8009. $thumbwidth = 104;
  8010. } else {
  8011. $thumbwidth = $picture_infos[0];
  8012. }
  8013. if ($picture_infos[1] > 96) {
  8014. $new_height = 96;
  8015. } else {
  8016. $new_height = $picture_infos[1];
  8017. }
  8018. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  8019. $temp->resize($thumbwidth,$new_height, 0);
  8020. $type = $picture_infos[2];
  8021. $result = false;
  8022. switch ($type) {
  8023. case 2 :
  8024. $result = $temp->send_image('JPG', $new_path);
  8025. break;
  8026. case 3 :
  8027. $result = $temp->send_image('PNG', $new_path);
  8028. break;
  8029. case 1 :
  8030. $result = $temp->send_image('GIF', $new_path);
  8031. break;
  8032. }
  8033. $temp->resize($thumbwidth, $new_height, 0);
  8034. $type = $picture_infos[2];
  8035. $result = false;
  8036. switch ($type) {
  8037. case 2 :
  8038. $result = $temp->send_image('JPG', $new_path);
  8039. break;
  8040. case 3 :
  8041. $result = $temp->send_image('PNG', $new_path);
  8042. break;
  8043. case 1 :
  8044. $result = $temp->send_image('GIF', $new_path);
  8045. break;
  8046. }
  8047. // Storing the image filename.
  8048. if ($result) {
  8049. $image_moved = true;
  8050. $this->set_preview_image($new_file_name);
  8051. return true;
  8052. }
  8053. }
  8054. }
  8055. }
  8056. return false;
  8057. }
  8058. public function set_autolunch($lp_id, $status) {
  8059. $lp_id = intval($lp_id);
  8060. $status = intval($status);
  8061. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  8062. //Setting everything to autolunch = 0
  8063. $attributes['autolunch'] = 0;
  8064. $where = array('session_id = ? '=> api_get_session_id());
  8065. Database::update($lp_table, $attributes,$where);
  8066. if ($status == 1) {
  8067. //Setting my lp_id to autolunch = 1
  8068. $attributes['autolunch'] = 1;
  8069. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  8070. Database::update($lp_table, $attributes, $where );
  8071. }
  8072. }
  8073. }
  8074. if (!function_exists('trim_value')) {
  8075. function trim_value(& $value) {
  8076. $value = trim($value);
  8077. }
  8078. }