learnpath.class.php 417 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This (abstract?) 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. * @license GNU/GPL
  11. */
  12. /**
  13. * Defines the learnpath parent class
  14. * @package chamilo.learnpath
  15. */
  16. class learnpath {
  17. public $attempt = 0; // The number for the current ID view.
  18. public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
  19. public $current; // Id of the current item the user is viewing.
  20. public $current_score; // The score of the current item.
  21. public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
  22. public $current_time_stop; // The time the user closed this resource.
  23. public $default_status = 'not attempted';
  24. public $encoding = 'UTF-8';
  25. public $error = '';
  26. public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath.
  27. public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue().
  28. public $index; // The index of the active learnpath_item in $ordered_items array.
  29. public $items = array();
  30. public $last; // item_id of last item viewed in the learning path.
  31. public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized.
  32. public $license; // Which license this course has been given - not used yet on 20060522.
  33. public $lp_id; // DB ID for this learnpath.
  34. public $lp_view_id; // DB ID for lp_view
  35. public $log_file; // File where to log learnpath API msg.
  36. public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
  37. public $message = '';
  38. public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
  39. public $name; // Learnpath name (they generally have one).
  40. public $ordered_items = array(); // List of the learnpath items in the order they are to be read.
  41. public $path = ''; // Path inside the scorm directory (if scorm).
  42. public $theme; // The current theme of the learning path.
  43. public $preview_image; // The current image of the learning path.
  44. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
  45. public $prevent_reinit = 1;
  46. // Describes the mode of progress bar display.
  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->license = $row['content_license'];
  125. $this->scorm_debug = $row['debug'];
  126. $this->js_lib = $row['js_lib'];
  127. $this->path = $row['path'];
  128. $this->preview_image = $row['preview_image'];
  129. $this->author = $row['author'];
  130. $this->lp_session_id = $row['session_id'];
  131. $this->use_max_score = $row['use_max_score'];
  132. $this->created_on = $row['created_on'];
  133. $this->modified_on = $row['modified_on'];
  134. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  135. $this->publicated_on = $row['publicated_on'];
  136. }
  137. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  138. $this->expired_on = $row['expired_on'];
  139. }
  140. if ($this->type == 2) {
  141. if ($row['force_commit'] == 1) {
  142. $this->force_commit = true;
  143. }
  144. }
  145. $this->mode = $row['default_view_mod'];
  146. } else {
  147. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  148. return false;
  149. }
  150. }
  151. // Check user ID.
  152. if (empty($user_id)) {
  153. $this->error = 'User ID is empty';
  154. return false;
  155. } else {
  156. //$main_table = Database::get_main_user_table();
  157. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  158. //$user_id = Database::escape_integer($user_id);
  159. $user_id = $this->escape_string($user_id);
  160. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  161. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  162. $res = Database::query($sql);
  163. if (Database::num_rows($res) > 0) {
  164. $this->user_id = $user_id;
  165. } else {
  166. $this->error = 'User ID does not exist in database ('.$sql.')';
  167. return false;
  168. }
  169. }
  170. // End of variables checking.
  171. $session_id = api_get_session_id();
  172. // Get the session condition for learning paths of the base + session.
  173. $session = api_get_session_condition($session_id);
  174. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  175. $lp_table = Database::get_course_table(TABLE_LP_VIEW, $course_db);
  176. // Selecting by view_count descending allows to get the highest view_count first.
  177. $sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  178. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  179. $res = Database::query($sql);
  180. $view_id = 0; // Used later to query lp_item_view.
  181. if (Database :: num_rows($res) > 0) {
  182. if ($this->debug > 2) {
  183. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  184. }
  185. $row = Database :: fetch_array($res);
  186. $this->attempt = $row['view_count'];
  187. $this->lp_view_id = $row['id'];
  188. $this->last_item_seen = $row['last_item'];
  189. $this->progress_db = $row['progress'];
  190. $this->lp_view_session_id = $row['session_id'];
  191. } else {
  192. if ($this->debug > 2) {
  193. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  194. }
  195. $this->attempt = 1;
  196. $sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count, session_id) VALUES ($lp_id,$user_id,1,$session_id)";
  197. $res_ins = Database::query($sql_ins);
  198. $this->lp_view_id = Database :: insert_id();
  199. if ($this->debug > 2) {
  200. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  201. }
  202. }
  203. // Initialise items.
  204. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM, $course_db);
  205. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  206. $res = Database::query($sql);
  207. while ($row = Database::fetch_array($res)) {
  208. $oItem = '';
  209. //$this->ordered_items[] = $row['id'];
  210. switch ($this->type) {
  211. case 3: //aicc
  212. $oItem = new aiccItem('db', $row['id'], $course_db);
  213. if (is_object($oItem)) {
  214. $my_item_id = $oItem->get_id();
  215. $oItem->set_lp_view($this->lp_view_id, $course_db);
  216. $oItem->set_prevent_reinit($this->prevent_reinit);
  217. // Don't use reference here as the next loop will make the pointed object change.
  218. $this->items[$my_item_id] = $oItem;
  219. $this->refs_list[$oItem->ref] = $my_item_id;
  220. if ($this->debug > 2) {
  221. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  222. }
  223. }
  224. break;
  225. case 2:
  226. require_once 'scorm.class.php';
  227. require_once 'scormItem.class.php';
  228. $oItem = new scormItem('db', $row['id'], $course_db);
  229. if (is_object($oItem)) {
  230. $my_item_id = $oItem->get_id();
  231. $oItem->set_lp_view($this->lp_view_id, $course_db);
  232. $oItem->set_prevent_reinit($this->prevent_reinit);
  233. // Don't use reference here as the next loop will make the pointed object change.
  234. error_log('my_item_id->'.$my_item_id);
  235. $this->items[$my_item_id] = $oItem;
  236. $this->refs_list[$oItem->ref] = $my_item_id;
  237. if ($this->debug > 2) {
  238. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  239. }
  240. }
  241. break;
  242. case 1:
  243. default:
  244. require_once 'learnpathItem.class.php';
  245. $oItem = new learnpathItem($row['id'], $user_id, $course_db);
  246. if (is_object($oItem)) {
  247. $my_item_id = $oItem->get_id();
  248. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  249. $oItem->set_prevent_reinit($this->prevent_reinit);
  250. // Don't use reference here as the next loop will make the pointed object change.
  251. $this->items[$my_item_id] = $oItem;
  252. $this->refs_list[$my_item_id] = $my_item_id;
  253. if ($this->debug > 2) {
  254. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  255. }
  256. }
  257. break;
  258. }
  259. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  260. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  261. if (is_object($this->items[$row['id']])) {
  262. $this->items[$row['id']]->set_level(0);
  263. }
  264. } else {
  265. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  266. $this->items[$row['id']]->set_level($level);
  267. if (is_object($this->items[$row['parent_item_id']])) {
  268. // Items is a list of pointers from item DB ids to item objects.
  269. $this->items[$row['parent_item_id']]->add_child($row['id']);
  270. } else {
  271. if ($this->debug > 2) {
  272. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  273. }
  274. }
  275. }
  276. // Get last viewing vars.
  277. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  278. // This query should only return one or zero result.
  279. $sql = "SELECT * " .
  280. "FROM $lp_item_view_table " .
  281. "WHERE lp_view_id = " . $this->lp_view_id . " " .
  282. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  283. if ($this->debug > 2) {
  284. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  285. }
  286. // Get the item status.
  287. $res2 = Database::query($sql);
  288. if (Database :: num_rows($res2) > 0) {
  289. // If this learnpath has already been used by this user, get his last attempt count and
  290. // the last item seen back into this object.
  291. //$max = 0;
  292. $row2 = Database :: fetch_array($res2);
  293. if ($this->debug > 2) {
  294. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  295. }
  296. if (is_object($this->items[$row['id']])) {
  297. $this->items[$row['id']]->set_status($row2['status']);
  298. if (empty ($row2['status'])) {
  299. $this->items[$row['id']]->set_status($this->default_status);
  300. }
  301. }
  302. //$this->attempt = $row['view_count'];
  303. //$this->last_item = $row['id'];
  304. } else { // No item has been found in lp_item_view for this view.
  305. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  306. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  307. //$this->attempt = 1;
  308. //$this->last_item = 0;
  309. if (is_object($this->items[$row['id']])) {
  310. $this->items[$row['id']]->set_status($this->default_status);
  311. }
  312. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  313. $sql_ins = "INSERT INTO $lp_item_view_table " .
  314. "(lp_item_id, lp_view_id, view_count, status) VALUES " .
  315. "(" . $row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  316. if ($this->debug > 2) {
  317. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  318. }
  319. $res_ins = Database::query($sql_ins);
  320. }
  321. // Setting the view in the item object.
  322. if (is_object($this->items[$row['id']])) {
  323. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_db);
  324. }
  325. }
  326. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_db);
  327. $this->max_ordered_items = 0;
  328. foreach ($this->ordered_items as $index => $dummy) {
  329. if ($index > $this->max_ordered_items && !empty($dummy)) {
  330. $this->max_ordered_items = $index;
  331. }
  332. }
  333. // TODO: Define the current item better.
  334. $this->first();
  335. if ($this->debug > 2) {
  336. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  337. }
  338. }
  339. /**
  340. * 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
  341. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  342. *
  343. * @param int $parent
  344. * @param int $previous
  345. * @param string $type
  346. * @param int resource ID (ref)
  347. * @param string $title
  348. * @param string $description
  349. * @return int
  350. */
  351. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  352. if ($this->debug > 0) {
  353. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  354. }
  355. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  356. $parent = intval($parent);
  357. $previous = intval($previous);
  358. $type = $this->escape_string($type);
  359. $id = intval($id);
  360. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  361. if (empty ($max_time_allowed)) {
  362. $max_time_allowed = 0;
  363. }
  364. $title = $this->escape_string($title);
  365. $description = $this->escape_string($description);
  366. $sql_count = " SELECT COUNT(id) AS num
  367. FROM " . $tbl_lp_item . "
  368. WHERE lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  369. $res_count = Database::query($sql_count);
  370. $row = Database :: fetch_array($res_count);
  371. $num = $row['num'];
  372. if ($num > 0) {
  373. if ($previous == 0) {
  374. $sql = "SELECT id, next_item_id, display_order
  375. FROM " . $tbl_lp_item . "
  376. WHERE
  377. lp_id = " . $this->get_id() . " AND
  378. parent_item_id = " . $parent . " AND
  379. previous_item_id = 0 OR previous_item_id=" . $parent;
  380. $result = Database::query($sql);
  381. $row = Database :: fetch_array($result);
  382. $tmp_previous = 0;
  383. $next = $row['id'];
  384. $display_order = 0;
  385. } else {
  386. $previous = (int) $previous;
  387. $sql = "
  388. SELECT
  389. id,
  390. previous_item_id,
  391. next_item_id,
  392. display_order
  393. FROM " . $tbl_lp_item . "
  394. WHERE
  395. lp_id = " . $this->get_id() . " AND
  396. id = " . $previous;
  397. $result = Database::query($sql);
  398. $row = Database :: fetch_array($result);
  399. $tmp_previous = $row['id'];
  400. $next = $row['next_item_id'];
  401. $display_order = $row['display_order'];
  402. }
  403. } else {
  404. $tmp_previous = 0;
  405. $next = 0;
  406. $display_order = 0;
  407. }
  408. $new_item_id = -1;
  409. $id = $this->escape_string($id);
  410. if ($type == 'quiz') {
  411. $sql = 'SELECT SUM(ponderation)
  412. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  413. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  414. ON quiz_question.id = quiz_rel_question.question_id
  415. AND quiz_rel_question.exercice_id = ' . $id;
  416. $rsQuiz = Database::query($sql);
  417. $max_score = Database :: result($rsQuiz, 0, 0);
  418. } else {
  419. $max_score = 100;
  420. }
  421. if ($prerequisites != 0) {
  422. $sql_ins = "
  423. INSERT INTO " . $tbl_lp_item . " ( ".
  424. "lp_id, ".
  425. "item_type, ".
  426. "ref, ".
  427. "title, ".
  428. "description, ".
  429. "path, ".
  430. "max_score, ".
  431. "parent_item_id, ".
  432. "previous_item_id, ".
  433. "next_item_id, ".
  434. "display_order, ".
  435. "prerequisite, ".
  436. "max_time_allowed ".
  437. ") VALUES ( ".
  438. $this->get_id() . ", ".
  439. "'" . $type . "', ".
  440. "'', ".
  441. "'" . $title . "', ".
  442. "'" . $description . "', ".
  443. "'" . $id . "', ".
  444. "'" . $max_score . "', ".
  445. $parent . ", ".
  446. $previous . ", ".
  447. $next . ", ".
  448. ($display_order +1) . ", ".
  449. $prerequisites . ", ".
  450. $max_time_allowed .
  451. ")";
  452. } else {
  453. // Insert new item.
  454. $sql_ins = "
  455. INSERT INTO " . $tbl_lp_item . " ( ".
  456. "lp_id, ".
  457. "item_type, ".
  458. "ref, ".
  459. "title, ".
  460. "description, ".
  461. "path, ".
  462. "max_score, ".
  463. "parent_item_id, ".
  464. "previous_item_id, ".
  465. "next_item_id, ".
  466. "display_order, ".
  467. "max_time_allowed ".
  468. ") VALUES (".
  469. $this->get_id() . ",".
  470. "'" . $type . "',".
  471. "'',".
  472. "'" . $title . "',".
  473. "'" . $description . "',".
  474. "'" . $id . "',".
  475. "'" . $max_score . "',".
  476. $parent . ",".
  477. $previous . ",".
  478. $next . ",".
  479. ($display_order +1) . ",".
  480. $max_time_allowed .
  481. ")";
  482. }
  483. if ($this->debug > 2) {
  484. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  485. }
  486. $res_ins = Database::query($sql_ins);
  487. if ($res_ins > 0) {
  488. $new_item_id = Database :: insert_id($res_ins);
  489. // Update the item that should come after the new item.
  490. $sql_update_next = "
  491. UPDATE " . $tbl_lp_item . "
  492. SET previous_item_id = " . $new_item_id . "
  493. WHERE id = " . $next;
  494. $res_update_next = Database::query($sql_update_next);
  495. // Update the item that should be before the new item.
  496. $sql_update_previous = "
  497. UPDATE " . $tbl_lp_item . "
  498. SET next_item_id = " . $new_item_id . "
  499. WHERE id = " . $tmp_previous;
  500. $res_update_previous = Database::query($sql_update_previous);
  501. // Update all the items after the new item.
  502. $sql_update_order = "
  503. UPDATE " . $tbl_lp_item . "
  504. SET display_order = display_order + 1
  505. WHERE
  506. lp_id = " . $this->get_id() . " AND
  507. id <> " . $new_item_id . " AND
  508. parent_item_id = " . $parent . " AND
  509. display_order > " . $display_order;
  510. $res_update_previous = Database::query($sql_update_order);
  511. // Update the item that should come after the new item.
  512. $sql_update_ref = "
  513. UPDATE " . $tbl_lp_item . "
  514. SET ref = " . $new_item_id . "
  515. WHERE id = " . $new_item_id;
  516. Database::query($sql_update_ref);
  517. }
  518. // Upload audio.
  519. if (!empty ($_FILES['mp3']['name'])) {
  520. // Create the audio folder if it does not exist yet.
  521. global $_course;
  522. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  523. if (!is_dir($filepath . 'audio')) {
  524. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  525. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  526. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  527. }
  528. // Upload the file in the documents tool.
  529. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  530. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  531. // Getting the filename only.
  532. $file_components = explode('/', $file_path);
  533. $file = $file_components[count($file_components) - 1];
  534. // Store the mp3 file in the lp_item table.
  535. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  536. Database::query($sql_insert_audio);
  537. }
  538. return $new_item_id;
  539. }
  540. /**
  541. * Static admin function allowing addition of a learnpath to a course.
  542. * @param string Course code
  543. * @param string Learnpath name
  544. * @param string Learnpath description string, if provided
  545. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  546. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  547. * @param string Zip file containing the learnpath or directory containing the learnpath
  548. * @return integer The new learnpath ID on success, 0 on failure
  549. */
  550. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  551. global $charset;
  552. //if ($this->debug > 0) { error_log('New LP - In learnpath::add_lp()', 0); }
  553. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  554. // Check course code exists.
  555. // Check lp_name doesn't exist, otherwise append something.
  556. $i = 0;
  557. $name = learnpath :: escape_string($name);
  558. // Session id.
  559. $session_id = api_get_session_id();
  560. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  561. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  562. $res_name = Database::query($check_name);
  563. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  564. //by default the publication date is the same that the creation date
  565. $publicated_on = api_get_utc_datetime();
  566. } else {
  567. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  568. }
  569. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  570. $expired_on = '';
  571. } else {
  572. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  573. }
  574. while (Database :: num_rows($res_name)) {
  575. // There is already one such name, update the current one a bit.
  576. $i++;
  577. $name = $name . ' - ' . $i;
  578. $check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
  579. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  580. $res_name = Database::query($check_name);
  581. }
  582. // New name does not exist yet; keep it.
  583. // Escape description.
  584. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  585. $type = 1;
  586. switch ($learnpath) {
  587. case 'guess':
  588. break;
  589. case 'dokeos':
  590. case 'chamilo':
  591. $type = 1;
  592. break;
  593. case 'aicc':
  594. break;
  595. }
  596. switch ($origin) {
  597. case 'zip':
  598. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  599. break;
  600. case 'manual':
  601. default:
  602. $get_max = "SELECT MAX(display_order) FROM $tbl_lp";
  603. $res_max = Database::query($get_max);
  604. if (Database :: num_rows($res_max) < 1) {
  605. $dsp = 1;
  606. } else {
  607. $row = Database :: fetch_array($res_max);
  608. $dsp = $row[0] + 1;
  609. }
  610. $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) " .
  611. "VALUES ($type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  612. //if ($this->debug > 2) { error_log('New LP - Inserting new lp '.$sql_insert, 0); }
  613. $res_insert = Database::query($sql_insert);
  614. $id = Database :: insert_id();
  615. if ($id > 0) {
  616. // Insert into item_property.
  617. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  618. return $id;
  619. }
  620. break;
  621. }
  622. }
  623. /**
  624. * Appends a message to the message attribute
  625. * @param string Message to append.
  626. */
  627. public function append_message($string) {
  628. if ($this->debug > 0) {
  629. error_log('New LP - In learnpath::append_message()', 0);
  630. }
  631. $this->message .= $string;
  632. }
  633. /**
  634. * Autocompletes the parents of an item in case it's been completed or passed
  635. * @param integer Optional ID of the item from which to look for parents
  636. */
  637. public function autocomplete_parents($item) {
  638. if ($this->debug > 0) {
  639. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  640. }
  641. if (empty ($item)) {
  642. $item = $this->current;
  643. }
  644. $parent_id = $this->items[$item]->get_parent();
  645. if ($this->debug > 2) {
  646. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  647. }
  648. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  649. // if $item points to an object and there is a parent.
  650. if ($this->debug > 2) {
  651. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  652. }
  653. $current_item = & $this->items[$item];
  654. $parent = & $this->items[$parent_id]; // Get the parent.
  655. // New experiment including failed and browsed in completed status.
  656. $current_status = $current_item->get_status();
  657. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  658. // If the current item is completed or passes or succeeded.
  659. $completed = true;
  660. if ($this->debug > 2) {
  661. error_log('New LP - Status of current item is alright', 0);
  662. }
  663. foreach ($parent->get_children() as $child) {
  664. // Check all his brothers (his parent's children) for completion status.
  665. if ($child != $item) {
  666. if ($this->debug > 2) {
  667. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  668. }
  669. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  670. // Trying completing parents of failed and browsed items as well.
  671. if ($this->items[$child]->status_is(array (
  672. 'completed',
  673. 'passed',
  674. 'succeeded',
  675. 'browsed',
  676. 'failed'
  677. ))) {
  678. // Keep completion status to true.
  679. } else {
  680. if ($this->debug > 2) {
  681. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  682. }
  683. $completed = false;
  684. }
  685. }
  686. }
  687. if ($completed) { // If all the children were completed:
  688. $parent->set_status('completed');
  689. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  690. $this->update_queue[$parent->get_id()] = $parent->get_status();
  691. if ($this->debug > 2) {
  692. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  693. }
  694. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  695. }
  696. } else {
  697. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  698. }
  699. }
  700. }
  701. /**
  702. * Autosaves the current results into the database for the whole learnpath
  703. */
  704. public function autosave() {
  705. if ($this->debug > 0) {
  706. error_log('New LP - In learnpath::autosave()', 0);
  707. }
  708. // TODO: Add save operations for the learnpath itself.
  709. }
  710. /**
  711. * Clears the message attribute
  712. */
  713. public function clear_message() {
  714. if ($this->debug > 0) {
  715. error_log('New LP - In learnpath::clear_message()', 0);
  716. }
  717. $this->message = '';
  718. }
  719. /**
  720. * Closes the current resource
  721. *
  722. * Stops the timer
  723. * Saves into the database if required
  724. * Clears the current resource data from this object
  725. * @return boolean True on success, false on failure
  726. */
  727. public function close() {
  728. if ($this->debug > 0) {
  729. error_log('New LP - In learnpath::close()', 0);
  730. }
  731. if (empty ($this->lp_id)) {
  732. $this->error = 'Trying to close this learnpath but no ID is set';
  733. return false;
  734. }
  735. $this->current_time_stop = time();
  736. if ($this->save) {
  737. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  738. /*
  739. $sql = "UPDATE $learnpath_view_table " .
  740. "SET " .
  741. "stop_time = ".$this->current_time_stop.", " .
  742. "score = ".$this->current_score.", ".
  743. "WHERE learnpath_id = '".$this->lp_id."'";
  744. //$res = Database::query($sql);
  745. $res = Database::query($res);
  746. if (Database::affected_rows($res) < 1) {
  747. $this->error = 'Could not update learnpath_view table while closing learnpath';
  748. return false;
  749. }
  750. */
  751. }
  752. $this->ordered_items = array ();
  753. $this->index = 0;
  754. unset ($this->lp_id);
  755. //unset other stuff
  756. return true;
  757. }
  758. /**
  759. * Static admin function allowing removal of a learnpath
  760. * @param string Course code
  761. * @param integer Learnpath ID
  762. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  763. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  764. */
  765. public function delete($course = null, $id = null, $delete = 'keep') {
  766. // TODO: Implement a way of getting this to work when the current object is not set.
  767. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  768. //if (empty($course)) { $course = api_get_course_id(); }
  769. //if (empty($id)) { $id = $this->get_id(); }
  770. // If an ID is specifically given and the current LP is not the same, prevent delete.
  771. if (!empty ($id) && ($id != $this->lp_id)) {
  772. return false;
  773. }
  774. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  775. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  776. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  777. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  778. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  779. // Delete lp item id.
  780. foreach ($this->items as $id => $dummy) {
  781. //$this->items[$id]->delete();
  782. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  783. $res_del_item_view = Database::query($sql_del_view);
  784. }
  785. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  786. $sql_del_item = "DELETE FROM $lp_item WHERE lp_id = " . $this->lp_id;
  787. $res_del_item = Database::query($sql_del_item);
  788. $sql_del_view = "DELETE FROM $lp_view WHERE lp_id = " . $this->lp_id;
  789. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  790. $res_del_view = Database::query($sql_del_view);
  791. $this->toggle_publish($this->lp_id, 'i');
  792. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  793. if ($this->type == 2 || $this->type == 3) {
  794. // This is a scorm learning path, delete the files as well.
  795. $sql = "SELECT path FROM $lp WHERE id = " . $this->lp_id;
  796. $res = Database::query($sql);
  797. if (Database :: num_rows($res) > 0) {
  798. $row = Database :: fetch_array($res);
  799. $path = $row['path'];
  800. $sql = "SELECT id FROM $lp WHERE path = '$path' AND id != " . $this->lp_id;
  801. $res = Database::query($sql);
  802. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  803. if ($this->debug > 2) {
  804. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  805. }
  806. } else {
  807. // No other LP uses that directory, delete it.
  808. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  809. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  810. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  811. if ($this->debug > 2) {
  812. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  813. }
  814. // Proposed by Christophe (clefevre).
  815. if (strcmp(substr($path, -2), "/.") == 0) {
  816. $path = substr($path, 0, -1); // Remove "." at the end.
  817. }
  818. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  819. rmdirr($course_scorm_dir . $path);
  820. }
  821. }
  822. }
  823. }
  824. $sql_del_lp = "DELETE FROM $lp WHERE id = " . $this->lp_id;
  825. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  826. $res_del_lp = Database::query($sql_del_lp);
  827. $this->update_display_order(); // Updates the display order of all lps.
  828. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  829. require_once '../gradebook/lib/be.inc.php';
  830. $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  831. // Delete link of gradebook tool.
  832. $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  833. $result = Database::query($sql);
  834. $row = Database :: fetch_array($result, 'ASSOC');
  835. // Fixing gradebook link deleted see #5229.
  836. if (!empty($row['id'])) {
  837. $link = LinkFactory :: load($row['id']);
  838. if ($link[0] != null) {
  839. $link[0]->delete();
  840. }
  841. }
  842. if (api_get_setting('search_enabled') == 'true') {
  843. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  844. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  845. }
  846. }
  847. /**
  848. * Removes all the children of one item - dangerous!
  849. * @param integer Element ID of which children have to be removed
  850. * @return integer Total number of children removed
  851. */
  852. public function delete_children_items($id) {
  853. if ($this->debug > 0) {
  854. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  855. }
  856. $num = 0;
  857. if (empty ($id) || $id != strval(intval($id))) {
  858. return false;
  859. }
  860. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  861. $sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
  862. $res = Database::query($sql);
  863. while ($row = Database :: fetch_array($res)) {
  864. $num += $this->delete_children_items($row['id']);
  865. $sql_del = "DELETE FROM $lp_item WHERE id = " . $row['id'];
  866. $res_del = Database::query($sql_del);
  867. $num++;
  868. }
  869. return $num;
  870. }
  871. /**
  872. * Removes an item from the current learnpath
  873. * @param integer Elem ID (0 if first)
  874. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  875. * @return integer Number of elements moved
  876. * @todo implement resource removal
  877. */
  878. public function delete_item($id, $remove = 'keep') {
  879. if ($this->debug > 0) {
  880. error_log('New LP - In learnpath::delete_item()', 0);
  881. }
  882. // TODO: Implement the resource removal.
  883. if (empty ($id) || $id != strval(intval($id))) {
  884. return false;
  885. }
  886. // First select item to get previous, next, and display order.
  887. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  888. $sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
  889. $res_sel = Database::query($sql_sel);
  890. if (Database :: num_rows($res_sel) < 1) {
  891. return false;
  892. }
  893. $row = Database :: fetch_array($res_sel);
  894. $previous = $row['previous_item_id'];
  895. $next = $row['next_item_id'];
  896. $display = $row['display_order'];
  897. $parent = $row['parent_item_id'];
  898. $lp = $row['lp_id'];
  899. // Delete children items.
  900. $num = $this->delete_children_items($id);
  901. if ($this->debug > 2) {
  902. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  903. }
  904. // Now delete the item.
  905. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  906. if ($this->debug > 2) {
  907. error_log('New LP - Deleting item: ' . $sql_del, 0);
  908. }
  909. $res_del = Database::query($sql_del);
  910. // Now update surrounding items.
  911. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
  912. $res_upd = Database::query($sql_upd);
  913. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
  914. $res_upd = Database::query($sql_upd);
  915. // Now update all following items with new display order.
  916. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  917. $res_all = Database::query($sql_all);
  918. //Removing prerequisites since the item will not longer exist
  919. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE prerequisite = $id";
  920. $res_all = Database::query($sql_all);
  921. // Remove from search engine if enabled.
  922. if (api_get_setting('search_enabled') == 'true') {
  923. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  924. $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';
  925. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  926. $res = Database::query($sql);
  927. if (Database :: num_rows($res) > 0) {
  928. $row2 = Database :: fetch_array($res);
  929. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  930. $di = new DokeosIndexer();
  931. $di->remove_document((int) $row2['search_did']);
  932. }
  933. $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';
  934. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  935. Database::query($sql);
  936. }
  937. }
  938. /**
  939. * Updates an item's content in place
  940. * @param integer Element ID
  941. * @param integer Parent item ID
  942. * @param integer Previous item ID
  943. * @param string Item title
  944. * @param string Item description
  945. * @param string Prerequisites (optional)
  946. * @param string Indexing terms (optional)
  947. * @param array The array resulting of the $_FILES[mp3] element
  948. * @return boolean True on success, false on error
  949. */
  950. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  951. if ($this->debug > 0) {
  952. error_log('New LP - In learnpath::edit_item()', 0);
  953. }
  954. if (empty ($max_time_allowed)) {
  955. $max_time_allowed = 0;
  956. }
  957. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  958. return false;
  959. }
  960. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  961. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE id = " . $id;
  962. $res_select = Database::query($sql_select);
  963. $row_select = Database :: fetch_array($res_select);
  964. $audio_update_sql = '';
  965. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  966. // Create the audio folder if it does not exist yet.
  967. global $_course;
  968. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  969. if (!is_dir($filepath . 'audio')) {
  970. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  971. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  972. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  973. }
  974. // Upload file in documents.
  975. $pi = pathinfo($audio['name']);
  976. if ($pi['extension'] == 'mp3') {
  977. $c_det = api_get_course_info($this->cc);
  978. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  979. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  980. $path = substr($path, 7);
  981. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  982. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  983. }
  984. }
  985. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  986. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  987. // TODO: htmlspecialchars to be checked for encoding related problems.
  988. if ($same_parent && $same_previous) {
  989. // Only update title and description.
  990. $sql_update = " UPDATE " . $tbl_lp_item . "
  991. SET title = '" . $this->escape_string($title) . "',
  992. prerequisite = '" . $prerequisites . "',
  993. description = '" . $this->escape_string($description) . "'
  994. " . $audio_update_sql . ",
  995. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  996. WHERE id = " . $id;
  997. $res_update = Database::query($sql_update);
  998. } else {
  999. $old_parent = $row_select['parent_item_id'];
  1000. $old_previous = $row_select['previous_item_id'];
  1001. $old_next = $row_select['next_item_id'];
  1002. $old_order = $row_select['display_order'];
  1003. $old_prerequisite = $row_select['prerequisite'];
  1004. $old_max_time_allowed = $row_select['max_time_allowed'];
  1005. /* BEGIN -- virtually remove the current item id */
  1006. /* for the next and previous item it is like the current item doesn't exist anymore */
  1007. if ($old_previous != 0) {
  1008. $sql_update_next = "
  1009. UPDATE " . $tbl_lp_item . "
  1010. SET next_item_id = " . $old_next . "
  1011. WHERE id = " . $old_previous;
  1012. $res_update_next = Database::query($sql_update_next);
  1013. //echo '<p>' . $sql_update_next . '</p>';
  1014. }
  1015. if ($old_next != 0) {
  1016. $sql_update_previous = "
  1017. UPDATE " . $tbl_lp_item . "
  1018. SET previous_item_id = " . $old_previous . "
  1019. WHERE id = " . $old_next;
  1020. $res_update_previous = Database::query($sql_update_previous);
  1021. //echo '<p>' . $sql_update_previous . '</p>';
  1022. }
  1023. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1024. $sql_update_order = "
  1025. UPDATE " . $tbl_lp_item . "
  1026. SET display_order = display_order - 1
  1027. WHERE
  1028. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1029. parent_item_id = " . $old_parent;
  1030. $res_update_order = Database::query($sql_update_order);
  1031. //echo '<p>' . $sql_update_order . '</p>';
  1032. /* END -- virtually remove the current item id */
  1033. /* BEGIN -- update the current item id to his new location */
  1034. if ($previous == 0) {
  1035. // Select the data of the item that should come after the current item.
  1036. $sql_select_old = "
  1037. SELECT
  1038. id,
  1039. display_order
  1040. FROM " . $tbl_lp_item . "
  1041. WHERE
  1042. lp_id = " . $this->lp_id . " AND
  1043. parent_item_id = " . $parent . " AND
  1044. previous_item_id = " . $previous;
  1045. $res_select_old = Database::query($sql_select_old);
  1046. $row_select_old = Database :: fetch_array($res_select_old);
  1047. //echo '<p>' . $sql_select_old . '</p>';
  1048. // If the new parent didn't have children before.
  1049. if (Database :: num_rows($res_select_old) == 0) {
  1050. $new_next = 0;
  1051. $new_order = 1;
  1052. } else {
  1053. $new_next = $row_select_old['id'];
  1054. $new_order = $row_select_old['display_order'];
  1055. }
  1056. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1057. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1058. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1059. } else {
  1060. // Select the data of the item that should come before the current item.
  1061. $sql_select_old = "
  1062. SELECT
  1063. next_item_id,
  1064. display_order
  1065. FROM " . $tbl_lp_item . "
  1066. WHERE id = " . $previous;
  1067. $res_select_old = Database::query($sql_select_old);
  1068. $row_select_old = Database :: fetch_array($res_select_old);
  1069. //echo '<p>' . $sql_select_old . '</p>';
  1070. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1071. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1072. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1073. $new_next = $row_select_old['next_item_id'];
  1074. $new_order = $row_select_old['display_order'] + 1;
  1075. }
  1076. // TODO: htmlspecialchars to be checked for encoding related problems.
  1077. // Update the current item with the new data.
  1078. $sql_update = "
  1079. UPDATE " . $tbl_lp_item . "
  1080. SET
  1081. title = '" . $this->escape_string($title) . "',
  1082. description = '" . $this->escape_string($description) . "',
  1083. parent_item_id = " . $parent . ",
  1084. previous_item_id = " . $previous . ",
  1085. next_item_id = " . $new_next . ",
  1086. display_order = " . $new_order . "
  1087. " . $audio_update_sql . "
  1088. WHERE id = " . $id;
  1089. $res_update_next = Database::query($sql_update);
  1090. //echo '<p>' . $sql_update . '</p>';
  1091. if ($previous != 0) {
  1092. // Update the previous item's next_item_id.
  1093. $sql_update_previous = "
  1094. UPDATE " . $tbl_lp_item . "
  1095. SET next_item_id = " . $id . "
  1096. WHERE id = " . $previous;
  1097. $res_update_next = Database::query($sql_update_previous);
  1098. //echo '<p>' . $sql_update_previous . '</p>';
  1099. }
  1100. if ($new_next != 0) {
  1101. // Update the next item's previous_item_id.
  1102. $sql_update_next = "
  1103. UPDATE " . $tbl_lp_item . "
  1104. SET previous_item_id = " . $id . "
  1105. WHERE id = " . $new_next;
  1106. $res_update_next = Database::query($sql_update_next);
  1107. //echo '<p>' . $sql_update_next . '</p>';
  1108. }
  1109. if ($old_prerequisite != $prerequisites) {
  1110. $sql_update_next = "
  1111. UPDATE " . $tbl_lp_item . "
  1112. SET prerequisite = " . $prerequisites . "
  1113. WHERE id = " . $id;
  1114. $res_update_next = Database::query($sql_update_next);
  1115. }
  1116. if ($old_max_time_allowed != $max_time_allowed) {
  1117. $sql_update_max_time_allowed = "
  1118. UPDATE " . $tbl_lp_item . "
  1119. SET max_time_allowed = " . $max_time_allowed . "
  1120. WHERE id = " . $id;
  1121. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1122. }
  1123. // Update all the items with the same or a bigger display_order than the current item.
  1124. $sql_update_order = "
  1125. UPDATE " . $tbl_lp_item . "
  1126. SET display_order = display_order + 1
  1127. WHERE
  1128. lp_id = " . $this->get_id() . " AND
  1129. id <> " . $id . " AND
  1130. parent_item_id = " . $parent . " AND
  1131. display_order >= " . $new_order;
  1132. $res_update_next = Database::query($sql_update_order);
  1133. }
  1134. }
  1135. /**
  1136. * Updates an item's prereq in place
  1137. * @param integer Element ID
  1138. * @param string Prerequisite Element ID
  1139. * @param string Prerequisite item type
  1140. * @param string Prerequisite min score
  1141. * @param string Prerequisite max score
  1142. * @return boolean True on success, false on error
  1143. */
  1144. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1145. if ($this->debug > 0) {
  1146. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1147. }
  1148. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1149. return false;
  1150. }
  1151. $prerequisite_id = $this->escape_string($prerequisite_id);
  1152. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1153. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1154. $mastery_score = 0;
  1155. if (!is_numeric($max_score) || $max_score < 0)
  1156. $max_score = 100;
  1157. if ($mastery_score > $max_score)
  1158. $max_score = $mastery_score;
  1159. if (!is_numeric($prerequisite_id))
  1160. $prerequisite_id = 'NULL';
  1161. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1162. SET prerequisite = " . $prerequisite_id . " WHERE id = " . $id;
  1163. $res_upd = Database::query($sql_upd);
  1164. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1165. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1166. mastery_score = " . $mastery_score .
  1167. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1168. " WHERE ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1169. $res_upd = Database::query($sql_upd);
  1170. }
  1171. // TODO: Update the item object (can be ignored for now because refreshed).
  1172. return true;
  1173. }
  1174. /**
  1175. * Escapes a string with the available database escape function
  1176. * @param string String to escape
  1177. * @return string String escaped
  1178. */
  1179. public function escape_string($string) {
  1180. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1181. return Database :: escape_string($string);
  1182. }
  1183. /**
  1184. * Static admin function exporting a learnpath into a zip file
  1185. * @param string Export type (scorm, zip, cd)
  1186. * @param string Course code
  1187. * @param integer Learnpath ID
  1188. * @param string Zip file name
  1189. * @return string Zip file path (or false on error)
  1190. */
  1191. public function export_lp($type, $course, $id, $zipname) {
  1192. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1193. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1194. return false;
  1195. }
  1196. $url = '';
  1197. switch ($type) {
  1198. case 'scorm':
  1199. break;
  1200. case 'zip':
  1201. break;
  1202. case 'cdrom':
  1203. break;
  1204. }
  1205. return $url;
  1206. }
  1207. /**
  1208. * Gets all the chapters belonging to the same parent as the item/chapter given
  1209. * Can also be called as abstract method
  1210. * @param integer Item ID
  1211. * @return array A list of all the "brother items" (or an empty array on failure)
  1212. */
  1213. public function get_brother_chapters($id) {
  1214. if ($this->debug > 0) {
  1215. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1216. }
  1217. if (empty ($id) OR $id != strval(intval($id))) {
  1218. return array ();
  1219. }
  1220. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1221. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
  1222. $res_parent = Database::query($sql_parent);
  1223. if (Database :: num_rows($res_parent) > 0) {
  1224. $row_parent = Database :: fetch_array($res_parent);
  1225. $parent = $row_parent['parent_item_id'];
  1226. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1227. $res_bros = Database::query($sql_bros);
  1228. $list = array ();
  1229. while ($row_bro = Database :: fetch_array($res_bros)) {
  1230. $list[] = $row_bro;
  1231. }
  1232. return $list;
  1233. }
  1234. return array ();
  1235. }
  1236. /**
  1237. * Gets all the items belonging to the same parent as the item given
  1238. * Can also be called as abstract method
  1239. * @param integer Item ID
  1240. * @return array A list of all the "brother items" (or an empty array on failure)
  1241. */
  1242. public function get_brother_items($id) {
  1243. if ($this->debug > 0) {
  1244. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1245. }
  1246. if (empty ($id) OR $id != strval(intval($id))) {
  1247. return array ();
  1248. }
  1249. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1250. $sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
  1251. $res_parent = Database::query($sql_parent);
  1252. if (Database :: num_rows($res_parent) > 0) {
  1253. $row_parent = Database :: fetch_array($res_parent);
  1254. $parent = $row_parent['parent_item_id'];
  1255. $sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
  1256. $res_bros = Database::query($sql_bros);
  1257. $list = array ();
  1258. while ($row_bro = Database :: fetch_array($res_bros)) {
  1259. $list[] = $row_bro;
  1260. }
  1261. return $list;
  1262. }
  1263. return array ();
  1264. }
  1265. /**
  1266. * Get the specific prefix index terms of this learning path
  1267. * @return array Array of terms
  1268. */
  1269. public function get_common_index_terms_by_prefix($prefix) {
  1270. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1271. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1272. $prefix_terms = array();
  1273. if (!empty($terms)) {
  1274. foreach ($terms as $term) {
  1275. $prefix_terms[] = $term['value'];
  1276. }
  1277. }
  1278. return $prefix_terms;
  1279. }
  1280. /**
  1281. * Gets the number of items currently completed
  1282. * @return integer The number of items currently completed
  1283. */
  1284. public function get_complete_items_count() {
  1285. if ($this->debug > 0) {
  1286. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1287. }
  1288. $i = 0;
  1289. foreach ($this->items as $id => $dummy) {
  1290. // Trying failed and browsed considered "progressed" as well.
  1291. if ($this->items[$id]->status_is(array (
  1292. 'completed',
  1293. 'passed',
  1294. 'succeeded',
  1295. 'browsed',
  1296. 'failed'
  1297. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1298. $i++;
  1299. }
  1300. }
  1301. return $i;
  1302. }
  1303. /**
  1304. * Gets the current item ID
  1305. * @return integer The current learnpath item id
  1306. */
  1307. public function get_current_item_id() {
  1308. $current = 0;
  1309. if ($this->debug > 0) {
  1310. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1311. }
  1312. if (!empty ($this->current)) {
  1313. $current = $this->current;
  1314. }
  1315. if ($this->debug > 2) {
  1316. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1317. }
  1318. return $current;
  1319. }
  1320. /**
  1321. * Force to get the first learnpath item id
  1322. * @return integer The current learnpath item id
  1323. */
  1324. public function get_first_item_id() {
  1325. $current = 0;
  1326. if (is_array($this->ordered_items)) {
  1327. $current = $this->ordered_items[0];
  1328. }
  1329. return $current;
  1330. }
  1331. /**
  1332. * Gets the total number of items available for viewing in this SCORM
  1333. * @return integer The total number of items
  1334. */
  1335. public function get_total_items_count() {
  1336. if ($this->debug > 0) {
  1337. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1338. }
  1339. return count($this->items);
  1340. }
  1341. /**
  1342. * Gets the total number of items available for viewing in this SCORM but without chapters
  1343. * @return integer The total no-chapters number of items
  1344. */
  1345. public function get_total_items_count_without_chapters() {
  1346. if ($this->debug > 0) {
  1347. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1348. }
  1349. $total = 0;
  1350. foreach ($this->items as $temp => $temp2) {
  1351. if (!in_array($temp2->get_type(), array (
  1352. 'dokeos_chapter',
  1353. 'chapter',
  1354. 'dir'
  1355. )))
  1356. $total++;
  1357. }
  1358. return $total;
  1359. }
  1360. /**
  1361. * Gets the first element URL.
  1362. * @return string URL to load into the viewer
  1363. */
  1364. public function first() {
  1365. if ($this->debug > 0) {
  1366. error_log('New LP - In learnpath::first()', 0);
  1367. }
  1368. // Test if the last_item_seen exists and is not a dir.
  1369. if (count($this->ordered_items) == 0) {
  1370. $this->index = 0;
  1371. }
  1372. 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()) {
  1373. if ($this->debug > 2) {
  1374. 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);
  1375. }
  1376. $index = -1;
  1377. foreach ($this->ordered_items as $myindex => $item_id) {
  1378. if ($item_id == $this->last_item_seen) {
  1379. $index = $myindex;
  1380. break;
  1381. }
  1382. }
  1383. if ($index == -1) {
  1384. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1385. if ($this->debug > 2) {
  1386. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1387. }
  1388. return false;
  1389. } else {
  1390. $this->last = $this->last_item_seen;
  1391. $this->current = $this->last_item_seen;
  1392. $this->index = $index;
  1393. }
  1394. } else {
  1395. if ($this->debug > 2) {
  1396. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1397. }
  1398. $index = 0;
  1399. // Loop through all ordered items and stop at the first item that is
  1400. // not a directory *and* that has not been completed yet.
  1401. 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) {
  1402. $index++;
  1403. }
  1404. $this->last = $this->current;
  1405. // current is
  1406. $this->current = $this->ordered_items[$index];
  1407. $this->index = $index;
  1408. if ($this->debug > 2) {
  1409. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1410. }
  1411. }
  1412. if ($this->debug > 2) {
  1413. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1414. }
  1415. }
  1416. /**
  1417. * Gets the information about an item in a format usable as JavaScript to update
  1418. * the JS API by just printing this content into the <head> section of the message frame
  1419. * @param integer Item ID
  1420. * @return string
  1421. */
  1422. public function get_js_info($item_id = '') {
  1423. if ($this->debug > 0) {
  1424. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1425. }
  1426. $info = '';
  1427. $item_id = $this->escape_string($item_id);
  1428. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1429. //if item is defined, return values from DB
  1430. $oItem = $this->items[$item_id];
  1431. $info .= '<script language="javascript">';
  1432. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1433. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1434. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1435. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1436. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1437. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1438. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1439. $info .= "top.set_flag_synchronized();";
  1440. $info .= '</script>';
  1441. if ($this->debug > 2) {
  1442. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1443. }
  1444. return $info;
  1445. } else {
  1446. // If item_id is empty, just update to default SCORM data.
  1447. $info .= '<script language="javascript">';
  1448. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1449. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1450. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1451. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1452. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1453. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1454. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1455. $info .= "top.set_flag_synchronized();";
  1456. $info .= '</script>';
  1457. if ($this->debug > 2) {
  1458. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1459. }
  1460. return $info;
  1461. }
  1462. }
  1463. /**
  1464. * Gets the js library from the database
  1465. * @return string The name of the javascript library to be used
  1466. */
  1467. public function get_js_lib() {
  1468. $lib = '';
  1469. if (!empty ($this->js_lib)) {
  1470. $lib = $this->js_lib;
  1471. }
  1472. return $lib;
  1473. }
  1474. /**
  1475. * Gets the learnpath database ID
  1476. * @return integer Learnpath ID in the lp table
  1477. */
  1478. public function get_id() {
  1479. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1480. if (!empty ($this->lp_id)) {
  1481. return $this->lp_id;
  1482. } else {
  1483. return 0;
  1484. }
  1485. }
  1486. /**
  1487. * Gets the last element URL.
  1488. * @return string URL to load into the viewer
  1489. */
  1490. public function get_last() {
  1491. if ($this->debug > 0) {
  1492. error_log('New LP - In learnpath::get_last()', 0);
  1493. }
  1494. $this->index = count($this->ordered_items) - 1;
  1495. return $this->ordered_items[$this->index];
  1496. }
  1497. /**
  1498. * Gets the navigation bar for the learnpath display screen
  1499. * @return string The HTML string to use as a navigation bar
  1500. */
  1501. public function get_navigation_bar() {
  1502. if ($this->debug > 0) {
  1503. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1504. }
  1505. // TODO: Find a good value for the following variables.
  1506. $file = '';
  1507. $openDir = '';
  1508. $edoceo = '';
  1509. $time = 0;
  1510. $navbar = '';
  1511. $RequestUri = '';
  1512. $mycurrentitemid = $this->get_current_item_id();
  1513. if ($this->mode == 'fullscreen') {
  1514. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1515. ' <tr> ' . "\n" .
  1516. ' <td>' . "\n" .
  1517. ' <div class="buttons">' . "\n" .
  1518. ' <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" .
  1519. ' <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" .
  1520. ' <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" .
  1521. //' <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" .
  1522. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1523. ' </div>' . "\n" .
  1524. ' </td>' . "\n" .
  1525. ' </tr>' . "\n" .
  1526. '</table>' . "\n";
  1527. } else {
  1528. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1529. ' <tr> ' . "\n" .
  1530. ' <td>' . "\n" .
  1531. ' <div class="buttons">' . "\n" .
  1532. ' <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" .
  1533. ' <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" .
  1534. ' <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" .
  1535. // ' <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" .
  1536. ' </div>' . "\n" .
  1537. ' </td>' . "\n" .
  1538. ' </tr>' . "\n" .
  1539. '</table>' . "\n";
  1540. }
  1541. return $navbar;
  1542. }
  1543. /**
  1544. * Gets the next resource in queue (url).
  1545. * @return string URL to load into the viewer
  1546. */
  1547. public function get_next_index() {
  1548. if ($this->debug > 0) {
  1549. error_log('New LP - In learnpath::get_next_index()', 0);
  1550. }
  1551. // TODO
  1552. $index = $this->index;
  1553. $index++;
  1554. if ($this->debug > 2) {
  1555. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1556. }
  1557. 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) {
  1558. $index++;
  1559. if ($index == $this->max_ordered_items){
  1560. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1561. return $this->index;
  1562. } else {
  1563. return $index;
  1564. }
  1565. }
  1566. }
  1567. if (empty ($this->ordered_items[$index])) {
  1568. return $this->index;
  1569. }
  1570. if ($this->debug > 2) {
  1571. error_log('New LP - index is now ' . $index, 0);
  1572. }
  1573. return $index;
  1574. }
  1575. /**
  1576. * Gets item_id for the next element
  1577. * @return integer Next item (DB) ID
  1578. */
  1579. public function get_next_item_id() {
  1580. if ($this->debug > 0) {
  1581. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1582. }
  1583. $new_index = $this->get_next_index();
  1584. if (!empty ($new_index)) {
  1585. if (isset ($this->ordered_items[$new_index])) {
  1586. if ($this->debug > 2) {
  1587. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1588. }
  1589. return $this->ordered_items[$new_index];
  1590. }
  1591. }
  1592. if ($this->debug > 2) {
  1593. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1594. }
  1595. return 0;
  1596. }
  1597. /**
  1598. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1599. *
  1600. * Generally, the package provided is in the form of a zip file, so the function
  1601. * has been written to test a zip file. If not a zip, the function will return the
  1602. * default return value: ''
  1603. * @param string the path to the file
  1604. * @param string the original name of the file
  1605. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1606. */
  1607. public function get_package_type($file_path, $file_name) {
  1608. // Get name of the zip file without the extension.
  1609. $file_info = pathinfo($file_name);
  1610. $filename = $file_info['basename']; // Name including extension.
  1611. $extension = $file_info['extension']; // Extension only.
  1612. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1613. 'dll',
  1614. 'exe'
  1615. ))) {
  1616. return 'oogie';
  1617. }
  1618. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1619. 'dll',
  1620. 'exe'
  1621. ))) {
  1622. return 'woogie';
  1623. }
  1624. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1625. $zipFile = new pclZip($file_path);
  1626. // Check the zip content (real size and file extension).
  1627. $zipContentArray = $zipFile->listContent();
  1628. $package_type = '';
  1629. $at_root = false;
  1630. $manifest = '';
  1631. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1632. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1633. foreach ($zipContentArray as $thisContent) {
  1634. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1635. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1636. }
  1637. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1638. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1639. $package_type = 'scorm';
  1640. break; // Exit the foreach loop.
  1641. }
  1642. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1643. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1644. $package_type = 'aicc';
  1645. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1646. } else {
  1647. $package_type = '';
  1648. }
  1649. }
  1650. }
  1651. return $package_type;
  1652. }
  1653. /**
  1654. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1655. * @return string URL to load into the viewer
  1656. */
  1657. public function get_previous_index() {
  1658. if ($this->debug > 0) {
  1659. error_log('New LP - In learnpath::get_previous_index()', 0);
  1660. }
  1661. $index = $this->index;
  1662. if (isset ($this->ordered_items[$index -1])) {
  1663. $index--;
  1664. 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')) {
  1665. $index--;
  1666. if ($index < 0) {
  1667. return $this->index;
  1668. }
  1669. }
  1670. } else {
  1671. if ($this->debug > 2) {
  1672. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1673. }
  1674. // There is no previous item.
  1675. }
  1676. return $index;
  1677. }
  1678. /**
  1679. * Gets item_id for the next element
  1680. * @return integer Previous item (DB) ID
  1681. */
  1682. public function get_previous_item_id() {
  1683. if ($this->debug > 0) {
  1684. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1685. }
  1686. $new_index = $this->get_previous_index();
  1687. return $this->ordered_items[$new_index];
  1688. }
  1689. /**
  1690. * Gets the progress value from the progress_db attribute
  1691. * @return integer Current progress value
  1692. */
  1693. public function get_progress() {
  1694. if ($this->debug > 0) {
  1695. error_log('New LP - In learnpath::get_progress()', 0);
  1696. }
  1697. if (!empty ($this->progress_db)) {
  1698. return $this->progress_db;
  1699. }
  1700. return 0;
  1701. }
  1702. /**
  1703. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1704. * @param integer Learnpath ID
  1705. * @param integer User ID
  1706. * @param string Mode of display ('%','abs' or 'both')
  1707. * @param string Course database name (optional, defaults to '')
  1708. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1709. * @return integer Current progress value as found in the database
  1710. */
  1711. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false,$session_id = 0) {
  1712. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1713. $session_id = intval($session_id);
  1714. $session_condition = api_get_session_condition($session_id);
  1715. $table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
  1716. $sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
  1717. $res = Database::query($sql);
  1718. $view_id = 0;
  1719. if (Database :: num_rows($res) > 0) {
  1720. $row = Database :: fetch_array($res);
  1721. $progress = $row['progress'];
  1722. $view_id = $row['id'];
  1723. } else {
  1724. if ($sincere) {
  1725. return null;
  1726. }
  1727. }
  1728. if (empty ($progress)) {
  1729. $progress = '0';
  1730. }
  1731. if ($mode == '%') {
  1732. return $progress . '%';
  1733. } else {
  1734. // Get the number of items completed and the number of items total.
  1735. $tbl = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1736. $sql = "SELECT count(*) FROM $tbl WHERE lp_id = " . $lp_id . "
  1737. AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1738. $res = Database::query($sql);
  1739. $row = Database :: fetch_array($res);
  1740. $total = $row[0];
  1741. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_db);
  1742. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  1743. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1744. // Trying as also counting browsed and failed items.
  1745. $sql = "SELECT count(distinct(lp_item_id))
  1746. FROM $tbl_item_view as item_view
  1747. INNER JOIN $tbl_item as item
  1748. ON item.id = item_view.lp_item_id
  1749. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1750. WHERE lp_view_id = " . $view_id . "
  1751. AND status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1752. $res = Database::query($sql);
  1753. $row = Database :: fetch_array($res);
  1754. $completed = $row[0];
  1755. if ($mode == 'abs') {
  1756. return $completed . '/' . $total;
  1757. }
  1758. elseif ($mode == 'both') {
  1759. if ($progress < ($completed / ($total ? $total : 1))) {
  1760. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1761. }
  1762. return $progress . '% (' . $completed . '/' . $total . ')';
  1763. }
  1764. }
  1765. return $progress;
  1766. }
  1767. /**
  1768. * Returns the HTML necessary to print a mediaplayer block inside a page
  1769. * @return string The mediaplayer HTML
  1770. */
  1771. public function get_mediaplayer($autostart='true') {
  1772. global $_course;
  1773. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1774. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1775. // Getting all the information about the item.
  1776. $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 " .
  1777. "WHERE lp.id = '" . $_SESSION['oLP']->current . "'";
  1778. $result = Database::query($sql);
  1779. $row = Database::fetch_assoc($result);
  1780. $output = '';
  1781. if (!empty ($row['audio'])) {
  1782. $list = $_SESSION['oLP']->get_toc();
  1783. $type_quiz = false;
  1784. foreach($list as $toc) {
  1785. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1786. $type_quiz = true;
  1787. }
  1788. }
  1789. if ($type_quiz) {
  1790. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1791. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1792. } else {
  1793. $autostart_audio = $autostart;
  1794. }
  1795. } else {
  1796. $autostart_audio = 'true';
  1797. }
  1798. // The mp3 player.
  1799. $output = '<div id="container">';
  1800. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1801. $output .= '<script type="text/javascript">
  1802. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1803. s1.addParam("allowscriptaccess","always");
  1804. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1805. s1.write("container");
  1806. </script></div>';
  1807. }
  1808. return $output;
  1809. }
  1810. /**
  1811. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1812. * @param int Learnpath id
  1813. * @param int Student id
  1814. * @param string Course code (optional)
  1815. * @return bool True if
  1816. */
  1817. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1818. $lp_id = (int)$lp_id;
  1819. $course = api_get_course_info($course);
  1820. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN,$course['dbName']);
  1821. // Get current prerequisite
  1822. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE id = $lp_id";
  1823. $rs = Database::query($sql);
  1824. if (Database::num_rows($rs)>0) {
  1825. $row = Database::fetch_array($rs);
  1826. $prerequisite = $row['prerequisite'];
  1827. $find = array(' ','-',':');
  1828. $from = str_replace($find,'',api_get_local_time($row['publicated_on']));
  1829. $to = str_replace($find,'',api_get_local_time($row['expired_on']));
  1830. $is_visible = true;
  1831. $progress = 0;
  1832. if (!empty($prerequisite)) {
  1833. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1834. $progress = intval($progress);
  1835. if ($progress < 100) {
  1836. $is_visible = false;
  1837. }
  1838. }
  1839. // Also check the time availability of the learning path
  1840. if ($is_visible) {
  1841. $now = str_replace($find,'',api_get_local_time());
  1842. if ((($row['publicated_on']!='0000-00-00 00:00:00') && ($now<$from)) or (($row['expired_on']!='0000-00-00 00:00:00') && ($now>$to))) {
  1843. $is_visible = false;
  1844. }
  1845. }
  1846. return $is_visible;
  1847. }
  1848. return false;
  1849. }
  1850. /**
  1851. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1852. * completed so far.
  1853. * @param string Mode in which we want the values
  1854. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1855. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1856. * @param boolean true if it comes from a Diplay LP view
  1857. * @return string HTML string containing the progress bar
  1858. */
  1859. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1860. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1861. global $lp_theme_css;
  1862. // Setting up the CSS path of the current style if exists.
  1863. if (!empty ($lp_theme_css)) {
  1864. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1865. } else {
  1866. $css_path = '../img/';
  1867. }
  1868. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1869. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1870. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1871. }
  1872. $text = $percentage . $text_add;
  1873. // Default progress bar config
  1874. // times that will be greater or shorter
  1875. $factor = 1.2;
  1876. if ($from_lp)
  1877. $progress_height = '26';
  1878. else
  1879. $progress_height = '16';
  1880. $size = str_replace('%', '', $percentage);
  1881. $output ='<div style="width:135px">' .
  1882. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1883. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1884. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1885. if ($percentage <= 98) {
  1886. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1887. } else {
  1888. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1889. }
  1890. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1891. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1892. return $output;
  1893. }
  1894. /**
  1895. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1896. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1897. * @param integer Additional steps to fake as completed
  1898. * @return list Percentage or number and symbol (% or /xx)
  1899. */
  1900. public function get_progress_bar_text($mode = '', $add = 0) {
  1901. if ($this->debug > 0) {
  1902. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1903. }
  1904. if (empty ($mode)) {
  1905. $mode = $this->progress_bar_mode;
  1906. }
  1907. $total_items = $this->get_total_items_count_without_chapters();
  1908. if ($this->debug > 2) {
  1909. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1910. }
  1911. $i = $this->get_complete_items_count();
  1912. if ($this->debug > 2) {
  1913. error_log('New LP - Items completed so far: ' . $i, 0);
  1914. }
  1915. if ($add != 0) {
  1916. $i += $add;
  1917. if ($this->debug > 2) {
  1918. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1919. }
  1920. }
  1921. $text = '';
  1922. if ($i > $total_items) {
  1923. $i = $total_items;
  1924. }
  1925. if ($mode == '%') {
  1926. if ($total_items > 0) {
  1927. $percentage = ((float) $i / (float) $total_items) * 100;
  1928. } else {
  1929. $percentage = 0;
  1930. }
  1931. $percentage = number_format($percentage, 0);
  1932. $text = '%';
  1933. }
  1934. elseif ($mode == 'abs') {
  1935. $percentage = $i;
  1936. $text = '/' . $total_items;
  1937. }
  1938. return array (
  1939. $percentage,
  1940. $text
  1941. );
  1942. }
  1943. /**
  1944. * Gets the progress bar mode
  1945. * @return string The progress bar mode attribute
  1946. */
  1947. public function get_progress_bar_mode() {
  1948. if ($this->debug > 0) {
  1949. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1950. }
  1951. if (!empty ($this->progress_bar_mode)) {
  1952. return $this->progress_bar_mode;
  1953. } else {
  1954. return '%';
  1955. }
  1956. }
  1957. /**
  1958. * Gets the learnpath proximity (remote or local)
  1959. * @return string Learnpath proximity
  1960. */
  1961. public function get_proximity() {
  1962. if ($this->debug > 0) {
  1963. error_log('New LP - In learnpath::get_proximity()', 0);
  1964. }
  1965. if (!empty ($this->proximity)) {
  1966. return $this->proximity;
  1967. } else {
  1968. return '';
  1969. }
  1970. }
  1971. /**
  1972. * Gets the learnpath theme (remote or local)
  1973. * @return string Learnpath theme
  1974. */
  1975. public function get_theme() {
  1976. if ($this->debug > 0) {
  1977. error_log('New LP - In learnpath::get_theme()', 0);
  1978. }
  1979. if (!empty ($this->theme)) {
  1980. return $this->theme;
  1981. } else {
  1982. return '';
  1983. }
  1984. }
  1985. /**
  1986. * Gets the learnpath session id
  1987. * @return string Learnpath theme
  1988. */
  1989. public function get_lp_session_id() {
  1990. if ($this->debug > 0) {
  1991. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  1992. }
  1993. if (!empty ($this->lp_session_id)) {
  1994. return $this->lp_session_id;
  1995. } else {
  1996. return 0;
  1997. }
  1998. }
  1999. /**
  2000. * Gets the learnpath image
  2001. * @return string Web URL of the LP image
  2002. */
  2003. public function get_preview_image() {
  2004. if ($this->debug > 0) {
  2005. error_log('New LP - In learnpath::get_preview_image()', 0);
  2006. }
  2007. if (!empty ($this->preview_image)) {
  2008. return $this->preview_image;
  2009. } else {
  2010. return '';
  2011. }
  2012. }
  2013. /**
  2014. * Gets the learnpath author
  2015. * @return string LP's author
  2016. */
  2017. public function get_author() {
  2018. if ($this->debug > 0) {
  2019. error_log('New LP - In learnpath::get_author()', 0);
  2020. }
  2021. if (!empty ($this->author)) {
  2022. return $this->author;
  2023. } else {
  2024. return '';
  2025. }
  2026. }
  2027. /**
  2028. * Generate a new prerequisites string for a given item. If this item was a sco and
  2029. * its prerequisites were strings (instead of IDs), then transform those strings into
  2030. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2031. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2032. * same rule as the scorm_export() method
  2033. * @param integer Item ID
  2034. * @return string Prerequisites string ready for the export as SCORM
  2035. */
  2036. public function get_scorm_prereq_string($item_id) {
  2037. if ($this->debug > 0) {
  2038. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2039. }
  2040. if (!is_object($this->items[$item_id])) {
  2041. return false;
  2042. }
  2043. $oItem = $this->items[$item_id];
  2044. $prereq = $oItem->get_prereq_string();
  2045. if (empty ($prereq)) {
  2046. return '';
  2047. }
  2048. 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,
  2049. // then simply return it (with the ITEM_ prefix).
  2050. return 'ITEM_' . $prereq;
  2051. } else {
  2052. if (isset ($this->refs_list[$prereq])) {
  2053. // It's a simple string item from which the ID can be found in the refs list,
  2054. // so we can transform it directly to an ID for export.
  2055. return 'ITEM_' . $this->refs_list[$prereq];
  2056. } else {
  2057. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2058. // and replace them, one by one, by the internal IDs (chamilo db)
  2059. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2060. // by a space as well.
  2061. $find = array (
  2062. '&',
  2063. '|',
  2064. '~',
  2065. '=',
  2066. '<>',
  2067. '{',
  2068. '}',
  2069. '*',
  2070. '(',
  2071. ')'
  2072. );
  2073. $replace = array (
  2074. ' ',
  2075. ' ',
  2076. ' ',
  2077. ' ',
  2078. ' ',
  2079. ' ',
  2080. ' ',
  2081. ' ',
  2082. ' ',
  2083. ' '
  2084. );
  2085. $prereq_mod = str_replace($find, $replace, $prereq);
  2086. $ids = split(' ', $prereq_mod);
  2087. foreach ($ids as $id) {
  2088. $id = trim($id);
  2089. if (isset ($this->refs_list[$id])) {
  2090. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2091. }
  2092. }
  2093. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2094. return $prereq;
  2095. }
  2096. }
  2097. }
  2098. /**
  2099. * Returns the XML DOM document's node
  2100. * @param resource Reference to a list of objects to search for the given ITEM_*
  2101. * @param string The identifier to look for
  2102. * @return mixed The reference to the element found with that identifier. False if not found
  2103. */
  2104. public function get_scorm_xml_node(& $children, $id) {
  2105. for ($i = 0; $i < $children->length; $i++) {
  2106. $item_temp = $children->item($i);
  2107. if ($item_temp->nodeName == 'item') {
  2108. if ($item_temp->getAttribute('identifier') == $id) {
  2109. return $item_temp;
  2110. }
  2111. }
  2112. $subchildren = $item_temp->childNodes;
  2113. if ($subchildren->length > 0) {
  2114. $val = $this->get_scorm_xml_node($subchildren, $id);
  2115. if (is_object($val)) {
  2116. return $val;
  2117. }
  2118. }
  2119. }
  2120. return false;
  2121. }
  2122. /**
  2123. * Returns a usable array of stats related to the current learnpath and user
  2124. * @return array Well-formatted array containing status for the current learnpath
  2125. */
  2126. public function get_stats() {
  2127. if ($this->debug > 0) {
  2128. error_log('New LP - In learnpath::get_stats()', 0);
  2129. }
  2130. // TODO
  2131. }
  2132. /**
  2133. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2134. * the given course (for all learnpaths and all users)
  2135. * @param string Course code
  2136. * @return array Well-formatted array containing status for the course's learnpaths
  2137. */
  2138. public function get_stats_course($course) {
  2139. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2140. // TODO
  2141. }
  2142. /**
  2143. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2144. * the given course and learnpath (for all users)
  2145. * @param string Course code
  2146. * @param integer Learnpath ID
  2147. * @return array Well-formatted array containing status for the specified learnpath
  2148. */
  2149. public function get_stats_lp($course, $lp) {
  2150. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2151. // TODO
  2152. }
  2153. /**
  2154. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2155. * the given course, learnpath and user.
  2156. * @param string Course code
  2157. * @param integer Learnpath ID
  2158. * @param integer User ID
  2159. * @return array Well-formatted array containing status for the specified learnpath and user
  2160. */
  2161. public function get_stats_lp_user($course, $lp, $user) {
  2162. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2163. // TODO
  2164. }
  2165. /**
  2166. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2167. * the given course and learnpath (for all users)
  2168. * @param string Course code
  2169. * @param integer User ID
  2170. * @return array Well-formatted array containing status for the user's learnpaths
  2171. */
  2172. public function get_stats_user($course, $user) {
  2173. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2174. // TODO
  2175. }
  2176. /**
  2177. * Gets the status list for all LP's items
  2178. * @return array Array of [index] => [item ID => current status]
  2179. */
  2180. public function get_items_status_list() {
  2181. if ($this->debug > 0) {
  2182. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2183. }
  2184. $list = array ();
  2185. foreach ($this->ordered_items as $item_id) {
  2186. $list[] = array (
  2187. $item_id => $this->items[$item_id]->get_status()
  2188. );
  2189. }
  2190. return $list;
  2191. }
  2192. /**
  2193. * Return the number of interactions for the given learnpath Item View ID.
  2194. * This method can be used as static.
  2195. * @param integer Item View ID
  2196. * @return integer Number of interactions
  2197. */
  2198. public function get_interactions_count_from_db($lp_iv_id = 0) {
  2199. if (empty ($lp_iv_id)) {
  2200. return -1;
  2201. }
  2202. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2203. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2204. $res = Database::query($sql);
  2205. $row = Database :: fetch_array($res);
  2206. $num = $row[0];
  2207. return $num;
  2208. }
  2209. /**
  2210. * Return the interactions as an array for the given lp_iv_id.
  2211. * This method can be used as static.
  2212. * @param integer Learnpath Item View ID
  2213. * @return array
  2214. * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2215. */
  2216. public function get_iv_interactions_array($lp_iv_id = 0) {
  2217. $list = array ();
  2218. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2219. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2220. $res = Database::query($sql);
  2221. $num = Database :: num_rows($res);
  2222. if ($num > 0) {
  2223. $list[] = array (
  2224. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2225. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2226. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2227. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2228. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2229. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2230. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2231. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2232. );
  2233. while ($row = Database :: fetch_array($res)) {
  2234. $list[] = array (
  2235. 'order_id' => ($row['order_id'] + 1),
  2236. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2237. 'type' => $row['interaction_type'],
  2238. 'time' => $row['completion_time'],
  2239. //'correct_responses' => $row['correct_responses'],
  2240. 'correct_responses' => '', // Hide correct responses from students.
  2241. 'student_response' => $row['student_response'],
  2242. 'result' => $row['result'],
  2243. 'latency' => $row['latency']
  2244. );
  2245. }
  2246. }
  2247. return $list;
  2248. }
  2249. /**
  2250. * Return the number of objectives for the given learnpath Item View ID.
  2251. * This method can be used as static.
  2252. * @param integer Item View ID
  2253. * @return integer Number of objectives
  2254. */
  2255. public function get_objectives_count_from_db($lp_iv_id = 0) {
  2256. if (empty ($lp_iv_id)) {
  2257. return -1;
  2258. }
  2259. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2260. $sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
  2261. $res = Database::query($sql);
  2262. $row = Database :: fetch_array($res);
  2263. $num = $row[0];
  2264. return $num;
  2265. }
  2266. /**
  2267. * Return the objectives as an array for the given lp_iv_id.
  2268. * This method can be used as static.
  2269. * @param integer Learnpath Item View ID
  2270. * @return array
  2271. * @todo Translate labels
  2272. */
  2273. public function get_iv_objectives_array($lp_iv_id = 0) {
  2274. $list = array();
  2275. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2276. $sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2277. $res = Database::query($sql);
  2278. $num = Database :: num_rows($res);
  2279. if ($num > 0) {
  2280. $list[] = array (
  2281. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2282. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2283. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2284. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2285. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2286. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2287. );
  2288. while ($row = Database :: fetch_array($res)) {
  2289. $list[] = array (
  2290. 'order_id' => ($row['order_id'] + 1),
  2291. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2292. 'score_raw' => $row['score_raw'],
  2293. 'score_max' => $row['score_max'],
  2294. 'score_min' => $row['score_min'],
  2295. 'status' => $row['status']
  2296. );
  2297. }
  2298. }
  2299. return $list;
  2300. }
  2301. /**
  2302. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2303. * used by get_html_toc() to be ready to display
  2304. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2305. */
  2306. public function get_toc() {
  2307. if ($this->debug > 0) {
  2308. error_log('New LP - In learnpath::get_toc()', 0);
  2309. }
  2310. $toc = array ();
  2311. //echo "<pre>".print_r($this->items,true)."</pre>";
  2312. foreach ($this->ordered_items as $item_id) {
  2313. if ($this->debug > 2) {
  2314. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2315. }
  2316. // TODO: Change this link generation and use new function instead.
  2317. $toc[] = array (
  2318. 'id' => $item_id,
  2319. 'title' => $this->items[$item_id]->get_title(),
  2320. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2321. 'status' => $this->items[$item_id]->get_status(),
  2322. 'level' => $this->items[$item_id]->get_level(),
  2323. 'type' => $this->items[$item_id]->get_type(),
  2324. 'description' => $this->items[$item_id]->get_description(),
  2325. 'path' => $this->items[$item_id]->get_path(),
  2326. );
  2327. }
  2328. if ($this->debug > 2) {
  2329. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2330. }
  2331. return $toc;
  2332. }
  2333. /**
  2334. * Generate and return the table of contents for this learnpath. The JS
  2335. * table returned is used inside of scorm_api.php
  2336. * @return string A JS array vairiable construction
  2337. */
  2338. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2339. if ($this->debug > 0) {
  2340. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2341. }
  2342. $toc = $varname.' = new Array();';
  2343. //echo "<pre>".print_r($this->items,true)."</pre>";
  2344. foreach ($this->ordered_items as $item_id) {
  2345. if ($this->debug > 2) {
  2346. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2347. }
  2348. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2349. }
  2350. if ($this->debug > 2) {
  2351. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2352. }
  2353. return $toc;
  2354. }
  2355. /**
  2356. * Gets the learning path type
  2357. * @param boolean Return the name? If false, return the ID. Default is false.
  2358. * @return mixed Type ID or name, depending on the parameter
  2359. */
  2360. public function get_type($get_name = false) {
  2361. $res = false;
  2362. if ($this->debug > 0) {
  2363. error_log('New LP - In learnpath::get_type()', 0);
  2364. }
  2365. if (!empty ($this->type)) {
  2366. if ($get_name) {
  2367. // Get it from the lp_type table in main db.
  2368. } else {
  2369. $res = $this->type;
  2370. }
  2371. }
  2372. if ($this->debug > 2) {
  2373. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2374. }
  2375. return $res;
  2376. }
  2377. /**
  2378. * Gets the learning path type as static method
  2379. * @param boolean Return the name? If false, return the ID. Default is false.
  2380. * @return mixed Type ID or name, depending on the parameter
  2381. */
  2382. public function get_type_static($lp_id = 0) {
  2383. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2384. $sql = "SELECT lp_type FROM $tbl_lp WHERE id = '" . $lp_id . "'";
  2385. $res = Database::query($sql);
  2386. if ($res === false) {
  2387. return null;
  2388. }
  2389. if (Database :: num_rows($res) <= 0) {
  2390. return null;
  2391. }
  2392. $row = Database :: fetch_array($res);
  2393. return $row['lp_type'];
  2394. }
  2395. /**
  2396. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2397. * This method can be used as abstract and is recursive
  2398. * @param integer Learnpath ID
  2399. * @param integer Parent ID of the items to look for
  2400. * @return mixed Ordered list of item IDs or false on error
  2401. */
  2402. public function get_flat_ordered_items_list($lp, $parent = 0, $course_db = '') {
  2403. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')', 0); }
  2404. $list = array();
  2405. if (empty ($lp)) {
  2406. return false;
  2407. }
  2408. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $course_db);
  2409. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2410. $res = Database::query($sql);
  2411. while ($row = Database :: fetch_array($res)) {
  2412. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_db);
  2413. $list[] = $row['id'];
  2414. foreach ($sublist as $item) {
  2415. $list[] = $item;
  2416. }
  2417. }
  2418. return $list;
  2419. }
  2420. /**
  2421. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2422. * @return string HTML TOC ready to display
  2423. */
  2424. public function get_html_toc() {
  2425. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2426. $charset = api_get_system_encoding();
  2427. $display_action_links_with_icons = false;
  2428. if ($this->debug > 0) {
  2429. error_log('New LP - In learnpath::get_html_toc()', 0);
  2430. }
  2431. $list = $this->get_toc();
  2432. //echo $this->current;
  2433. //$parent = $this->items[$this->current]->get_parent();
  2434. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2435. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2436. // Build, display.
  2437. if ($is_allowed_to_edit) {
  2438. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2439. //var_dump($this->get_lp_session_id());
  2440. if ($this->get_lp_session_id() == api_get_session_id()) {
  2441. $html .= '<div id="actions_lp" class="actions_lp">';
  2442. if ($display_action_links_with_icons) {
  2443. $html .= '<div style = "text-align:center;">';
  2444. $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>";
  2445. $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>";
  2446. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2447. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2448. $html .= '</div>';
  2449. } else {
  2450. $html .= '<div style = "text-align:center;">';
  2451. $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>";
  2452. $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>";
  2453. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2454. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2455. $html .= '</div>';
  2456. }
  2457. $html .= '</div>';
  2458. }
  2459. }
  2460. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2461. require_once 'resourcelinker.inc.php';
  2462. // Temporary variables.
  2463. $mycurrentitemid = $this->get_current_item_id();
  2464. $color_counter = 0;
  2465. $i = 0;
  2466. foreach ($list as $item) {
  2467. if ($this->debug > 2) {
  2468. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2469. }
  2470. // TODO: Complete this.
  2471. $icon_name = array (
  2472. 'not attempted' => '../img/notattempted.gif',
  2473. 'incomplete' => '../img/incomplete.png',
  2474. 'failed' => '../img/delete.png',
  2475. 'completed' => '../img/completed.png',
  2476. 'passed' => '../img/passed.gif',
  2477. 'succeeded' => '../img/succeeded.gif',
  2478. 'browsed' => '../img/completed.png',
  2479. );
  2480. $style = 'scorm_item';
  2481. $scorm_color_background = 'scorm_item';
  2482. $style_item = 'scorm_item';
  2483. $current = false;
  2484. if ($item['id'] == $this->current) {
  2485. $style = 'scorm_item_highlight';
  2486. $scorm_color_background = 'scorm_item_highlight';
  2487. } else
  2488. if ($color_counter % 2 == 0) {
  2489. $scorm_color_background = 'scorm_item_1';
  2490. } else {
  2491. $scorm_color_background = 'scorm_item_2';
  2492. }
  2493. if ($scorm_color_background != '') {
  2494. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2495. }
  2496. // The anchor will let us center the TOC on the currently viewed item &^D
  2497. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2498. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2499. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2500. } else {
  2501. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2502. }
  2503. $title = $item['title'];
  2504. if (empty ($title)) {
  2505. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2506. }
  2507. $title = Security::remove_XSS($title);
  2508. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2509. //$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>" ;
  2510. $url = $this->get_link('http', $item['id']);
  2511. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2512. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2513. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2514. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2515. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2516. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2517. } elseif ($item['type'] == 'dir') {
  2518. $html .= stripslashes($title);
  2519. }
  2520. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2521. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2522. $user_id = api_get_user_id();
  2523. $course_id = api_get_course_id();
  2524. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2525. WHERE path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
  2526. $result = Database::query($sql);
  2527. $count = Database :: num_rows($result);
  2528. if ($item['type'] == 'quiz') {
  2529. if ($item['status'] == 'completed') {
  2530. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2531. }
  2532. } else {
  2533. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2534. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2535. }
  2536. }
  2537. $html .= "</div>";
  2538. if ($scorm_color_background != '') {
  2539. $html .= '</div>';
  2540. }
  2541. $color_counter++;
  2542. }
  2543. $html .= "</div>";
  2544. return $html;
  2545. }
  2546. /**
  2547. * Gets the learnpath maker name - generally the editor's name
  2548. * @return string Learnpath maker name
  2549. */
  2550. public function get_maker() {
  2551. if ($this->debug > 0) {
  2552. error_log('New LP - In learnpath::get_maker()', 0);
  2553. }
  2554. if (!empty ($this->maker)) {
  2555. return $this->maker;
  2556. } else {
  2557. return '';
  2558. }
  2559. }
  2560. /**
  2561. * Gets the user-friendly message stored in $this->message
  2562. * @return string Message
  2563. */
  2564. public function get_message() {
  2565. if ($this->debug > 0) {
  2566. error_log('New LP - In learnpath::get_message()', 0);
  2567. }
  2568. return $this->message;
  2569. }
  2570. /**
  2571. * Gets the learnpath name/title
  2572. * @return string Learnpath name/title
  2573. */
  2574. public function get_name() {
  2575. if ($this->debug > 0) {
  2576. error_log('New LP - In learnpath::get_name()', 0);
  2577. }
  2578. if (!empty ($this->name)) {
  2579. return $this->name;
  2580. } else {
  2581. return 'N/A';
  2582. }
  2583. }
  2584. /**
  2585. * Gets a link to the resource from the present location, depending on item ID.
  2586. * @param string Type of link expected
  2587. * @param integer Learnpath item ID
  2588. * @return string Link to the lp_item resource
  2589. */
  2590. public function get_link($type = 'http', $item_id = null) {
  2591. if ($this->debug > 0) {
  2592. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2593. }
  2594. if (empty($item_id)) {
  2595. if ($this->debug > 2) {
  2596. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2597. }
  2598. $item_id = $this->get_current_item_id();
  2599. }
  2600. if (empty ($item_id)) {
  2601. if ($this->debug > 2) {
  2602. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2603. }
  2604. //still empty, this means there was no item_id given and we are not in an object context or
  2605. //the object property is empty, return empty link
  2606. $item_id = $this->first();
  2607. return '';
  2608. }
  2609. $file = '';
  2610. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  2611. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  2612. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  2613. $item_id = Database::escape_string($item_id);
  2614. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
  2615. "FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
  2616. if ($this->debug > 2) {
  2617. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2618. }
  2619. $res = Database::query($sel);
  2620. if (Database :: num_rows($res) > 0) {
  2621. $row = Database :: fetch_array($res);
  2622. //var_dump($row);
  2623. $lp_type = $row['ltype'];
  2624. $lp_path = $row['lpath'];
  2625. $lp_item_type = $row['litype'];
  2626. $lp_item_path = $row['lipath'];
  2627. $lp_item_params = $row['liparams'];
  2628. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2629. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2630. }
  2631. //$lp_item_params = '?'.$lp_item_params;
  2632. //add ? if none - left commented to give freedom to scorm implementation
  2633. //if(substr($lp_item_params,0,1)!='?'){
  2634. // $lp_item_params = '?'.$lp_item_params;
  2635. //}
  2636. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2637. if ($type == 'http') {
  2638. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2639. } else {
  2640. $course_path = $sys_course_path; //system path
  2641. }
  2642. // 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.
  2643. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2644. $lp_type = 1;
  2645. }
  2646. // Now go through the specific cases to get the end of the path.
  2647. // @todo Use constants instead of int values.
  2648. switch ($lp_type) {
  2649. case 1 :
  2650. if ($lp_item_type == 'dokeos_chapter') {
  2651. $file = 'lp_content.php?type=dir';
  2652. } else {
  2653. require_once 'resourcelinker.inc.php';
  2654. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2655. //CEV CHANGE
  2656. if ($lp_item_type == 'link') {
  2657. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2658. if (is_youtube_link($file)) {
  2659. $src = get_youtube_video_id($file);
  2660. $file = 'embed.php?type=youtube&src='.$src;
  2661. }
  2662. } else {
  2663. // check how much attempts of a exercise exits in lp
  2664. $lp_item_id = $this->get_current_item_id();
  2665. $lp_view_id = $this->get_view_id();
  2666. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2667. $list = $this->get_toc();
  2668. $type_quiz = false;
  2669. foreach ($list as $toc) {
  2670. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2671. $type_quiz = true;
  2672. }
  2673. }
  2674. if ($type_quiz) {
  2675. $lp_item_id = Database :: escape_string($lp_item_id);
  2676. $lp_view_id = Database :: escape_string($lp_view_id);
  2677. $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'";
  2678. $result = Database::query($sql);
  2679. $row_count = Database :: fetch_row($result);
  2680. $count_item_view = (int) $row_count[0];
  2681. $not_multiple_attempt = 0;
  2682. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2683. $not_multiple_attempt = 1;
  2684. }
  2685. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2686. }
  2687. $tmp_array = explode('/', $file);
  2688. $document_name = $tmp_array[count($tmp_array) - 1];
  2689. if (strpos($document_name, '_DELETED_')) {
  2690. $file = 'blank.php?error=document_deleted';
  2691. }
  2692. }
  2693. }
  2694. break;
  2695. case 2 :
  2696. if ($this->debug > 2) {
  2697. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2698. }
  2699. if ($lp_item_type != 'dir') {
  2700. // Quite complex here:
  2701. // We want to make sure 'http://' (and similar) links can
  2702. // be loaded as is (withouth the Chamilo path in front) but
  2703. // some contents use this form: resource.htm?resource=http://blablabla
  2704. // which means we have to find a protocol at the path's start, otherwise
  2705. // it should not be considered as an external URL.
  2706. //if ($this->prerequisites_match($item_id)) {
  2707. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2708. if ($this->debug > 2) {
  2709. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2710. }
  2711. // Distant url, return as is.
  2712. $file = $lp_item_path;
  2713. } else {
  2714. if ($this->debug > 2) {
  2715. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2716. }
  2717. // Prevent getting untranslatable urls.
  2718. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2719. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2720. // Prepare the path.
  2721. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2722. // TODO: Fix this for urls with protocol header.
  2723. $file = str_replace('//', '/', $file);
  2724. $file = str_replace(':/', '://', $file);
  2725. if (substr($lp_path, -1) == '/') {
  2726. $lp_path = substr($lp_path, 0, -1);
  2727. }
  2728. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2729. // if file not found.
  2730. $decoded = html_entity_decode($lp_item_path);
  2731. list ($decoded) = explode('?', $decoded);
  2732. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2733. require_once 'resourcelinker.inc.php';
  2734. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2735. if (empty($file)) {
  2736. $file = 'blank.php?error=document_not_found';
  2737. } else {
  2738. $tmp_array = explode('/', $file);
  2739. $document_name = $tmp_array[count($tmp_array) - 1];
  2740. if (strpos($document_name, '_DELETED_')) {
  2741. $file = 'blank.php?error=document_deleted';
  2742. } else {
  2743. $file = 'blank.php?error=document_not_found';
  2744. }
  2745. }
  2746. } else {
  2747. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2748. }
  2749. }
  2750. }
  2751. //}else{
  2752. //prerequisites did not match
  2753. //$file = 'blank.php';
  2754. //}
  2755. // We want to use parameters if they were defined in the imsmanifest.
  2756. if ($file != 'blank.php') {
  2757. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2758. }
  2759. } else {
  2760. $file = 'lp_content.php?type=dir';
  2761. }
  2762. break;
  2763. case 3 :
  2764. if ($this->debug > 2) {
  2765. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2766. }
  2767. // Formatting AICC HACP append URL.
  2768. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2769. if ($lp_item_type != 'dir') {
  2770. // Quite complex here:
  2771. // We want to make sure 'http://' (and similar) links can
  2772. // be loaded as is (withouth the Chamilo path in front) but
  2773. // some contents use this form: resource.htm?resource=http://blablabla
  2774. // which means we have to find a protocol at the path's start, otherwise
  2775. // it should not be considered as an external URL.
  2776. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2777. if ($this->debug > 2) {
  2778. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2779. }
  2780. // Distant url, return as is.
  2781. $file = $lp_item_path;
  2782. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2783. /*
  2784. if (stristr($file,'<servername>') !== false) {
  2785. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2786. }
  2787. */
  2788. if (stripos($file, '<servername>') !== false) {
  2789. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2790. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2791. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2792. }
  2793. //
  2794. $file .= $aicc_append;
  2795. } else {
  2796. if ($this->debug > 2) {
  2797. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2798. }
  2799. // Prevent getting untranslatable urls.
  2800. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2801. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2802. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2803. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2804. // TODO: Fix this for urls with protocol header.
  2805. $file = str_replace('//', '/', $file);
  2806. $file = str_replace(':/', '://', $file);
  2807. $file .= $aicc_append;
  2808. }
  2809. } else {
  2810. $file = 'lp_content.php?type=dir';
  2811. }
  2812. break;
  2813. case 4 :
  2814. break;
  2815. default :
  2816. break;
  2817. }
  2818. }
  2819. if ($this->debug > 2) {
  2820. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2821. }
  2822. return $file;
  2823. }
  2824. /**
  2825. * Gets the latest usable view or generate a new one
  2826. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2827. * @return integer DB lp_view id
  2828. */
  2829. public function get_view($attempt_num = 0) {
  2830. if ($this->debug > 0) {
  2831. error_log('New LP - In learnpath::get_view()', 0);
  2832. }
  2833. $search = '';
  2834. // Use $attempt_num to enable multi-views management (disabled so far).
  2835. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2836. $search = 'AND view_count = ' . $attempt_num;
  2837. }
  2838. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2839. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2840. $sql = "SELECT id, view_count FROM $lp_view_table " .
  2841. "WHERE lp_id = " . $this->get_id() . " " .
  2842. "AND user_id = " . $this->get_user_id() . " " .
  2843. $search .
  2844. " ORDER BY view_count DESC";
  2845. $res = Database::query($sql);
  2846. if (Database :: num_rows($res) > 0) {
  2847. $row = Database :: fetch_array($res);
  2848. $this->lp_view_id = $row['id'];
  2849. } else {
  2850. // There is no database record, create one.
  2851. $sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
  2852. "VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2853. $res = Database::query($sql);
  2854. $id = Database :: insert_id();
  2855. $this->lp_view_id = $id;
  2856. }
  2857. return $this->lp_view_id;
  2858. }
  2859. /**
  2860. * Gets the current view id
  2861. * @return integer View ID (from lp_view)
  2862. */
  2863. public function get_view_id() {
  2864. if ($this->debug > 0) {
  2865. error_log('New LP - In learnpath::get_view_id()', 0);
  2866. }
  2867. if (!empty ($this->lp_view_id)) {
  2868. return $this->lp_view_id;
  2869. } else {
  2870. return 0;
  2871. }
  2872. }
  2873. /**
  2874. * Gets the update queue
  2875. * @return array Array containing IDs of items to be updated by JavaScript
  2876. */
  2877. public function get_update_queue() {
  2878. if ($this->debug > 0) {
  2879. error_log('New LP - In learnpath::get_update_queue()', 0);
  2880. }
  2881. return $this->update_queue;
  2882. }
  2883. /**
  2884. * Gets the user ID
  2885. * @return integer User ID
  2886. */
  2887. public function get_user_id() {
  2888. if ($this->debug > 0) {
  2889. error_log('New LP - In learnpath::get_user_id()', 0);
  2890. }
  2891. if (!empty ($this->user_id)) {
  2892. return $this->user_id;
  2893. } else {
  2894. return false;
  2895. }
  2896. }
  2897. /**
  2898. * Checks if any of the items has an audio element attached
  2899. * @return bool True or false
  2900. */
  2901. public function has_audio() {
  2902. if ($this->debug > 1) {
  2903. error_log('New LP - In learnpath::has_audio()', 0);
  2904. }
  2905. $has = false;
  2906. foreach ($this->items as $i => $item) {
  2907. if (!empty ($this->items[$i]->audio)) {
  2908. $has = true;
  2909. break;
  2910. }
  2911. }
  2912. return $has;
  2913. }
  2914. /**
  2915. * Logs a message into a file
  2916. * @param string Message to log
  2917. * @return boolean True on success, false on error or if msg empty
  2918. */
  2919. public function log($msg) {
  2920. if ($this->debug > 0) {
  2921. error_log('New LP - In learnpath::log()', 0);
  2922. }
  2923. // TODO
  2924. $this->error .= $msg . "\n";
  2925. return true;
  2926. }
  2927. /**
  2928. * Moves an item up and down at its level
  2929. * @param integer Item to move up and down
  2930. * @param string Direction 'up' or 'down'
  2931. * @return integer New display order, or false on error
  2932. */
  2933. public function move_item($id, $direction) {
  2934. if ($this->debug > 0) {
  2935. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  2936. }
  2937. if (empty ($id) or empty ($direction)) {
  2938. return false;
  2939. }
  2940. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2941. $sql_sel = "
  2942. SELECT *
  2943. FROM " . $tbl_lp_item . "
  2944. WHERE id = " . $id;
  2945. $res_sel = Database::query($sql_sel);
  2946. // Check if elem exists.
  2947. if (Database :: num_rows($res_sel) < 1) {
  2948. return false;
  2949. }
  2950. // Gather data.
  2951. $row = Database :: fetch_array($res_sel);
  2952. $previous = $row['previous_item_id'];
  2953. $next = $row['next_item_id'];
  2954. $display = $row['display_order'];
  2955. $parent = $row['parent_item_id'];
  2956. $lp = $row['lp_id'];
  2957. // Update the item (switch with previous/next one).
  2958. switch ($direction) {
  2959. case 'up' :
  2960. if ($this->debug > 2) {
  2961. error_log('Movement up detected', 0);
  2962. }
  2963. if ($display <= 1) { /*do nothing*/
  2964. } else {
  2965. $sql_sel2 = "SELECT *
  2966. FROM $tbl_lp_item
  2967. WHERE id = $previous";
  2968. if ($this->debug > 2) {
  2969. error_log('Selecting previous: ' . $sql_sel2, 0);
  2970. }
  2971. $res_sel2 = Database::query($sql_sel2);
  2972. if (Database :: num_rows($res_sel2) < 1) {
  2973. $previous_previous = 0;
  2974. }
  2975. // Gather data.
  2976. $row2 = Database :: fetch_array($res_sel2);
  2977. $previous_previous = $row2['previous_item_id'];
  2978. // Update previous_previous item (switch "next" with current).
  2979. if ($previous_previous != 0) {
  2980. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
  2981. if ($this->debug > 2) {
  2982. error_log($sql_upd2, 0);
  2983. }
  2984. $res_upd2 = Database::query($sql_upd2);
  2985. }
  2986. // Update previous item (switch with current).
  2987. if ($previous != 0) {
  2988. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
  2989. if ($this->debug > 2) {
  2990. error_log($sql_upd2, 0);
  2991. }
  2992. $res_upd2 = Database::query($sql_upd2);
  2993. }
  2994. // Update current item (switch with previous).
  2995. if ($id != 0) {
  2996. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
  2997. if ($this->debug > 2) {
  2998. error_log($sql_upd2, 0);
  2999. }
  3000. $res_upd2 = Database::query($sql_upd2);
  3001. }
  3002. // Update next item (new previous item).
  3003. if ($next != 0) {
  3004. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
  3005. if ($this->debug > 2) {
  3006. error_log($sql_upd2, 0);
  3007. }
  3008. $res_upd2 = Database::query($sql_upd2);
  3009. }
  3010. $display = $display -1;
  3011. }
  3012. break;
  3013. case 'down' :
  3014. if ($this->debug > 2) {
  3015. error_log('Movement down detected', 0);
  3016. }
  3017. if ($next == 0) { /* Do nothing. */
  3018. } else {
  3019. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
  3020. if ($this->debug > 2) {
  3021. error_log('Selecting next: ' . $sql_sel2, 0);
  3022. }
  3023. $res_sel2 = Database::query($sql_sel2);
  3024. if (Database :: num_rows($res_sel2) < 1) {
  3025. $next_next = 0;
  3026. }
  3027. // Gather data.
  3028. $row2 = Database :: fetch_array($res_sel2);
  3029. $next_next = $row2['next_item_id'];
  3030. // Update previous item (switch with current).
  3031. if ($previous != 0) {
  3032. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
  3033. $res_upd2 = Database::query($sql_upd2);
  3034. }
  3035. // Update current item (switch with previous).
  3036. if ($id != 0) {
  3037. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
  3038. $res_upd2 = Database::query($sql_upd2);
  3039. }
  3040. // Update next item (new previous item).
  3041. if ($next != 0) {
  3042. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
  3043. $res_upd2 = Database::query($sql_upd2);
  3044. }
  3045. // Update next_next item (switch "previous" with current).
  3046. if ($next_next != 0) {
  3047. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
  3048. $res_upd2 = Database::query($sql_upd2);
  3049. }
  3050. $display = $display +1;
  3051. }
  3052. break;
  3053. default :
  3054. return false;
  3055. }
  3056. return $display;
  3057. }
  3058. /**
  3059. * Move a learnpath up (display_order)
  3060. * @param integer Learnpath ID
  3061. */
  3062. public function move_up($lp_id) {
  3063. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3064. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3065. $res = Database::query($sql);
  3066. if ($res === false)
  3067. return false;
  3068. $lps = array ();
  3069. $lp_order = array ();
  3070. $num = Database :: num_rows($res);
  3071. // First check the order is correct, globally (might be wrong because
  3072. // of versions < 1.8.4)
  3073. if ($num > 0) {
  3074. $i = 1;
  3075. while ($row = Database :: fetch_array($res)) {
  3076. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3077. $need_fix = true;
  3078. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3079. $res_u = Database::query($sql_u);
  3080. }
  3081. $row['display_order'] = $i;
  3082. $lps[$row['id']] = $row;
  3083. $lp_order[$i] = $row['id'];
  3084. $i++;
  3085. }
  3086. }
  3087. if ($num > 1) { // If there's only one element, no need to sort.
  3088. $order = $lps[$lp_id]['display_order'];
  3089. if ($order > 1) { // If it's the first element, no need to move up.
  3090. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order - 1];
  3091. $res_u1 = Database::query($sql_u1);
  3092. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE id = " . $lp_id;
  3093. $res_u2 = Database::query($sql_u2);
  3094. }
  3095. }
  3096. }
  3097. /**
  3098. * Move a learnpath down (display_order)
  3099. * @param integer Learnpath ID
  3100. */
  3101. public function move_down($lp_id) {
  3102. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3103. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3104. $res = Database::query($sql);
  3105. if ($res === false)
  3106. return false;
  3107. $lps = array ();
  3108. $lp_order = array ();
  3109. $num = Database :: num_rows($res);
  3110. $max = 0;
  3111. // First check the order is correct, globally (might be wrong because
  3112. // of versions < 1.8.4).
  3113. if ($num > 0) {
  3114. $i = 1;
  3115. while ($row = Database :: fetch_array($res)) {
  3116. $max = $i;
  3117. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3118. $need_fix = true;
  3119. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3120. $res_u = Database::query($sql_u);
  3121. }
  3122. $row['display_order'] = $i;
  3123. $lps[$row['id']] = $row;
  3124. $lp_order[$i] = $row['id'];
  3125. $i++;
  3126. }
  3127. }
  3128. if ($num > 1) { // If there's only one element, no need to sort.
  3129. $order = $lps[$lp_id]['display_order'];
  3130. if ($order < $max) { // If it's the first element, no need to move up.
  3131. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = " . $lp_order[$order + 1];
  3132. $res_u1 = Database::query($sql_u1);
  3133. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . " WHERE id = " . $lp_id;
  3134. $res_u2 = Database::query($sql_u2);
  3135. }
  3136. }
  3137. }
  3138. /**
  3139. * Updates learnpath attributes to point to the next element
  3140. * The last part is similar to set_current_item but processing the other way around
  3141. */
  3142. public function next() {
  3143. if ($this->debug > 0) {
  3144. error_log('New LP - In learnpath::next()', 0);
  3145. }
  3146. $this->last = $this->get_current_item_id();
  3147. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3148. $this->autocomplete_parents($this->last);
  3149. $new_index = $this->get_next_index();
  3150. if ($this->debug > 2) {
  3151. error_log('New LP - New index: ' . $new_index, 0);
  3152. }
  3153. $this->index = $new_index;
  3154. if ($this->debug > 2) {
  3155. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3156. }
  3157. $this->current = $this->ordered_items[$new_index];
  3158. if ($this->debug > 2) {
  3159. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3160. }
  3161. }
  3162. /**
  3163. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3164. * class, this might be redefined to allow several behaviours depending on the document type.
  3165. * @param integer Resource ID
  3166. * @return boolean True on success, false otherwise
  3167. */
  3168. public function open($id) {
  3169. if ($this->debug > 0) {
  3170. error_log('New LP - In learnpath::open()', 0);
  3171. }
  3172. // TODO:
  3173. // set the current resource attribute to this resource
  3174. // switch on element type (redefine in child class?)
  3175. // set status for this item to "opened"
  3176. // start timer
  3177. // initialise score
  3178. $this->index = 0; //or = the last item seen (see $this->last)
  3179. }
  3180. /**
  3181. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3182. * and the prerequisite string on error.
  3183. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3184. * @param integer Optional item ID. If none given, uses the current open item.
  3185. * @return boolean True if prerequisites are matched, false otherwise
  3186. * @return string Empty string if true returned, prerequisites string otherwise.
  3187. */
  3188. public function prerequisites_match($item = null) {
  3189. if ($this->debug > 0) {
  3190. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3191. }
  3192. if (empty ($item)) {
  3193. $item = $this->current;
  3194. }
  3195. if (is_object($this->items[$item])) {
  3196. $prereq_string = $this->items[$item]->get_prereq_string();
  3197. if (empty ($prereq_string)) {
  3198. return true;
  3199. }
  3200. // Clean spaces.
  3201. $prereq_string = str_replace(' ', '', $prereq_string);
  3202. if ($this->debug > 0) {
  3203. error_log('Found prereq_string: ' . $prereq_string, 0);
  3204. }
  3205. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3206. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3207. if ($result === false) {
  3208. $this->set_error_msg($this->items[$item]->prereq_alert);
  3209. }
  3210. } else {
  3211. $result = true;
  3212. if ($this->debug > 1) {
  3213. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3214. }
  3215. }
  3216. if ($this->debug > 1) {
  3217. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3218. }
  3219. return $result;
  3220. }
  3221. /**
  3222. * Updates learnpath attributes to point to the previous element
  3223. * The last part is similar to set_current_item but processing the other way around
  3224. */
  3225. public function previous() {
  3226. if ($this->debug > 0) {
  3227. error_log('New LP - In learnpath::previous()', 0);
  3228. }
  3229. $this->last = $this->get_current_item_id();
  3230. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3231. $this->autocomplete_parents($this->last);
  3232. $new_index = $this->get_previous_index();
  3233. $this->index = $new_index;
  3234. $this->current = $this->ordered_items[$new_index];
  3235. }
  3236. /**
  3237. * Publishes a learnpath. This basically means show or hide the learnpath
  3238. * to normal users.
  3239. * Can be used as abstract
  3240. * @param integer Learnpath ID
  3241. * @param string New visibility
  3242. */
  3243. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3244. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3245. $action = 'visible';
  3246. if ($set_visibility != 1) {
  3247. $action = 'invisible';
  3248. }
  3249. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3250. }
  3251. /**
  3252. * Publishes a learnpath. This basically means show or hide the learnpath
  3253. * on the course homepage
  3254. * Can be used as abstract
  3255. * @param integer Learnpath id
  3256. * @param string New visibility (v/s - visible/invisible)
  3257. */
  3258. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3259. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3260. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3261. $sql = "SELECT * FROM $tbl_lp where id=$lp_id";
  3262. $result = Database::query($sql);
  3263. $row = Database :: fetch_array($result);
  3264. $name = domesticate($row['name']);
  3265. if ($set_visibility == 'i') {
  3266. $s = $name . " " . get_lang('_no_published');
  3267. $dialogBox = $s;
  3268. $v = 0;
  3269. }
  3270. if ($set_visibility == 'v') {
  3271. $s = $name . " " . get_lang('_published');
  3272. $dialogBox = $s;
  3273. $v = 1;
  3274. }
  3275. $session_id = api_get_session_id();
  3276. $session_condition = api_get_session_condition($session_id);
  3277. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3278. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3279. $sql = "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3280. $result = Database::query($sql);
  3281. $num = Database :: num_rows($result);
  3282. $row2 = Database :: fetch_array($result);
  3283. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3284. if (($set_visibility == 'i') && ($num > 0)) {
  3285. $sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3286. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3287. $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)";
  3288. } else {
  3289. // Parameter and database incompatible, do nothing.
  3290. }
  3291. $result = Database::query($sql);
  3292. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3293. }
  3294. /**
  3295. * Restart the whole learnpath. Return the URL of the first element.
  3296. * Make sure the results are saved with anoter method. This method should probably be
  3297. * redefined in children classes.
  3298. * To use a similar method statically, use the create_new_attempt() method
  3299. * @return string URL to load in the viewer
  3300. */
  3301. public function restart() {
  3302. if ($this->debug > 0) {
  3303. error_log('New LP - In learnpath::restart()', 0);
  3304. }
  3305. // TODO
  3306. // Call autosave method to save the current progress.
  3307. //$this->index = 0;
  3308. $session_id = api_get_session_id();
  3309. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3310. $sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count, session_id) " .
  3311. "VALUES (" . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3312. if ($this->debug > 2) {
  3313. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3314. }
  3315. $res = Database::query($sql);
  3316. if ($view_id = Database :: insert_id($res)) {
  3317. $this->lp_view_id = $view_id;
  3318. $this->attempt = $this->attempt + 1;
  3319. } else {
  3320. $this->error = 'Could not insert into item_view table...';
  3321. return false;
  3322. }
  3323. $this->autocomplete_parents($this->current);
  3324. foreach ($this->items as $index => $dummy) {
  3325. $this->items[$index]->restart();
  3326. $this->items[$index]->set_lp_view($this->lp_view_id);
  3327. }
  3328. $this->first();
  3329. return true;
  3330. }
  3331. /**
  3332. * Saves the current item
  3333. * @return boolean
  3334. */
  3335. public function save_current() {
  3336. if ($this->debug > 0) {
  3337. error_log('New LP - In learnpath::save_current()', 0);
  3338. }
  3339. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3340. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3341. if ($this->debug > 2) {
  3342. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3343. }
  3344. if ($this->debug > 2) {
  3345. error_log('' . print_r($this->items, true), 0);
  3346. }
  3347. if (is_object($this->items[$this->current])) {
  3348. //$res = $this->items[$this->current]->save(false);
  3349. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3350. $this->autocomplete_parents($this->current);
  3351. $status = $this->items[$this->current]->get_status();
  3352. $this->append_message('new_item_status: ' . $status);
  3353. $this->update_queue[$this->current] = $status;
  3354. return $res;
  3355. }
  3356. return false;
  3357. }
  3358. /**
  3359. * Saves the given item
  3360. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3361. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3362. * @return boolean
  3363. */
  3364. public function save_item($item_id = null, $from_outside = true) {
  3365. if ($this->debug > 0) {
  3366. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3367. }
  3368. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3369. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3370. if (empty ($item_id)) {
  3371. $item_id = $this->escape_string($_REQUEST['id']);
  3372. }
  3373. if (empty ($item_id)) {
  3374. $item_id = $this->get_current_item_id();
  3375. }
  3376. if ($this->debug > 2) {
  3377. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3378. }
  3379. if (is_object($this->items[$item_id])) {
  3380. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3381. //$res = $this->items[$item_id]->save($from_outside);
  3382. $this->autocomplete_parents($item_id);
  3383. $status = $this->items[$item_id]->get_status();
  3384. $this->append_message('new_item_status: ' . $status);
  3385. $this->update_queue[$item_id] = $status;
  3386. return $res;
  3387. }
  3388. return false;
  3389. }
  3390. /**
  3391. * Saves the last item seen's ID only in case
  3392. */
  3393. public function save_last() {
  3394. if ($this->debug > 0) {
  3395. error_log('New LP - In learnpath::save_last()', 0);
  3396. }
  3397. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3398. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3399. if (isset ($this->current)) {
  3400. if ($this->debug > 2) {
  3401. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3402. }
  3403. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3404. "WHERE lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3405. if ($this->debug > 2) {
  3406. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3407. }
  3408. $res = Database::query($sql);
  3409. }
  3410. // Save progress.
  3411. list($progress, $text) = $this->get_progress_bar_text('%');
  3412. if ($progress >= 0 && $progress <= 100) {
  3413. $progress = (int) $progress;
  3414. $sql = "UPDATE $table SET progress = $progress " .
  3415. "WHERE lp_id = " . $this->get_id() . " AND " .
  3416. "user_id = " . $this->get_user_id().' '.$session_condition;
  3417. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3418. $this->progress_db = $progress;
  3419. }
  3420. }
  3421. /**
  3422. * Sets the current item ID (checks if valid and authorized first)
  3423. * @param integer New item ID. If not given or not authorized, defaults to current
  3424. */
  3425. public function set_current_item($item_id = null) {
  3426. if ($this->debug > 0) {
  3427. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3428. }
  3429. if (empty ($item_id)) {
  3430. if ($this->debug > 2) {
  3431. error_log('New LP - No new current item given, ignore...', 0);
  3432. }
  3433. // Do nothing.
  3434. } else {
  3435. if ($this->debug > 2) {
  3436. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3437. }
  3438. if (is_numeric($item_id)) {
  3439. $item_id = $this->escape_string($item_id);
  3440. // TODO: Check in database here.
  3441. $this->last = $this->current;
  3442. $this->current = $item_id;
  3443. // TODO: Update $this->index as well.
  3444. foreach ($this->ordered_items as $index => $item) {
  3445. if ($item == $this->current) {
  3446. $this->index = $index;
  3447. break;
  3448. }
  3449. }
  3450. if ($this->debug > 2) {
  3451. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3452. }
  3453. } else {
  3454. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3455. }
  3456. }
  3457. }
  3458. /**
  3459. * Sets the encoding
  3460. * @param string New encoding
  3461. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3462. */
  3463. public function set_encoding($enc = 'UTF-8') {
  3464. if ($this->debug > 0) {
  3465. error_log('New LP - In learnpath::set_encoding()', 0);
  3466. }
  3467. /* // Deprecated code (Chamilo 1.8.8).
  3468. $enc = strtoupper($enc);
  3469. $encodings = array (
  3470. 'UTF-8',
  3471. 'ISO-8859-1',
  3472. 'ISO-8859-15',
  3473. 'cp1251',
  3474. 'cp1252',
  3475. 'KOI8-R',
  3476. 'BIG5',
  3477. 'GB2312',
  3478. 'Shift_JIS',
  3479. 'EUC-JP',
  3480. ''
  3481. );
  3482. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3483. $lp = $this->get_id();
  3484. if ($lp != 0) {
  3485. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3486. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3487. $res = Database::query($sql);
  3488. return $res;
  3489. }
  3490. }
  3491. return false;
  3492. */
  3493. $enc = api_refine_encoding_id($enc);
  3494. if (empty($enc)) {
  3495. $enc = api_get_system_encoding();
  3496. }
  3497. if (api_is_encoding_supported($enc)) {
  3498. $lp = $this->get_id();
  3499. if ($lp != 0) {
  3500. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3501. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3502. $res = Database::query($sql);
  3503. return $res;
  3504. }
  3505. }
  3506. return false;
  3507. }
  3508. /**
  3509. * Sets the JS lib setting in the database directly.
  3510. * This is the JavaScript library file this lp needs to load on startup
  3511. * @param string Proximity setting
  3512. * @return boolean True on update success. False otherwise.
  3513. */
  3514. public function set_jslib($lib = '') {
  3515. if ($this->debug > 0) {
  3516. error_log('New LP - In learnpath::set_jslib()', 0);
  3517. }
  3518. $lp = $this->get_id();
  3519. if ($lp != 0) {
  3520. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3521. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = " . $lp;
  3522. $res = Database::query($sql);
  3523. return $res;
  3524. } else {
  3525. return false;
  3526. }
  3527. }
  3528. /**
  3529. * Sets the name of the LP maker (publisher) (and save)
  3530. * @param string Optional string giving the new content_maker of this learnpath
  3531. * @return boolean True
  3532. */
  3533. public function set_maker($name = '') {
  3534. if ($this->debug > 0) {
  3535. error_log('New LP - In learnpath::set_maker()', 0);
  3536. }
  3537. if (empty ($name))
  3538. return false;
  3539. $this->maker = $this->escape_string($name);
  3540. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3541. $lp_id = $this->get_id();
  3542. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE id = '$lp_id'";
  3543. if ($this->debug > 2) {
  3544. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3545. }
  3546. $res = Database::query($sql);
  3547. return true;
  3548. }
  3549. /**
  3550. * Sets the name of the current learnpath (and save)
  3551. * @param string Optional string giving the new name of this learnpath
  3552. * @return boolean True/False
  3553. */
  3554. public function set_name($name = '') {
  3555. if ($this->debug > 0) {
  3556. error_log('New LP - In learnpath::set_name()', 0);
  3557. }
  3558. if (empty ($name))
  3559. return false;
  3560. $this->name = $this->escape_string($name);
  3561. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3562. $lp_id = $this->get_id();
  3563. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE id = '$lp_id'";
  3564. if ($this->debug > 2) {
  3565. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3566. }
  3567. $res = Database::query($sql);
  3568. // If the lp is visible on the homepage, change his name there.
  3569. if (Database::affected_rows()) {
  3570. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3571. $sql = 'UPDATE ' . $table . ' SET
  3572. name = "' . $this->name . '"
  3573. WHERE link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3574. Database::query($sql);
  3575. }
  3576. return true;
  3577. }
  3578. /**
  3579. * Set index specified prefix terms for all items in this path
  3580. * @param string Comma-separated list of terms
  3581. * @param char Xapian term prefix
  3582. * @return boolean False on error, true otherwise
  3583. */
  3584. public function set_terms_by_prefix($terms_string, $prefix) {
  3585. if (api_get_setting('search_enabled') !== 'true')
  3586. return false;
  3587. $terms_string = trim($terms_string);
  3588. $terms = explode(',', $terms_string);
  3589. array_walk($terms, 'trim_value');
  3590. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3591. //var_dump($stored_terms);
  3592. //var_dump($terms);
  3593. // Don't do anything if no change, verify only at DB, not the search engine.
  3594. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3595. return false;
  3596. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3597. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3598. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3599. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3600. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3601. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3602. $lp_id = intval($_POST['lp_id']);
  3603. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3604. $result = Database::query($sql);
  3605. $di = new DokeosIndexer();
  3606. while ($lp_item = Database :: fetch_array($result)) {
  3607. // Get search_did.
  3608. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3609. $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';
  3610. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3611. //echo $sql; echo '<br>';
  3612. $res = Database::query($sql);
  3613. if (Database::num_rows($res) > 0) {
  3614. $se_ref = Database :: fetch_array($res);
  3615. // Compare terms.
  3616. $doc = $di->get_document($se_ref['search_did']);
  3617. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3618. $xterms = array ();
  3619. foreach ($xapian_terms as $xapian_term) {
  3620. $xterms[] = substr($xapian_term['name'], 1);
  3621. }
  3622. $dterms = $terms;
  3623. $missing_terms = array_diff($dterms, $xterms);
  3624. $deprecated_terms = array_diff($xterms, $dterms);
  3625. // Save it to search engine.
  3626. foreach ($missing_terms as $term) {
  3627. $doc->add_term($prefix . $term, 1);
  3628. }
  3629. foreach ($deprecated_terms as $term) {
  3630. $doc->remove_term($prefix . $term);
  3631. }
  3632. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3633. $di->getDb()->flush();
  3634. } else {
  3635. //@todo What we should do here?
  3636. }
  3637. }
  3638. return true;
  3639. }
  3640. /**
  3641. * Sets the theme of the LP (local/remote) (and save)
  3642. * @param string Optional string giving the new theme of this learnpath
  3643. * @return bool Returns true if theme name is not empty
  3644. */
  3645. public function set_theme($name = '') {
  3646. if ($this->debug > 0) {
  3647. error_log('New LP - In learnpath::set_theme()', 0);
  3648. }
  3649. $this->theme = $this->escape_string($name);
  3650. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3651. $lp_id = $this->get_id();
  3652. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE id = '$lp_id'";
  3653. if ($this->debug > 2) {
  3654. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3655. }
  3656. //$res = Database::query($sql);
  3657. $res = Database::query($sql);
  3658. return true;
  3659. }
  3660. /**
  3661. * Sets the image of an LP (and save)
  3662. * @param string Optional string giving the new image of this learnpath
  3663. * @return bool Returns true if theme name is not empty
  3664. */
  3665. public function set_preview_image($name = '') {
  3666. if ($this->debug > 0) {
  3667. error_log('New LP - In learnpath::set_preview_image()', 0);
  3668. }
  3669. $this->preview_image = $this->escape_string($name);
  3670. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3671. $lp_id = $this->get_id();
  3672. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE id = '$lp_id'";
  3673. if ($this->debug > 2) {
  3674. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3675. }
  3676. $res = Database::query($sql);
  3677. return true;
  3678. }
  3679. /**
  3680. * Sets the author of a LP (and save)
  3681. * @param string Optional string giving the new author of this learnpath
  3682. * @return bool Returns true if author's name is not empty
  3683. */
  3684. public function set_author($name = '') {
  3685. if ($this->debug > 0) {
  3686. error_log('New LP - In learnpath::set_author()', 0);
  3687. }
  3688. $this->author = $this->escape_string($name);
  3689. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3690. $lp_id = $this->get_id();
  3691. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE id = '$lp_id'";
  3692. if ($this->debug > 2) {
  3693. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3694. }
  3695. $res = Database::query($sql);
  3696. return true;
  3697. }
  3698. /**
  3699. * Sets the prerequisite of a LP (and save)
  3700. * @param int integer giving the new prerequisite of this learnpath
  3701. * @return bool returns true if prerequisite is not empty
  3702. */
  3703. public function set_prerequisite($prerequisite) {
  3704. if ($this->debug > 0) {
  3705. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3706. }
  3707. $this->prerequisite = intval($prerequisite);
  3708. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3709. $lp_id = $this->get_id();
  3710. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."' WHERE id = '$lp_id'";
  3711. if ($this->debug > 2) {
  3712. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3713. }
  3714. $res = Database::query($sql);
  3715. return true;
  3716. }
  3717. /**
  3718. * Sets the location/proximity of the LP (local/remote) (and save)
  3719. * @param string Optional string giving the new location of this learnpath
  3720. * @return boolean True on success / False on error
  3721. */
  3722. public function set_proximity($name = '') {
  3723. if ($this->debug > 0) {
  3724. error_log('New LP - In learnpath::set_proximity()', 0);
  3725. }
  3726. if (empty ($name))
  3727. return false;
  3728. $this->proximity = $this->escape_string($name);
  3729. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3730. $lp_id = $this->get_id();
  3731. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "' WHERE id = '$lp_id'";
  3732. if ($this->debug > 2) {
  3733. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3734. }
  3735. $res = Database::query($sql);
  3736. return true;
  3737. }
  3738. /**
  3739. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3740. * @param integer DB ID of the item
  3741. */
  3742. public function set_previous_item($id) {
  3743. if ($this->debug > 0) {
  3744. error_log('New LP - In learnpath::set_previous_item()', 0);
  3745. }
  3746. $this->last = $id;
  3747. }
  3748. /**
  3749. * Sets use_max_score
  3750. * @param string Optional string giving the new location of this learnpath
  3751. * @return boolean True on success / False on error
  3752. */
  3753. public function set_use_max_score($use_max_score = 1) {
  3754. if ($this->debug > 0) {
  3755. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3756. }
  3757. $use_max_score = intval($use_max_score);
  3758. $this->use_max_score = $use_max_score;
  3759. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3760. $lp_id = $this->get_id();
  3761. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE id = '$lp_id'";
  3762. if ($this->debug > 2) {
  3763. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3764. }
  3765. $res = Database::query($sql);
  3766. return true;
  3767. }
  3768. /**
  3769. * Sets and saves the expired_on date
  3770. * @param string Optional string giving the new author of this learnpath
  3771. * @return bool Returns true if author's name is not empty
  3772. */
  3773. public function set_expired_on($expired_on) {
  3774. if ($this->debug > 0) {
  3775. error_log('New LP - In learnpath::set_expired_on()', 0);
  3776. }
  3777. if (!empty($expired_on)) {
  3778. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3779. } else {
  3780. $this->expired_on = '';
  3781. }
  3782. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3783. $lp_id = $this->get_id();
  3784. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE id = '$lp_id'";
  3785. if ($this->debug > 2) {
  3786. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3787. }
  3788. $res = Database::query($sql);
  3789. return true;
  3790. }
  3791. /**
  3792. * Sets and saves the publicated_on date
  3793. * @param string Optional string giving the new author of this learnpath
  3794. * @return bool Returns true if author's name is not empty
  3795. */
  3796. public function set_publicated_on($publicated_on) {
  3797. if ($this->debug > 0) {
  3798. error_log('New LP - In learnpath::set_expired_on()', 0);
  3799. }
  3800. if (!empty($publicated_on)) {
  3801. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3802. } else {
  3803. $this->publicated_on = '';
  3804. }
  3805. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3806. $lp_id = $this->get_id();
  3807. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE id = '$lp_id'";
  3808. if ($this->debug > 2) {
  3809. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3810. }
  3811. $res = Database::query($sql);
  3812. return true;
  3813. }
  3814. /**
  3815. * Sets and saves the expired_on date
  3816. * @param string Optional string giving the new author of this learnpath
  3817. * @return bool Returns true if author's name is not empty
  3818. */
  3819. public function set_modified_on() {
  3820. if ($this->debug > 0) {
  3821. error_log('New LP - In learnpath::set_expired_on()', 0);
  3822. }
  3823. $this->modified_on = api_get_utc_datetime();
  3824. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3825. $lp_id = $this->get_id();
  3826. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE id = '$lp_id'";
  3827. if ($this->debug > 2) {
  3828. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3829. }
  3830. $res = Database::query($sql);
  3831. return true;
  3832. }
  3833. /**
  3834. * Sets the object's error message
  3835. * @param string Error message. If empty, reinits the error string
  3836. * @return void
  3837. */
  3838. public function set_error_msg($error = '') {
  3839. if ($this->debug > 0) {
  3840. error_log('New LP - In learnpath::set_error_msg()', 0);
  3841. }
  3842. if (empty ($error)) {
  3843. $this->error = '';
  3844. } else {
  3845. $this->error .= $error;
  3846. }
  3847. }
  3848. /**
  3849. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3850. * @param boolean Whether to allow a new attempt or not
  3851. * @return boolean True
  3852. */
  3853. public function start_current_item($allow_new_attempt = false) {
  3854. if ($this->debug > 0) {
  3855. error_log('New LP - In learnpath::start_current_item()', 0);
  3856. }
  3857. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3858. $type = $this->get_type();
  3859. $item_type = $this->items[$this->current]->get_type();
  3860. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3861. $this->items[$this->current]->open($allow_new_attempt);
  3862. $this->autocomplete_parents($this->current);
  3863. $prereq_check = $this->prerequisites_match($this->current);
  3864. $this->items[$this->current]->save(false, $prereq_check);
  3865. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3866. } else {
  3867. // If sco, then it is supposed to have been updated by some other call.
  3868. }
  3869. if ($item_type == 'sco') {
  3870. $this->items[$this->current]->restart();
  3871. }
  3872. }
  3873. if ($this->debug > 0) {
  3874. error_log('New LP - End of learnpath::start_current_item()', 0);
  3875. }
  3876. return true;
  3877. }
  3878. /**
  3879. * Stops the processing and counters for the old item (as held in $this->last)
  3880. * @return boolean True/False
  3881. */
  3882. public function stop_previous_item() {
  3883. if ($this->debug > 0) {
  3884. error_log('New LP - In learnpath::stop_previous_item()', 0);
  3885. }
  3886. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  3887. if ($this->debug > 2) {
  3888. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  3889. }
  3890. switch ($this->get_type()) {
  3891. case '3' :
  3892. if ($this->items[$this->last]->get_type() != 'au') {
  3893. if ($this->debug > 2) {
  3894. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  3895. }
  3896. $this->items[$this->last]->close();
  3897. //$this->autocomplete_parents($this->last);
  3898. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3899. } else {
  3900. if ($this->debug > 2) {
  3901. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  3902. }
  3903. }
  3904. case '2' :
  3905. if ($this->items[$this->last]->get_type() != 'sco') {
  3906. if ($this->debug > 2) {
  3907. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  3908. }
  3909. $this->items[$this->last]->close();
  3910. //$this->autocomplete_parents($this->last);
  3911. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3912. } else {
  3913. if ($this->debug > 2) {
  3914. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  3915. }
  3916. }
  3917. break;
  3918. case '1' :
  3919. default :
  3920. if ($this->debug > 2) {
  3921. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  3922. }
  3923. $this->items[$this->last]->close();
  3924. break;
  3925. }
  3926. } else {
  3927. if ($this->debug > 2) {
  3928. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  3929. }
  3930. return false;
  3931. }
  3932. return true;
  3933. }
  3934. /**
  3935. * Updates the default view mode from fullscreen to embedded and inversely
  3936. * @return string The current default view mode ('fullscreen' or 'embedded')
  3937. */
  3938. public function update_default_view_mode() {
  3939. if ($this->debug > 0) {
  3940. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  3941. }
  3942. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3943. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3944. $res = Database::query($sql);
  3945. if (Database :: num_rows($res) > 0) {
  3946. $row = Database :: fetch_array($res);
  3947. $view_mode = $row['default_view_mod'];
  3948. if ($view_mode == 'fullscreen') {
  3949. $view_mode = 'embedded';
  3950. } elseif ($view_mode == 'embedded') {
  3951. $view_mode = 'embedframe';
  3952. } elseif ($view_mode == 'embedframe') {
  3953. $view_mode = 'fullscreen';
  3954. }
  3955. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = " . $this->get_id();
  3956. $res = Database::query($sql);
  3957. $this->mode = $view_mode;
  3958. return $view_mode;
  3959. } else {
  3960. if ($this->debug > 2) {
  3961. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3962. }
  3963. }
  3964. return -1;
  3965. }
  3966. /**
  3967. * Updates the default behaviour about auto-commiting SCORM updates
  3968. * @return boolean True if auto-commit has been set to 'on', false otherwise
  3969. */
  3970. public function update_default_scorm_commit() {
  3971. if ($this->debug > 0) {
  3972. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  3973. }
  3974. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3975. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  3976. $res = Database::query($sql);
  3977. if (Database :: num_rows($res) > 0) {
  3978. $row = Database :: fetch_array($res);
  3979. $force = $row['force_commit'];
  3980. if ($force == 1) {
  3981. $force = 0;
  3982. $force_return = false;
  3983. } elseif ($force == 0) {
  3984. $force = 1;
  3985. $force_return = true;
  3986. }
  3987. $sql = "UPDATE $lp_table SET force_commit = $force WHERE id = " . $this->get_id();
  3988. $res = Database::query($sql);
  3989. $this->force_commit = $force_return;
  3990. return $force_return;
  3991. } else {
  3992. if ($this->debug > 2) {
  3993. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  3994. }
  3995. }
  3996. return -1;
  3997. }
  3998. /**
  3999. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4000. * @return bool True on success, false on failure
  4001. */
  4002. public function update_display_order() {
  4003. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4004. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  4005. $res = Database::query($sql);
  4006. if ($res === false)
  4007. return false;
  4008. $lps = array ();
  4009. $lp_order = array ();
  4010. $num = Database :: num_rows($res);
  4011. // First check the order is correct, globally (might be wrong because
  4012. // of versions < 1.8.4).
  4013. if ($num > 0) {
  4014. $i = 1;
  4015. while ($row = Database :: fetch_array($res)) {
  4016. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4017. $need_fix = true;
  4018. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  4019. $res_u = Database::query($sql_u);
  4020. }
  4021. $i++;
  4022. }
  4023. }
  4024. return true;
  4025. }
  4026. /**
  4027. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4028. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4029. */
  4030. public function update_reinit() {
  4031. if ($this->debug > 0) {
  4032. error_log('New LP - In learnpath::update_reinit()', 0);
  4033. }
  4034. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4035. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4036. $res = Database::query($sql);
  4037. if (Database :: num_rows($res) > 0) {
  4038. $row = Database :: fetch_array($res);
  4039. $force = $row['prevent_reinit'];
  4040. if ($force == 1) {
  4041. $force = 0;
  4042. } elseif ($force == 0) {
  4043. $force = 1;
  4044. }
  4045. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = " . $this->get_id();
  4046. $res = Database::query($sql);
  4047. $this->prevent_reinit = $force;
  4048. return $force;
  4049. } else {
  4050. if ($this->debug > 2) {
  4051. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4052. }
  4053. }
  4054. return -1;
  4055. }
  4056. /**
  4057. * Updates the "scorm_debug" value that shows or hide the debug window
  4058. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4059. */
  4060. public function update_scorm_debug() {
  4061. if ($this->debug > 0) {
  4062. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4063. }
  4064. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4065. $sql = "SELECT * FROM $lp_table WHERE id = " . $this->get_id();
  4066. $res = Database::query($sql);
  4067. if (Database :: num_rows($res) > 0) {
  4068. $row = Database :: fetch_array($res);
  4069. $force = $row['debug'];
  4070. if ($force == 1) {
  4071. $force = 0;
  4072. } elseif ($force == 0) {
  4073. $force = 1;
  4074. }
  4075. $sql = "UPDATE $lp_table SET debug = $force WHERE id = " . $this->get_id();
  4076. $res = Database::query($sql);
  4077. $this->scorm_debug = $force;
  4078. return $force;
  4079. } else {
  4080. if ($this->debug > 2) {
  4081. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4082. }
  4083. }
  4084. return -1;
  4085. }
  4086. /**
  4087. * Function that makes a call to the function sort_tree_array and create_tree_array
  4088. * @author Kevin Van Den Haute
  4089. * @param array
  4090. */
  4091. public function tree_array($array) {
  4092. if ($this->debug > 1) {
  4093. error_log('New LP - In learnpath::tree_array()', 0);
  4094. }
  4095. $array = $this->sort_tree_array($array);
  4096. $this->create_tree_array($array);
  4097. }
  4098. /**
  4099. * Creates an array with the elements of the learning path tree in it
  4100. *
  4101. * @author Kevin Van Den Haute
  4102. * @param array $array
  4103. * @param int $parent
  4104. * @param int $depth
  4105. * @param array $tmp
  4106. */
  4107. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4108. if ($this->debug > 1) {
  4109. error_log('New LP - In learnpath::create_tree_array())', 0);
  4110. }
  4111. if (is_array($array)) {
  4112. for ($i = 0; $i < count($array); $i++) {
  4113. if ($array[$i]['parent_item_id'] == $parent) {
  4114. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4115. $tmp[] = $array[$i]['parent_item_id'];
  4116. $depth++;
  4117. }
  4118. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4119. $this->arrMenu[] = array (
  4120. 'id' => $array[$i]['id'],
  4121. 'item_type' => $array[$i]['item_type'],
  4122. 'title' => $array[$i]['title'],
  4123. 'path' => $array[$i]['path'],
  4124. 'description' => $array[$i]['description'],
  4125. 'parent_item_id' => $array[$i]['parent_item_id'],
  4126. 'previous_item_id' => $array[$i]['previous_item_id'],
  4127. 'next_item_id' => $array[$i]['next_item_id'],
  4128. 'min_score' => $array[$i]['min_score'],
  4129. 'max_score' => $array[$i]['max_score'],
  4130. 'mastery_score' => $array[$i]['mastery_score'],
  4131. 'display_order' => $array[$i]['display_order'],
  4132. 'prerequisite' => $preq,
  4133. 'depth' => $depth,
  4134. 'audio' => $array[$i]['audio']
  4135. );
  4136. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4137. }
  4138. }
  4139. }
  4140. }
  4141. /**
  4142. * Sorts a multi dimensional array by parent id and display order
  4143. * @author Kevin Van Den Haute
  4144. *
  4145. * @param array $array (array with al the learning path items in it)
  4146. *
  4147. * @return array
  4148. */
  4149. public function sort_tree_array($array) {
  4150. foreach ($array as $key => $row) {
  4151. $parent[$key] = $row['parent_item_id'];
  4152. $position[$key] = $row['display_order'];
  4153. }
  4154. if (count($array) > 0)
  4155. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4156. return $array;
  4157. }
  4158. /**
  4159. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4160. * Also the actions for the modules, chapters and documents are in this table.
  4161. * @author Kevin Van Den Haute
  4162. * @param int $lp_id
  4163. * @return string
  4164. */
  4165. public function overview() {
  4166. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4167. if ($this->debug > 0) {
  4168. error_log('New LP - In learnpath::overview()', 0);
  4169. }
  4170. global $charset, $_course;
  4171. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  4172. $return = '';
  4173. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4174. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4175. WHERE lp_id = " . $this->lp_id;
  4176. $result = Database::query($sql);
  4177. $arrLP = array ();
  4178. while ($row = Database :: fetch_array($result)) {
  4179. $row['title'] = Security :: remove_XSS($row['title']);
  4180. $row['description'] = Security :: remove_XSS($row['description']);
  4181. $arrLP[] = array (
  4182. 'id' => $row['id'],
  4183. 'item_type' => $row['item_type'],
  4184. 'title' => $row['title'],
  4185. 'path' => $row['path'],
  4186. 'description' => $row['description'],
  4187. 'parent_item_id' => $row['parent_item_id'],
  4188. 'previous_item_id' => $row['previous_item_id'],
  4189. 'next_item_id' => $row['next_item_id'],
  4190. 'max_score' => $row['max_score'],
  4191. 'min_score' => $row['min_score'],
  4192. 'mastery_score' => $row['mastery_score'],
  4193. 'prerequisite' => $row['prerequisite'],
  4194. 'display_order' => $row['display_order'],
  4195. 'audio' => $row['audio']
  4196. );
  4197. }
  4198. $this->tree_array($arrLP);
  4199. $arrLP = $this->arrMenu;
  4200. unset ($this->arrMenu);
  4201. if ($is_allowed_to_edit) {
  4202. $token = Security::get_token();
  4203. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4204. $return .= '<div class="actions">';
  4205. $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>';
  4206. $return .= '<span>' . Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'','32').'</span>';
  4207. $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>';
  4208. $return .= ' '.Display :: return_icon('i.gif');
  4209. $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') . '">
  4210. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4211. $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') . '">
  4212. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4213. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4214. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4215. $return .= '</div>';
  4216. }
  4217. // we need to start a form when we want to update all the mp3 files
  4218. if ($_GET['updateaudio'] == 'true' AND count($arrLP) <> 0) {
  4219. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4220. $return .= Display :: display_warning_message(get_lang('LeaveEmptyToKeepCurrentFile'));
  4221. }
  4222. $return .= '<table class="data_table">' . "\n";
  4223. $return .= "\t" . '<tr>' . "\n";
  4224. $return .= "\t" . '<th width="60%">' . get_lang('Title') . '</th>' . "\n";
  4225. //$return .= "\t" . '<th>'.get_lang('Description').'</th>' . "\n";
  4226. $return .= "\t" . '<th>' . get_lang('Audio') . '</th>' . "\n";
  4227. $return .= "\t" . '<th>' . get_lang('Move') . '</th>' . "\n";
  4228. $return .= "\t" . '<th>' . get_lang('Actions') . '</th>' . "\n";
  4229. $return .= "\t" . '</tr>' . "\n";
  4230. for ($i = 0; $i < count($arrLP); $i++) {
  4231. $title = $arrLP[$i]['title'];
  4232. if ($arrLP[$i]['description'] == '')
  4233. $arrLP[$i]['description'] = '&nbsp;';
  4234. if (($i % 2) == 0) {
  4235. $oddclass = 'row_odd';
  4236. } else {
  4237. $oddclass = 'row_even';
  4238. }
  4239. $return .= "\t" . '<tr class="' . $oddclass . '">' . "\n";
  4240. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4241. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4242. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4243. } else {
  4244. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4245. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4246. } else {
  4247. //$return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>' . "\n";
  4248. $return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>' . "\n";
  4249. }
  4250. }
  4251. //$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
  4252. // The audio column.
  4253. $return .= "\t\t" . '<td align="center">';
  4254. if (!$_GET['updateaudio'] OR $_GET['updateaudio'] <> 'true') {
  4255. if (!empty ($arrLP[$i]['audio'])) {
  4256. $return .= '<span id="container' . $i . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4257. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4258. $return .= '<script type="text/javascript">
  4259. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4260. s1.addParam("allowscriptaccess","always");
  4261. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4262. s1.write("container' . $i . '");
  4263. </script>';
  4264. } else {
  4265. $return .= ' - ';
  4266. }
  4267. } else {
  4268. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4269. $return .= ' <input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4270. if (!empty ($arrLP[$i]['audio'])) {
  4271. $return .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4272. }
  4273. }
  4274. }
  4275. $return .= '</td>';
  4276. if ($is_allowed_to_edit) {
  4277. $return .= '<td align="center">';
  4278. if ($arrLP[$i]['previous_item_id'] != 0) {
  4279. $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.'">';
  4280. $return .= '<img style="margin:1px;" alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveUp') . '"/>';
  4281. $return .= '</a>';
  4282. } else
  4283. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4284. if ($arrLP[$i]['next_item_id'] != 0) {
  4285. $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.'">';
  4286. $return .= '<img style="margin:1px;" src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" title="' . get_lang('MoveDown') . '" />';
  4287. $return .= '</a>';
  4288. } else
  4289. $return .= '<img alt="" src="../img/blanco.png" title="" />';
  4290. $return .= '</td>';
  4291. $return .= '<td align="center">';
  4292. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4293. $return .= "\t\t\t" . '<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'] . '">';
  4294. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4295. $return .= '</a>' . "\n";
  4296. } else {
  4297. $return .= "\t\t\t" . '<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'] . '">';
  4298. $return .= '<img style="margin:1px;" alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
  4299. $return .= '</a>' . "\n";
  4300. }
  4301. $return .= "\t\t\t" . '<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) . '\');">';
  4302. $return .= '<img style="margin:1px;" alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
  4303. $return .= '</a>' . "\n";
  4304. $return .= '</td>';
  4305. }
  4306. $return .= '</tr>';
  4307. }
  4308. if (count($arrLP) == 0) {
  4309. $return .= "\t" . '<tr>' . "\n";
  4310. $return .= "\t\t" . '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>' . "\n";
  4311. $return .= "\t" . '</tr>' . "\n";
  4312. }
  4313. $return .= '</table>' . "\n";
  4314. // We need to close the form when we are updating the mp3 files.
  4315. if ($_GET['updateaudio'] == 'true') {
  4316. $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?
  4317. }
  4318. // We need to close the form when we are updating the mp3 files.
  4319. if ($_GET['updateaudio'] == 'true' && count($arrLP) != 0) {
  4320. $return .= '</form>';
  4321. }
  4322. return $return;
  4323. }
  4324. /**
  4325. * This function builds the action menu
  4326. * @return void
  4327. */
  4328. public function build_action_menu() {
  4329. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  4330. echo '<div class="actions">';
  4331. //echo '<span>'.Display::return_icon('build_learnpath.png','-','','32').' '.get_lang('Build').'</span>';
  4332. echo '<span>' . Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32').'</span>';
  4333. 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>';
  4334. 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> ';
  4335. Display :: display_icon('i.gif');
  4336. 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>';
  4337. 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>';
  4338. echo '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4339. echo '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=admin_view&amp;lp_id=' . Security :: remove_XSS($_GET['lp_id']) . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4340. echo '</div>';
  4341. }
  4342. /**
  4343. * This functions builds the LP tree based on data from the database.
  4344. * @return string
  4345. * @uses dtree.js :: necessary javascript for building this tree
  4346. */
  4347. public function build_tree() {
  4348. $return = "<script type=\"text/javascript\">\n";
  4349. $return .= "\tm = new dTree('m');\n\n";
  4350. $return .= "\tm.config.folderLinks = true;\n";
  4351. $return .= "\tm.config.useCookies = true;\n";
  4352. $return .= "\tm.config.useIcons = true;\n";
  4353. $return .= "\tm.config.useLines = true;\n";
  4354. $return .= "\tm.config.useSelection = true;\n";
  4355. $return .= "\tm.config.useStatustext = false;\n\n";
  4356. $menu = 0;
  4357. $parent = '';
  4358. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4359. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4360. $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
  4361. FROM " . $tbl_lp_item . "
  4362. WHERE lp_id = " . Database :: escape_string($this->lp_id);
  4363. $result = Database::query($sql);
  4364. $arrLP = array ();
  4365. while ($row = Database :: fetch_array($result)) {
  4366. $row['title'] = Security :: remove_XSS($row['title']);
  4367. $row['description'] = Security :: remove_XSS($row['description']);
  4368. $arrLP[] = array (
  4369. 'id' => $row['id'],
  4370. 'item_type' => $row['item_type'],
  4371. 'title' => $row['title'],
  4372. 'path' => $row['path'],
  4373. 'description' => $row['description'],
  4374. 'parent_item_id' => $row['parent_item_id'],
  4375. 'previous_item_id' => $row['previous_item_id'],
  4376. 'next_item_id' => $row['next_item_id'],
  4377. 'max_score' => $row['max_score'],
  4378. 'min_score' => $row['min_score'],
  4379. 'mastery_score' => $row['mastery_score'],
  4380. 'display_order' => $row['display_order']
  4381. );
  4382. }
  4383. $this->tree_array($arrLP);
  4384. $arrLP = $this->arrMenu;
  4385. unset ($this->arrMenu);
  4386. $title = '';
  4387. for ($i = 0; $i < count($arrLP); $i++) {
  4388. $title = addslashes($arrLP[$i]['title']);
  4389. $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;
  4390. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4391. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4392. $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";
  4393. } else
  4394. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4395. $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";
  4396. } else {
  4397. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4398. }
  4399. if ($menu < $arrLP[$i]['id'])
  4400. $menu = $arrLP[$i]['id'];
  4401. }
  4402. $return .= "\n\tdocument.write(m);\n";
  4403. $return .= "\t if(!m.selectedNode) m.s(1);";
  4404. $return .= "</script>\n";
  4405. return $return;
  4406. }
  4407. /**
  4408. * Create a new document //still needs some finetuning
  4409. * @param array $_course
  4410. * @return string
  4411. */
  4412. public function create_document($_course) {
  4413. global $charset;
  4414. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4415. if (strstr($dir, '..'))
  4416. $dir = '/';
  4417. if ($dir[0] == '.')
  4418. $dir = substr($dir, 1);
  4419. if ($dir[0] != '/')
  4420. $dir = '/' . $dir;
  4421. if ($dir[strlen($dir) - 1] != '/')
  4422. $dir .= '/';
  4423. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4424. if (!is_dir($filepath)) {
  4425. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4426. $dir = '/';
  4427. }
  4428. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4429. // is already escaped twice when it gets here.
  4430. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4431. $title = disable_dangerous_file($title);
  4432. $filename = $title;
  4433. $content = $_POST['content_lp'];
  4434. $tmp_filename = $filename;
  4435. $i = 0;
  4436. while (file_exists($filepath . $tmp_filename . '.html'))
  4437. $tmp_filename = $filename . '_' . ++ $i;
  4438. $filename = $tmp_filename . '.html';
  4439. $content = stripslashes(text_filter($content));
  4440. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
  4441. // Change the path of mp3 to absolute.
  4442. // The first regexp deals with ../../../ urls.
  4443. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4444. // The second regexp deals with audio/ urls.
  4445. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4446. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4447. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4448. if (!file_exists($filepath . $filename)) {
  4449. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4450. fputs($fp, $content);
  4451. fclose($fp);
  4452. $file_size = filesize($filepath . $filename);
  4453. $save_file_path = $dir . $filename;
  4454. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
  4455. if ($document_id) {
  4456. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4457. // Update parent folders.
  4458. //item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
  4459. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4460. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4461. if ($new_comment || $new_title) {
  4462. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4463. $ct = '';
  4464. if ($new_comment)
  4465. $ct .= ", comment='" . $new_comment . "'";
  4466. if ($new_title)
  4467. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . ".html '";
  4468. $sql_update = "
  4469. UPDATE " . $tbl_doc . "
  4470. SET " . substr($ct, 1) . "
  4471. WHERE id = " . $document_id;
  4472. Database::query($sql_update);
  4473. }
  4474. }
  4475. return $document_id;
  4476. }
  4477. }
  4478. }
  4479. /**
  4480. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4481. * @param array $_course array
  4482. * @return void
  4483. */
  4484. public function edit_document($_course) {
  4485. global $_configuration;
  4486. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4487. if (strstr($dir, '..'))
  4488. $dir = '/';
  4489. if ($dir[0] == '.')
  4490. $dir = substr($dir, 1);
  4491. if ($dir[0] != '/')
  4492. $dir = '/' . $dir;
  4493. if ($dir[strlen($dir) - 1] != '/')
  4494. $dir .= '/';
  4495. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4496. if (!is_dir($filepath)) {
  4497. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4498. $dir = '/';
  4499. }
  4500. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4501. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4502. $sql = "SELECT path
  4503. FROM " . $table_doc . "
  4504. WHERE id = " . Database::escape_string($_POST['path']);
  4505. $res = Database::query($sql);
  4506. $row = Database :: fetch_array($res);
  4507. $content = stripslashes($_POST['content_lp']);
  4508. $file = $filepath . $row['path'];
  4509. if ($fp = @ fopen($file, 'w')) {
  4510. $content = text_filter($content);
  4511. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4512. // Change the path of mp3 to absolute.
  4513. // The first regexp deals with ../../../ urls.
  4514. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4515. // The second regexp deals with audio/ urls.
  4516. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4517. fputs($fp, $content);
  4518. fclose($fp);
  4519. }
  4520. }
  4521. }
  4522. /**
  4523. * Displays the selected item, with a panel for manipulating the item
  4524. * @param int $item_id
  4525. * @param string $msg
  4526. * @return string
  4527. */
  4528. public function display_item($item_id, $iframe = true, $msg = '') {
  4529. global $_course; // It will disappear.
  4530. $return = '';
  4531. if (is_numeric($item_id)) {
  4532. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4533. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4534. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4535. WHERE lp.id = " . Database :: escape_string($item_id);
  4536. $result = Database::query($sql);
  4537. while ($row = Database :: fetch_array($result)) {
  4538. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4539. // Prevents wrong parent selection for document, see Bug#1251.
  4540. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4541. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4542. }
  4543. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4544. $return .= '<div style="padding:10px;">';
  4545. if ($msg != '')
  4546. $return .= $msg;
  4547. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4548. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4549. //$return .= '<hr />';
  4550. switch ($row['item_type']) {
  4551. case TOOL_QUIZ:
  4552. if (!empty($row['path'])) {
  4553. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4554. $exercise = new Exercise();
  4555. $exercise->read($row['path']);
  4556. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4557. $return .=$exercise->description.'<br />';
  4558. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4559. }
  4560. break;
  4561. case TOOL_DOCUMENT:
  4562. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4563. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . Database :: escape_string($row['path']);
  4564. $result = Database::query($sql_doc);
  4565. $path_file = Database :: result($result, 0, 0);
  4566. $path_parts = pathinfo($path_file);
  4567. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4568. if (in_array($path_parts['extension'], array (
  4569. 'html',
  4570. 'txt',
  4571. 'png',
  4572. 'jpg',
  4573. 'JPG',
  4574. 'jpeg',
  4575. 'JPEG',
  4576. 'gif',
  4577. 'swf'
  4578. ))) {
  4579. $return .= $this->display_document($row['path'], true, true);
  4580. }
  4581. break;
  4582. }
  4583. $return .= '</div>';
  4584. }
  4585. }
  4586. return $return;
  4587. }
  4588. /**
  4589. * Shows the needed forms for editing a specific item
  4590. * @param int $item_id
  4591. * @return string
  4592. */
  4593. public function display_edit_item($item_id) {
  4594. global $_course; // It will disappear.
  4595. $return = '';
  4596. if (is_numeric($item_id)) {
  4597. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4598. $sql = "SELECT *
  4599. FROM " . $tbl_lp_item . "
  4600. WHERE id = " . Database :: escape_string($item_id);
  4601. $res = Database::query($sql);
  4602. $row = Database :: fetch_array($res);
  4603. switch ($row['item_type']) {
  4604. case 'dokeos_chapter' :
  4605. case 'dir' :
  4606. case 'asset' :
  4607. case 'sco' :
  4608. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4609. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4610. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4611. } else {
  4612. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4613. }
  4614. break;
  4615. case TOOL_DOCUMENT :
  4616. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4617. $sql_step = " SELECT lp.*, doc.path as dir
  4618. FROM " . $tbl_lp_item . " as lp
  4619. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  4620. WHERE lp.id = " . Database :: escape_string($item_id);
  4621. $res_step = Database::query($sql_step);
  4622. $row_step = Database :: fetch_array($res_step);
  4623. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4624. $return .= $this->display_document_form('edit', $item_id, $row_step);
  4625. break;
  4626. case TOOL_LINK :
  4627. $link_id = (string) $row['path'];
  4628. if (ctype_digit($link_id)) {
  4629. $tbl_link = Database :: get_course_table(TABLE_LINK);
  4630. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE id = ' . Database :: escape_string($link_id);
  4631. $res_link = Database::query($sql_select);
  4632. $row_link = Database :: fetch_array($res_link);
  4633. if (is_array($row_link)) {
  4634. $row['url'] = $row_link['url'];
  4635. }
  4636. }
  4637. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4638. $return .= $this->display_link_form('edit', $item_id, $row);
  4639. break;
  4640. case 'dokeos_module' :
  4641. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4642. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4643. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  4644. } else {
  4645. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  4646. }
  4647. break;
  4648. case TOOL_QUIZ :
  4649. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4650. $return .= $this->display_quiz_form('edit', $item_id, $row);
  4651. break;
  4652. case TOOL_HOTPOTATOES :
  4653. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4654. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  4655. break;
  4656. case TOOL_STUDENTPUBLICATION :
  4657. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4658. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  4659. break;
  4660. case TOOL_FORUM :
  4661. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4662. $return .= $this->display_forum_form('edit', $item_id, $row);
  4663. break;
  4664. case TOOL_THREAD :
  4665. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4666. $return .= $this->display_thread_form('edit', $item_id, $row);
  4667. break;
  4668. }
  4669. }
  4670. return $return;
  4671. }
  4672. /**
  4673. * Function that displays a list with al the resources that could be added to the learning path
  4674. * @return string
  4675. */
  4676. public function display_resources() {
  4677. global $_course; // TODO: Don't use globals.
  4678. $return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  4679. $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>'; // TODO: A hardcoded Spanish text is here.
  4680. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';
  4681. $return .= '<div class="sectioncomment">';
  4682. /* Get all the docs. */
  4683. $return .= $this->get_documents();
  4684. /* Get all the exercises. */
  4685. $return .= $this->get_exercises();
  4686. /* Get all the links. */
  4687. $return .= $this->get_links();
  4688. /* Get al the student publications. */
  4689. $return .= $this->get_student_publications();
  4690. /* Get al the forums. */
  4691. $return .= $this->get_forums();
  4692. $return .= '</div>';
  4693. return $return;
  4694. }
  4695. /**
  4696. * Returns the extension of a document
  4697. * @param string filename
  4698. * @return string Extension (part after the last dot)
  4699. */
  4700. public function get_extension($filename) {
  4701. $explode = explode('.', $filename);
  4702. return $explode[count($explode) - 1];
  4703. }
  4704. /**
  4705. * Displays a document by id
  4706. *
  4707. * @param unknown_type $id
  4708. * @return unknown
  4709. */
  4710. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  4711. global $_course; // It is temporary.
  4712. $return = '';
  4713. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4714. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  4715. WHERE id = " . $id;
  4716. $res_doc = Database::query($sql_doc);
  4717. $row_doc = Database :: fetch_array($res_doc);
  4718. //if ($show_title)
  4719. //$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>';
  4720. // TODO: Add a path filter.
  4721. if ($iframe) {
  4722. $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>';
  4723. } else {
  4724. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  4725. }
  4726. return $return;
  4727. }
  4728. /**
  4729. * Return HTML form to add/edit a quiz
  4730. * @param string Action (add/edit)
  4731. * @param integer Item ID if already exists
  4732. * @param mixed Extra information (quiz ID if integer)
  4733. * @return string HTML form
  4734. */
  4735. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  4736. global $charset;
  4737. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4738. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  4739. if ($id != 0 && is_array($extra_info)) {
  4740. $item_title = stripslashes($extra_info['title']);
  4741. $item_description = stripslashes($extra_info['description']);
  4742. }
  4743. elseif (is_numeric($extra_info)) {
  4744. $sql_quiz = "
  4745. SELECT
  4746. title,
  4747. description
  4748. FROM " . $tbl_quiz . "
  4749. WHERE id = " . $extra_info;
  4750. $result = Database::query($sql_quiz);
  4751. $row = Database :: fetch_array($result);
  4752. $item_title = $row['title'];
  4753. $item_description = $row['description'];
  4754. } else {
  4755. $item_title = '';
  4756. $item_description = '';
  4757. }
  4758. $return = ' <div class="row">
  4759. <div class="form_header">';
  4760. if ($id != 0 && is_array($extra_info))
  4761. $parent = $extra_info['parent_item_id'];
  4762. else
  4763. $parent = 0;
  4764. $sql = "
  4765. SELECT *
  4766. FROM " . $tbl_lp_item . "
  4767. WHERE
  4768. lp_id = " . $this->lp_id;
  4769. $result = Database::query($sql);
  4770. $arrLP = array ();
  4771. while ($row = Database :: fetch_array($result)) {
  4772. $arrLP[] = array (
  4773. 'id' => $row['id'],
  4774. 'item_type' => $row['item_type'],
  4775. 'title' => $row['title'],
  4776. 'path' => $row['path'],
  4777. 'description' => $row['description'],
  4778. 'parent_item_id' => $row['parent_item_id'],
  4779. 'previous_item_id' => $row['previous_item_id'],
  4780. 'next_item_id' => $row['next_item_id'],
  4781. 'display_order' => $row['display_order'],
  4782. 'max_score' => $row['max_score'],
  4783. 'min_score' => $row['min_score'],
  4784. 'mastery_score' => $row['mastery_score'],
  4785. 'prerequisite' => $row['prerequisite'],
  4786. 'max_time_allowed' => $row['max_time_allowed']
  4787. );
  4788. }
  4789. $this->tree_array($arrLP);
  4790. $arrLP = $this->arrMenu;
  4791. unset ($this->arrMenu);
  4792. if ($action == 'add')
  4793. $return .= get_lang('CreateTheExercise') . '&nbsp;:' . "\n";
  4794. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:' . "\n";
  4795. else
  4796. $return .= get_lang('EditCurrentExecice') . '&nbsp;:' . "\n";
  4797. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4798. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4799. }
  4800. $return .= ' </div>
  4801. </div>';
  4802. $return .= '<div class="sectioncomment">';
  4803. $return .= '<form method="POST">' . "\n";
  4804. $return .= "\t" . '<table class="lp_form">' . "\n";
  4805. if ($action != 'move') {
  4806. $return .= "\t\t" . '<tr>' . "\n";
  4807. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  4808. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>' . "\n";
  4809. $return .= "\t\t" . '</tr>' . "\n";
  4810. }
  4811. $return .= "\t\t" . '<tr>' . "\n";
  4812. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  4813. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4814. $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">';
  4815. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  4816. $arrHide = array (
  4817. $id
  4818. );
  4819. //$parent_item_id = $_SESSION['parent_item_id'];
  4820. for ($i = 0; $i < count($arrLP); $i++) {
  4821. if ($action != 'add') {
  4822. 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)) {
  4823. $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>';
  4824. } else {
  4825. $arrHide[] = $arrLP[$i]['id'];
  4826. }
  4827. } else {
  4828. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  4829. $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>';
  4830. }
  4831. }
  4832. if (is_array($arrLP)) {
  4833. reset($arrLP);
  4834. }
  4835. $return .= '</select>';
  4836. $return .= '</td>';
  4837. $return .= '</tr>';
  4838. $return .= '<tr>';
  4839. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  4840. $return .= "\t\t\t" . '<td class="input">' . "\n";
  4841. $return .= "\t\t\t\t" . '<select class="learnpath_item_form" style="width:100%;" id="idPosition" name="previous" size="1">';
  4842. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  4843. for ($i = 0; $i < count($arrLP); $i++) {
  4844. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  4845. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4846. $selected = 'selected="selected" ';
  4847. elseif ($action == 'add') $selected = 'selected="selected" ';
  4848. else
  4849. $selected = '';
  4850. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  4851. }
  4852. }
  4853. $return .= "\t\t\t\t" . '</select>';
  4854. $return .= "\t\t\t" . '</td>' . "\n";
  4855. $return .= "\t\t" . '</tr>' . "\n";
  4856. if ($action != 'move') {
  4857. $id_prerequisite = 0;
  4858. if (is_array($arrLP)) {
  4859. foreach ($arrLP as $key => $value) {
  4860. if ($value['id'] == $id) {
  4861. $id_prerequisite = $value['prerequisite'];
  4862. break;
  4863. }
  4864. }
  4865. }
  4866. $arrHide = array ();
  4867. for ($i = 0; $i < count($arrLP); $i++) {
  4868. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  4869. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  4870. $s_selected_position = $arrLP[$i]['id'];
  4871. elseif ($action == 'add') $s_selected_position = 0;
  4872. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  4873. }
  4874. }
  4875. /*// Commented the prerequisites, only visible in edit (exercise).
  4876. $return .= "\t\t" . '<tr>' . "\n";
  4877. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  4878. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  4879. foreach($arrHide as $key => $value){
  4880. if($key==$s_selected_position && $action == 'add'){
  4881. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4882. }
  4883. elseif($key==$id_prerequisite && $action == 'edit'){
  4884. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  4885. }
  4886. else{
  4887. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  4888. }
  4889. }
  4890. $return .= "</select></td>";
  4891. */
  4892. $return .= "\t\t" . '</tr>' . "\n";
  4893. /*$return .= "\t\t" . '<tr>' . "\n";
  4894. $return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>' . "\n";
  4895. $return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  4896. // Remove temporarily the test description.
  4897. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>' . "\n";
  4898. //$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
  4899. $return .= "\t\t" . '</tr>' . "\n"; */
  4900. }
  4901. $return .= "\t\t" . '<tr>' . "\n";
  4902. if ($action == 'add') {
  4903. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  4904. } else {
  4905. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  4906. }
  4907. $return .= "\t\t" . '</tr>' . "\n";
  4908. $return .= "\t" . '</table>' . "\n";
  4909. if ($action == 'move') {
  4910. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  4911. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  4912. }
  4913. if (is_numeric($extra_info)) {
  4914. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  4915. }
  4916. elseif (is_array($extra_info)) {
  4917. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  4918. }
  4919. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />' . "\n";
  4920. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  4921. $return .= '</form>' . "\n";
  4922. $return .= '</div>' . "\n";
  4923. return $return;
  4924. }
  4925. /**
  4926. * Addition of Hotpotatoes tests
  4927. * @param string Action
  4928. * @param integer Internal ID of the item
  4929. * @param mixed Extra information - can be an array with title and description indexes
  4930. * @return string HTML structure to display the hotpotatoes addition formular
  4931. */
  4932. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  4933. global $charset;
  4934. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  4935. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4936. if ($id != 0 && is_array($extra_info)) {
  4937. $item_title = stripslashes($extra_info['title']);
  4938. $item_description = stripslashes($extra_info['description']);
  4939. }
  4940. elseif (is_numeric($extra_info)) {
  4941. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  4942. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  4943. WHERE path LIKE '" . $uploadPath . "/%/%htm%'
  4944. AND id = " . (int) $extra_info . " ORDER BY id ASC";
  4945. $res_hot = Database::query($sql_hot);
  4946. $row = Database :: fetch_array($res_hot);
  4947. $item_title = $row['title'];
  4948. $item_description = $row['description'];
  4949. if (!empty ($row['comment'])) {
  4950. $item_title = $row['comment'];
  4951. }
  4952. } else {
  4953. $item_title = '';
  4954. $item_description = '';
  4955. }
  4956. $return = '<div style="margin:3px 12px;">';
  4957. if ($id != 0 && is_array($extra_info))
  4958. $parent = $extra_info['parent_item_id'];
  4959. else
  4960. $parent = 0;
  4961. $sql = "
  4962. SELECT *
  4963. FROM " . $tbl_lp_item . "
  4964. WHERE
  4965. lp_id = " . $this->lp_id;
  4966. $result = Database::query($sql);
  4967. $arrLP = array ();
  4968. while ($row = Database :: fetch_array($result)) {
  4969. $arrLP[] = array (
  4970. 'id' => $row['id'],
  4971. 'item_type' => $row['item_type'],
  4972. 'title' => $row['title'],
  4973. 'path' => $row['path'],
  4974. 'description' => $row['description'],
  4975. 'parent_item_id' => $row['parent_item_id'],
  4976. 'previous_item_id' => $row['previous_item_id'],
  4977. 'next_item_id' => $row['next_item_id'],
  4978. 'display_order' => $row['display_order'],
  4979. 'max_score' => $row['max_score'],
  4980. 'min_score' => $row['min_score'],
  4981. 'mastery_score' => $row['mastery_score'],
  4982. 'prerequisite' => $row['prerequisite'],
  4983. 'max_time_allowed' => $row['max_time_allowed']
  4984. );
  4985. }
  4986. $this->tree_array($arrLP);
  4987. $arrLP = $this->arrMenu;
  4988. unset ($this->arrMenu);
  4989. if ($action == 'add')
  4990. $return .= '<p class="lp_title">' . get_lang('CreateTheExercise') . '&nbsp;:</p>' . "\n";
  4991. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>' . "\n";
  4992. else
  4993. $return .= '<p class="lp_title">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>' . "\n";
  4994. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  4995. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  4996. }
  4997. $return .= '<form method="POST">' . "\n";
  4998. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  4999. $return .= "\t\t" . '<tr>' . "\n";
  5000. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>' . "\n";
  5001. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5002. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5003. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5004. $arrHide = array (
  5005. $id
  5006. );
  5007. if (count($arrLP) > 0) {
  5008. for ($i = 0; $i < count($arrLP); $i++) {
  5009. if ($action != 'add') {
  5010. 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)) {
  5011. $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>';
  5012. } else {
  5013. $arrHide[] = $arrLP[$i]['id'];
  5014. }
  5015. } else {
  5016. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5017. $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>';
  5018. }
  5019. }
  5020. reset($arrLP);
  5021. }
  5022. $return .= "\t\t\t\t" . '</select>';
  5023. $return .= "\t\t\t" . '</td>' . "\n";
  5024. $return .= "\t\t" . '</tr>' . "\n";
  5025. $return .= "\t\t" . '<tr>' . "\n";
  5026. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . ' :</label></td>' . "\n";
  5027. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5028. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5029. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5030. for ($i = 0; $i < count($arrLP); $i++) {
  5031. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5032. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5033. $selected = 'selected="selected" ';
  5034. elseif ($action == 'add') $selected = 'selected="selected" ';
  5035. else
  5036. $selected = '';
  5037. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5038. }
  5039. }
  5040. $return .= "\t\t\t\t" . '</select>';
  5041. $return .= "\t\t\t" . '</td>' . "\n";
  5042. $return .= "\t\t" . '</tr>' . "\n";
  5043. if ($action != 'move') {
  5044. $return .= "\t\t" . '<tr>' . "\n";
  5045. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>' . "\n";
  5046. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5047. $return .= "\t\t" . '</tr>' . "\n";
  5048. $id_prerequisite = 0;
  5049. if (is_array($arrLP) && count($arrLP) > 0) {
  5050. foreach ($arrLP as $key => $value) {
  5051. if ($value['id'] == $id) {
  5052. $id_prerequisite = $value['prerequisite'];
  5053. break;
  5054. }
  5055. }
  5056. $arrHide = array ();
  5057. for ($i = 0; $i < count($arrLP); $i++) {
  5058. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5059. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5060. $s_selected_position = $arrLP[$i]['id'];
  5061. elseif ($action == 'add') $s_selected_position = 0;
  5062. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5063. }
  5064. }
  5065. }
  5066. $return .= "\t\t" . '<tr>' . "\n";
  5067. //$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>' . "\n";
  5068. //$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5069. foreach ($arrHide as $key => $value) {
  5070. if ($key == $s_selected_position && $action == 'add') {
  5071. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5072. }
  5073. elseif ($key == $id_prerequisite && $action == 'edit') {
  5074. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5075. } else {
  5076. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5077. }
  5078. }
  5079. $return .= "</select></td>";
  5080. $return .= "\t\t" . '</tr>' . "\n";
  5081. $return .= "\t\t" . '<tr>' . "\n";
  5082. $return .= "\t\t" . '</tr>' . "\n";
  5083. }
  5084. $return .= "\t\t" . '<tr>' . "\n";
  5085. $return .= "\t\t\t" . '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>' . "\n";
  5086. $return .= "\t\t" . '</tr>' . "\n";
  5087. $return .= "\t" . '</table>' . "\n";
  5088. if ($action == 'move') {
  5089. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5090. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5091. }
  5092. if (is_numeric($extra_info)) {
  5093. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5094. }
  5095. elseif (is_array($extra_info)) {
  5096. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5097. }
  5098. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />' . "\n";
  5099. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5100. $return .= '</form>' . "\n";
  5101. $return .= '</div>' . "\n";
  5102. return $return;
  5103. }
  5104. /**
  5105. * Return the form to display the forum edit/add option
  5106. * @param string Action (add/edit)
  5107. * @param integer ID of the lp_item if already exists
  5108. * @param mixed Forum ID or title
  5109. * @return string HTML form
  5110. */
  5111. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5112. global $charset;
  5113. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5114. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5115. if ($id != 0 && is_array($extra_info)) {
  5116. $item_title = stripslashes($extra_info['title']);
  5117. }
  5118. elseif (is_numeric($extra_info)) {
  5119. $sql_forum = "
  5120. SELECT
  5121. forum_title as title, forum_comment as comment
  5122. FROM " . $tbl_forum . "
  5123. WHERE forum_id = " . $extra_info;
  5124. $result = Database::query($sql_forum);
  5125. $row = Database :: fetch_array($result);
  5126. $item_title = $row['title'];
  5127. $item_description = $row['comment'];
  5128. } else {
  5129. $item_title = '';
  5130. $item_description = '';
  5131. }
  5132. $return = ' <div class="row">
  5133. <div class="form_header">';
  5134. if ($id != 0 && is_array($extra_info))
  5135. $parent = $extra_info['parent_item_id'];
  5136. else
  5137. $parent = 0;
  5138. $sql = "
  5139. SELECT *
  5140. FROM " . $tbl_lp_item . "
  5141. WHERE
  5142. lp_id = " . $this->lp_id;
  5143. $result = Database::query($sql);
  5144. $arrLP = array ();
  5145. while ($row = Database :: fetch_array($result)) {
  5146. $arrLP[] = array (
  5147. 'id' => $row['id'],
  5148. 'item_type' => $row['item_type'],
  5149. 'title' => $row['title'],
  5150. 'path' => $row['path'],
  5151. 'description' => $row['description'],
  5152. 'parent_item_id' => $row['parent_item_id'],
  5153. 'previous_item_id' => $row['previous_item_id'],
  5154. 'next_item_id' => $row['next_item_id'],
  5155. 'display_order' => $row['display_order'],
  5156. 'max_score' => $row['max_score'],
  5157. 'min_score' => $row['min_score'],
  5158. 'mastery_score' => $row['mastery_score'],
  5159. 'prerequisite' => $row['prerequisite']
  5160. );
  5161. }
  5162. $this->tree_array($arrLP);
  5163. $arrLP = $this->arrMenu;
  5164. unset ($this->arrMenu);
  5165. if ($action == 'add')
  5166. $return .= get_lang('CreateTheForum') . '&nbsp;:' . "\n";
  5167. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:' . "\n";
  5168. else
  5169. $return .= get_lang('EditCurrentForum') . '&nbsp;:' . "\n";
  5170. $return .= ' </div>
  5171. </div>';
  5172. $return .= '<div class="sectioncomment">';
  5173. $return .= '<form method="POST">' . "\n";
  5174. $return .= "\t" . '<table class="lp_form">' . "\n";
  5175. if ($action != 'move') {
  5176. $return .= "\t\t" . '<tr>' . "\n";
  5177. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5178. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  5179. $return .= "\t\t" . '</tr>' . "\n";
  5180. }
  5181. $return .= "\t\t" . '<tr>' . "\n";
  5182. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5183. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5184. $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">';
  5185. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5186. $arrHide = array (
  5187. $id
  5188. );
  5189. //$parent_item_id = $_SESSION['parent_item_id'];
  5190. for ($i = 0; $i < count($arrLP); $i++) {
  5191. if ($action != 'add') {
  5192. if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
  5193. $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>';
  5194. } else {
  5195. $arrHide[] = $arrLP[$i]['id'];
  5196. }
  5197. } else {
  5198. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5199. $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>';
  5200. }
  5201. }
  5202. if (is_array($arrLP)) {
  5203. reset($arrLP);
  5204. }
  5205. $return .= "\t\t\t\t" . '</select>';
  5206. $return .= "\t\t\t" . '</td>' . "\n";
  5207. $return .= "\t\t" . '</tr>' . "\n";
  5208. $return .= "\t\t" . '<tr>' . "\n";
  5209. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  5210. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5211. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5212. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5213. for ($i = 0; $i < count($arrLP); $i++) {
  5214. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5215. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5216. $selected = 'selected="selected" ';
  5217. elseif ($action == 'add') $selected = 'selected="selected" ';
  5218. else
  5219. $selected = '';
  5220. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5221. }
  5222. }
  5223. $return .= "\t\t\t\t" . '</select>';
  5224. $return .= "\t\t\t" . '</td>' . "\n";
  5225. $return .= "\t\t" . '</tr>' . "\n";
  5226. if ($action != 'move') {
  5227. $return .= "\t\t" . '<tr>' . "\n";
  5228. $return .= "\t\t" . '</tr>' . "\n";
  5229. $id_prerequisite = 0;
  5230. if (is_array($arrLP)) {
  5231. foreach ($arrLP as $key => $value) {
  5232. if ($value['id'] == $id) {
  5233. $id_prerequisite = $value['prerequisite'];
  5234. break;
  5235. }
  5236. }
  5237. }
  5238. $arrHide = array ();
  5239. for ($i = 0; $i < count($arrLP); $i++) {
  5240. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5241. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5242. $s_selected_position = $arrLP[$i]['id'];
  5243. elseif ($action == 'add') $s_selected_position = 0;
  5244. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5245. }
  5246. }
  5247. $return .= "\t\t" . '</tr>' . "\n";
  5248. }
  5249. $return .= "\t\t" . '<tr>' . "\n";
  5250. if ($action == 'add') {
  5251. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5252. } else {
  5253. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5254. }
  5255. $return .= "\t\t" . '</tr>' . "\n";
  5256. $return .= "\t" . '</table>' . "\n";
  5257. if ($action == 'move') {
  5258. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5259. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5260. }
  5261. if (is_numeric($extra_info)) {
  5262. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5263. }
  5264. elseif (is_array($extra_info)) {
  5265. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5266. }
  5267. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />' . "\n";
  5268. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5269. $return .= '</form>' . "\n";
  5270. $return .= '</div>' . "\n";
  5271. return $return;
  5272. }
  5273. /**
  5274. * Return HTML form to add/edit forum threads
  5275. * @param string Action (add/edit)
  5276. * @param integer Item ID if already exists in learning path
  5277. * @param mixed Extra information (thread ID if integer)
  5278. * @return string HTML form
  5279. */
  5280. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5281. global $charset;
  5282. echo '
  5283. <style>
  5284. div.row div.label {
  5285. width:110px;
  5286. }
  5287. div.row div.formw {
  5288. width: 82%;
  5289. }
  5290. </style>';
  5291. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5292. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5293. if ($id != 0 && is_array($extra_info)) {
  5294. $item_title = stripslashes($extra_info['title']);
  5295. }
  5296. elseif (is_numeric($extra_info)) {
  5297. $sql_forum = "
  5298. SELECT
  5299. thread_title as title
  5300. FROM " . $tbl_forum . "
  5301. WHERE thread_id = " . $extra_info;
  5302. $result = Database::query($sql_forum);
  5303. $row = Database :: fetch_array($result);
  5304. $item_title = $row['title'];
  5305. $item_description = '';
  5306. } else {
  5307. $item_title = '';
  5308. $item_description = '';
  5309. }
  5310. $return = '<div style="margin:3px 12px;">';
  5311. if ($id != 0 && is_array($extra_info))
  5312. $parent = $extra_info['parent_item_id'];
  5313. else
  5314. $parent = 0;
  5315. $sql = "
  5316. SELECT *
  5317. FROM " . $tbl_lp_item . "
  5318. WHERE
  5319. lp_id = " . $this->lp_id;
  5320. $result = Database::query($sql);
  5321. $arrLP = array ();
  5322. while ($row = Database :: fetch_array($result)) {
  5323. $arrLP[] = array (
  5324. 'id' => $row['id'],
  5325. 'item_type' => $row['item_type'],
  5326. 'title' => $row['title'],
  5327. 'path' => $row['path'],
  5328. 'description' => $row['description'],
  5329. 'parent_item_id' => $row['parent_item_id'],
  5330. 'previous_item_id' => $row['previous_item_id'],
  5331. 'next_item_id' => $row['next_item_id'],
  5332. 'display_order' => $row['display_order'],
  5333. 'max_score' => $row['max_score'],
  5334. 'min_score' => $row['min_score'],
  5335. 'mastery_score' => $row['mastery_score'],
  5336. 'prerequisite' => $row['prerequisite']
  5337. );
  5338. }
  5339. $this->tree_array($arrLP);
  5340. $arrLP = $this->arrMenu;
  5341. unset ($this->arrMenu);
  5342. if ($action == 'add')
  5343. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>' . "\n";
  5344. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>' . "\n";
  5345. else
  5346. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>' . "\n";
  5347. $return .= '<form method="POST">' . "\n";
  5348. $return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
  5349. $return .= "\t\t" . '<tr>' . "\n";
  5350. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>' . "\n";
  5351. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5352. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5353. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5354. $arrHide = array (
  5355. $id
  5356. );
  5357. for ($i = 0; $i < count($arrLP); $i++) {
  5358. if ($action != 'add') {
  5359. 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)) {
  5360. $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>';
  5361. } else {
  5362. $arrHide[] = $arrLP[$i]['id'];
  5363. }
  5364. } else {
  5365. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5366. $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>';
  5367. }
  5368. }
  5369. if ($arrLP != null) {
  5370. reset($arrLP);
  5371. }
  5372. $return .= "\t\t\t\t" . '</select>';
  5373. $return .= "\t\t\t" . '</td>' . "\n";
  5374. $return .= "\t\t" . '</tr>' . "\n";
  5375. $return .= "\t\t" . '<tr>' . "\n";
  5376. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '&nbsp;:</label></td>' . "\n";
  5377. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5378. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
  5379. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5380. for ($i = 0; $i < count($arrLP); $i++) {
  5381. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5382. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5383. $selected = 'selected="selected" ';
  5384. elseif ($action == 'add') $selected = 'selected="selected" ';
  5385. else
  5386. $selected = '';
  5387. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5388. }
  5389. }
  5390. $return .= "\t\t\t\t" . '</select>';
  5391. $return .= "\t\t\t" . '</td>' . "\n";
  5392. $return .= "\t\t" . '</tr>' . "\n";
  5393. if ($action != 'move') {
  5394. $return .= "\t\t" . '<tr>' . "\n";
  5395. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>' . "\n";
  5396. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
  5397. $return .= "\t\t" . '</tr>' . "\n";
  5398. $return .= "\t\t" . '<tr>' . "\n";
  5399. $return .= "\t\t" . '</tr>' . "\n";
  5400. $id_prerequisite = 0;
  5401. if ($arrLP != null) {
  5402. foreach ($arrLP as $key => $value) {
  5403. if ($value['id'] == $id) {
  5404. $id_prerequisite = $value['prerequisite'];
  5405. break;
  5406. }
  5407. }
  5408. }
  5409. $arrHide = array();
  5410. for ($i = 0; $i < count($arrLP); $i++) {
  5411. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5412. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5413. $s_selected_position = $arrLP[$i]['id'];
  5414. elseif ($action == 'add') $s_selected_position = 0;
  5415. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5416. }
  5417. }
  5418. $return .= "\t\t" . '<tr>' . "\n";
  5419. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>' . "\n";
  5420. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5421. foreach ($arrHide as $key => $value) {
  5422. if ($key == $s_selected_position && $action == 'add') {
  5423. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5424. }
  5425. elseif ($key == $id_prerequisite && $action == 'edit') {
  5426. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5427. } else {
  5428. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5429. }
  5430. }
  5431. $return .= "</select></td>";
  5432. $return .= "\t\t" . '</tr>' . "\n";
  5433. }
  5434. $return .= "\t\t" . '<tr>' . "\n";
  5435. $return .= "\t\t\t" . '<td colspan="2">
  5436. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>' . "\n";
  5437. $return .= "\t\t" . '</tr>' . "\n";
  5438. $return .= "\t" . '</table>' . "\n";
  5439. if ($action == 'move') {
  5440. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  5441. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  5442. }
  5443. if (is_numeric($extra_info)) {
  5444. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  5445. }
  5446. elseif (is_array($extra_info)) {
  5447. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  5448. }
  5449. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />' . "\n";
  5450. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  5451. $return .= '</form>' . "\n";
  5452. $return .= '</div>' . "\n";
  5453. return $return;
  5454. }
  5455. /**
  5456. * Return the HTML form to display an item (generally a section/module item)
  5457. * @param string Item type (module/dokeos_module)
  5458. * @param string Title (optional, only when creating)
  5459. * @param string Action ('add'/'edit')
  5460. * @param integer lp_item ID
  5461. * @param mixed Extra info
  5462. * @return string HTML form
  5463. */
  5464. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5465. global $_course;
  5466. global $charset;
  5467. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5468. if ($id != 0 && is_array($extra_info)) {
  5469. $item_title = $extra_info['title'];
  5470. $item_description = $extra_info['description'];
  5471. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5472. } else {
  5473. $item_title = '';
  5474. $item_description = '';
  5475. }
  5476. $return = ' <div class="row">
  5477. <div class="form_header">';
  5478. if ($id != 0 && is_array($extra_info))
  5479. $parent = $extra_info['parent_item_id'];
  5480. else
  5481. $parent = 0;
  5482. $sql = "
  5483. SELECT *
  5484. FROM " . $tbl_lp_item . "
  5485. WHERE lp_id = " . $this->lp_id . " AND id != " . $id . " ";
  5486. if ($item_type == 'module')
  5487. $sql .= " AND parent_item_id = 0";
  5488. $result = Database::query($sql);
  5489. $arrLP = array ();
  5490. while ($row = Database :: fetch_array($result)) {
  5491. $arrLP[] = array (
  5492. 'id' => $row['id'],
  5493. 'item_type' => $row['item_type'],
  5494. 'title' => $row['title'],
  5495. 'path' => $row['path'],
  5496. 'description' => $row['description'],
  5497. 'parent_item_id' => $row['parent_item_id'],
  5498. 'previous_item_id' => $row['previous_item_id'],
  5499. 'next_item_id' => $row['next_item_id'],
  5500. 'max_score' => $row['max_score'],
  5501. 'min_score' => $row['min_score'],
  5502. 'mastery_score' => $row['mastery_score'],
  5503. 'prerequisite' => $row['prerequisite'],
  5504. 'display_order' => $row['display_order']
  5505. );
  5506. }
  5507. $this->tree_array($arrLP);
  5508. $arrLP = $this->arrMenu;
  5509. unset ($this->arrMenu);
  5510. $return .= $title . "\n";
  5511. $return .= ' </div>
  5512. </div>';
  5513. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5514. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5515. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5516. $defaults['description'] = $item_description;
  5517. $form->addElement('html', $return);
  5518. //$arrHide = array($id);
  5519. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5520. $arrHide[0]['padding'] = 3;
  5521. $charset = api_get_system_encoding();
  5522. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5523. for ($i = 0; $i < count($arrLP); $i++) {
  5524. if ($action != 'add') {
  5525. 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)) {
  5526. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5527. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5528. if ($parent == $arrLP[$i]['id']) {
  5529. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5530. }
  5531. }
  5532. } else {
  5533. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5534. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5535. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5536. if ($parent == $arrLP[$i]['id']) {
  5537. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5538. }
  5539. }
  5540. }
  5541. }
  5542. if ($action != 'move') {
  5543. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5544. $form->applyFilter('title', 'html_filter');
  5545. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5546. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5547. } else {
  5548. $form->addElement('hidden', 'title');
  5549. }
  5550. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5551. foreach ($arrHide as $key => $value) {
  5552. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5553. }
  5554. $parent_select->setSelected($s_selected_parent);
  5555. }
  5556. if (is_array($arrLP)) {
  5557. reset($arrLP);
  5558. }
  5559. $arrHide = array ();
  5560. // POSITION
  5561. for ($i = 0; $i < count($arrLP); $i++) {
  5562. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5563. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5564. $s_selected_position = $arrLP[$i]['id'];
  5565. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5566. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5567. }
  5568. }
  5569. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_chapter_form" style="width:37%;"');
  5570. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $value['padding'] . 'px;"');
  5571. foreach ($arrHide as $key => $value) {
  5572. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5573. }
  5574. if (!empty ($s_selected_position)) {
  5575. $position->setSelected($s_selected_position);
  5576. }
  5577. if (is_array($arrLP)) {
  5578. reset($arrLP);
  5579. }
  5580. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5581. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5582. $form->addElement('hidden', 'parent', '0');
  5583. }
  5584. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5585. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5586. if ($item_type == 'sco') {
  5587. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5588. }
  5589. $renderer = $form->defaultRenderer();
  5590. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5591. $form->addElement('html_editor', 'content_lp', '', null, array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '400', 'FullPage' => true));
  5592. $defaults['content_lp'] = file_get_contents($item_path);
  5593. }
  5594. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5595. $form->addElement('hidden', 'post_time', time());
  5596. $form->setDefaults($defaults);
  5597. return $form->return_form();
  5598. }
  5599. /**
  5600. * Returns the form to update or create a document
  5601. * @param string Action (add/edit)
  5602. * @param integer ID of the lp_item (if already exists)
  5603. * @param mixed Integer if document ID, string if info ('new')
  5604. * @return string HTML form
  5605. */
  5606. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  5607. global $charset;
  5608. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5609. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5610. $path_parts = pathinfo($extra_info['dir']);
  5611. $no_display_edit_textarea = false;
  5612. //If action==edit document
  5613. //We don't display the document form if it's not an editable document (html or txt file)
  5614. if ($action == "edit") {
  5615. if (is_array($extra_info)) {
  5616. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5617. $no_display_edit_textarea = true;
  5618. }
  5619. }
  5620. }
  5621. $no_display_add = false;
  5622. // If action==add an existing document
  5623. // We don't display the document form if it's not an editable document (html or txt file).
  5624. if ($action == "add") {
  5625. if (is_numeric($extra_info)) {
  5626. $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database :: escape_string($extra_info);
  5627. $result = Database::query($sql_doc);
  5628. $path_file = Database :: result($result, 0, 0);
  5629. $path_parts = pathinfo($path_file);
  5630. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  5631. $no_display_add = true;
  5632. }
  5633. }
  5634. }
  5635. if ($id != 0 && is_array($extra_info)) {
  5636. $item_title = stripslashes($extra_info['title']);
  5637. $item_description = stripslashes($extra_info['description']);
  5638. $item_terms = stripslashes($extra_info['terms']);
  5639. if (empty ($item_title)) {
  5640. $path_parts = pathinfo($extra_info['path']);
  5641. $item_title = stripslashes($path_parts['filename']);
  5642. }
  5643. } elseif (is_numeric($extra_info)) {
  5644. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  5645. WHERE id = " . Database :: escape_string($extra_info);
  5646. $result = Database::query($sql_doc);
  5647. $row = Database :: fetch_array($result);
  5648. $explode = explode('.', $row['title']);
  5649. if (count($explode) > 1) {
  5650. for ($i = 0; $i < count($explode) - 1; $i++)
  5651. $item_title .= $explode[$i];
  5652. } else {
  5653. $item_title = $row['title'];
  5654. }
  5655. $item_title = str_replace('_', ' ', $item_title);
  5656. if (empty ($item_title)) {
  5657. $path_parts = pathinfo($row['path']);
  5658. $item_title = stripslashes($path_parts['filename']);
  5659. }
  5660. } else {
  5661. $item_title = '';
  5662. $item_description = '';
  5663. }
  5664. $return = ' <div class="row">
  5665. <div class="form_header">';
  5666. if ($id != 0 && is_array($extra_info))
  5667. $parent = $extra_info['parent_item_id'];
  5668. else
  5669. $parent = 0;
  5670. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5671. WHERE lp_id = " . $this->lp_id;
  5672. $result = Database::query($sql);
  5673. $arrLP = array ();
  5674. while ($row = Database :: fetch_array($result)) {
  5675. $arrLP[] = array (
  5676. 'id' => $row['id'],
  5677. 'item_type' => $row['item_type'],
  5678. 'title' => $row['title'],
  5679. 'path' => $row['path'],
  5680. 'description' => $row['description'],
  5681. 'parent_item_id' => $row['parent_item_id'],
  5682. 'previous_item_id' => $row['previous_item_id'],
  5683. 'next_item_id' => $row['next_item_id'],
  5684. 'display_order' => $row['display_order'],
  5685. 'max_score' => $row['max_score'],
  5686. 'min_score' => $row['min_score'],
  5687. 'mastery_score' => $row['mastery_score'],
  5688. 'prerequisite' => $row['prerequisite']
  5689. );
  5690. }
  5691. $this->tree_array($arrLP);
  5692. $arrLP = $this->arrMenu;
  5693. unset ($this->arrMenu);
  5694. if ($action == 'add') {
  5695. $return .= get_lang('CreateTheDocument') . "\n";
  5696. }
  5697. elseif ($action == 'move') {
  5698. $return .= get_lang('MoveTheCurrentDocument') . "\n";
  5699. } else {
  5700. $return .= get_lang('EditTheCurrentDocument') . "\n";
  5701. }
  5702. $return .= '</div>
  5703. </div>';
  5704. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5705. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  5706. }
  5707. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5708. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  5709. $defaults['title'] = Security :: remove_XSS($item_title);
  5710. if (empty($item_title)) {
  5711. $defaults['title'] = Security::remove_XSS($item_title);
  5712. }
  5713. $defaults['description'] = $item_description;
  5714. $form->addElement('html', $return);
  5715. if ($action != 'move') {
  5716. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  5717. $form->applyFilter('title', 'html_filter');
  5718. }
  5719. //$arrHide = array($id);
  5720. $arrHide[0]['value'] = $this->name;
  5721. $arrHide[0]['padding'] = 3;
  5722. for ($i = 0; $i < count($arrLP); $i++) {
  5723. if ($action != 'add') {
  5724. 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)) {
  5725. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5726. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5727. if ($parent == $arrLP[$i]['id']) {
  5728. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5729. }
  5730. }
  5731. } else {
  5732. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5733. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5734. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5735. if ($parent == $arrLP[$i]['id']) {
  5736. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5737. }
  5738. }
  5739. }
  5740. }
  5741. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  5742. $my_count=0;
  5743. foreach ($arrHide as $key => $value) {
  5744. if ($my_count!=0) {
  5745. // The LP name is also the first section and is not in the same charset like the other sections.
  5746. $value['value'] = Security :: remove_XSS($value['value']);
  5747. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5748. } else {
  5749. $value['value'] = Security :: remove_XSS($value['value']);
  5750. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5751. }
  5752. $my_count++;
  5753. }
  5754. if (!empty ($id)) {
  5755. $parent_select->setSelected($parent);
  5756. } else {
  5757. $parent_item_id = $_SESSION['parent_item_id'];
  5758. $parent_select->setSelected($parent_item_id);
  5759. }
  5760. if (is_array($arrLP)) {
  5761. reset($arrLP);
  5762. }
  5763. $arrHide = array ();
  5764. //POSITION
  5765. for ($i = 0; $i < count($arrLP); $i++) {
  5766. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5767. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5768. $s_selected_position = $arrLP[$i]['id'];
  5769. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5770. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5771. }
  5772. }
  5773. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
  5774. $position->addOption(get_lang('FirstPosition'), 0);
  5775. foreach ($arrHide as $key => $value) {
  5776. $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5777. }
  5778. $position->setSelected($s_selected_position);
  5779. if (is_array($arrLP)) {
  5780. reset($arrLP);
  5781. }
  5782. if ($action != 'move') {
  5783. $id_prerequisite = 0;
  5784. if (is_array($arrLP)) {
  5785. foreach ($arrLP as $key => $value) {
  5786. if ($value['id'] == $id) {
  5787. $id_prerequisite = $value['prerequisite'];
  5788. break;
  5789. }
  5790. }
  5791. }
  5792. // Commented the prerequisites, only visible in edit (new document).
  5793. //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
  5794. //$select_prerequisites->addOption(get_lang('NoPrerequisites'), 0);
  5795. // Form element for uploading an mp3 file.
  5796. //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
  5797. //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
  5798. /* Code deprecated - moved to lp level (not lp-item).
  5799. if (api_get_setting('search_enabled') === 'true') {
  5800. //add terms field
  5801. $terms = $form->addElement('text', 'terms', get_lang('SearchFeatureTerms').'&nbsp;:', 'id="idTerms" class="learnpath_item_form"');
  5802. $terms->setValue($item_terms);
  5803. }
  5804. */
  5805. $arrHide = array ();
  5806. for ($i = 0; $i < count($arrLP); $i++) {
  5807. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5808. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5809. $s_selected_position = $arrLP[$i]['id'];
  5810. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5811. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5812. }
  5813. }
  5814. /* foreach ($arrHide as $key => $value) {
  5815. $select_prerequisites->addOption($value['value'], $key, 'style="padding-left:'.$value['padding'].'px;"');
  5816. if ($key == $s_selected_position && $action == 'add') {
  5817. $select_prerequisites -> setSelected(0);
  5818. }
  5819. elseif ($key == $id_prerequisite && $action == 'edit') {
  5820. $select_prerequisites -> setSelected($id_prerequisite);
  5821. }
  5822. }
  5823. */
  5824. if (!$no_display_add) {
  5825. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  5826. if (isset ($_POST['content']))
  5827. $content = stripslashes($_POST['content']);
  5828. elseif (is_array($extra_info)) {
  5829. //If it's an html document or a text file
  5830. if (!$no_display_edit_textarea) {
  5831. $content = $this->display_document($extra_info['path'], false, false);
  5832. }
  5833. }
  5834. elseif (is_numeric($extra_info)) $content = $this->display_document($extra_info, false, false);
  5835. else
  5836. $content = '';
  5837. if (!$no_display_edit_textarea) {
  5838. // We need to claculate here some specific settings for the online editor.
  5839. // The calculated settings work for documents in the Documents tool
  5840. // (on the root or in subfolders).
  5841. // For documents in native scorm packages it is unclear whether the
  5842. // online editor should be activated or not.
  5843. $relative_path = $extra_info['dir'];
  5844. if ($relative_path == 'n/') {
  5845. // A new document, it is in the root of the repository.
  5846. $relative_path = '';
  5847. $relative_prefix = '';
  5848. } else {
  5849. // The document already exists. Whe have to determine its relative path towards the repository root.
  5850. $relative_path = explode('/', $relative_path);
  5851. $cnt = count($relative_path) - 2;
  5852. if ($cnt < 0) {
  5853. $cnt = 0;
  5854. }
  5855. $relative_prefix = str_repeat('../', $cnt);
  5856. $relative_path = array_slice($relative_path, 1, $cnt);
  5857. $relative_path = implode('/', $relative_path);
  5858. if (strlen($relative_path) > 0) {
  5859. $relative_path = $relative_path . '/';
  5860. }
  5861. }
  5862. $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '700', 'FullPage' => true,
  5863. 'CreateDocumentDir' => $relative_prefix,
  5864. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/',
  5865. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path
  5866. );
  5867. if ($_GET['action'] == 'add_item') {
  5868. $class = 'add';
  5869. $text = get_lang('LPCreateDocument');
  5870. } else
  5871. if ($_GET['action'] == 'edit_item') {
  5872. $class = 'save';
  5873. $text = get_lang('SaveDocument');
  5874. }
  5875. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  5876. $renderer = $form->defaultRenderer();
  5877. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5878. $form->addElement('html', '<div style="margin:3px 12px">');
  5879. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5880. $form->addElement('html', '</div>');
  5881. $defaults['content_lp'] = $content;
  5882. }
  5883. }
  5884. elseif (is_numeric($extra_info)) {
  5885. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5886. $return = $this->display_document($extra_info, true, true, true);
  5887. $form->addElement('html', $return);
  5888. }
  5889. }
  5890. }
  5891. if ($action == 'move') {
  5892. $form->addElement('hidden', 'title', $item_title);
  5893. $form->addElement('hidden', 'description', $item_description);
  5894. }
  5895. if (is_numeric($extra_info)) {
  5896. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  5897. $form->addElement('hidden', 'path', $extra_info);
  5898. }
  5899. elseif (is_array($extra_info)) {
  5900. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  5901. $form->addElement('hidden', 'path', $extra_info['path']);
  5902. }
  5903. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  5904. $form->addElement('hidden', 'post_time', time());
  5905. $form->setDefaults($defaults);
  5906. return $form->return_form();
  5907. }
  5908. /**
  5909. * Return HTML form to add/edit a link item
  5910. * @param string Action (add/edit)
  5911. * @param integer Item ID if exists
  5912. * @param mixed Extra info
  5913. * @return string HTML form
  5914. */
  5915. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  5916. global $charset;
  5917. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5918. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5919. if ($id != 0 && is_array($extra_info)) {
  5920. $item_title = stripslashes($extra_info['title']);
  5921. $item_description = stripslashes($extra_info['description']);
  5922. $item_url = stripslashes($extra_info['url']);
  5923. }
  5924. elseif (is_numeric($extra_info)) {
  5925. $sql_link = "
  5926. SELECT
  5927. title,
  5928. description,
  5929. url
  5930. FROM " . $tbl_link . "
  5931. WHERE id = " . $extra_info;
  5932. $result = Database::query($sql_link);
  5933. $row = Database :: fetch_array($result);
  5934. $item_title = $row['title'];
  5935. $item_description = $row['description'];
  5936. $item_url = $row['url'];
  5937. } else {
  5938. $item_title = '';
  5939. $item_description = '';
  5940. $item_url = '';
  5941. }
  5942. $return = ' <div class="row">
  5943. <div class="form_header">';
  5944. if ($id != 0 && is_array($extra_info))
  5945. $parent = $extra_info['parent_item_id'];
  5946. else
  5947. $parent = 0;
  5948. $sql = "
  5949. SELECT *
  5950. FROM " . $tbl_lp_item . "
  5951. WHERE
  5952. lp_id = " . $this->lp_id;
  5953. $result = Database::query($sql);
  5954. $arrLP = array ();
  5955. while ($row = Database :: fetch_array($result)) {
  5956. $arrLP[] = array (
  5957. 'id' => $row['id'],
  5958. 'item_type' => $row['item_type'],
  5959. 'title' => $row['title'],
  5960. 'path' => $row['path'],
  5961. 'description' => $row['description'],
  5962. 'parent_item_id' => $row['parent_item_id'],
  5963. 'previous_item_id' => $row['previous_item_id'],
  5964. 'next_item_id' => $row['next_item_id'],
  5965. 'display_order' => $row['display_order'],
  5966. 'max_score' => $row['max_score'],
  5967. 'min_score' => $row['min_score'],
  5968. 'mastery_score' => $row['mastery_score'],
  5969. 'prerequisite' => $row['prerequisite']
  5970. );
  5971. }
  5972. $this->tree_array($arrLP);
  5973. $arrLP = $this->arrMenu;
  5974. unset ($this->arrMenu);
  5975. if ($action == 'add')
  5976. $return .= get_lang('CreateTheLink') . '&nbsp;:' . "\n";
  5977. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:' . "\n";
  5978. else
  5979. $return .= get_lang('EditCurrentLink') . '&nbsp;:' . "\n";
  5980. $return .= ' </div>
  5981. </div>';
  5982. $return .= '<div class="sectioncomment">';
  5983. $return .= '<form method="POST">' . "\n";
  5984. $return .= "\t" . '<table>' . "\n";
  5985. if ($action != 'move') {
  5986. $return .= "\t\t" . '<tr>' . "\n";
  5987. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  5988. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>' . "\n";
  5989. $return .= "\t\t" . '</tr>' . "\n";
  5990. }
  5991. $return .= "\t\t" . '<tr>' . "\n";
  5992. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  5993. $return .= "\t\t\t" . '<td class="input">' . "\n";
  5994. $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">';
  5995. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5996. $arrHide = array (
  5997. $id
  5998. );
  5999. $parent_item_id = $_SESSION['parent_item_id'];
  6000. for ($i = 0; $i < count($arrLP); $i++) {
  6001. if ($action != 'add') {
  6002. 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)) {
  6003. $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>';
  6004. } else {
  6005. $arrHide[] = $arrLP[$i]['id'];
  6006. }
  6007. } else {
  6008. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6009. $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>';
  6010. }
  6011. }
  6012. if (is_array($arrLP)) {
  6013. reset($arrLP);
  6014. }
  6015. $return .= "\t\t\t\t" . '</select>';
  6016. $return .= "\t\t\t" . '</td>' . "\n";
  6017. $return .= "\t\t" . '</tr>' . "\n";
  6018. $return .= "\t\t" . '<tr>' . "\n";
  6019. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6020. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6021. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6022. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6023. for ($i = 0; $i < count($arrLP); $i++) {
  6024. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6025. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6026. $selected = 'selected="selected" ';
  6027. elseif ($action == 'add') $selected = 'selected="selected" ';
  6028. else
  6029. $selected = '';
  6030. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6031. }
  6032. }
  6033. $return .= "\t\t\t\t" . '</select>';
  6034. $return .= "\t\t\t" . '</td>' . "\n";
  6035. $return .= "\t\t" . '</tr>' . "\n";
  6036. if ($action != 'move') {
  6037. $return .= "\t\t" . '<tr>' . "\n";
  6038. $return .= "\t\t\t" . '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>' . "\n";
  6039. $return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>' . "\n";
  6040. $return .= "\t\t" . '</tr>' . "\n";
  6041. $id_prerequisite = 0;
  6042. if (is_array($arrLP)) {
  6043. foreach ($arrLP as $key => $value) {
  6044. if ($value['id'] == $id) {
  6045. $id_prerequisite = $value['prerequisite'];
  6046. break;
  6047. }
  6048. }
  6049. }
  6050. $arrHide = array ();
  6051. for ($i = 0; $i < count($arrLP); $i++) {
  6052. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6053. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6054. $s_selected_position = $arrLP[$i]['id'];
  6055. elseif ($action == 'add') $s_selected_position = 0;
  6056. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6057. }
  6058. }
  6059. /*// Commented the prerequisites, only visible in edit (link).
  6060. $return .= "\t\t" . '<tr>' . "\n";
  6061. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6062. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6063. foreach($arrHide as $key => $value) {
  6064. if ($key == $s_selected_position && $action == 'add') {
  6065. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6066. }
  6067. elseif ($key == $id_prerequisite && $action == 'edit') {
  6068. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6069. }
  6070. else {
  6071. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6072. }
  6073. }
  6074. $return .= "</select></td>";
  6075. */
  6076. $return .= "\t\t" . '</tr>' . "\n";
  6077. }
  6078. $return .= "\t\t" . '<tr>' . "\n";
  6079. if ($action == 'add') {
  6080. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6081. } else {
  6082. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6083. }
  6084. $return .= "\t\t" . '</tr>' . "\n";
  6085. $return .= "\t" . '</table>' . "\n";
  6086. if ($action == 'move') {
  6087. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6088. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6089. }
  6090. if (is_numeric($extra_info)) {
  6091. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6092. }
  6093. elseif (is_array($extra_info)) {
  6094. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6095. }
  6096. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_LINK . '" />' . "\n";
  6097. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6098. $return .= '</form>' . "\n";
  6099. $return .= '</div>' . "\n";
  6100. return $return;
  6101. }
  6102. /**
  6103. * Return HTML form to add/edit a student publication (work)
  6104. * @param string Action (add/edit)
  6105. * @param integer Item ID if already exists
  6106. * @param mixed Extra info (work ID if integer)
  6107. * @return string HTML form
  6108. */
  6109. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6110. global $charset;
  6111. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6112. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6113. if ($id != 0 && is_array($extra_info)) {
  6114. $item_title = stripslashes($extra_info['title']);
  6115. $item_description = stripslashes($extra_info['description']);
  6116. }
  6117. elseif (is_numeric($extra_info)) {
  6118. $sql_publication = "
  6119. SELECT
  6120. title,
  6121. description
  6122. FROM " . $tbl_publication . "
  6123. WHERE id = " . $extra_info;
  6124. $result = Database::query($sql_publication);
  6125. $row = Database :: fetch_array($result);
  6126. $item_title = $row['title'];
  6127. } else {
  6128. $item_title = get_lang('Student_publication');
  6129. }
  6130. $return = ' <div class="row">
  6131. <div class="form_header">';
  6132. if ($id != 0 && is_array($extra_info))
  6133. $parent = $extra_info['parent_item_id'];
  6134. else
  6135. $parent = 0;
  6136. $sql = "
  6137. SELECT *
  6138. FROM " . $tbl_lp_item . "
  6139. WHERE
  6140. lp_id = " . $this->lp_id;
  6141. $result = Database::query($sql);
  6142. $arrLP = array ();
  6143. while ($row = Database :: fetch_array($result)) {
  6144. $arrLP[] = array (
  6145. 'id' => $row['id'],
  6146. 'item_type' => $row['item_type'],
  6147. 'title' => $row['title'],
  6148. 'path' => $row['path'],
  6149. 'description' => $row['description'],
  6150. 'parent_item_id' => $row['parent_item_id'],
  6151. 'previous_item_id' => $row['previous_item_id'],
  6152. 'next_item_id' => $row['next_item_id'],
  6153. 'display_order' => $row['display_order'],
  6154. 'max_score' => $row['max_score'],
  6155. 'min_score' => $row['min_score'],
  6156. 'mastery_score' => $row['mastery_score'],
  6157. 'prerequisite' => $row['prerequisite']
  6158. );
  6159. }
  6160. $this->tree_array($arrLP);
  6161. $arrLP = $this->arrMenu;
  6162. unset ($this->arrMenu);
  6163. if ($action == 'add')
  6164. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6165. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6166. else
  6167. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6168. $return .= ' </div>
  6169. </div>';
  6170. $return .= '<div class="sectioncomment">';
  6171. $return .= '<form method="POST">' . "\n";
  6172. $return .= "\t" . '<table class="lp_form">' . "\n";
  6173. if ($action != 'move') {
  6174. $return .= "\t\t" . '<tr>' . "\n";
  6175. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>' . "\n";
  6176. $return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>' . "\n";
  6177. $return .= "\t\t" . '</tr>' . "\n";
  6178. }
  6179. $return .= "\t\t" . '<tr>' . "\n";
  6180. $return .= "\t\t\t" . '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>' . "\n";
  6181. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6182. $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">';
  6183. //$parent_item_id = $_SESSION['parent_item_id'];
  6184. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6185. $arrHide = array (
  6186. $id
  6187. );
  6188. for ($i = 0; $i < count($arrLP); $i++) {
  6189. if ($action != 'add') {
  6190. 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)) {
  6191. $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>';
  6192. } else {
  6193. $arrHide[] = $arrLP[$i]['id'];
  6194. }
  6195. } else {
  6196. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6197. $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>';
  6198. }
  6199. }
  6200. if (is_array($arrLP)) {
  6201. reset($arrLP);
  6202. }
  6203. $return .= "\t\t\t\t" . '</select>';
  6204. $return .= "\t\t\t" . '</td>' . "\n";
  6205. $return .= "\t\t" . '</tr>' . "\n";
  6206. $return .= "\t\t" . '<tr>' . "\n";
  6207. $return .= "\t\t\t" . '<td class="label"><label for="idPosition">' . get_lang('Position') . '</label></td>' . "\n";
  6208. $return .= "\t\t\t" . '<td class="input">' . "\n";
  6209. $return .= "\t\t\t\t" . '<select id="idPosition" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6210. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6211. for ($i = 0; $i < count($arrLP); $i++) {
  6212. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6213. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6214. $selected = 'selected="selected" ';
  6215. elseif ($action == 'add') $selected = 'selected="selected" ';
  6216. else
  6217. $selected = '';
  6218. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6219. }
  6220. }
  6221. $return .= "\t\t\t\t" . '</select>';
  6222. $return .= "\t\t\t" . '</td>' . "\n";
  6223. $return .= "\t\t" . '</tr>' . "\n";
  6224. if ($action != 'move') {
  6225. $id_prerequisite = 0;
  6226. if (is_array($arrLP)) {
  6227. foreach ($arrLP as $key => $value) {
  6228. if ($value['id'] == $id) {
  6229. $id_prerequisite = $value['prerequisite'];
  6230. break;
  6231. }
  6232. }
  6233. }
  6234. $arrHide = array ();
  6235. for ($i = 0; $i < count($arrLP); $i++) {
  6236. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6237. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6238. $s_selected_position = $arrLP[$i]['id'];
  6239. elseif ($action == 'add') $s_selected_position = 0;
  6240. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6241. }
  6242. }
  6243. // Commented the prerequisites, only visible in edit (work).
  6244. /*
  6245. $return .= "\t\t" . '<tr>' . "\n";
  6246. $return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>' . "\n";
  6247. $return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6248. foreach($arrHide as $key => $value) {
  6249. if ($key == $s_selected_position && $action == 'add') {
  6250. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6251. }
  6252. elseif ($key == $id_prerequisite && $action == 'edit') {
  6253. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6254. }
  6255. else {
  6256. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6257. }
  6258. }
  6259. $return .= "</select></td>";
  6260. */
  6261. $return .= "\t\t" . '</tr>' . "\n";
  6262. }
  6263. $return .= "\t\t" . '<tr>' . "\n";
  6264. if ($action == 'add') {
  6265. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6266. } else {
  6267. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6268. }
  6269. $return .= "\t\t" . '</tr>' . "\n";
  6270. $return .= "\t" . '</table>' . "\n";
  6271. if ($action == 'move') {
  6272. $return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
  6273. $return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
  6274. }
  6275. if (is_numeric($extra_info)) {
  6276. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
  6277. } elseif (is_array($extra_info)) {
  6278. $return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
  6279. }
  6280. $return .= "\t" . '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />' . "\n";
  6281. $return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
  6282. $return .= '</form>' . "\n";
  6283. $return .= '</div>' . "\n";
  6284. return $return;
  6285. }
  6286. /**
  6287. * Displays the menu for manipulating a step
  6288. * @return unknown
  6289. */
  6290. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6291. global $charset, $_course;
  6292. $return = '<div class="actions">';
  6293. switch ($item_type) {
  6294. case 'dokeos_chapter' :
  6295. case 'chapter' :
  6296. // Commented the message cause should not show it.
  6297. //$lang = get_lang('TitleManipulateChapter');
  6298. break;
  6299. case 'dokeos_module' :
  6300. case 'module' :
  6301. // Commented the message cause should not show it.
  6302. //$lang = get_lang('TitleManipulateModule');
  6303. break;
  6304. case TOOL_DOCUMENT :
  6305. // Commented the message cause should not show it.
  6306. //$lang = get_lang('TitleManipulateDocument');
  6307. break;
  6308. case TOOL_LINK :
  6309. case 'link' :
  6310. // Commented the message cause should not show it.
  6311. //$lang = get_lang('TitleManipulateLink');
  6312. break;
  6313. case TOOL_QUIZ :
  6314. // Commented the message cause should not show it.
  6315. //$lang = get_lang('TitleManipulateQuiz');
  6316. break;
  6317. case TOOL_STUDENTPUBLICATION :
  6318. // Commented the message cause should not show it.
  6319. //$lang = get_lang('TitleManipulateStudentPublication');
  6320. break;
  6321. }
  6322. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6323. $sql = "
  6324. SELECT
  6325. *
  6326. FROM " . $tbl_lp_item . " as lp
  6327. WHERE
  6328. lp.id = " . $item_id;
  6329. $result = Database::query($sql);
  6330. $row = Database::fetch_assoc($result);
  6331. $s_title = $row['title'];
  6332. // We display an audio player if needed.
  6333. if (!empty ($row['audio'])) {
  6334. $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>';
  6335. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6336. $return .= '<script type="text/javascript">
  6337. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6338. s1.addParam("allowscriptaccess","always");
  6339. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6340. s1.write("container");
  6341. </script>';
  6342. }
  6343. // Commented ":" for message in step.
  6344. //$return .= $lang.': ';
  6345. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '&path_item=' . $row['path'] . '" title="' . get_lang('Edit') . '"><img align="absbottom" alt="Edit the current item" src="../img/edit.gif" title="' . get_lang('Edit') . '" /> ' . get_lang('Edit') . '</a>';
  6346. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=move_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="Move the current item"><img align="absbottom" alt="Move the current item" src="../img/deplacer_fichier.gif" title="' . get_lang('Move') . '" /> ' . get_lang('Move') . '</a>';
  6347. // Commented for now as prerequisites cannot be added to chapters.
  6348. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6349. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item_prereq&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('Prerequisites') . '"><img align="absbottom" alt="' . get_lang('Prerequisites') . '" src="../img/right.gif" title="' . get_lang('Prerequisites') . '" /> ' . get_lang('Prerequisites') . '</a>';
  6350. }
  6351. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;view=build&amp;id=' . $item_id . '&amp;lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($s_title) . '\');" title="Delete the current item"><img alt="Delete the current item" align="absbottom" src="../img/delete.gif" title="' . get_lang('Delete') . '" /> ' . get_lang('Delete') . '</a>';
  6352. //$return .= '<br /><br /><p class="lp_text">' . ((trim($s_description) == '') ? ''.get_lang('NoDescription').'' : stripslashes(nl2br($s_description))) . '</p>';
  6353. //$return.="</td><td valign='top'>";
  6354. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6355. ob_start();
  6356. $audio_recorder_studentview = 'false';
  6357. $audio_recorder_item_id = $item_id;
  6358. if (api_get_setting('service_visio', 'active') == 'true') {
  6359. include 'audiorecorder.inc.php';
  6360. }
  6361. $return .= ob_get_contents();
  6362. ob_end_clean();
  6363. // End of audiorecorder include.
  6364. $return .= '</div>';
  6365. return $return;
  6366. }
  6367. /**
  6368. * Creates the javascript needed for filling up the checkboxes without page reload
  6369. *
  6370. * @return string
  6371. */
  6372. public function get_js_dropdown_array() {
  6373. $return = 'var child_name = new Array();' . "\n";
  6374. $return .= 'var child_value = new Array();' . "\n\n";
  6375. $return .= 'child_name[0] = new Array();' . "\n";
  6376. $return .= 'child_value[0] = new Array();' . "\n\n";
  6377. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6378. $sql_zero = "
  6379. SELECT *
  6380. FROM " . $tbl_lp_item . "
  6381. WHERE
  6382. lp_id = " . $this->lp_id . " AND
  6383. parent_item_id = 0
  6384. ORDER BY display_order ASC";
  6385. $res_zero = Database::query($sql_zero);
  6386. global $charset;
  6387. $i = 0;
  6388. while ($row_zero = Database :: fetch_array($res_zero)) {
  6389. $return .= 'child_name[0][' . $i . '] = "' . get_lang('After') . ' \"' . $row_zero['title'] . '\"";' . "\n";
  6390. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6391. }
  6392. $return .= "\n";
  6393. $sql = "
  6394. SELECT *
  6395. FROM " . $tbl_lp_item . "
  6396. WHERE
  6397. lp_id = " . $this->lp_id;
  6398. $res = Database::query($sql);
  6399. while ($row = Database :: fetch_array($res)) {
  6400. $sql_parent = "
  6401. SELECT *
  6402. FROM " . $tbl_lp_item . "
  6403. WHERE parent_item_id = " . $row['id'] . "
  6404. ORDER BY display_order ASC";
  6405. $res_parent = Database::query($sql_parent);
  6406. $i = 0;
  6407. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6408. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6409. while ($row_parent = Database :: fetch_array($res_parent)) {
  6410. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = "' . get_lang('After') . ' \"' . api_html_entity_decode($row_parent['title'], ENT_QUOTES) . '\"";' . "\n";
  6411. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6412. }
  6413. $return .= "\n";
  6414. }
  6415. return $return;
  6416. }
  6417. /**
  6418. * Display the form to allow moving an item
  6419. * @param integer Item ID
  6420. * @return string HTML form
  6421. */
  6422. public function display_move_item($item_id) {
  6423. global $_course; //will disappear
  6424. global $charset;
  6425. $return = '';
  6426. if (is_numeric($item_id)) {
  6427. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6428. $sql = "SELECT *
  6429. FROM " . $tbl_lp_item . "
  6430. WHERE id = " . $item_id;
  6431. $res = Database::query($sql);
  6432. $row = Database :: fetch_array($res);
  6433. switch ($row['item_type']) {
  6434. case 'dokeos_chapter' :
  6435. case 'dir' :
  6436. case 'asset' :
  6437. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6438. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6439. break;
  6440. case 'dokeos_module' :
  6441. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6442. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6443. break;
  6444. case TOOL_DOCUMENT :
  6445. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6446. $return .= $this->display_document_form('move', $item_id, $row);
  6447. break;
  6448. case TOOL_LINK :
  6449. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6450. $return .= $this->display_link_form('move', $item_id, $row);
  6451. break;
  6452. case TOOL_HOTPOTATOES :
  6453. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6454. $return .= $this->display_link_form('move', $item_id, $row);
  6455. break;
  6456. case TOOL_QUIZ :
  6457. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6458. $return .= $this->display_quiz_form('move', $item_id, $row);
  6459. break;
  6460. case TOOL_STUDENTPUBLICATION :
  6461. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6462. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6463. break;
  6464. case TOOL_FORUM :
  6465. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6466. $return .= $this->display_forum_form('move', $item_id, $row);
  6467. break;
  6468. case TOOL_THREAD :
  6469. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6470. $return .= $this->display_forum_form('move', $item_id, $row);
  6471. break;
  6472. }
  6473. }
  6474. return $return;
  6475. }
  6476. /**
  6477. * Displays a basic form on the overview page for changing the item title and the item description.
  6478. * @param string $item_type
  6479. * @param string $title
  6480. * @param array $data
  6481. * @return string
  6482. */
  6483. public function display_item_small_form($item_type, $title = '', $data) {
  6484. global $charset;
  6485. $return .= '<div class="lp_small_form">' . "\n";
  6486. $return .= '<p class="lp_title">' . $title . '</p>';
  6487. $return .= '<form method="post">' . "\n";
  6488. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6489. $return .= "\t\t" . '<tr>' . "\n";
  6490. $return .= "\t\t\t" . '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>' . "\n";
  6491. $return .= "\t\t\t" . '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>' . "\n";
  6492. $return .= "\t\t" . '</tr>' . "\n";
  6493. // It said these lines of code - see SVN#11724 and SVN#10770
  6494. //$return .= "\t\t" . '<tr>' . "\n";
  6495. //$return .= "\t\t\t" . '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>' . "\n";
  6496. //$return .= "\t\t\t" . '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>' . "\n";
  6497. //$return .= "\t\t" . '</tr>' . "\n";
  6498. $return .= "\t\t" . '<tr>' . "\n";
  6499. $return .= "\t\t\t" . '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>' . "\n";
  6500. $return .= "\t\t" . '</tr>' . "\n";
  6501. $return .= "\t\t" . '</table>' . "\n";
  6502. $return .= "\t" . '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>' . "\n";
  6503. $return .= "\t" . '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>' . "\n";
  6504. $return .= '</form>';
  6505. $return .= '</div>';
  6506. return $return;
  6507. }
  6508. /**
  6509. * Return HTML form to allow prerequisites selection
  6510. * @param integer Item ID
  6511. * @return string HTML form
  6512. */
  6513. public function display_item_prerequisites_form($item_id) {
  6514. global $charset;
  6515. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6516. /* Current prerequisite */
  6517. $sql = "
  6518. SELECT *
  6519. FROM " . $tbl_lp_item . "
  6520. WHERE id = " . $item_id;
  6521. $result = Database::query($sql);
  6522. $row = Database :: fetch_array($result);
  6523. $preq_id = $row['prerequisite'];
  6524. //$preq_mastery = $row['mastery_score'];
  6525. //$preq_max = $row['max_score'];
  6526. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6527. $return = ' <div class="row">
  6528. <div class="form_header">';
  6529. $return .= get_lang('AddEditPrerequisites');
  6530. $return .= '</div> </div>';
  6531. $return .= '<div class="sectioncomment">';
  6532. $return .= '<form method="POST">';
  6533. $return .= '<table class="lp_prerequisites" style="border-collapse:collapse;">';
  6534. $return .= '<tr style="border-collapse:collapse;">';
  6535. $return .= '<th height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Prerequisites') . '</th>';
  6536. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Minimum') . '</th>';
  6537. $return .= '<th width="70" height="24" style="border:1px solid gray; background-color:#F0F0F0;">' . get_lang('Maximum') . '</th>';
  6538. $return .= '</tr>';
  6539. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6540. $return .= '<tr >';
  6541. $return .= '<td colspan="3" class="radio" style="border:1px solid gray;border-collapse:collapse;">';
  6542. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0; margin-right:10px;" type="radio" />';
  6543. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6544. $return .= '</td><td />';
  6545. $return .= '</tr>';
  6546. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE lp_id = " . $this->lp_id;
  6547. $result = Database::query($sql);
  6548. $arrLP = array ();
  6549. while ($row = Database :: fetch_array($result)) {
  6550. $arrLP[] = array (
  6551. 'id' => $row['id'],
  6552. 'item_type' => $row['item_type'],
  6553. 'title' => $row['title'],
  6554. 'ref' => $row['ref'],
  6555. 'description' => $row['description'],
  6556. 'parent_item_id' => $row['parent_item_id'],
  6557. 'previous_item_id' => $row['previous_item_id'],
  6558. 'next_item_id' => $row['next_item_id'],
  6559. 'max_score' => $row['max_score'],
  6560. 'min_score' => $row['min_score'],
  6561. 'mastery_score' => $row['mastery_score'],
  6562. 'prerequisite' => $row['prerequisite'],
  6563. 'next_item_id' => $row['next_item_id'],
  6564. 'display_order' => $row['display_order']
  6565. );
  6566. if ($row['ref'] == $preq_id) {
  6567. $preq_mastery = $row['mastery_score'];
  6568. $preq_max = $row['max_score'];
  6569. }
  6570. }
  6571. $this->tree_array($arrLP);
  6572. $arrLP = $this->arrMenu;
  6573. unset ($this->arrMenu);
  6574. for ($i = 0; $i < count($arrLP); $i++) {
  6575. if ($arrLP[$i]['id'] == $item_id)
  6576. break;
  6577. $return .= '<tr >';
  6578. $return .= '<td style="border:1px solid #B0B0B0; border-collapse:collapse; height:25px; padding: 3px 5px 3px 3px;" class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6579. $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'] . '" />';
  6580. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6581. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6582. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6583. } else
  6584. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6585. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6586. } else {
  6587. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6588. }
  6589. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6590. $return .= '</td>';
  6591. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6592. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6593. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6594. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6595. $return .= '</td>';
  6596. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6597. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6598. $return .= '</td>';
  6599. }
  6600. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6601. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6602. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6603. $return .= '</td>';
  6604. $return .= '<td class="exercise" style="border:1px solid #B0B0B0;">';
  6605. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6606. $return .= '</td>';
  6607. }
  6608. $return .= '</tr>';
  6609. }
  6610. $return .= '<tr>';
  6611. $return .= '<td colspan="3">';
  6612. $return .= '</td>';
  6613. $return .= '</tr>';
  6614. $return .= '</table>';
  6615. $return .= '<div style="padding-top:3px;">';
  6616. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>' . "\n";
  6617. $return .= '</div>';
  6618. $return .= '</form>';
  6619. $return .= '</div>';
  6620. return $return;
  6621. }
  6622. /**
  6623. * Return HTML list to allow prerequisites selection for lp
  6624. * @param integer Item ID
  6625. * @return string HTML form
  6626. */
  6627. public function display_lp_prerequisites_list() {
  6628. global $charset;
  6629. $lp_id = $this->lp_id;
  6630. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6631. // get current prerequisite
  6632. $sql = "SELECT * FROM $tbl_lp WHERE id = $lp_id ";
  6633. $result = Database::query($sql);
  6634. $row = Database :: fetch_array($result);
  6635. $preq_id = $row['prerequisite'];
  6636. $session_id = api_get_session_id();
  6637. $session_condition = api_get_session_condition($session_id, false);
  6638. $sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order ";
  6639. $rs = Database::query($sql);
  6640. $return = '';
  6641. $return .= '<select name="prerequisites" >';
  6642. $return .= '<option value="0">'.get_lang('None').'</option>';
  6643. if (Database::num_rows($rs) > 0) {
  6644. while ($row = Database::fetch_array($rs)) {
  6645. if ($row['id'] == $lp_id) {
  6646. continue;
  6647. }
  6648. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6649. }
  6650. }
  6651. $return .= '</select>';
  6652. return $return;
  6653. }
  6654. /**
  6655. * Creates a list with all the documents in it
  6656. * @return string
  6657. */
  6658. public function get_documents() {
  6659. global $_course;
  6660. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6661. $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
  6662. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  6663. $path = '/';
  6664. $path = Database::escape_string(str_replace('_', '\_', $path));
  6665. $added_slash = ($path == '/') ? '' : '/';
  6666. //condition for the session
  6667. $current_session_id = api_get_session_id();
  6668. $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]}')))";
  6669. $sql_doc = "SELECT docs.*
  6670. FROM $tbl_item_prop AS last, $tbl_doc AS docs
  6671. WHERE docs.id = last.ref
  6672. AND docs.path LIKE '".$path.$added_slash."%'
  6673. AND docs.path NOT LIKE '%_DELETED_%'
  6674. AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
  6675. //$sql_doc = "SELECT * FROM $tbl_doc WHERE path NOT LIKE '%_DELETED_%' ORDER BY path ASC";
  6676. $res_doc = Database::query($sql_doc);
  6677. $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>';
  6678. $return .= '<div class="lp_resource_elements" id="resDoc">';
  6679. $resources = Database::store_result($res_doc);
  6680. $resources_sorted = array();
  6681. // If you want to debug it, I advise you to do "echo" on the eval statements.
  6682. foreach ($resources as $resource) {
  6683. $resource_paths = explode('/', $resource['path']);
  6684. array_shift($resource_paths);
  6685. $path_to_eval = $last_path = '';
  6686. $is_file = false;
  6687. foreach ($resource_paths as $key => $resource_path) {
  6688. if (strpos($resource_path, '.') === false && $key != count($resource_paths) - 1) { // It's a folder.
  6689. $path_to_eval .= '["' . $resource_path . '"]["files"]';
  6690. } else
  6691. if (strpos($resource_path, '.') !== false)
  6692. $is_file = true;
  6693. $last_path = $resource_path;
  6694. }
  6695. if ($is_file) {
  6696. //eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' . $last_path . '";');
  6697. //for backward compatibility
  6698. if (empty($resource['title'])) {
  6699. $resource['title'] = basename($resource['path']);
  6700. }
  6701. eval ('$resources_sorted' . $path_to_eval . '[' . $resource['id'] . '] = "' .$resource['title']."/". $last_path. '";');
  6702. } else {
  6703. eval ('$resources_sorted' . $path_to_eval . '["' . $last_path . '"]["id"]=' . $resource['id'] . ';');
  6704. }
  6705. }
  6706. $return .= $this->write_resources_tree($resources_sorted);
  6707. if (Database :: num_rows($res_doc) == 0) {
  6708. $return .= '<div class="lp_resource_element">' . get_lang('NoDocuments') . '</div>';
  6709. }
  6710. $return .= '</div>';
  6711. return $return;
  6712. }
  6713. /**
  6714. * Generate and return an HTML list of resources based on a given array.
  6715. * This list is used to show the course creator a list of available resources to choose from
  6716. * when creating a learning path.
  6717. * @param array Array of elements to add to the list
  6718. * @param integer Enables the tree display by shifting the new elements a certain distance to the right
  6719. * @return string The HTML list
  6720. */
  6721. public function write_resources_tree($resources_sorted, $num = 0) {
  6722. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
  6723. if (count($resources_sorted) > 0) {
  6724. foreach ($resources_sorted as $key => $resource) {
  6725. if (is_int($resource['id'])) {
  6726. // It's a folder.
  6727. //hide some folders
  6728. if (in_array($key, array('shared_folder','chat_files', 'HotPotatoes_files', 'css', 'certificates'))){
  6729. continue;
  6730. }elseif(preg_match('/_groupdocs/', $key)){
  6731. continue;
  6732. }elseif(preg_match('/sf_user_/', $key)){
  6733. continue;
  6734. }elseif(preg_match('/shared_folder_session_/', $key)){
  6735. continue;
  6736. }
  6737. //trad some titles
  6738. if ($key=='images'){
  6739. $key=get_lang('Images');
  6740. }
  6741. elseif($key=='gallery'){
  6742. $key=get_lang('Gallery');
  6743. }
  6744. elseif($key=='flash'){
  6745. $key=get_lang('Flash');
  6746. }
  6747. elseif($key=='audio'){
  6748. $key=get_lang('Audio');
  6749. }
  6750. elseif($key=='video'){
  6751. $key=get_lang('Video');
  6752. }
  6753. $return .= '<div><div style="margin-left:' . ($num * 15) . 'px;margin-right:5px;"><img style="cursor: pointer;" src="../img/nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '" onClick="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'] . '">';
  6754. $return .= $this->write_resources_tree($resource['files'], $num +1);
  6755. $return .= '</div></div>';
  6756. } else {
  6757. if (!is_array($resource)) {
  6758. // It's a file.
  6759. $icon = choose_image($resource);
  6760. $position = strrpos($icon, '.');
  6761. $icon = substr($icon, 0, $position) . '_small.gif';
  6762. $file_info = explode('/', $resource);
  6763. $my_file_title = $file_info[0];
  6764. $my_file_name = $file_info[1];
  6765. //$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>';
  6766. // Show the "image name" not the filename of the image.
  6767. $return .= '<div><div style="margin-left:' . (($num +1) * 15) . '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"; }
  6768. }
  6769. }
  6770. }
  6771. return $return;
  6772. }
  6773. /**
  6774. * Creates a list with all the exercises (quiz) in it
  6775. * @return string
  6776. */
  6777. public function get_exercises() {
  6778. // New for hotpotatoes.
  6779. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  6780. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6781. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  6782. $session_id = api_get_session_id();
  6783. $condition_session = api_get_session_condition($session_id);
  6784. $sql_quiz = "
  6785. SELECT *
  6786. FROM " . $tbl_quiz . "
  6787. WHERE active<>'-1' $condition_session
  6788. ORDER BY title ASC";
  6789. $sql_hot = "SELECT * FROM " . $tbl_doc . " " .
  6790. " WHERE path LIKE '" . $uploadPath . "/%/%htm%' $condition_session " .
  6791. " ORDER BY id ASC";
  6792. $res_quiz = Database::query($sql_quiz);
  6793. $res_hot = Database::query($sql_hot);
  6794. $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>';
  6795. $return .= '<div class="lp_resource_elements" id="resExercise">';
  6796. while ($row_hot = Database :: fetch_array($res_hot)) {
  6797. $return .= '<div class="lp_resource_element">';
  6798. // Display quizhotpotatoes.
  6799. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  6800. $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>';
  6801. //$return .= $row_quiz['title'];
  6802. $return .= '</div>';
  6803. }
  6804. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  6805. $return .= '<div class="lp_resource_element">';
  6806. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  6807. $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>';
  6808. //$return .= $row_quiz['title'];
  6809. $return .= '</div>';
  6810. }
  6811. if (Database :: num_rows($res_quiz) == 0) {
  6812. $return .= '<div class="lp_resource_element">' . get_lang('NoExercisesAvailable') . '</div>';
  6813. }
  6814. $return .= '<div class="lp_resource_element">';
  6815. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  6816. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php">' . get_lang('NewExercise') . '</a>';
  6817. $return .= '</div>';
  6818. $return .= '</div>';
  6819. return $return;
  6820. }
  6821. /**
  6822. * Creates a list with all the links in it
  6823. * @return string
  6824. */
  6825. public function get_links() {
  6826. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6827. $session_id = api_get_session_id();
  6828. $condition_session = api_get_session_condition($session_id,false);
  6829. $sql_link = "SELECT * FROM $tbl_link $condition_session ORDER BY title ASC";
  6830. $res_link = Database::query($sql_link);
  6831. $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>';
  6832. $return .= '<div class="lp_resource_elements" id="resLink">';
  6833. while ($row_link = Database :: fetch_array($res_link)) {
  6834. $return .= '<div class="lp_resource_element">';
  6835. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  6836. $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>';
  6837. $return .= '</div>';
  6838. }
  6839. $return .= '<div class="lp_resource_element">';
  6840. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  6841. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  6842. $return .= '</div>';
  6843. if (Database :: num_rows($res_link) == 0)
  6844. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  6845. $return .= '</div>';
  6846. return $return;
  6847. }
  6848. /**
  6849. * Creates a list with all the student publications in it
  6850. * @return unknown
  6851. */
  6852. public function get_student_publications() {
  6853. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6854. $session_id = api_get_session_id();
  6855. $condition_session = api_get_session_condition($session_id, false);
  6856. $sql_student = "SELECT * FROM $tbl_student $condition_session ORDER BY title ASC";
  6857. $res_student = Database::query($sql_student);
  6858. $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>';
  6859. $return .= '<div class="lp_resource_elements" id="resStudent">';
  6860. $return .= '<div class="lp_resource_element">';
  6861. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  6862. $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>';
  6863. $return .= '</div>';
  6864. $return .= '</div>';
  6865. return $return;
  6866. }
  6867. /**
  6868. * Creates a list with all the forums in it
  6869. * @return string
  6870. */
  6871. public function get_forums() {
  6872. include '../forum/forumfunction.inc.php';
  6873. include '../forum/forumconfig.inc.php';
  6874. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  6875. $table_forums = Database :: get_course_table(TABLE_FORUM);
  6876. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  6877. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  6878. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  6879. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  6880. $a_forums = get_forums();
  6881. $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>';
  6882. $return .= '<div class="lp_resource_elements" style="border:1px solid #999999;" id="forums">';
  6883. foreach ($a_forums as $forum) {
  6884. $return .= '<div class="lp_resource_element">';
  6885. $return .= '<script type="text/javascript">
  6886. function toggle_forum(forum_id){
  6887. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  6888. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  6889. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  6890. }
  6891. else {
  6892. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  6893. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  6894. }
  6895. }
  6896. </script>
  6897. ';
  6898. if (!empty($forum['forum_id'])) {
  6899. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  6900. $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>
  6901. <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">';
  6902. }
  6903. $a_threads = get_threads($forum['forum_id']);
  6904. if (is_array($a_threads)) {
  6905. foreach ($a_threads as $thread) {
  6906. $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>';
  6907. }
  6908. }
  6909. $return .= '</ul></div>';
  6910. }
  6911. $return .= '<div class="lp_resource_element">';
  6912. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  6913. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&amp;content=forum" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
  6914. $return .= '</div>';
  6915. return $return;
  6916. }
  6917. /**
  6918. * // TODO: The output encoding should be equal to the system encoding.
  6919. *
  6920. * Exports the learning path as a SCORM package. This is the main function that
  6921. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  6922. * whole thing and returns the zip.
  6923. *
  6924. * This method needs to be called in PHP5, as it will fail with non-adequate
  6925. * XML package (like the ones for PHP4), and it is *not* a static method, so
  6926. * you need to call it on a learnpath object.
  6927. * @TODO The method might be redefined later on in the scorm class itself to avoid
  6928. * creating a SCORM structure if there is one already. However, if the initial SCORM
  6929. * path has been modified, it should use the generic method here below.
  6930. * @TODO link this function with the export_lp() function in the same class
  6931. * @param string Optional name of zip file. If none, title of learnpath is
  6932. * domesticated and trailed with ".zip"
  6933. * @return string Returns the zip package string, or null if error
  6934. */
  6935. public function scorm_export() {
  6936. global $_course;
  6937. // Remove memory and time limits as much as possible as this might be a long process...
  6938. if (function_exists('ini_set')) {
  6939. $mem = ini_get('memory_limit');
  6940. if (substr($mem, -1, 1) == 'M') {
  6941. $mem_num = substr($mem, 0, -1);
  6942. if ($mem_num < 128) {
  6943. ini_set('memory_limit', '128M');
  6944. }
  6945. } else {
  6946. ini_set('memory_limit', '128M');
  6947. }
  6948. ini_set('max_execution_time', 600);
  6949. //} else {
  6950. //error_log('Scorm export: could not change memory and time limits', 0);
  6951. }
  6952. // Create the zip handler (this will remain available throughout the method).
  6953. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  6954. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  6955. $temp_dir_short = uniqid();
  6956. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  6957. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  6958. $zip_folder = new PclZip($temp_zip_file);
  6959. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  6960. $root_path = $main_path = api_get_path(SYS_PATH);
  6961. $files_cleanup = array();
  6962. // Place to temporarily stash the zipfiles.
  6963. // create the temp dir if it doesn't exist
  6964. // or do a cleanup befor creating the zipfile.
  6965. if (!is_dir($temp_zip_dir)) {
  6966. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  6967. } else {
  6968. // Cleanup: Check the temp dir for old files and delete them.
  6969. $handle = opendir($temp_zip_dir);
  6970. while (false !== ($file = readdir($handle))) {
  6971. if ($file != '.' && $file != '..') {
  6972. unlink("$temp_zip_dir/$file");
  6973. }
  6974. }
  6975. closedir($handle);
  6976. }
  6977. $zip_files = $zip_files_abs = $zip_files_dist = array();
  6978. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  6979. // Remove the possible . at the end of the path.
  6980. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  6981. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  6982. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  6983. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  6984. }
  6985. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  6986. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  6987. // Aggregation Model official document, secion "2.3 Content Packaging".
  6988. $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.
  6989. $root = $xmldoc->createElement('manifest');
  6990. $root->setAttribute('identifier', 'SingleCourseManifest');
  6991. $root->setAttribute('version', '1.1');
  6992. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  6993. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  6994. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  6995. $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');
  6996. // Build mandatory sub-root container elements.
  6997. $metadata = $xmldoc->createElement('metadata');
  6998. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  6999. $metadata->appendChild($md_schema);
  7000. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7001. $metadata->appendChild($md_schemaversion);
  7002. $root->appendChild($metadata);
  7003. $organizations = $xmldoc->createElement('organizations');
  7004. $resources = $xmldoc->createElement('resources');
  7005. // Build the only organization we will use in building our learnpaths.
  7006. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7007. $organization = $xmldoc->createElement('organization');
  7008. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7009. // To set the title of the SCORM entity (=organization), we take the name given
  7010. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7011. // learning path charset) as it is the encoding that defines how it is stored
  7012. // in the database. Then we convert it to HTML entities again as the "&" character
  7013. // alone is not authorized in XML (must be &amp;).
  7014. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7015. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7016. $organization->appendChild($org_title);
  7017. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7018. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7019. $link_updates = array();
  7020. foreach ($this->items as $index => $item) {
  7021. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7022. // Get included documents from this item.
  7023. if ($item->type == 'sco')
  7024. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7025. else
  7026. $inc_docs = $item->get_resources_from_source();
  7027. // Give a child element <item> to the <organization> element.
  7028. $my_item_id = $item->get_id();
  7029. $my_item = $xmldoc->createElement('item');
  7030. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7031. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7032. $my_item->setAttribute('isvisible', 'true');
  7033. // Give a child element <title> to the <item> element.
  7034. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7035. $my_item->appendChild($my_title);
  7036. // Give a child element <adlcp:prerequisites> to the <item> element.
  7037. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7038. $my_prereqs->setAttribute('type', 'aicc_script');
  7039. $my_item->appendChild($my_prereqs);
  7040. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7041. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7042. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7043. //$xmldoc->createElement('adlcp:timelimitaction','');
  7044. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7045. //$xmldoc->createElement('adlcp:datafromlms','');
  7046. // Give a child element <adlcp:masteryscore> to the <item> element.
  7047. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7048. $my_item->appendChild($my_masteryscore);
  7049. // Attach this item to the organization element or hits parent if there is one.
  7050. if (!empty($item->parent) && $item->parent != 0) {
  7051. $children = $organization->childNodes;
  7052. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7053. if (is_object($possible_parent)) {
  7054. $possible_parent->appendChild($my_item);
  7055. } else {
  7056. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7057. }
  7058. } else {
  7059. if ($this->debug > 0) { error_log('No parent'); }
  7060. $organization->appendChild($my_item);
  7061. }
  7062. // Get the path of the file(s) from the course directory root.
  7063. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7064. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7065. $my_xml_file_path = $my_file_path;
  7066. $my_sub_dir = dirname($my_file_path);
  7067. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7068. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7069. $my_xml_sub_dir = $my_sub_dir;
  7070. // Give a <resource> child to the <resources> element
  7071. $my_resource = $xmldoc->createElement('resource');
  7072. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7073. $my_resource->setAttribute('type', 'webcontent');
  7074. $my_resource->setAttribute('href', $my_xml_file_path);
  7075. // adlcp:scormtype can be either 'sco' or 'asset'.
  7076. if ($item->type == 'sco') {
  7077. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7078. } else {
  7079. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7080. }
  7081. // xml:base is the base directory to find the files declared in this resource.
  7082. $my_resource->setAttribute('xml:base', '');
  7083. // Give a <file> child to the <resource> element.
  7084. $my_file = $xmldoc->createElement('file');
  7085. $my_file->setAttribute('href', $my_xml_file_path);
  7086. $my_resource->appendChild($my_file);
  7087. // Dependency to other files - not yet supported.
  7088. $i = 1;
  7089. foreach ($inc_docs as $doc_info) {
  7090. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7091. $my_dep = $xmldoc->createElement('resource');
  7092. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7093. $my_dep->setAttribute('identifier', $res_id);
  7094. $my_dep->setAttribute('type', 'webcontent');
  7095. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7096. $my_dep_file = $xmldoc->createElement('file');
  7097. // Check type of URL.
  7098. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7099. if ($doc_info[1] == 'remote') {
  7100. // Remote file. Save url as is.
  7101. $my_dep_file->setAttribute('href', $doc_info[0]);
  7102. $my_dep->setAttribute('xml:base', '');
  7103. } elseif ($doc_info[1] == 'local') {
  7104. switch ($doc_info[2]) {
  7105. case 'url': // Local URL - save path as url for now, don't zip file.
  7106. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7107. $current_dir = dirname($abs_path);
  7108. $current_dir = str_replace('\\', '/', $current_dir);
  7109. $file_path = realpath($abs_path);
  7110. $file_path = str_replace('\\', '/', $file_path);
  7111. $my_dep_file->setAttribute('href', $file_path);
  7112. $my_dep->setAttribute('xml:base', '');
  7113. if (strstr($file_path, $main_path) !== false) {
  7114. // The calculated real path is really inside Chamilo's root path.
  7115. // Reduce file path to what's under the DocumentRoot.
  7116. $file_path = substr($file_path, strlen($root_path) - 1);
  7117. //echo $file_path;echo '<br /><br />';
  7118. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7119. $zip_files_abs[] = $file_path;
  7120. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7121. $my_dep_file->setAttribute('href', $file_path);
  7122. $my_dep->setAttribute('xml:base', '');
  7123. }
  7124. elseif (empty($file_path)) {
  7125. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7126. if (strpos($document_root, -1) == '/') {
  7127. $document_root = substr(0, -1, $document_root);
  7128. }*/
  7129. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7130. $file_path = str_replace('//', '/', $file_path);
  7131. if (file_exists($file_path)) {
  7132. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7133. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7134. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7135. $my_dep_file->setAttribute('href', $file_path);
  7136. $my_dep->setAttribute('xml:base', '');
  7137. }
  7138. }
  7139. break;
  7140. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7141. $my_dep_file->setAttribute('href', $doc_info[0]);
  7142. $my_dep->setAttribute('xml:base', '');
  7143. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7144. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7145. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7146. $abs_img_path_without_subdir = $doc_info[0];
  7147. $relp = api_get_path(REL_PATH); // The url-append config param.
  7148. $pos = strpos($abs_img_path_without_subdir, $relp);
  7149. if ($pos === 0) {
  7150. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7151. }
  7152. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7153. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7154. $file_path = str_replace('\\', '/', $file_path);
  7155. $file_path = str_replace('//', '/', $file_path);
  7156. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7157. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7158. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7159. // Check if the current document is in that path.
  7160. if (strstr($file_path, $cur_path) !== false) {
  7161. // The document is in that path, now get the relative path
  7162. // to the containing document.
  7163. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7164. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7165. $relative_path = '';
  7166. if (strstr($file_path, $cur_path) !== false) {
  7167. $relative_path = substr($file_path, strlen($orig_file_path));
  7168. $file_path = substr($file_path, strlen($cur_path));
  7169. } else {
  7170. // This case is still a problem as it's difficult to calculate a relative path easily
  7171. // might still generate wrong links.
  7172. //$file_path = substr($file_path,strlen($cur_path));
  7173. // Calculate the directory path to the current file (without trailing slash).
  7174. $my_relative_path = dirname($file_path);
  7175. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7176. $my_relative_file = basename($file_path);
  7177. // Calculate the directory path to the containing file (without trailing slash).
  7178. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7179. $dotdot = '';
  7180. $subdir = '';
  7181. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7182. $my_relative_path2 = dirname($my_relative_path);
  7183. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7184. $my_orig_file_path = dirname($my_orig_file_path);
  7185. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7186. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7187. $dotdot += '../';
  7188. $my_relative_path = $my_relative_path2;
  7189. }
  7190. $relative_path = $dotdot.$subdir.$my_relative_file;
  7191. }
  7192. // Put the current document in the zip (this array is the array
  7193. // that will manage documents already in the course folder - relative).
  7194. $zip_files[] = $file_path;
  7195. // Update the links to the current document in the containing document (make them relative).
  7196. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7197. $my_dep_file->setAttribute('href', $file_path);
  7198. $my_dep->setAttribute('xml:base', '');
  7199. }
  7200. elseif (strstr($file_path,$main_path) !== false) {
  7201. // The calculated real path is really inside Chamilo's root path.
  7202. // Reduce file path to what's under the DocumentRoot.
  7203. $file_path = substr($file_path, strlen($root_path));
  7204. //echo $file_path;echo '<br /><br />';
  7205. //error_log('Reduced path: '.$file_path, 0);
  7206. $zip_files_abs[] = $file_path;
  7207. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7208. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7209. $my_dep->setAttribute('xml:base', '');
  7210. }
  7211. elseif (empty($file_path)) {
  7212. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7213. if(strpos($document_root,-1) == '/') {
  7214. $document_root = substr(0, -1, $document_root);
  7215. }*/
  7216. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7217. $file_path = str_replace('//', '/', $file_path);
  7218. if (file_exists($file_path)) {
  7219. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7220. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7221. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7222. $my_dep_file->setAttribute('href','document/'.$file_path);
  7223. $my_dep->setAttribute('xml:base', '');
  7224. }
  7225. }
  7226. break;
  7227. 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
  7228. if (substr($doc_info[0], 0, 2) == '..') {
  7229. // Relative path going up.
  7230. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7231. $current_dir = str_replace('\\', '/', $current_dir);
  7232. $file_path = realpath($current_dir.$doc_info[0]);
  7233. $file_path = str_replace('\\', '/', $file_path);
  7234. //error_log($file_path.' <-> '.$main_path,0);
  7235. if (strstr($file_path, $main_path) !== false) {
  7236. // The calculated real path is really inside Chamilo's root path.
  7237. // Reduce file path to what's under the DocumentRoot.
  7238. $file_path = substr($file_path, strlen($root_path));
  7239. //error_log('Reduced path: '.$file_path, 0);
  7240. $zip_files_abs[] = $file_path;
  7241. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7242. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7243. $my_dep->setAttribute('xml:base', '');
  7244. }
  7245. } else {
  7246. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7247. $my_dep_file->setAttribute('href', $doc_info[0]);
  7248. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7249. }
  7250. break;
  7251. default:
  7252. $my_dep_file->setAttribute('href', $doc_info[0]);
  7253. $my_dep->setAttribute('xml:base', '');
  7254. break;
  7255. }
  7256. }
  7257. $my_dep->appendChild($my_dep_file);
  7258. $resources->appendChild($my_dep);
  7259. $dependency = $xmldoc->createElement('dependency');
  7260. $dependency->setAttribute('identifierref', $res_id);
  7261. $my_resource->appendChild($dependency);
  7262. $i++;
  7263. }
  7264. //$my_dependency = $xmldoc->createElement('dependency');
  7265. //$my_dependency->setAttribute('identifierref', '');
  7266. $resources->appendChild($my_resource);
  7267. $zip_files[] = $my_file_path;
  7268. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7269. } else {
  7270. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7271. if ($item->type == TOOL_LINK) {
  7272. $my_item = $xmldoc->createElement('item');
  7273. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7274. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7275. $my_item->setAttribute('isvisible', 'true');
  7276. // Give a child element <title> to the <item> element.
  7277. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7278. $my_item->appendChild($my_title);
  7279. // Give a child element <adlcp:prerequisites> to the <item> element.
  7280. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7281. $my_prereqs->setAttribute('type', 'aicc_script');
  7282. $my_item->appendChild($my_prereqs);
  7283. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7284. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7285. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7286. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7287. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7288. //$xmldoc->createElement('adlcp:datafromlms', '');
  7289. // Give a child element <adlcp:masteryscore> to the <item> element.
  7290. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7291. $my_item->appendChild($my_masteryscore);
  7292. // Attach this item to the organization element or its parent if there is one.
  7293. if (!empty($item->parent) && $item->parent != 0) {
  7294. $children = $organization->childNodes;
  7295. for ($i = 0; $i < $children->length; $i++) {
  7296. $item_temp = $children->item($i);
  7297. if ($item_temp -> nodeName == 'item') {
  7298. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7299. $item_temp -> appendChild($my_item);
  7300. }
  7301. }
  7302. }
  7303. } else {
  7304. $organization->appendChild($my_item);
  7305. }
  7306. $my_file_path = 'link_'.$item->get_id().'.html';
  7307. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7308. $rs = Database::query($sql);
  7309. if ($link = Database :: fetch_array($rs)) {
  7310. $url = $link['url'];
  7311. $title = stripslashes($link['title']);
  7312. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7313. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7314. $my_xml_file_path = $my_file_path;
  7315. $my_sub_dir = dirname($my_file_path);
  7316. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7317. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7318. $my_xml_sub_dir = $my_sub_dir;
  7319. // Give a <resource> child to the <resources> element.
  7320. $my_resource = $xmldoc->createElement('resource');
  7321. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7322. $my_resource->setAttribute('type', 'webcontent');
  7323. $my_resource->setAttribute('href', $my_xml_file_path);
  7324. // adlcp:scormtype can be either 'sco' or 'asset'.
  7325. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7326. // xml:base is the base directory to find the files declared in this resource.
  7327. $my_resource->setAttribute('xml:base', '');
  7328. // give a <file> child to the <resource> element.
  7329. $my_file = $xmldoc->createElement('file');
  7330. $my_file->setAttribute('href', $my_xml_file_path);
  7331. $my_resource->appendChild($my_file);
  7332. $resources->appendChild($my_resource);
  7333. }
  7334. }
  7335. elseif ($item->type == TOOL_QUIZ) {
  7336. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7337. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7338. $exe = new Exercise();
  7339. $exe->read($exe_id);
  7340. $my_item = $xmldoc->createElement('item');
  7341. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7342. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7343. $my_item->setAttribute('isvisible', 'true');
  7344. // Give a child element <title> to the <item> element.
  7345. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7346. $my_item->appendChild($my_title);
  7347. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7348. //$my_item->appendChild($my_max_score);
  7349. // Give a child element <adlcp:prerequisites> to the <item> element.
  7350. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7351. $my_prereqs->setAttribute('type','aicc_script');
  7352. $my_item->appendChild($my_prereqs);
  7353. // Give a child element <adlcp:masteryscore> to the <item> element.
  7354. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7355. $my_item->appendChild($my_masteryscore);
  7356. // Attach this item to the organization element or hits parent if there is one.
  7357. if (!empty($item->parent) && $item->parent != 0) {
  7358. $children = $organization->childNodes;
  7359. for ($i = 0; $i < $children->length; $i++) {
  7360. $item_temp = $children->item($i);
  7361. if ($item_temp -> nodeName == 'item') {
  7362. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7363. $item_temp -> appendChild($my_item);
  7364. }
  7365. }
  7366. }
  7367. } else {
  7368. $organization->appendChild($my_item);
  7369. }
  7370. // Include export scripts.
  7371. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7372. // Get the path of the file(s) from the course directory root
  7373. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7374. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7375. // Write the contents of the exported exercise into a (big) html file
  7376. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7377. $contents = export_exercise($exe_id,true);
  7378. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7379. $res = file_put_contents($tmp_file_path, $contents);
  7380. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7381. $files_cleanup[] = $tmp_file_path;
  7382. //error_log($tmp_path); die();
  7383. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7384. $my_xml_file_path = $my_file_path;
  7385. $my_sub_dir = dirname($my_file_path);
  7386. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7387. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7388. $my_xml_sub_dir = $my_sub_dir;
  7389. // Give a <resource> child to the <resources> element.
  7390. $my_resource = $xmldoc->createElement('resource');
  7391. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7392. $my_resource->setAttribute('type', 'webcontent');
  7393. $my_resource->setAttribute('href', $my_xml_file_path);
  7394. // adlcp:scormtype can be either 'sco' or 'asset'.
  7395. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7396. // xml:base is the base directory to find the files declared in this resource.
  7397. $my_resource->setAttribute('xml:base', '');
  7398. // Give a <file> child to the <resource> element.
  7399. $my_file = $xmldoc->createElement('file');
  7400. $my_file->setAttribute('href', $my_xml_file_path);
  7401. $my_resource->appendChild($my_file);
  7402. // Get included docs.
  7403. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7404. // Dependency to other files - not yet supported.
  7405. $i = 1;
  7406. foreach ($inc_docs as $doc_info) {
  7407. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7408. $my_dep = $xmldoc->createElement('resource');
  7409. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7410. $my_dep->setAttribute('identifier', $res_id);
  7411. $my_dep->setAttribute('type', 'webcontent');
  7412. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7413. $my_dep_file = $xmldoc->createElement('file');
  7414. // Check type of URL.
  7415. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7416. if ($doc_info[1] == 'remote') {
  7417. // Remote file. Save url as is.
  7418. $my_dep_file->setAttribute('href', $doc_info[0]);
  7419. $my_dep->setAttribute('xml:base', '');
  7420. } elseif ($doc_info[1] == 'local') {
  7421. switch ($doc_info[2]) {
  7422. case 'url': // Local URL - save path as url for now, don't zip file.
  7423. // Save file but as local file (retrieve from URL).
  7424. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7425. $current_dir = dirname($abs_path);
  7426. $current_dir = str_replace('\\', '/', $current_dir);
  7427. $file_path = realpath($abs_path);
  7428. $file_path = str_replace('\\', '/', $file_path);
  7429. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7430. $my_dep->setAttribute('xml:base', '');
  7431. if (strstr($file_path, $main_path) !== false) {
  7432. // The calculated real path is really inside the chamilo root path.
  7433. // Reduce file path to what's under the DocumentRoot.
  7434. $file_path = substr($file_path, strlen($root_path));
  7435. //echo $file_path;echo '<br /><br />';
  7436. //error_log('Reduced path: '.$file_path, 0);
  7437. $zip_files_abs[] = $file_path;
  7438. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7439. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7440. $my_dep->setAttribute('xml:base', '');
  7441. }
  7442. elseif (empty($file_path)) {
  7443. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7444. if (strpos($document_root,-1) == '/') {
  7445. $document_root = substr(0, -1, $document_root);
  7446. }*/
  7447. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7448. $file_path = str_replace('//', '/', $file_path);
  7449. if (file_exists($file_path)) {
  7450. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7451. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7452. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7453. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7454. $my_dep->setAttribute('xml:base', '');
  7455. }
  7456. }
  7457. break;
  7458. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7459. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7460. $current_dir = str_replace('\\', '/', $current_dir);
  7461. $file_path = realpath($doc_info[0]);
  7462. $file_path = str_replace('\\', '/', $file_path);
  7463. $my_dep_file->setAttribute('href', $file_path);
  7464. $my_dep->setAttribute('xml:base', '');
  7465. if (strstr($file_path,$main_path) !== false) {
  7466. // The calculated real path is really inside the chamilo root path.
  7467. // Reduce file path to what's under the DocumentRoot.
  7468. $file_path = substr($file_path, strlen($root_path));
  7469. //echo $file_path;echo '<br /><br />';
  7470. //error_log('Reduced path: '.$file_path, 0);
  7471. $zip_files_abs[] = $file_path;
  7472. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7473. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7474. $my_dep->setAttribute('xml:base', '');
  7475. }
  7476. elseif (empty($file_path)) {
  7477. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7478. if (strpos($document_root,-1) == '/') {
  7479. $document_root = substr(0, -1, $document_root);
  7480. }*/
  7481. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7482. $file_path = str_replace('//', '/', $file_path);
  7483. if (file_exists($file_path)) {
  7484. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7485. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7486. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7487. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7488. $my_dep->setAttribute('xml:base', '');
  7489. }
  7490. }
  7491. break;
  7492. 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
  7493. if (substr($doc_info[0], 0, 2) == '..') {
  7494. // Relative path going up.
  7495. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7496. $current_dir = str_replace('\\', '/', $current_dir);
  7497. $file_path = realpath($current_dir.$doc_info[0]);
  7498. $file_path = str_replace('\\', '/', $file_path);
  7499. //error_log($file_path.' <-> '.$main_path, 0);
  7500. if (strstr($file_path, $main_path) !== false) {
  7501. // The calculated real path is really inside Chamilo's root path.
  7502. // Reduce file path to what's under the DocumentRoot.
  7503. $file_path = substr($file_path, strlen($root_path));
  7504. $file_path_dest = $file_path;
  7505. // File path is courses/CHAMILO/document/....
  7506. $info_file_path = explode('/', $file_path);
  7507. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7508. $file_path_dest = 'document/'.$file_path;
  7509. }
  7510. //error_log('Reduced path: '.$file_path, 0);
  7511. $zip_files_abs[] = $file_path;
  7512. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7513. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7514. $my_dep->setAttribute('xml:base', '');
  7515. }
  7516. } else {
  7517. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7518. $my_dep_file->setAttribute('href', $doc_info[0]);
  7519. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7520. }
  7521. break;
  7522. default:
  7523. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7524. $my_dep->setAttribute('xml:base', '');
  7525. break;
  7526. }
  7527. }
  7528. $my_dep->appendChild($my_dep_file);
  7529. $resources->appendChild($my_dep);
  7530. $dependency = $xmldoc->createElement('dependency');
  7531. $dependency->setAttribute('identifierref', $res_id);
  7532. $my_resource->appendChild($dependency);
  7533. $i++;
  7534. }
  7535. $resources->appendChild($my_resource);
  7536. $zip_files[] = $my_file_path;
  7537. } else {
  7538. // Get the path of the file(s) from the course directory root
  7539. $my_file_path = 'non_exportable.html';
  7540. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7541. $my_xml_file_path = $my_file_path;
  7542. $my_sub_dir = dirname($my_file_path);
  7543. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7544. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7545. $my_xml_sub_dir = $my_sub_dir;
  7546. // Give a <resource> child to the <resources> element.
  7547. $my_resource = $xmldoc->createElement('resource');
  7548. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7549. $my_resource->setAttribute('type', 'webcontent');
  7550. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7551. // adlcp:scormtype can be either 'sco' or 'asset'.
  7552. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7553. // xml:base is the base directory to find the files declared in this resource.
  7554. $my_resource->setAttribute('xml:base', '');
  7555. // Give a <file> child to the <resource> element.
  7556. $my_file = $xmldoc->createElement('file');
  7557. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7558. $my_resource->appendChild($my_file);
  7559. $resources->appendChild($my_resource);
  7560. }
  7561. }
  7562. }
  7563. $organizations->appendChild($organization);
  7564. $root->appendChild($organizations);
  7565. $root->appendChild($resources);
  7566. $xmldoc->appendChild($root);
  7567. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7568. // then add the file to the zip, then destroy the file (this is done automatically).
  7569. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7570. //error_log(print_r($zip_files,true), 0);
  7571. foreach ($zip_files as $file_path) {
  7572. if (empty($file_path)) { continue; }
  7573. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7574. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7575. $this->create_path($dest_file);
  7576. //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);
  7577. //echo $main_path.$file_path.'<br />';
  7578. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7579. // Check if the file needs a link update.
  7580. if (in_array($file_path, array_keys($link_updates))) {
  7581. $string = file_get_contents($dest_file);
  7582. unlink($dest_file);
  7583. foreach ($link_updates[$file_path] as $old_new) {
  7584. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7585. // This is an ugly hack that allows .flv files to be found by the flv player that
  7586. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7587. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7588. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7589. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7590. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7591. }
  7592. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7593. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7594. }
  7595. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7596. }
  7597. file_put_contents($dest_file, $string);
  7598. }
  7599. }
  7600. foreach ($zip_files_abs as $file_path) {
  7601. if (empty($file_path)) { continue; }
  7602. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7603. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7604. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7605. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7606. $this->create_path($dest_file);
  7607. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7608. //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);
  7609. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7610. copy($main_path.$file_path, $dest_file);
  7611. // Check if the file needs a link update.
  7612. if (in_array($file_path, array_keys($link_updates))) {
  7613. $string = file_get_contents($dest_file);
  7614. unlink($dest_file);
  7615. foreach ($link_updates[$file_path] as $old_new) {
  7616. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7617. // This is an ugly hack that allows .flv files to be found by the flv player that
  7618. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7619. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7620. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7621. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7622. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7623. }
  7624. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7625. }
  7626. file_put_contents($dest_file, $string);
  7627. }
  7628. }
  7629. if (is_array($links_to_create)) {
  7630. foreach ($links_to_create as $file => $link) {
  7631. $file_content = '<!DOCTYPE html
  7632. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7633. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7634. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7635. <head>
  7636. <title>'.$link['title'].'</title>
  7637. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7638. </head>
  7639. <body dir="'.api_get_text_direction().'">
  7640. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7641. </body>
  7642. </html>';
  7643. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7644. }
  7645. }
  7646. // Add non exportable message explanation.
  7647. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7648. $file_content = '<!DOCTYPE html
  7649. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7650. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7651. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7652. <head>
  7653. <title>'.$lang_not_exportable.'</title>
  7654. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7655. </head>
  7656. <body dir="'.api_get_text_direction().'">
  7657. ';
  7658. $file_content .=
  7659. <<<EOD
  7660. <style>
  7661. .error-message {
  7662. font-family: arial, verdana, helvetica, sans-serif;
  7663. border-width: 1px;
  7664. border-style: solid;
  7665. left: 50%;
  7666. margin: 10px auto;
  7667. min-height: 30px;
  7668. padding: 5px;
  7669. right: 50%;
  7670. width: 500px;
  7671. background-color: #FFD1D1;
  7672. border-color: #FF0000;
  7673. color: #000;
  7674. }
  7675. </style>
  7676. <body>
  7677. <div class="error-message">
  7678. $lang_not_exportable
  7679. </div>
  7680. </body>
  7681. </html>
  7682. EOD;
  7683. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7684. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7685. }
  7686. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7687. // Add the extra files that go along with a SCORM package.
  7688. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7689. $extra_files = scandir($main_code_path);
  7690. foreach ($extra_files as $extra_file) {
  7691. if (strpos($extra_file, '.') === 0)
  7692. continue;
  7693. else {
  7694. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7695. $this->create_path($dest_file);
  7696. copy($main_code_path.$extra_file, $dest_file);
  7697. }
  7698. }
  7699. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7700. $manifest = @$xmldoc->saveXML();
  7701. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7702. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7703. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7704. // Clean possible temporary files.
  7705. foreach ($files_cleanup as $file) {
  7706. $res = unlink($file);
  7707. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7708. }
  7709. // Send file to client.
  7710. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7711. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7712. $name = replace_dangerous_char($this->get_name()).'.zip';
  7713. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7714. }
  7715. public function scorm_export_to_pdf($lp_id) {
  7716. $lp_id = intval($lp_id);
  7717. $files_to_export = array();
  7718. $course_data = api_get_course_info($this->cc);
  7719. if (!empty($course_data)) {
  7720. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7721. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7722. $list = $this->get_flat_ordered_items_list($lp_id);
  7723. foreach($list as $item_id) {
  7724. $item = $this->items[$item_id];
  7725. //Getting documents from a LP with chamilo documents
  7726. switch ($item->type) {
  7727. case 'document':
  7728. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7729. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7730. if (file_exists($file_path)) {
  7731. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7732. }
  7733. break;
  7734. case 'sco':
  7735. $file_path = $scorm_path.'/'.$item->path;
  7736. if (file_exists($file_path)) {
  7737. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7738. }
  7739. break;
  7740. case 'dokeos_chapter':
  7741. case 'dir':
  7742. case 'chapter':
  7743. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7744. break;
  7745. }
  7746. }
  7747. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7748. $pdf = new PDF();
  7749. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7750. return $result;
  7751. }
  7752. return false;
  7753. }
  7754. /**
  7755. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7756. * if it doesn't exist
  7757. */
  7758. public function create_path($path) {
  7759. $path_bits = split('/', dirname($path));
  7760. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7761. $path_built = IS_WINDOWS_OS ? '' : '/';
  7762. foreach ($path_bits as $bit) {
  7763. if (!empty ($bit)) {
  7764. $new_path = $path_built . $bit;
  7765. if (is_dir($new_path)) {
  7766. $path_built = $new_path . '/';
  7767. } else {
  7768. mkdir($new_path, api_get_permissions_for_new_directories());
  7769. $path_built = $new_path . '/';
  7770. }
  7771. }
  7772. }
  7773. }
  7774. /**
  7775. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  7776. * @return boolean The results of the unlink function, or false if there was no image to start with
  7777. */
  7778. public function delete_lp_image() {
  7779. $img = $this->get_preview_image();
  7780. if ($img != '') {
  7781. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  7782. $this->set_preview_image('');
  7783. return @ unlink($del_file);
  7784. } else {
  7785. return false;
  7786. }
  7787. }
  7788. /**
  7789. * Uploads an author image to the upload/learning_path/images directory
  7790. * @param array The image array, coming from the $_FILES superglobal
  7791. * @return boolean True on success, false on error
  7792. */
  7793. public function upload_image($image_array) {
  7794. $image_moved = false;
  7795. if (!empty ($image_array['name'])) {
  7796. $upload_ok = process_uploaded_file($image_array);
  7797. $has_attachment = true;
  7798. } else {
  7799. $image_moved = true;
  7800. }
  7801. if ($upload_ok) {
  7802. if ($has_attachment) {
  7803. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  7804. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7805. $updir = $sys_course_path . $courseDir;
  7806. // Try to add an extension to the file if it hasn't one.
  7807. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  7808. if (!filter_extension($new_file_name)) {
  7809. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  7810. $image_moved = false;
  7811. } else {
  7812. $file_extension = explode('.', $image_array['name']);
  7813. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  7814. $new_file_name = uniqid('') . '.' . $file_extension;
  7815. $new_path = $updir . '/' . $new_file_name;
  7816. //$result = @move_uploaded_file($image_array['tmp_name'], $new_path);
  7817. // Resize the image.
  7818. include_once api_get_path(LIBRARY_PATH).'image.lib.php';
  7819. $temp = new image($image_array['tmp_name']);
  7820. $picture_infos = @getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width
  7821. if ($picture_infos[0] > 104) {
  7822. $thumbwidth = 104;
  7823. } else {
  7824. $thumbwidth = $picture_infos[0];
  7825. }
  7826. if ($picture_infos[1] > 96) {
  7827. $new_height = 96;
  7828. } else {
  7829. $new_height = $picture_infos[1];
  7830. }
  7831. //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  7832. $temp->resize($thumbwidth,$new_height, 0);
  7833. $type = $picture_infos[2];
  7834. $result = false;
  7835. switch ($type) {
  7836. case 2 :
  7837. $result = $temp->send_image('JPG', $new_path);
  7838. break;
  7839. case 3 :
  7840. $result = $temp->send_image('PNG', $new_path);
  7841. break;
  7842. case 1 :
  7843. $result = $temp->send_image('GIF', $new_path);
  7844. break;
  7845. }
  7846. $temp->resize($thumbwidth, $new_height, 0);
  7847. $type = $picture_infos[2];
  7848. $result = false;
  7849. switch ($type) {
  7850. case 2 :
  7851. $result = $temp->send_image('JPG', $new_path);
  7852. break;
  7853. case 3 :
  7854. $result = $temp->send_image('PNG', $new_path);
  7855. break;
  7856. case 1 :
  7857. $result = $temp->send_image('GIF', $new_path);
  7858. break;
  7859. }
  7860. // Storing the image filename.
  7861. if ($result) {
  7862. $image_moved = true;
  7863. $this->set_preview_image($new_file_name);
  7864. return true;
  7865. }
  7866. }
  7867. }
  7868. }
  7869. return false;
  7870. }
  7871. public function set_autolunch($lp_id, $status) {
  7872. $lp_id = intval($lp_id);
  7873. $status = intval($status);
  7874. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  7875. //Setting everything to autolunch = 0
  7876. $attributes['autolunch'] = 0;
  7877. $where = array('session_id = ? '=> api_get_session_id());
  7878. Database::update($lp_table, $attributes,$where);
  7879. if ($status == 1) {
  7880. //Setting my lp_id to autolunch = 1
  7881. $attributes['autolunch'] = 1;
  7882. $where = array('id = ? AND session_id = ? '=> array($lp_id, api_get_session_id()));
  7883. Database::update($lp_table, $attributes, $where );
  7884. }
  7885. }
  7886. }
  7887. if (!function_exists('trim_value')) {
  7888. function trim_value(& $value) {
  7889. $value = trim($value);
  7890. }
  7891. }