learnpath.class.php 423 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This class defines the parent attributes and methods for Chamilo learnpaths and SCORM
  5. * learnpaths. It is used by the scorm class.
  6. *
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @author Julio Montoya <gugli100@gmail.com> Several improvements and fixes
  10. */
  11. /**
  12. * Defines the learnpath parent class
  13. * @package chamilo.learnpath
  14. */
  15. class learnpath {
  16. public $attempt = 0; // The number for the current ID view.
  17. public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
  18. public $current; // Id of the current item the user is viewing.
  19. public $current_score; // The score of the current item.
  20. public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
  21. public $current_time_stop; // The time the user closed this resource.
  22. public $default_status = 'not attempted';
  23. public $encoding = 'UTF-8';
  24. public $error = '';
  25. public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath.
  26. public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue().
  27. public $index; // The index of the active learnpath_item in $ordered_items array.
  28. public $items = array();
  29. public $last; // item_id of last item viewed in the learning path.
  30. public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized.
  31. public $license; // Which license this course has been given - not used yet on 20060522.
  32. public $lp_id; // DB ID for this learnpath.
  33. public $lp_view_id; // DB ID for lp_view
  34. public $log_file; // File where to log learnpath API msg.
  35. public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
  36. public $message = '';
  37. public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
  38. public $name; // Learnpath name (they generally have one).
  39. public $ordered_items = array(); // List of the learnpath items in the order they are to be read.
  40. public $path = ''; // Path inside the scorm directory (if scorm).
  41. public $theme; // The current theme of the learning path.
  42. public $preview_image; // The current image of the learning path.
  43. // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
  44. public $prevent_reinit = 1;
  45. // Describes the mode of progress bar display.
  46. public $seriousgame_mode = 0;
  47. public $progress_bar_mode = '%';
  48. // Percentage progress as saved in the db.
  49. public $progress_db = '0';
  50. public $proximity; // Wether the content is distant or local or unknown.
  51. public $refs_list = array (); //list of items by ref => db_id. Used only for prerequisites match.
  52. // !!!This array (refs_list) is built differently depending on the nature of the LP.
  53. // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
  54. public $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
  55. // TODO: Check if this type variable is useful here (instead of just in the controller script).
  56. public $user_id; //ID of the user that is viewing/using the course
  57. public $update_queue = array();
  58. public $scorm_debug = 0;
  59. public $arrMenu = array(); // Array for the menu items.
  60. public $debug = 0; // Logging level.
  61. public $lp_session_id =0;
  62. public $lp_view_session_id =0; // The specific view might be bound to a session.
  63. public $prerequisite = 0;
  64. public $use_max_score = 1; // 1 or 0
  65. public $created_on = '';
  66. public $modified_on = '';
  67. public $publicated_on = '';
  68. public $expired_on = '';
  69. /**
  70. * Class constructor. Needs a database handler, a course code and a learnpath id from the database.
  71. * Also builds the list of items into $this->items.
  72. * @param string Course code
  73. * @param integer Learnpath ID
  74. * @param integer User ID
  75. * @return boolean True on success, false on error
  76. */
  77. public function __construct($course, $lp_id, $user_id) {
  78. $this->encoding = api_get_system_encoding(); // Chamilo 1.8.8: We intend always to use the system encoding.
  79. // Check params.
  80. // Check course code.
  81. $course_db = '';
  82. $course_id = api_get_course_int_id();
  83. if ($this->debug > 0) {error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); }
  84. if (empty($course)) {
  85. $this->error = 'Course code is empty';
  86. return false;
  87. } else {
  88. $main_table = Database::get_main_table(TABLE_MAIN_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_id = $row_course['id'];
  97. $course_db = $row_course['db_name'];
  98. } else {
  99. $this->error = 'Course code does not exist in database ('.$sql.')';
  100. return false;
  101. }
  102. }
  103. // Check learnpath ID.
  104. if (empty($lp_id)) {
  105. $this->error = 'Learnpath ID is empty';
  106. return false;
  107. } else {
  108. // TODO: Make it flexible to use any course_code (still using env course code here).
  109. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  110. //$id = Database::escape_integer($id);
  111. $lp_id = $this->escape_string($lp_id);
  112. $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id' AND c_id = $course_id";
  113. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); }
  114. $res = Database::query($sql);
  115. if (Database::num_rows($res) > 0) {
  116. $this->lp_id = $lp_id;
  117. $row = Database::fetch_array($res);
  118. $this->type = $row['lp_type'];
  119. $this->name = stripslashes($row['name']);
  120. //$this->encoding = $row['default_encoding']; // Chamilo 1.8.8: We intend not to use 'default_encoding' field anymore.
  121. $this->proximity = $row['content_local'];
  122. $this->theme = $row['theme'];
  123. $this->maker = $row['content_maker'];
  124. $this->prevent_reinit = $row['prevent_reinit'];
  125. $this->seriousgame_mode = $row['seriousgame_mode'];
  126. $this->license = $row['content_license'];
  127. $this->scorm_debug = $row['debug'];
  128. $this->js_lib = $row['js_lib'];
  129. $this->path = $row['path'];
  130. $this->preview_image = $row['preview_image'];
  131. $this->author = $row['author'];
  132. $this->hide_toc_frame = $row['hide_toc_frame'];
  133. $this->lp_session_id = $row['session_id'];
  134. $this->use_max_score = $row['use_max_score'];
  135. $this->created_on = $row['created_on'];
  136. $this->modified_on = $row['modified_on'];
  137. if ($row['publicated_on'] != '0000-00-00 00:00:00') {
  138. $this->publicated_on = $row['publicated_on'];
  139. }
  140. if ($row['expired_on'] != '0000-00-00 00:00:00') {
  141. $this->expired_on = $row['expired_on'];
  142. }
  143. if ($this->type == 2) {
  144. if ($row['force_commit'] == 1) {
  145. $this->force_commit = true;
  146. }
  147. }
  148. $this->mode = $row['default_view_mod'];
  149. } else {
  150. $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
  151. return false;
  152. }
  153. }
  154. // Check user ID.
  155. if (empty($user_id)) {
  156. $this->error = 'User ID is empty';
  157. return false;
  158. } else {
  159. //$main_table = Database::get_main_user_table();
  160. $main_table = Database::get_main_table(TABLE_MAIN_USER);
  161. //$user_id = Database::escape_integer($user_id);
  162. $user_id = $this->escape_string($user_id);
  163. $sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
  164. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying user: '.$sql, 0); }
  165. $res = Database::query($sql);
  166. if (Database::num_rows($res) > 0) {
  167. $this->user_id = $user_id;
  168. } else {
  169. $this->error = 'User ID does not exist in database ('.$sql.')';
  170. return false;
  171. }
  172. }
  173. // End of variables checking.
  174. $session_id = api_get_session_id();
  175. // Get the session condition for learning paths of the base + session.
  176. $session = api_get_session_condition($session_id);
  177. // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
  178. $lp_table = Database::get_course_table(TABLE_LP_VIEW);
  179. // Selecting by view_count descending allows to get the highest view_count first.
  180. $sql = "SELECT * FROM $lp_table WHERE c_id = '.$course_id.' AND lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
  181. if ($this->debug > 2) { error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0); }
  182. $res = Database::query($sql);
  183. $view_id = 0; // Used later to query lp_item_view.
  184. if (Database :: num_rows($res) > 0) {
  185. if ($this->debug > 2) {
  186. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Found previous view', 0);
  187. }
  188. $row = Database :: fetch_array($res);
  189. $this->attempt = $row['view_count'];
  190. $this->lp_view_id = $row['id'];
  191. $this->last_item_seen = $row['last_item'];
  192. $this->progress_db = $row['progress'];
  193. $this->lp_view_session_id = $row['session_id'];
  194. } else {
  195. if ($this->debug > 2) {
  196. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
  197. }
  198. $this->attempt = 1;
  199. $sql_ins = "INSERT INTO $lp_table (c_id, lp_id,user_id,view_count, session_id) VALUES ($course_id, $lp_id, $user_id, 1, $session_id)";
  200. $res_ins = Database::query($sql_ins);
  201. $this->lp_view_id = Database :: insert_id();
  202. if ($this->debug > 2) {
  203. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
  204. }
  205. }
  206. // Initialise items.
  207. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  208. $sql = "SELECT * FROM $lp_item_table WHERE c_id = $course_id AND lp_id = '".$this->lp_id."' ORDER BY parent_item_id, display_order";
  209. $res = Database::query($sql);
  210. while ($row = Database::fetch_array($res)) {
  211. $oItem = '';
  212. //$this->ordered_items[] = $row['id'];
  213. switch ($this->type) {
  214. case 3: //aicc
  215. $oItem = new aiccItem('db', $row['id'], $course_db);
  216. if (is_object($oItem)) {
  217. $my_item_id = $oItem->get_id();
  218. $oItem->set_lp_view($this->lp_view_id, $course_id);
  219. $oItem->set_prevent_reinit($this->prevent_reinit);
  220. // Don't use reference here as the next loop will make the pointed object change.
  221. $this->items[$my_item_id] = $oItem;
  222. $this->refs_list[$oItem->ref] = $my_item_id;
  223. if ($this->debug > 2) {
  224. error_log('New LP - learnpath::__construct() - aicc object with id ' . $my_item_id . ' set in items[]', 0);
  225. }
  226. }
  227. break;
  228. case 2:
  229. require_once 'scorm.class.php';
  230. require_once 'scormItem.class.php';
  231. $oItem = new scormItem('db', $row['id'], $course_db);
  232. if (is_object($oItem)) {
  233. $my_item_id = $oItem->get_id();
  234. $oItem->set_lp_view($this->lp_view_id, $course_id);
  235. $oItem->set_prevent_reinit($this->prevent_reinit);
  236. // Don't use reference here as the next loop will make the pointed object change.
  237. $this->items[$my_item_id] = $oItem;
  238. $this->refs_list[$oItem->ref] = $my_item_id;
  239. if ($this->debug > 2) {
  240. error_log('New LP - object with id ' . $my_item_id . ' set in items[]', 0);
  241. }
  242. }
  243. break;
  244. case 1:
  245. default:
  246. require_once 'learnpathItem.class.php';
  247. $oItem = new learnpathItem($row['id'], $user_id, $course_id);
  248. if (is_object($oItem)) {
  249. $my_item_id = $oItem->get_id();
  250. //$oItem->set_lp_view($this->lp_view_id); // Moved down to when we are sure the item_view exists.
  251. $oItem->set_prevent_reinit($this->prevent_reinit);
  252. // Don't use reference here as the next loop will make the pointed object change.
  253. $this->items[$my_item_id] = $oItem;
  254. $this->refs_list[$my_item_id] = $my_item_id;
  255. if ($this->debug > 2) {
  256. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - object with id ' . $my_item_id . ' set in items[]', 0);
  257. }
  258. }
  259. break;
  260. }
  261. // Items is a list of pointers to all items, classified by DB ID, not SCO id.
  262. if ($row['parent_item_id'] == 0 || empty ($this->items[$row['parent_item_id']])) {
  263. if (is_object($this->items[$row['id']])) {
  264. $this->items[$row['id']]->set_level(0);
  265. }
  266. } else {
  267. $level = $this->items[$row['parent_item_id']]->get_level() + 1;
  268. $this->items[$row['id']]->set_level($level);
  269. if (is_object($this->items[$row['parent_item_id']])) {
  270. // Items is a list of pointers from item DB ids to item objects.
  271. $this->items[$row['parent_item_id']]->add_child($row['id']);
  272. } else {
  273. if ($this->debug > 2) {
  274. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - The parent item (' . $row['parent_item_id'] . ') of item ' . $row['id'] . ' could not be found', 0);
  275. }
  276. }
  277. }
  278. // Get last viewing vars.
  279. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  280. // This query should only return one or zero result.
  281. $sql = "SELECT * " .
  282. "FROM $lp_item_view_table " .
  283. "WHERE c_id = ".$course_id." AND lp_view_id = " . $this->lp_view_id . " " .
  284. "AND lp_item_id = " . $row['id'] . " ORDER BY view_count DESC ";
  285. if ($this->debug > 2) {
  286. error_log('New LP - learnpath::__construct() - Selecting item_views: ' . $sql, 0);
  287. }
  288. // Get the item status.
  289. $res2 = Database::query($sql);
  290. if (Database :: num_rows($res2) > 0) {
  291. // If this learnpath has already been used by this user, get his last attempt count and
  292. // the last item seen back into this object.
  293. //$max = 0;
  294. $row2 = Database :: fetch_array($res2);
  295. if ($this->debug > 2) {
  296. error_log('New LP - learnpath::__construct() - Got item_view: ' . print_r($row2, true), 0);
  297. }
  298. if (is_object($this->items[$row['id']])) {
  299. $this->items[$row['id']]->set_status($row2['status']);
  300. if (empty ($row2['status'])) {
  301. $this->items[$row['id']]->set_status($this->default_status);
  302. }
  303. }
  304. //$this->attempt = $row['view_count'];
  305. //$this->last_item = $row['id'];
  306. } else { // No item has been found in lp_item_view for this view.
  307. // The first attempt of this user. Set attempt to 1 and last_item to 0 (first item available).
  308. // TODO: If the learnpath has not got attempts activated, always use attempt '1'.
  309. //$this->attempt = 1;
  310. //$this->last_item = 0;
  311. if (is_object($this->items[$row['id']])) {
  312. $this->items[$row['id']]->set_status($this->default_status);
  313. }
  314. // Add that row to the lp_item_view table so that we have something to show in the stats page.
  315. $sql_ins = "INSERT INTO $lp_item_view_table (c_id, lp_item_id, lp_view_id, view_count, status)
  316. VALUES ($course_id, ".$row['id'] . "," . $this->lp_view_id . ",1,'not attempted')";
  317. if ($this->debug > 2) {
  318. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
  319. }
  320. $res_ins = Database::query($sql_ins);
  321. }
  322. // Setting the view in the item object.
  323. if (is_object($this->items[$row['id']])) {
  324. $this->items[$row['id']]->set_lp_view($this->lp_view_id, $course_id);
  325. }
  326. }
  327. $this->ordered_items = $this->get_flat_ordered_items_list($this->get_id(), 0, $course_id);
  328. $this->max_ordered_items = 0;
  329. foreach ($this->ordered_items as $index => $dummy) {
  330. if ($index > $this->max_ordered_items && !empty($dummy)) {
  331. $this->max_ordered_items = $index;
  332. }
  333. }
  334. // TODO: Define the current item better.
  335. $this->first();
  336. if ($this->debug > 2) {
  337. error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - End of learnpath constructor for learnpath ' . $this->get_id(), 0);
  338. }
  339. }
  340. /**
  341. * 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
  342. * I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
  343. *
  344. * @param int $parent
  345. * @param int $previous
  346. * @param string $type
  347. * @param int resource ID (ref)
  348. * @param string $title
  349. * @param string $description
  350. * @return int
  351. */
  352. public function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites = 0, $max_time_allowed = 0) {
  353. $course_id = api_get_course_int_id();
  354. if ($this->debug > 0) {
  355. error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0);
  356. }
  357. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  358. $parent = intval($parent);
  359. $previous = intval($previous);
  360. $type = $this->escape_string($type);
  361. $id = intval($id);
  362. $max_time_allowed = $this->escape_string(htmlentities($max_time_allowed));
  363. if (empty ($max_time_allowed)) {
  364. $max_time_allowed = 0;
  365. }
  366. $title = $this->escape_string($title);
  367. $description = $this->escape_string($description);
  368. $sql_count = " SELECT COUNT(id) AS num
  369. FROM " . $tbl_lp_item . "
  370. WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND parent_item_id = " . $parent;
  371. $res_count = Database::query($sql_count);
  372. $row = Database :: fetch_array($res_count);
  373. $num = $row['num'];
  374. if ($num > 0) {
  375. if ($previous == 0) {
  376. $sql = "SELECT id, next_item_id, display_order
  377. FROM " . $tbl_lp_item . "
  378. WHERE c_id = ".$course_id." AND
  379. lp_id = " . $this->get_id() . " AND
  380. parent_item_id = " . $parent . " AND
  381. previous_item_id = 0 OR previous_item_id=" . $parent;
  382. $result = Database::query($sql);
  383. $row = Database :: fetch_array($result);
  384. $tmp_previous = 0;
  385. $next = $row['id'];
  386. $display_order = 0;
  387. } else {
  388. $previous = (int) $previous;
  389. $sql = "SELECT id, previous_item_id, next_item_id, display_order
  390. FROM " . $tbl_lp_item . "
  391. WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND id = " . $previous;
  392. $result = Database::query($sql);
  393. $row = Database :: fetch_array($result);
  394. $tmp_previous = $row['id'];
  395. $next = $row['next_item_id'];
  396. $display_order = $row['display_order'];
  397. }
  398. } else {
  399. $tmp_previous = 0;
  400. $next = 0;
  401. $display_order = 0;
  402. }
  403. $new_item_id = -1;
  404. $id = $this->escape_string($id);
  405. $course_id = api_get_course_int_id();
  406. if ($type == 'quiz') {
  407. $sql = 'SELECT SUM(ponderation)
  408. FROM ' . Database :: get_course_table(TABLE_QUIZ_QUESTION) . ' as quiz_question
  409. INNER JOIN ' . Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION) . ' as quiz_rel_question
  410. ON quiz_question.id = quiz_rel_question.question_id
  411. WHERE quiz_rel_question.exercice_id = ' . $id." AND
  412. quiz_question.c_id = $course_id AND
  413. quiz_rel_question.c_id = $course_id ";
  414. $rsQuiz = Database::query($sql);
  415. $max_score = Database :: result($rsQuiz, 0, 0);
  416. } else {
  417. $max_score = 100;
  418. }
  419. if ($prerequisites != 0) {
  420. $sql_ins = "INSERT INTO " . $tbl_lp_item . " (
  421. c_id,
  422. lp_id, ".
  423. "item_type, ".
  424. "ref, ".
  425. "title, ".
  426. "description, ".
  427. "path, ".
  428. "max_score, ".
  429. "parent_item_id, ".
  430. "previous_item_id, ".
  431. "next_item_id, ".
  432. "display_order, ".
  433. "prerequisite, ".
  434. "max_time_allowed ".
  435. ") VALUES (
  436. $course_id ,
  437. ".$this->get_id() . ", ".
  438. "'" . $type . "', ".
  439. "'', ".
  440. "'" . $title . "', ".
  441. "'" . $description . "', ".
  442. "'" . $id . "', ".
  443. "'" . $max_score . "', ".
  444. $parent . ", ".
  445. $previous . ", ".
  446. $next . ", ".
  447. ($display_order +1) . ", ".
  448. $prerequisites . ", ".
  449. $max_time_allowed .
  450. ")";
  451. } else {
  452. // Insert new item.
  453. $sql_ins = "
  454. INSERT INTO " . $tbl_lp_item . " ( ".
  455. "c_id, ".
  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. $course_id. ",".
  470. $this->get_id() . ",".
  471. "'" . $type . "',".
  472. "'',".
  473. "'" . $title . "',".
  474. "'" . $description . "',".
  475. "'" . $id . "',".
  476. "'" . $max_score . "',".
  477. $parent . ",".
  478. $previous . ",".
  479. $next . ",".
  480. ($display_order +1) . ",".
  481. $max_time_allowed .
  482. ")";
  483. }
  484. if ($this->debug > 2) {
  485. error_log('New LP - Inserting dokeos_chapter: ' . $sql_ins, 0);
  486. }
  487. $res_ins = Database::query($sql_ins);
  488. if ($res_ins > 0) {
  489. $new_item_id = Database :: insert_id($res_ins);
  490. // Update the item that should come after the new item.
  491. $sql_update_next = "
  492. UPDATE " . $tbl_lp_item . "
  493. SET previous_item_id = " . $new_item_id . "
  494. WHERE c_id = $course_id AND id = " . $next;
  495. $res_update_next = Database::query($sql_update_next);
  496. // Update the item that should be before the new item.
  497. $sql_update_previous = "
  498. UPDATE " . $tbl_lp_item . "
  499. SET next_item_id = " . $new_item_id . "
  500. WHERE c_id = $course_id AND id = " . $tmp_previous;
  501. $res_update_previous = Database::query($sql_update_previous);
  502. // Update all the items after the new item.
  503. $sql_update_order = "
  504. UPDATE " . $tbl_lp_item . "
  505. SET display_order = display_order + 1
  506. WHERE
  507. c_id = $course_id AND
  508. lp_id = " . $this->get_id() . " AND
  509. id <> " . $new_item_id . " AND
  510. parent_item_id = " . $parent . " AND
  511. display_order > " . $display_order;
  512. $res_update_previous = Database::query($sql_update_order);
  513. // Update the item that should come after the new item.
  514. $sql_update_ref = "UPDATE " . $tbl_lp_item . "
  515. SET ref = " . $new_item_id . "
  516. WHERE c_id = $course_id AND id = " . $new_item_id;
  517. Database::query($sql_update_ref);
  518. }
  519. // Upload audio.
  520. if (!empty ($_FILES['mp3']['name'])) {
  521. // Create the audio folder if it does not exist yet.
  522. global $_course;
  523. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  524. if (!is_dir($filepath . 'audio')) {
  525. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  526. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  527. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  528. }
  529. // Upload the file in the documents tool.
  530. include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  531. $file_path = handle_uploaded_document($_course, $_FILES['mp3'], api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document', '/audio', api_get_user_id(), '', '', '', '', '', false);
  532. // Getting the filename only.
  533. $file_components = explode('/', $file_path);
  534. $file = $file_components[count($file_components) - 1];
  535. // Store the mp3 file in the lp_item table.
  536. $sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '" . Database :: escape_string($file) . "' WHERE id = '" . Database :: escape_string($new_item_id) . "'";
  537. Database::query($sql_insert_audio);
  538. }
  539. return $new_item_id;
  540. }
  541. /**
  542. * Static admin function allowing addition of a learnpath to a course.
  543. * @param string Course code
  544. * @param string Learnpath name
  545. * @param string Learnpath description string, if provided
  546. * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  547. * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  548. * @param string Zip file containing the learnpath or directory containing the learnpath
  549. * @return integer The new learnpath ID on success, 0 on failure
  550. */
  551. public function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $publicated_on = '', $expired_on = '') {
  552. global $charset;
  553. $course_id = api_get_course_int_id();
  554. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  555. // Check course code exists.
  556. // Check lp_name doesn't exist, otherwise append something.
  557. $i = 0;
  558. $name = learnpath :: escape_string($name);
  559. // Session id.
  560. $session_id = api_get_session_id();
  561. $check_name = "SELECT * FROM $tbl_lp WHERE c_id = ".$course_id." AND name = '$name'";
  562. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  563. $res_name = Database::query($check_name);
  564. if ($publicated_on == '0000-00-00 00:00:00' || empty($publicated_on)) {
  565. //by default the publication date is the same that the creation date
  566. //The behaviour above was changed due BT#2800
  567. global $_custom;
  568. if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date']) {
  569. $publicated_on = '';
  570. } else {
  571. $publicated_on = api_get_utc_datetime();
  572. }
  573. } else {
  574. $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
  575. }
  576. if ($expired_on == '0000-00-00 00:00:00' || empty($expired_on)) {
  577. $expired_on = '';
  578. } else {
  579. $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
  580. }
  581. while (Database :: num_rows($res_name)) {
  582. // There is already one such name, update the current one a bit.
  583. $i++;
  584. $name = $name . ' - ' . $i;
  585. $check_name = "SELECT * FROM $tbl_lp WHERE c_id = ".$course_id." AND name = '$name'";
  586. //if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
  587. $res_name = Database::query($check_name);
  588. }
  589. // New name does not exist yet; keep it.
  590. // Escape description.
  591. $description = learnpath :: escape_string(api_htmlentities($description, ENT_QUOTES, $charset)); // Kevin: added htmlentities().
  592. $type = 1;
  593. switch ($learnpath) {
  594. case 'guess':
  595. break;
  596. case 'dokeos':
  597. case 'chamilo':
  598. $type = 1;
  599. break;
  600. case 'aicc':
  601. break;
  602. }
  603. switch ($origin) {
  604. case 'zip':
  605. // Check zipname string. If empty, we are currently creating a new Chamilo learnpath.
  606. break;
  607. case 'manual':
  608. default:
  609. $get_max = "SELECT MAX(display_order) FROM $tbl_lp WHERE c_id = ".$course_id." ";
  610. $res_max = Database::query($get_max);
  611. if (Database :: num_rows($res_max) < 1) {
  612. $dsp = 1;
  613. } else {
  614. $row = Database :: fetch_array($res_max);
  615. $dsp = $row[0] + 1;
  616. }
  617. $sql_insert = "INSERT INTO $tbl_lp (c_id, 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) " .
  618. "VALUES ($course_id, $type,'$name','$description','','embedded','UTF-8','$dsp','Chamilo','local','','".$session_id."', '".api_get_utc_datetime()."' , '".$publicated_on."' , '".$expired_on."')";
  619. $res_insert = Database::query($sql_insert);
  620. $id = Database :: insert_id();
  621. if ($id > 0) {
  622. // Insert into item_property.
  623. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
  624. return $id;
  625. }
  626. break;
  627. }
  628. }
  629. /**
  630. * Appends a message to the message attribute
  631. * @param string Message to append.
  632. */
  633. public function append_message($string) {
  634. if ($this->debug > 0) {
  635. error_log('New LP - In learnpath::append_message()', 0);
  636. }
  637. $this->message .= $string;
  638. }
  639. /**
  640. * Autocompletes the parents of an item in case it's been completed or passed
  641. * @param integer Optional ID of the item from which to look for parents
  642. */
  643. public function autocomplete_parents($item) {
  644. $course_id = api_get_course_int_id();
  645. if ($this->debug > 0) {
  646. error_log('New LP - In learnpath::autocomplete_parents()', 0);
  647. }
  648. if (empty ($item)) {
  649. $item = $this->current;
  650. }
  651. $parent_id = $this->items[$item]->get_parent();
  652. if ($this->debug > 2) {
  653. error_log('New LP - autocompleting parent of item ' . $item . ' (item ' . $parent_id . ')', 0);
  654. }
  655. if (is_object($this->items[$item]) and !empty ($parent_id)) {
  656. // if $item points to an object and there is a parent.
  657. if ($this->debug > 2) {
  658. error_log('New LP - ' . $item . ' is an item, proceed', 0);
  659. }
  660. $current_item = & $this->items[$item];
  661. $parent = & $this->items[$parent_id]; // Get the parent.
  662. // New experiment including failed and browsed in completed status.
  663. $current_status = $current_item->get_status();
  664. if ($current_item->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
  665. // If the current item is completed or passes or succeeded.
  666. $completed = true;
  667. if ($this->debug > 2) {
  668. error_log('New LP - Status of current item is alright', 0);
  669. }
  670. foreach ($parent->get_children() as $child) {
  671. // Check all his brothers (his parent's children) for completion status.
  672. if ($child != $item) {
  673. if ($this->debug > 2) {
  674. error_log('New LP - Looking at brother with ID ' . $child . ', status is ' . $this->items[$child]->get_status(), 0);
  675. }
  676. //if($this->items[$child]->status_is(array('completed','passed','succeeded')))
  677. // Trying completing parents of failed and browsed items as well.
  678. if ($this->items[$child]->status_is(array (
  679. 'completed',
  680. 'passed',
  681. 'succeeded',
  682. 'browsed',
  683. 'failed'
  684. ))) {
  685. // Keep completion status to true.
  686. } else {
  687. if ($this->debug > 2) {
  688. error_log('New LP - Found one incomplete child of ' . $parent_id . ': ' . $child . ' is ' . $this->items[$child]->get_status(), 0);
  689. }
  690. $completed = false;
  691. }
  692. }
  693. }
  694. if ($completed) { // If all the children were completed:
  695. $parent->set_status('completed');
  696. $parent->save(false, $this->prerequisites_match($parent->get_id()));
  697. $this->update_queue[$parent->get_id()] = $parent->get_status();
  698. if ($this->debug > 2) {
  699. error_log('New LP - Added parent to update queue ' . print_r($this->update_queue, true), 0);
  700. }
  701. $this->autocomplete_parents($parent->get_id()); // Recursive call.
  702. }
  703. } else {
  704. //error_log('New LP - status of current item is not enough to get bothered with it', 0);
  705. }
  706. }
  707. }
  708. /**
  709. * Autosaves the current results into the database for the whole learnpath
  710. */
  711. public function autosave() {
  712. if ($this->debug > 0) {
  713. error_log('New LP - In learnpath::autosave()', 0);
  714. }
  715. // TODO: Add save operations for the learnpath itself.
  716. }
  717. /**
  718. * Clears the message attribute
  719. */
  720. public function clear_message() {
  721. if ($this->debug > 0) {
  722. error_log('New LP - In learnpath::clear_message()', 0);
  723. }
  724. $this->message = '';
  725. }
  726. /**
  727. * Closes the current resource
  728. *
  729. * Stops the timer
  730. * Saves into the database if required
  731. * Clears the current resource data from this object
  732. * @return boolean True on success, false on failure
  733. */
  734. public function close() {
  735. $course_id = api_get_course_int_id();
  736. if ($this->debug > 0) {
  737. error_log('New LP - In learnpath::close()', 0);
  738. }
  739. if (empty ($this->lp_id)) {
  740. $this->error = 'Trying to close this learnpath but no ID is set';
  741. return false;
  742. }
  743. $this->current_time_stop = time();
  744. if ($this->save) {
  745. $learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  746. /*
  747. $sql = "UPDATE $learnpath_view_table " .
  748. "SET " .
  749. "stop_time = ".$this->current_time_stop.", " .
  750. "score = ".$this->current_score.", ".
  751. "WHERE learnpath_id = '".$this->lp_id."'";
  752. //$res = Database::query($sql);
  753. $res = Database::query($res);
  754. if (Database::affected_rows($res) < 1) {
  755. $this->error = 'Could not update learnpath_view table while closing learnpath';
  756. return false;
  757. }
  758. */
  759. }
  760. $this->ordered_items = array ();
  761. $this->index = 0;
  762. unset ($this->lp_id);
  763. //unset other stuff
  764. return true;
  765. }
  766. /**
  767. * Static admin function allowing removal of a learnpath
  768. * @param string Course code
  769. * @param integer Learnpath ID
  770. * @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
  771. * @return boolean True on success, false on failure (might change that to return number of elements deleted)
  772. */
  773. public function delete($course = null, $id = null, $delete = 'keep') {
  774. $course_id = api_get_course_int_id();
  775. // TODO: Implement a way of getting this to work when the current object is not set.
  776. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
  777. //if (empty($course)) { $course = api_get_course_id(); }
  778. //if (empty($id)) { $id = $this->get_id(); }
  779. // If an ID is specifically given and the current LP is not the same, prevent delete.
  780. if (!empty ($id) && ($id != $this->lp_id)) {
  781. return false;
  782. }
  783. $lp = Database :: get_course_table(TABLE_LP_MAIN);
  784. $lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below.
  785. $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
  786. $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  787. //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
  788. // Delete lp item id.
  789. foreach ($this->items as $id => $dummy) {
  790. //$this->items[$id]->delete();
  791. $sql_del_view = "DELETE FROM $lp_item_view WHERE lp_item_id = '" . $id . "'";
  792. $res_del_item_view = Database::query($sql_del_view);
  793. }
  794. // Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673
  795. $sql_del_item = "DELETE FROM $lp_item WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  796. $res_del_item = Database::query($sql_del_item);
  797. $sql_del_view = "DELETE FROM $lp_view WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  798. //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
  799. $res_del_view = Database::query($sql_del_view);
  800. $this->toggle_publish($this->lp_id, 'i');
  801. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
  802. if ($this->type == 2 || $this->type == 3) {
  803. // This is a scorm learning path, delete the files as well.
  804. $sql = "SELECT path FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id;
  805. $res = Database::query($sql);
  806. if (Database :: num_rows($res) > 0) {
  807. $row = Database :: fetch_array($res);
  808. $path = $row['path'];
  809. $sql = "SELECT id FROM $lp WHERE c_id = ".$course_id." AND path = '$path' AND id != " . $this->lp_id;
  810. $res = Database::query($sql);
  811. if (Database :: num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it.
  812. if ($this->debug > 2) {
  813. error_log('New LP - In learnpath::delete(), found other LP using path ' . $path . ', keeping directory', 0);
  814. }
  815. } else {
  816. // No other LP uses that directory, delete it.
  817. $course_rel_dir = api_get_course_path() . '/scorm/'; // scorm dir web path starting from /courses
  818. $course_scorm_dir = api_get_path(SYS_COURSE_PATH) . $course_rel_dir; // The absolute system path for this course.
  819. if ($delete == 'remove' && is_dir($course_scorm_dir . $path) and !empty ($course_scorm_dir)) {
  820. if ($this->debug > 2) {
  821. error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: ' . $course_scorm_dir . $path, 0);
  822. }
  823. // Proposed by Christophe (clefevre).
  824. if (strcmp(substr($path, -2), "/.") == 0) {
  825. $path = substr($path, 0, -1); // Remove "." at the end.
  826. }
  827. //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
  828. rmdirr($course_scorm_dir . $path);
  829. }
  830. }
  831. }
  832. }
  833. $sql_del_lp = "DELETE FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id;
  834. //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
  835. $res_del_lp = Database::query($sql_del_lp);
  836. $this->update_display_order(); // Updates the display order of all lps.
  837. api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
  838. require_once '../gradebook/lib/be.inc.php';
  839. // Delete link of gradebook tool
  840. //$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  841. /*$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="4" AND gl.ref_id="' . $id . '";';
  842. $result = Database::query($sql);
  843. $row = Database :: fetch_array($result, 'ASSOC');*/
  844. // Fixing gradebook link deleted see #5229.
  845. /*
  846. if (!empty($row['id'])) {
  847. $link = LinkFactory :: load($row['id']);
  848. if ($link[0] != null) {
  849. $link[0]->delete();
  850. }
  851. }*/
  852. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  853. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 4 , $id, api_get_session_id());
  854. if ($link_id !== false) {
  855. remove_resource_from_course_gradebook($link_id);
  856. }
  857. if (api_get_setting('search_enabled') == 'true') {
  858. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  859. $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
  860. }
  861. }
  862. /**
  863. * Removes all the children of one item - dangerous!
  864. * @param integer Element ID of which children have to be removed
  865. * @return integer Total number of children removed
  866. */
  867. public function delete_children_items($id) {
  868. $course_id = api_get_course_int_id();
  869. if ($this->debug > 0) {
  870. error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
  871. }
  872. $num = 0;
  873. if (empty ($id) || $id != strval(intval($id))) {
  874. return false;
  875. }
  876. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  877. $sql = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $id";
  878. $res = Database::query($sql);
  879. while ($row = Database :: fetch_array($res)) {
  880. $num += $this->delete_children_items($row['id']);
  881. $sql_del = "DELETE FROM $lp_item WHERE c_id = ".$course_id." AND id = " . $row['id'];
  882. $res_del = Database::query($sql_del);
  883. $num++;
  884. }
  885. return $num;
  886. }
  887. /**
  888. * Removes an item from the current learnpath
  889. * @param integer Elem ID (0 if first)
  890. * @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
  891. * @return integer Number of elements moved
  892. * @todo implement resource removal
  893. */
  894. public function delete_item($id, $remove = 'keep') {
  895. $course_id = api_get_course_int_id();
  896. if ($this->debug > 0) {
  897. error_log('New LP - In learnpath::delete_item()', 0);
  898. }
  899. // TODO: Implement the resource removal.
  900. if (empty ($id) || $id != strval(intval($id))) {
  901. return false;
  902. }
  903. // First select item to get previous, next, and display order.
  904. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  905. $sql_sel = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND id = $id";
  906. $res_sel = Database::query($sql_sel);
  907. if (Database :: num_rows($res_sel) < 1) {
  908. return false;
  909. }
  910. $row = Database :: fetch_array($res_sel);
  911. $previous = $row['previous_item_id'];
  912. $next = $row['next_item_id'];
  913. $display = $row['display_order'];
  914. $parent = $row['parent_item_id'];
  915. $lp = $row['lp_id'];
  916. // Delete children items.
  917. $num = $this->delete_children_items($id);
  918. if ($this->debug > 2) {
  919. error_log('New LP - learnpath::delete_item() - deleted ' . $num . ' children of element ' . $id, 0);
  920. }
  921. // Now delete the item.
  922. $sql_del = "DELETE FROM $lp_item WHERE id = $id";
  923. if ($this->debug > 2) {
  924. error_log('New LP - Deleting item: ' . $sql_del, 0);
  925. }
  926. $res_del = Database::query($sql_del);
  927. // Now update surrounding items.
  928. $sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE c_id = ".$course_id." AND id = $previous";
  929. $res_upd = Database::query($sql_upd);
  930. $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE c_id = ".$course_id." AND id = $next";
  931. $res_upd = Database::query($sql_upd);
  932. // Now update all following items with new display order.
  933. $sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE c_id = ".$course_id." AND lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
  934. $res_all = Database::query($sql_all);
  935. //Removing prerequisites since the item will not longer exist
  936. $sql_all = "UPDATE $lp_item SET prerequisite = '' WHERE c_id = ".$course_id." AND prerequisite = $id";
  937. $res_all = Database::query($sql_all);
  938. // Remove from search engine if enabled.
  939. if (api_get_setting('search_enabled') == 'true') {
  940. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  941. $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';
  942. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  943. $res = Database::query($sql);
  944. if (Database :: num_rows($res) > 0) {
  945. $row2 = Database :: fetch_array($res);
  946. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  947. $di = new DokeosIndexer();
  948. $di->remove_document((int) $row2['search_did']);
  949. }
  950. $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';
  951. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
  952. Database::query($sql);
  953. }
  954. }
  955. /**
  956. * Updates an item's content in place
  957. * @param integer Element ID
  958. * @param integer Parent item ID
  959. * @param integer Previous item ID
  960. * @param string Item title
  961. * @param string Item description
  962. * @param string Prerequisites (optional)
  963. * @param string Indexing terms (optional)
  964. * @param array The array resulting of the $_FILES[mp3] element
  965. * @return boolean True on success, false on error
  966. */
  967. public function edit_item($id, $parent, $previous, $title, $description, $prerequisites = 0, $audio = null, $max_time_allowed = 0) {
  968. $course_id = api_get_course_int_id();
  969. if ($this->debug > 0) {
  970. error_log('New LP - In learnpath::edit_item()', 0);
  971. }
  972. if (empty ($max_time_allowed)) {
  973. $max_time_allowed = 0;
  974. }
  975. if (empty ($id) || ($id != strval(intval($id))) || empty ($title)) {
  976. return false;
  977. }
  978. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  979. $sql_select = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND id = " . $id;
  980. $res_select = Database::query($sql_select);
  981. $row_select = Database :: fetch_array($res_select);
  982. $audio_update_sql = '';
  983. if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
  984. // Create the audio folder if it does not exist yet.
  985. global $_course;
  986. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  987. if (!is_dir($filepath . 'audio')) {
  988. mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
  989. $audio_id = add_document($_course, '/audio', 'folder', 0, 'audio');
  990. api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
  991. }
  992. // Upload file in documents.
  993. $pi = pathinfo($audio['name']);
  994. if ($pi['extension'] == 'mp3') {
  995. $c_det = api_get_course_info($this->cc);
  996. $bp = api_get_path(SYS_COURSE_PATH) . $c_det['path'] . '/document';
  997. $path = handle_uploaded_document($c_det, $audio, $bp, '/audio', api_get_user_id(), 0, null, '', 0, 'rename', false, 0);
  998. $path = substr($path, 7);
  999. // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
  1000. $audio_update_sql = ", audio = '" . Database :: escape_string($path) . "' ";
  1001. }
  1002. }
  1003. $same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
  1004. $same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
  1005. // TODO: htmlspecialchars to be checked for encoding related problems.
  1006. if ($same_parent && $same_previous) {
  1007. // Only update title and description.
  1008. $sql_update = " UPDATE " . $tbl_lp_item . "
  1009. SET title = '" . $this->escape_string($title) . "',
  1010. prerequisite = '" . $prerequisites . "',
  1011. description = '" . $this->escape_string($description) . "'
  1012. " . $audio_update_sql . ",
  1013. max_time_allowed = '" . $this->escape_string($max_time_allowed) . "'
  1014. WHERE c_id = ".$course_id." AND id = " . $id;
  1015. $res_update = Database::query($sql_update);
  1016. } else {
  1017. $old_parent = $row_select['parent_item_id'];
  1018. $old_previous = $row_select['previous_item_id'];
  1019. $old_next = $row_select['next_item_id'];
  1020. $old_order = $row_select['display_order'];
  1021. $old_prerequisite = $row_select['prerequisite'];
  1022. $old_max_time_allowed = $row_select['max_time_allowed'];
  1023. /* BEGIN -- virtually remove the current item id */
  1024. /* for the next and previous item it is like the current item doesn't exist anymore */
  1025. if ($old_previous != 0) {
  1026. $sql_update_next = "
  1027. UPDATE " . $tbl_lp_item . "
  1028. SET next_item_id = " . $old_next . "
  1029. WHERE c_id = ".$course_id." AND id = " . $old_previous;
  1030. $res_update_next = Database::query($sql_update_next);
  1031. //echo '<p>' . $sql_update_next . '</p>';
  1032. }
  1033. if ($old_next != 0) {
  1034. $sql_update_previous = "
  1035. UPDATE " . $tbl_lp_item . "
  1036. SET previous_item_id = " . $old_previous . "
  1037. WHERE c_id = ".$course_id." AND id = " . $old_next;
  1038. $res_update_previous = Database::query($sql_update_previous);
  1039. //echo '<p>' . $sql_update_previous . '</p>';
  1040. }
  1041. // display_order - 1 for every item with a display_order bigger then the display_order of the current item.
  1042. $sql_update_order = "
  1043. UPDATE " . $tbl_lp_item . "
  1044. SET display_order = display_order - 1
  1045. WHERE
  1046. c_id = ".$course_id." AND
  1047. display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
  1048. parent_item_id = " . $old_parent;
  1049. $res_update_order = Database::query($sql_update_order);
  1050. //echo '<p>' . $sql_update_order . '</p>';
  1051. /* END -- virtually remove the current item id */
  1052. /* BEGIN -- update the current item id to his new location */
  1053. if ($previous == 0) {
  1054. // Select the data of the item that should come after the current item.
  1055. $sql_select_old = "SELECT id, display_order
  1056. FROM " . $tbl_lp_item . "
  1057. WHERE
  1058. c_id = ".$course_id." AND
  1059. lp_id = " . $this->lp_id . " AND
  1060. parent_item_id = " . $parent . " AND
  1061. previous_item_id = " . $previous;
  1062. $res_select_old = Database::query($sql_select_old);
  1063. $row_select_old = Database :: fetch_array($res_select_old);
  1064. //echo '<p>' . $sql_select_old . '</p>';
  1065. // If the new parent didn't have children before.
  1066. if (Database :: num_rows($res_select_old) == 0) {
  1067. $new_next = 0;
  1068. $new_order = 1;
  1069. } else {
  1070. $new_next = $row_select_old['id'];
  1071. $new_order = $row_select_old['display_order'];
  1072. }
  1073. //echo 'New next_item_id of current item: ' . $new_next . '<br />';
  1074. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1075. //echo 'New display_order of current item: ' . $new_order . '<br />';
  1076. } else {
  1077. // Select the data of the item that should come before the current item.
  1078. $sql_select_old = " SELECT next_item_id, display_order
  1079. FROM " . $tbl_lp_item . "
  1080. WHERE c_id = ".$course_id." AND id = " . $previous;
  1081. $res_select_old = Database::query($sql_select_old);
  1082. $row_select_old = Database :: fetch_array($res_select_old);
  1083. //echo '<p>' . $sql_select_old . '</p>';
  1084. //echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
  1085. //echo 'New previous_item_id of current item: ' . $previous . '<br />';
  1086. //echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
  1087. $new_next = $row_select_old['next_item_id'];
  1088. $new_order = $row_select_old['display_order'] + 1;
  1089. }
  1090. // TODO: htmlspecialchars to be checked for encoding related problems.
  1091. // Update the current item with the new data.
  1092. $sql_update = "UPDATE " . $tbl_lp_item . "
  1093. SET
  1094. title = '" . $this->escape_string($title) . "',
  1095. description = '" . $this->escape_string($description) . "',
  1096. parent_item_id = " . $parent . ",
  1097. previous_item_id = " . $previous . ",
  1098. next_item_id = " . $new_next . ",
  1099. display_order = " . $new_order . "
  1100. " . $audio_update_sql . "
  1101. WHERE c_id = ".$course_id." AND id = " . $id;
  1102. $res_update_next = Database::query($sql_update);
  1103. //echo '<p>' . $sql_update . '</p>';
  1104. if ($previous != 0) {
  1105. // Update the previous item's next_item_id.
  1106. $sql_update_previous = "
  1107. UPDATE " . $tbl_lp_item . "
  1108. SET next_item_id = " . $id . "
  1109. WHERE c_id = ".$course_id." AND id = " . $previous;
  1110. $res_update_next = Database::query($sql_update_previous);
  1111. //echo '<p>' . $sql_update_previous . '</p>';
  1112. }
  1113. if ($new_next != 0) {
  1114. // Update the next item's previous_item_id.
  1115. $sql_update_next = "
  1116. UPDATE " . $tbl_lp_item . "
  1117. SET previous_item_id = " . $id . "
  1118. WHERE c_id = ".$course_id." AND id = " . $new_next;
  1119. $res_update_next = Database::query($sql_update_next);
  1120. //echo '<p>' . $sql_update_next . '</p>';
  1121. }
  1122. if ($old_prerequisite != $prerequisites) {
  1123. $sql_update_next = "
  1124. UPDATE " . $tbl_lp_item . "
  1125. SET prerequisite = " . $prerequisites . "
  1126. WHERE c_id = ".$course_id." AND id = " . $id;
  1127. $res_update_next = Database::query($sql_update_next);
  1128. }
  1129. if ($old_max_time_allowed != $max_time_allowed) {
  1130. $sql_update_max_time_allowed = "
  1131. UPDATE " . $tbl_lp_item . "
  1132. SET max_time_allowed = " . $max_time_allowed . "
  1133. WHERE c_id = ".$course_id." AND id = " . $id;
  1134. $res_update_max_time_allowed = Database::query($sql_update_max_time_allowed);
  1135. }
  1136. // Update all the items with the same or a bigger display_order than the current item.
  1137. $sql_update_order = "
  1138. UPDATE " . $tbl_lp_item . "
  1139. SET display_order = display_order + 1
  1140. WHERE
  1141. c_id = ".$course_id." AND
  1142. lp_id = " . $this->get_id() . " AND
  1143. id <> " . $id . " AND
  1144. parent_item_id = " . $parent . " AND
  1145. display_order >= " . $new_order;
  1146. $res_update_next = Database::query($sql_update_order);
  1147. }
  1148. }
  1149. /**
  1150. * Updates an item's prereq in place
  1151. * @param integer Element ID
  1152. * @param string Prerequisite Element ID
  1153. * @param string Prerequisite item type
  1154. * @param string Prerequisite min score
  1155. * @param string Prerequisite max score
  1156. * @return boolean True on success, false on error
  1157. */
  1158. public function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100) {
  1159. $course_id = api_get_course_int_id();
  1160. if ($this->debug > 0) {
  1161. error_log('New LP - In learnpath::edit_item_prereq(' . $id . ',' . $prerequisite_id . ',' . $mastery_score . ',' . $max_score . ')', 0);
  1162. }
  1163. if (empty ($id) or ($id != strval(intval($id))) or empty ($prerequisite_id)) {
  1164. return false;
  1165. }
  1166. $prerequisite_id = $this->escape_string($prerequisite_id);
  1167. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1168. if (!is_numeric($mastery_score) || $mastery_score < 0)
  1169. $mastery_score = 0;
  1170. if (!is_numeric($max_score) || $max_score < 0)
  1171. $max_score = 100;
  1172. if ($mastery_score > $max_score)
  1173. $max_score = $mastery_score;
  1174. if (!is_numeric($prerequisite_id))
  1175. $prerequisite_id = 'NULL';
  1176. $sql_upd = " UPDATE " . $tbl_lp_item . "
  1177. SET prerequisite = " . $prerequisite_id . " WHERE c_id = ".$course_id." AND id = " . $id;
  1178. $res_upd = Database::query($sql_upd);
  1179. if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
  1180. $sql_upd = " UPDATE " . $tbl_lp_item . " SET
  1181. mastery_score = " . $mastery_score .
  1182. //", max_score = " . $max_score . " " . // Max score cannot be changed in the form anyway - see display_item_prerequisites_form().
  1183. " WHERE c_id = ".$course_id." AND ref = '" . $prerequisite_id . "'"; // Will this be enough to ensure unicity?
  1184. $res_upd = Database::query($sql_upd);
  1185. }
  1186. // TODO: Update the item object (can be ignored for now because refreshed).
  1187. return true;
  1188. }
  1189. /**
  1190. * Escapes a string with the available database escape function
  1191. * @param string String to escape
  1192. * @return string String escaped
  1193. */
  1194. public function escape_string($string) {
  1195. //if ($this->debug > 0) { error_log('New LP - In learnpath::escape_string('.$string.')', 0); }
  1196. return Database :: escape_string($string);
  1197. }
  1198. /**
  1199. * Static admin function exporting a learnpath into a zip file
  1200. * @param string Export type (scorm, zip, cd)
  1201. * @param string Course code
  1202. * @param integer Learnpath ID
  1203. * @param string Zip file name
  1204. * @return string Zip file path (or false on error)
  1205. */
  1206. public function export_lp($type, $course, $id, $zipname) {
  1207. $course_id = api_get_course_int_id();
  1208. //if ($this->debug > 0) { error_log('New LP - In learnpath::export_lp()', 0); }
  1209. if (empty($type) || empty($course) || empty($id) || empty($zipname)) {
  1210. return false;
  1211. }
  1212. $url = '';
  1213. switch ($type) {
  1214. case 'scorm':
  1215. break;
  1216. case 'zip':
  1217. break;
  1218. case 'cdrom':
  1219. break;
  1220. }
  1221. return $url;
  1222. }
  1223. /**
  1224. * Gets all the chapters belonging to the same parent as the item/chapter given
  1225. * Can also be called as abstract method
  1226. * @param integer Item ID
  1227. * @return array A list of all the "brother items" (or an empty array on failure)
  1228. */
  1229. public function get_brother_chapters($id) {
  1230. $course_id = api_get_course_int_id();
  1231. if ($this->debug > 0) {
  1232. error_log('New LP - In learnpath::get_brother_chapters()', 0);
  1233. }
  1234. if (empty ($id) OR $id != strval(intval($id))) {
  1235. return array ();
  1236. }
  1237. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1238. $sql_parent = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND id = $id AND item_type='dokeos_chapter'";
  1239. $res_parent = Database::query($sql_parent);
  1240. if (Database :: num_rows($res_parent) > 0) {
  1241. $row_parent = Database :: fetch_array($res_parent);
  1242. $parent = $row_parent['parent_item_id'];
  1243. $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
  1244. $res_bros = Database::query($sql_bros);
  1245. $list = array ();
  1246. while ($row_bro = Database :: fetch_array($res_bros)) {
  1247. $list[] = $row_bro;
  1248. }
  1249. return $list;
  1250. }
  1251. return array ();
  1252. }
  1253. /**
  1254. * Gets all the items belonging to the same parent as the item given
  1255. * Can also be called as abstract method
  1256. * @param integer Item ID
  1257. * @return array A list of all the "brother items" (or an empty array on failure)
  1258. */
  1259. public function get_brother_items($id) {
  1260. $course_id = api_get_course_int_id();
  1261. if ($this->debug > 0) {
  1262. error_log('New LP - In learnpath::get_brother_items(' . $id . ')', 0);
  1263. }
  1264. if (empty ($id) OR $id != strval(intval($id))) {
  1265. return array ();
  1266. }
  1267. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1268. $sql_parent = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = $id";
  1269. $res_parent = Database::query($sql_parent);
  1270. if (Database :: num_rows($res_parent) > 0) {
  1271. $row_parent = Database :: fetch_array($res_parent);
  1272. $parent = $row_parent['parent_item_id'];
  1273. $sql_bros = "SELECT * FROM $lp_item WHERE c_id = ".$course_id." AND parent_item_id = $parent ORDER BY display_order";
  1274. $res_bros = Database::query($sql_bros);
  1275. $list = array ();
  1276. while ($row_bro = Database :: fetch_array($res_bros)) {
  1277. $list[] = $row_bro;
  1278. }
  1279. return $list;
  1280. }
  1281. return array ();
  1282. }
  1283. /**
  1284. * Get the specific prefix index terms of this learning path
  1285. * @return array Array of terms
  1286. */
  1287. public function get_common_index_terms_by_prefix($prefix) {
  1288. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1289. $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
  1290. $prefix_terms = array();
  1291. if (!empty($terms)) {
  1292. foreach ($terms as $term) {
  1293. $prefix_terms[] = $term['value'];
  1294. }
  1295. }
  1296. return $prefix_terms;
  1297. }
  1298. /**
  1299. * Gets the number of items currently completed
  1300. * @return integer The number of items currently completed
  1301. */
  1302. public function get_complete_items_count() {
  1303. if ($this->debug > 0) {
  1304. error_log('New LP - In learnpath::get_complete_items_count()', 0);
  1305. }
  1306. $i = 0;
  1307. foreach ($this->items as $id => $dummy) {
  1308. // Trying failed and browsed considered "progressed" as well.
  1309. if ($this->items[$id]->status_is(array (
  1310. 'completed',
  1311. 'passed',
  1312. 'succeeded',
  1313. 'browsed',
  1314. 'failed'
  1315. )) && $this->items[$id]->get_type() != 'dokeos_chapter' && $this->items[$id]->get_type() != 'dir') {
  1316. $i++;
  1317. }
  1318. }
  1319. return $i;
  1320. }
  1321. /**
  1322. * Gets the current item ID
  1323. * @return integer The current learnpath item id
  1324. */
  1325. public function get_current_item_id() {
  1326. $current = 0;
  1327. if ($this->debug > 0) {
  1328. error_log('New LP - In learnpath::get_current_item_id()', 0);
  1329. }
  1330. if (!empty ($this->current)) {
  1331. $current = $this->current;
  1332. }
  1333. if ($this->debug > 2) {
  1334. error_log('New LP - In learnpath::get_current_item_id() - Returning ' . $current, 0);
  1335. }
  1336. return $current;
  1337. }
  1338. /**
  1339. * Force to get the first learnpath item id
  1340. * @return integer The current learnpath item id
  1341. */
  1342. public function get_first_item_id() {
  1343. $current = 0;
  1344. if (is_array($this->ordered_items)) {
  1345. $current = $this->ordered_items[0];
  1346. }
  1347. return $current;
  1348. }
  1349. /**
  1350. * Gets the total number of items available for viewing in this SCORM
  1351. * @return integer The total number of items
  1352. */
  1353. public function get_total_items_count() {
  1354. if ($this->debug > 0) {
  1355. error_log('New LP - In learnpath::get_total_items_count()', 0);
  1356. }
  1357. return count($this->items);
  1358. }
  1359. /**
  1360. * Gets the total number of items available for viewing in this SCORM but without chapters
  1361. * @return integer The total no-chapters number of items
  1362. */
  1363. public function get_total_items_count_without_chapters() {
  1364. if ($this->debug > 0) {
  1365. error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
  1366. }
  1367. $total = 0;
  1368. foreach ($this->items as $temp => $temp2) {
  1369. if (!in_array($temp2->get_type(), array (
  1370. 'dokeos_chapter',
  1371. 'chapter',
  1372. 'dir'
  1373. )))
  1374. $total++;
  1375. }
  1376. return $total;
  1377. }
  1378. /**
  1379. * Gets the first element URL.
  1380. * @return string URL to load into the viewer
  1381. */
  1382. public function first() {
  1383. if ($this->debug > 0) {
  1384. error_log('New LP - In learnpath::first()', 0);
  1385. }
  1386. // Test if the last_item_seen exists and is not a dir.
  1387. if (count($this->ordered_items) == 0) {
  1388. $this->index = 0;
  1389. }
  1390. 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()) {
  1391. if ($this->debug > 2) {
  1392. 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);
  1393. }
  1394. $index = -1;
  1395. foreach ($this->ordered_items as $myindex => $item_id) {
  1396. if ($item_id == $this->last_item_seen) {
  1397. $index = $myindex;
  1398. break;
  1399. }
  1400. }
  1401. if ($index == -1) {
  1402. // Index hasn't changed, so item not found - panic (this shouldn't happen).
  1403. if ($this->debug > 2) {
  1404. error_log('New LP - Last item (' . $this->last_item_seen . ') was found in items but not in ordered_items, panic!', 0);
  1405. }
  1406. return false;
  1407. } else {
  1408. $this->last = $this->last_item_seen;
  1409. $this->current = $this->last_item_seen;
  1410. $this->index = $index;
  1411. }
  1412. } else {
  1413. if ($this->debug > 2) {
  1414. error_log('New LP - In learnpath::first() - No last item seen', 0);
  1415. }
  1416. $index = 0;
  1417. // Loop through all ordered items and stop at the first item that is
  1418. // not a directory *and* that has not been completed yet.
  1419. 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) {
  1420. $index++;
  1421. }
  1422. $this->last = $this->current;
  1423. // current is
  1424. $this->current = $this->ordered_items[$index];
  1425. $this->index = $index;
  1426. if ($this->debug > 2) {
  1427. error_log('New LP - In learnpath::first() - No last item seen. New last = ' . $this->last . '(' . $this->ordered_items[$index] . ')', 0);
  1428. }
  1429. }
  1430. if ($this->debug > 2) {
  1431. error_log('New LP - In learnpath::first() - First item is ' . $this->get_current_item_id());
  1432. }
  1433. }
  1434. /**
  1435. * Gets the information about an item in a format usable as JavaScript to update
  1436. * the JS API by just printing this content into the <head> section of the message frame
  1437. * @param integer Item ID
  1438. * @return string
  1439. */
  1440. public function get_js_info($item_id = '') {
  1441. if ($this->debug > 0) {
  1442. error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
  1443. }
  1444. $info = '';
  1445. $item_id = $this->escape_string($item_id);
  1446. if (!empty($item_id) && is_object($this->items[$item_id])) {
  1447. //if item is defined, return values from DB
  1448. $oItem = $this->items[$item_id];
  1449. $info .= '<script language="javascript">';
  1450. $info .= "top.set_score(" . $oItem->get_score() . ");\n";
  1451. $info .= "top.set_max(" . $oItem->get_max() . ");\n";
  1452. $info .= "top.set_min(" . $oItem->get_min() . ");\n";
  1453. $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
  1454. $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
  1455. $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
  1456. $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
  1457. $info .= "top.set_flag_synchronized();";
  1458. $info .= '</script>';
  1459. if ($this->debug > 2) {
  1460. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1461. }
  1462. return $info;
  1463. } else {
  1464. // If item_id is empty, just update to default SCORM data.
  1465. $info .= '<script language="javascript">';
  1466. $info .= "top.set_score(" . learnpathItem :: get_score() . ");\n";
  1467. $info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
  1468. $info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
  1469. $info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
  1470. $info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
  1471. $info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
  1472. $info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
  1473. $info .= "top.set_flag_synchronized();";
  1474. $info .= '</script>';
  1475. if ($this->debug > 2) {
  1476. error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
  1477. }
  1478. return $info;
  1479. }
  1480. }
  1481. /**
  1482. * Gets the js library from the database
  1483. * @return string The name of the javascript library to be used
  1484. */
  1485. public function get_js_lib() {
  1486. $lib = '';
  1487. if (!empty ($this->js_lib)) {
  1488. $lib = $this->js_lib;
  1489. }
  1490. return $lib;
  1491. }
  1492. /**
  1493. * Gets the learnpath database ID
  1494. * @return integer Learnpath ID in the lp table
  1495. */
  1496. public function get_id() {
  1497. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_id()', 0); }
  1498. if (!empty ($this->lp_id)) {
  1499. return $this->lp_id;
  1500. } else {
  1501. return 0;
  1502. }
  1503. }
  1504. /**
  1505. * Gets the last element URL.
  1506. * @return string URL to load into the viewer
  1507. */
  1508. public function get_last() {
  1509. if ($this->debug > 0) {
  1510. error_log('New LP - In learnpath::get_last()', 0);
  1511. }
  1512. $this->index = count($this->ordered_items) - 1;
  1513. return $this->ordered_items[$this->index];
  1514. }
  1515. /**
  1516. * Gets the navigation bar for the learnpath display screen
  1517. * @return string The HTML string to use as a navigation bar
  1518. */
  1519. public function get_navigation_bar() {
  1520. if ($this->debug > 0) {
  1521. error_log('New LP - In learnpath::get_navigation_bar()', 0);
  1522. }
  1523. // TODO: Find a good value for the following variables.
  1524. $file = '';
  1525. $openDir = '';
  1526. $edoceo = '';
  1527. $time = 0;
  1528. $navbar = '';
  1529. $RequestUri = '';
  1530. $mycurrentitemid = $this->get_current_item_id();
  1531. if ($this->mode == 'fullscreen') {
  1532. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1533. ' <tr> ' . "\n" .
  1534. ' <td>' . "\n" .
  1535. ' <div class="buttons">' . "\n" .
  1536. ' <a href="lp_controller.php?action=stats" onClick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="' . get_lang('Reporting') . '"></a>' . "\n" .
  1537. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="' . get_lang('ScormPrevious') . '"></a>' . "\n" .
  1538. ' <a href="" onClick="switch_item(' . $mycurrentitemid . ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="' . get_lang('ScormNext') . '"></a>' . "\n" .
  1539. //' <a href="lp_controller.php?action=mode&mode=embedded" target="_top" title="embedded mode"><img border="0" src="../img/view_choose.gif" title="'.get_lang('ScormExitFullScreen').'"></a>'."\n" .
  1540. //' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
  1541. ' </div>' . "\n" .
  1542. ' </td>' . "\n" .
  1543. ' </tr>' . "\n" .
  1544. '</table>';
  1545. } else {
  1546. $navbar = '<table cellpadding="0" cellspacing="0" align="left">' . "\n" .
  1547. ' <tr> ' . "\n" .
  1548. ' <td>' . "\n" .
  1549. ' <div class="buttons">' . "\n" .
  1550. ' <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" .
  1551. ' <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" .
  1552. ' <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" .
  1553. // ' <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" .
  1554. ' </div>' . "\n" .
  1555. ' </td>' . "\n" .
  1556. ' </tr>' . "\n" .
  1557. '</table>';
  1558. }
  1559. return $navbar;
  1560. }
  1561. /**
  1562. * Gets the next resource in queue (url).
  1563. * @return string URL to load into the viewer
  1564. */
  1565. public function get_next_index() {
  1566. if ($this->debug > 0) {
  1567. error_log('New LP - In learnpath::get_next_index()', 0);
  1568. }
  1569. // TODO
  1570. $index = $this->index;
  1571. $index++;
  1572. if ($this->debug > 2) {
  1573. error_log('New LP - Now looking at ordered_items[' . ($index) . '] - type is ' . $this->items[$this->ordered_items[$index]]->type, 0);
  1574. }
  1575. 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) {
  1576. $index++;
  1577. if ($index == $this->max_ordered_items){
  1578. if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir' || $this->items[$this->ordered_items[$index]]->get_type() == 'dokeos_chapter') {
  1579. return $this->index;
  1580. } else {
  1581. return $index;
  1582. }
  1583. }
  1584. }
  1585. if (empty ($this->ordered_items[$index])) {
  1586. return $this->index;
  1587. }
  1588. if ($this->debug > 2) {
  1589. error_log('New LP - index is now ' . $index, 0);
  1590. }
  1591. return $index;
  1592. }
  1593. /**
  1594. * Gets item_id for the next element
  1595. * @return integer Next item (DB) ID
  1596. */
  1597. public function get_next_item_id() {
  1598. if ($this->debug > 0) {
  1599. error_log('New LP - In learnpath::get_next_item_id()', 0);
  1600. }
  1601. $new_index = $this->get_next_index();
  1602. if (!empty ($new_index)) {
  1603. if (isset ($this->ordered_items[$new_index])) {
  1604. if ($this->debug > 2) {
  1605. error_log('New LP - In learnpath::get_next_index() - Returning ' . $this->ordered_items[$new_index], 0);
  1606. }
  1607. return $this->ordered_items[$new_index];
  1608. }
  1609. }
  1610. if ($this->debug > 2) {
  1611. error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0);
  1612. }
  1613. return 0;
  1614. }
  1615. /**
  1616. * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
  1617. *
  1618. * Generally, the package provided is in the form of a zip file, so the function
  1619. * has been written to test a zip file. If not a zip, the function will return the
  1620. * default return value: ''
  1621. * @param string the path to the file
  1622. * @param string the original name of the file
  1623. * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
  1624. */
  1625. public function get_package_type($file_path, $file_name) {
  1626. // Get name of the zip file without the extension.
  1627. $file_info = pathinfo($file_name);
  1628. $filename = $file_info['basename']; // Name including extension.
  1629. $extension = $file_info['extension']; // Extension only.
  1630. if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), array (
  1631. 'dll',
  1632. 'exe'
  1633. ))) {
  1634. return 'oogie';
  1635. }
  1636. if (!empty($_POST['woogie']) && !in_array(strtolower($extension), array (
  1637. 'dll',
  1638. 'exe'
  1639. ))) {
  1640. return 'woogie';
  1641. }
  1642. $file_base_name = str_replace('.' . $extension, '', $filename); // Filename without its extension.
  1643. $zipFile = new pclZip($file_path);
  1644. // Check the zip content (real size and file extension).
  1645. $zipContentArray = $zipFile->listContent();
  1646. $package_type = '';
  1647. $at_root = false;
  1648. $manifest = '';
  1649. // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
  1650. if (is_array($zipContentArray) && count($zipContentArray) > 0) {
  1651. foreach ($zipContentArray as $thisContent) {
  1652. if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
  1653. // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
  1654. }
  1655. elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
  1656. $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
  1657. $package_type = 'scorm';
  1658. break; // Exit the foreach loop.
  1659. }
  1660. elseif (preg_match('/aicc\//i', $thisContent['filename'])) {
  1661. // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
  1662. $package_type = 'aicc';
  1663. //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
  1664. } else {
  1665. $package_type = '';
  1666. }
  1667. }
  1668. }
  1669. return $package_type;
  1670. }
  1671. /**
  1672. * Gets the previous resource in queue (url). Also initialises time values for this viewing
  1673. * @return string URL to load into the viewer
  1674. */
  1675. public function get_previous_index() {
  1676. if ($this->debug > 0) {
  1677. error_log('New LP - In learnpath::get_previous_index()', 0);
  1678. }
  1679. $index = $this->index;
  1680. if (isset ($this->ordered_items[$index -1])) {
  1681. $index--;
  1682. 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')) {
  1683. $index--;
  1684. if ($index < 0) {
  1685. return $this->index;
  1686. }
  1687. }
  1688. } else {
  1689. if ($this->debug > 2) {
  1690. error_log('New LP - get_previous_index() - there was no previous index available, reusing ' . $index, 0);
  1691. }
  1692. // There is no previous item.
  1693. }
  1694. return $index;
  1695. }
  1696. /**
  1697. * Gets item_id for the next element
  1698. * @return integer Previous item (DB) ID
  1699. */
  1700. public function get_previous_item_id() {
  1701. if ($this->debug > 0) {
  1702. error_log('New LP - In learnpath::get_previous_item_id()', 0);
  1703. }
  1704. $new_index = $this->get_previous_index();
  1705. return $this->ordered_items[$new_index];
  1706. }
  1707. /**
  1708. * Gets the progress value from the progress_db attribute
  1709. * @return integer Current progress value
  1710. */
  1711. public function get_progress() {
  1712. if ($this->debug > 0) {
  1713. error_log('New LP - In learnpath::get_progress()', 0);
  1714. }
  1715. if (!empty ($this->progress_db)) {
  1716. return $this->progress_db;
  1717. }
  1718. return 0;
  1719. }
  1720. /**
  1721. * Gets the progress value from the progress field in the database (allows use as abstract method)
  1722. * @param integer Learnpath ID
  1723. * @param integer User ID
  1724. * @param string Mode of display ('%','abs' or 'both')
  1725. * @param string Course database name (optional, defaults to '')
  1726. * @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
  1727. * @return integer Current progress value as found in the database
  1728. */
  1729. public function get_db_progress($lp_id, $user_id, $mode = '%', $course_code = '', $sincere = false,$session_id = 0) {
  1730. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); }
  1731. $session_id = intval($session_id);
  1732. $course_info = api_get_course_info($course_code);
  1733. $session_condition = api_get_session_condition($session_id);
  1734. $course_id = $course_info['real_id'];
  1735. $table = Database :: get_course_table(TABLE_LP_VIEW);
  1736. $sql = "SELECT * FROM $table WHERE c_id = ".$course_id." AND lp_id = $lp_id AND user_id = $user_id $session_condition";
  1737. $res = Database::query($sql);
  1738. $view_id = 0;
  1739. if (Database :: num_rows($res) > 0) {
  1740. $row = Database :: fetch_array($res);
  1741. $progress = $row['progress'];
  1742. $view_id = $row['id'];
  1743. } else {
  1744. if ($sincere) {
  1745. return null;
  1746. }
  1747. }
  1748. if (empty ($progress)) {
  1749. $progress = '0';
  1750. }
  1751. if ($mode == '%') {
  1752. return $progress . '%';
  1753. } else {
  1754. // Get the number of items completed and the number of items total.
  1755. $tbl = Database :: get_course_table(TABLE_LP_ITEM);
  1756. $sql = "SELECT count(*) FROM $tbl
  1757. WHERE c_id = $course_id AND c_id = ".$course_id." AND lp_id = " . $lp_id . " AND item_type NOT IN('dokeos_chapter','chapter','dir')";
  1758. $res = Database::query($sql);
  1759. $row = Database :: fetch_array($res);
  1760. $total = $row[0];
  1761. $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1762. $tbl_item = Database :: get_course_table(TABLE_LP_ITEM);
  1763. //$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
  1764. // Trying as also counting browsed and failed items.
  1765. $sql = "SELECT count(distinct(lp_item_id))
  1766. FROM $tbl_item_view as item_view
  1767. INNER JOIN $tbl_item as item
  1768. ON item.id = item_view.lp_item_id
  1769. AND item_type NOT IN('dokeos_chapter','chapter','dir')
  1770. WHERE
  1771. item_view.c_id = $course_id AND
  1772. item.c_id = $course_id AND
  1773. lp_view_id = " . $view_id . " AND
  1774. status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />';
  1775. $res = Database::query($sql);
  1776. $row = Database :: fetch_array($res);
  1777. $completed = $row[0];
  1778. if ($mode == 'abs') {
  1779. return $completed . '/' . $total;
  1780. } elseif ($mode == 'both') {
  1781. if ($progress < ($completed / ($total ? $total : 1))) {
  1782. $progress = number_format(($completed / ($total ? $total : 1)) * 100, 0);
  1783. }
  1784. return $progress . '% (' . $completed . '/' . $total . ')';
  1785. }
  1786. }
  1787. return $progress;
  1788. }
  1789. /**
  1790. * Returns the HTML necessary to print a mediaplayer block inside a page
  1791. * @return string The mediaplayer HTML
  1792. */
  1793. public function get_mediaplayer($autostart='true') {
  1794. $course_id = api_get_course_int_id();
  1795. global $_course;
  1796. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  1797. $tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  1798. // Getting all the information about the item.
  1799. $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 " .
  1800. "WHERE lp.id = '" . $_SESSION['oLP']->current . "' AND
  1801. lp.c_id = $course_id AND
  1802. lp_view.c_id = $course_id";
  1803. $result = Database::query($sql);
  1804. $row = Database::fetch_assoc($result);
  1805. $output = '';
  1806. if (!empty ($row['audio'])) {
  1807. $list = $_SESSION['oLP']->get_toc();
  1808. $type_quiz = false;
  1809. foreach($list as $toc) {
  1810. if ($toc['id'] == $_SESSION['oLP']->current && ($toc['type']=='quiz') ) {
  1811. $type_quiz = true;
  1812. }
  1813. }
  1814. if ($type_quiz) {
  1815. if ($_SESSION['oLP']->prevent_reinit == 1) {
  1816. $row['status'] === 'completed' ? $autostart_audio = 'false' : $autostart_audio = 'true';
  1817. } else {
  1818. $autostart_audio = $autostart;
  1819. }
  1820. } else {
  1821. $autostart_audio = 'true';
  1822. }
  1823. // The mp3 player.
  1824. $output = '<div id="container">';
  1825. $output .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  1826. $output .= '<script type="text/javascript">
  1827. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  1828. s1.addParam("allowscriptaccess","always");
  1829. s1.addParam("flashvars","file=' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=' . $autostart_audio.'");
  1830. s1.write("container");
  1831. </script></div>';
  1832. }
  1833. return $output;
  1834. }
  1835. /**
  1836. * This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability
  1837. * @param int Learnpath id
  1838. * @param int Student id
  1839. * @param string Course code (optional)
  1840. * @return bool True if
  1841. */
  1842. public function is_lp_visible_for_student($lp_id, $student_id, $course = null) {
  1843. $lp_id = (int)$lp_id;
  1844. $course = api_get_course_info($course);
  1845. $tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN);
  1846. // Get current prerequisite
  1847. $sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE c_id = ".$course['real_id']." AND id = $lp_id";
  1848. $rs = Database::query($sql);
  1849. $now = time();
  1850. if (Database::num_rows($rs)>0) {
  1851. $row = Database::fetch_array($rs, 'ASSOC');
  1852. $prerequisite = $row['prerequisite'];
  1853. $is_visible = true;
  1854. $progress = 0;
  1855. if (!empty($prerequisite)) {
  1856. $progress = self::get_db_progress($prerequisite,$student_id,'%', '', false, api_get_session_id());
  1857. $progress = intval($progress);
  1858. if ($progress < 100) {
  1859. $is_visible = false;
  1860. }
  1861. }
  1862. // Also check the time availability of the LP
  1863. if ($is_visible) {
  1864. //Adding visibility reestrinctions
  1865. if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
  1866. if ($now < api_strtotime($row['publicated_on'], 'UTC')) {
  1867. //api_not_allowed();
  1868. $is_visible = false;
  1869. }
  1870. }
  1871. //Blocking empty start times see BT#2800
  1872. global $_custom;
  1873. if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date']) {
  1874. if (empty($row['publicated_on']) || $row['publicated_on'] == '0000-00-00 00:00:00') {
  1875. //api_not_allowed();
  1876. $is_visible = false;
  1877. }
  1878. }
  1879. if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') {
  1880. if ($now > api_strtotime($row['expired_on'], 'UTC')) {
  1881. //api_not_allowed();
  1882. $is_visible = false;
  1883. }
  1884. }
  1885. }
  1886. return $is_visible;
  1887. }
  1888. return false;
  1889. }
  1890. /**
  1891. * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
  1892. * completed so far.
  1893. * @param string Mode in which we want the values
  1894. * @param integer Progress value to display (optional but mandatory if used in abstract context)
  1895. * @param string Text to display near the progress value (optional but mandatory in abstract context)
  1896. * @param boolean true if it comes from a Diplay LP view
  1897. * @return string HTML string containing the progress bar
  1898. */
  1899. public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
  1900. //if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); }
  1901. global $lp_theme_css;
  1902. // Setting up the CSS path of the current style if exists.
  1903. if (!empty ($lp_theme_css)) {
  1904. $css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
  1905. } else {
  1906. $css_path = '../img/';
  1907. }
  1908. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
  1909. if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
  1910. list($percentage, $text_add) = $this->get_progress_bar_text($mode);
  1911. }
  1912. $text = $percentage . $text_add;
  1913. // Default progress bar config
  1914. // times that will be greater or shorter
  1915. $factor = 1.2;
  1916. if ($from_lp)
  1917. $progress_height = '26';
  1918. else
  1919. $progress_height = '16';
  1920. $size = str_replace('%', '', $percentage);
  1921. $output ='<div style="width:135px">' .
  1922. '<img id="progress_img_limit_left" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '">' .
  1923. '<img id="progress_img_full" src="' . $css_path . 'bar_1u.gif" width="' . $size * $factor . 'px" height="' . $progress_height . '" id="full_portion">' .
  1924. '<img id="progress_img_limit_middle" src="' . $css_path . 'bar_1m.gif" width="1" height="' . $progress_height . '">';
  1925. if ($percentage <= 98) {
  1926. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="' . (100 - $size) * $factor . 'px" height="' . $progress_height . '" id="empty_portion">';
  1927. } else {
  1928. $output .= '<img id="progress_img_empty" src="' . $css_path . 'bar_1r.gif" width="0" height="' . $progress_height . '" id="empty_portion">';
  1929. }
  1930. $output .= '<img id="progress_bar_img_limit_right" src="' . $css_path . 'bar_1.gif" width="1" height="' . $progress_height . '"></div>' .
  1931. '<div class="progresstext" id="progress_text">' . $text . '</div>';
  1932. return $output;
  1933. }
  1934. /**
  1935. * Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
  1936. * @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
  1937. * @param integer Additional steps to fake as completed
  1938. * @return list Percentage or number and symbol (% or /xx)
  1939. */
  1940. public function get_progress_bar_text($mode = '', $add = 0) {
  1941. if ($this->debug > 0) {
  1942. error_log('New LP - In learnpath::get_progress_bar_text()', 0);
  1943. }
  1944. if (empty ($mode)) {
  1945. $mode = $this->progress_bar_mode;
  1946. }
  1947. $total_items = $this->get_total_items_count_without_chapters();
  1948. if ($this->debug > 2) {
  1949. error_log('New LP - Total items available in this learnpath: ' . $total_items, 0);
  1950. }
  1951. $i = $this->get_complete_items_count();
  1952. if ($this->debug > 2) {
  1953. error_log('New LP - Items completed so far: ' . $i, 0);
  1954. }
  1955. if ($add != 0) {
  1956. $i += $add;
  1957. if ($this->debug > 2) {
  1958. error_log('New LP - Items completed so far (+modifier): ' . $i, 0);
  1959. }
  1960. }
  1961. $text = '';
  1962. if ($i > $total_items) {
  1963. $i = $total_items;
  1964. }
  1965. if ($mode == '%') {
  1966. if ($total_items > 0) {
  1967. $percentage = ((float) $i / (float) $total_items) * 100;
  1968. } else {
  1969. $percentage = 0;
  1970. }
  1971. $percentage = number_format($percentage, 0);
  1972. $text = '%';
  1973. }
  1974. elseif ($mode == 'abs') {
  1975. $percentage = $i;
  1976. $text = '/' . $total_items;
  1977. }
  1978. return array (
  1979. $percentage,
  1980. $text
  1981. );
  1982. }
  1983. /**
  1984. * Gets the progress bar mode
  1985. * @return string The progress bar mode attribute
  1986. */
  1987. public function get_progress_bar_mode() {
  1988. if ($this->debug > 0) {
  1989. error_log('New LP - In learnpath::get_progress_bar_mode()', 0);
  1990. }
  1991. if (!empty ($this->progress_bar_mode)) {
  1992. return $this->progress_bar_mode;
  1993. } else {
  1994. return '%';
  1995. }
  1996. }
  1997. /**
  1998. * Gets the learnpath proximity (remote or local)
  1999. * @return string Learnpath proximity
  2000. */
  2001. public function get_proximity() {
  2002. if ($this->debug > 0) {
  2003. error_log('New LP - In learnpath::get_proximity()', 0);
  2004. }
  2005. if (!empty ($this->proximity)) {
  2006. return $this->proximity;
  2007. } else {
  2008. return '';
  2009. }
  2010. }
  2011. /**
  2012. * Gets the learnpath theme (remote or local)
  2013. * @return string Learnpath theme
  2014. */
  2015. public function get_theme() {
  2016. if ($this->debug > 0) {
  2017. error_log('New LP - In learnpath::get_theme()', 0);
  2018. }
  2019. if (!empty ($this->theme)) {
  2020. return $this->theme;
  2021. } else {
  2022. return '';
  2023. }
  2024. }
  2025. /**
  2026. * Gets the learnpath session id
  2027. * @return string Learnpath theme
  2028. */
  2029. public function get_lp_session_id() {
  2030. if ($this->debug > 0) {
  2031. error_log('New LP - In learnpath::get_lp_session_id()', 0);
  2032. }
  2033. if (!empty ($this->lp_session_id)) {
  2034. return $this->lp_session_id;
  2035. } else {
  2036. return 0;
  2037. }
  2038. }
  2039. /**
  2040. * Gets the learnpath image
  2041. * @return string Web URL of the LP image
  2042. */
  2043. public function get_preview_image() {
  2044. if ($this->debug > 0) {
  2045. error_log('New LP - In learnpath::get_preview_image()', 0);
  2046. }
  2047. if (!empty ($this->preview_image)) {
  2048. return $this->preview_image;
  2049. } else {
  2050. return '';
  2051. }
  2052. }
  2053. /**
  2054. * Gets the learnpath author
  2055. * @return string LP's author
  2056. */
  2057. public function get_author() {
  2058. if ($this->debug > 0) {
  2059. error_log('New LP - In learnpath::get_author()', 0);
  2060. }
  2061. if (!empty ($this->author)) {
  2062. return $this->author;
  2063. } else {
  2064. return '';
  2065. }
  2066. }
  2067. /**
  2068. * Gets the learnpath author
  2069. * @return string LP's author
  2070. */
  2071. public function get_hide_toc_frame() {
  2072. if ($this->debug > 0) {
  2073. error_log('New LP - In learnpath::get_author()', 0);
  2074. }
  2075. if (!empty ($this->hide_toc_frame)) {
  2076. return $this->hide_toc_frame;
  2077. } else {
  2078. return '';
  2079. }
  2080. }
  2081. /**
  2082. * Generate a new prerequisites string for a given item. If this item was a sco and
  2083. * its prerequisites were strings (instead of IDs), then transform those strings into
  2084. * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
  2085. * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
  2086. * same rule as the scorm_export() method
  2087. * @param integer Item ID
  2088. * @return string Prerequisites string ready for the export as SCORM
  2089. */
  2090. public function get_scorm_prereq_string($item_id) {
  2091. if ($this->debug > 0) {
  2092. error_log('New LP - In learnpath::get_scorm_prereq_string()', 0);
  2093. }
  2094. if (!is_object($this->items[$item_id])) {
  2095. return false;
  2096. }
  2097. $oItem = $this->items[$item_id];
  2098. $prereq = $oItem->get_prereq_string();
  2099. if (empty ($prereq)) {
  2100. return '';
  2101. }
  2102. 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,
  2103. // then simply return it (with the ITEM_ prefix).
  2104. return 'ITEM_' . $prereq;
  2105. } else {
  2106. if (isset ($this->refs_list[$prereq])) {
  2107. // It's a simple string item from which the ID can be found in the refs list,
  2108. // so we can transform it directly to an ID for export.
  2109. return 'ITEM_' . $this->refs_list[$prereq];
  2110. } else {
  2111. // The last case, if it's a complex form, then find all the IDs (SCORM strings)
  2112. // and replace them, one by one, by the internal IDs (chamilo db)
  2113. // TODO: Modify the '*' replacement to replace the multiplier in front of it
  2114. // by a space as well.
  2115. $find = array (
  2116. '&',
  2117. '|',
  2118. '~',
  2119. '=',
  2120. '<>',
  2121. '{',
  2122. '}',
  2123. '*',
  2124. '(',
  2125. ')'
  2126. );
  2127. $replace = array (
  2128. ' ',
  2129. ' ',
  2130. ' ',
  2131. ' ',
  2132. ' ',
  2133. ' ',
  2134. ' ',
  2135. ' ',
  2136. ' ',
  2137. ' '
  2138. );
  2139. $prereq_mod = str_replace($find, $replace, $prereq);
  2140. $ids = split(' ', $prereq_mod);
  2141. foreach ($ids as $id) {
  2142. $id = trim($id);
  2143. if (isset ($this->refs_list[$id])) {
  2144. $prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
  2145. }
  2146. }
  2147. error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
  2148. return $prereq;
  2149. }
  2150. }
  2151. }
  2152. /**
  2153. * Returns the XML DOM document's node
  2154. * @param resource Reference to a list of objects to search for the given ITEM_*
  2155. * @param string The identifier to look for
  2156. * @return mixed The reference to the element found with that identifier. False if not found
  2157. */
  2158. public function get_scorm_xml_node(& $children, $id) {
  2159. for ($i = 0; $i < $children->length; $i++) {
  2160. $item_temp = $children->item($i);
  2161. if ($item_temp->nodeName == 'item') {
  2162. if ($item_temp->getAttribute('identifier') == $id) {
  2163. return $item_temp;
  2164. }
  2165. }
  2166. $subchildren = $item_temp->childNodes;
  2167. if ($subchildren->length > 0) {
  2168. $val = $this->get_scorm_xml_node($subchildren, $id);
  2169. if (is_object($val)) {
  2170. return $val;
  2171. }
  2172. }
  2173. }
  2174. return false;
  2175. }
  2176. /**
  2177. * Returns a usable array of stats related to the current learnpath and user
  2178. * @return array Well-formatted array containing status for the current learnpath
  2179. */
  2180. public function get_stats() {
  2181. if ($this->debug > 0) {
  2182. error_log('New LP - In learnpath::get_stats()', 0);
  2183. }
  2184. // TODO
  2185. }
  2186. /**
  2187. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2188. * the given course (for all learnpaths and all users)
  2189. * @param string Course code
  2190. * @return array Well-formatted array containing status for the course's learnpaths
  2191. */
  2192. public function get_stats_course($course) {
  2193. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_course()', 0); }
  2194. // TODO
  2195. }
  2196. /**
  2197. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2198. * the given course and learnpath (for all users)
  2199. * @param string Course code
  2200. * @param integer Learnpath ID
  2201. * @return array Well-formatted array containing status for the specified learnpath
  2202. */
  2203. public function get_stats_lp($course, $lp) {
  2204. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp()', 0); }
  2205. // TODO
  2206. }
  2207. /**
  2208. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2209. * the given course, learnpath and user.
  2210. * @param string Course code
  2211. * @param integer Learnpath ID
  2212. * @param integer User ID
  2213. * @return array Well-formatted array containing status for the specified learnpath and user
  2214. */
  2215. public function get_stats_lp_user($course, $lp, $user) {
  2216. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_lp_user()', 0); }
  2217. // TODO
  2218. }
  2219. /**
  2220. * Static method. Can be re-implemented by children. Gives an array of statistics for
  2221. * the given course and learnpath (for all users)
  2222. * @param string Course code
  2223. * @param integer User ID
  2224. * @return array Well-formatted array containing status for the user's learnpaths
  2225. */
  2226. public function get_stats_user($course, $user) {
  2227. //if ($this->debug > 0) { error_log('New LP - In learnpath::get_stats_user()', 0); }
  2228. // TODO
  2229. }
  2230. /**
  2231. * Gets the status list for all LP's items
  2232. * @return array Array of [index] => [item ID => current status]
  2233. */
  2234. public function get_items_status_list() {
  2235. if ($this->debug > 0) {
  2236. error_log('New LP - In learnpath::get_items_status_list()', 0);
  2237. }
  2238. $list = array ();
  2239. foreach ($this->ordered_items as $item_id) {
  2240. $list[] = array (
  2241. $item_id => $this->items[$item_id]->get_status()
  2242. );
  2243. }
  2244. return $list;
  2245. }
  2246. /**
  2247. * Return the number of interactions for the given learnpath Item View ID.
  2248. * This method can be used as static.
  2249. * @param integer Item View ID
  2250. * @param integer course id
  2251. * @return integer Number of interactions
  2252. */
  2253. public function get_interactions_count_from_db($lp_iv_id, $course_id) {
  2254. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2255. $lp_iv_id = intval($lp_iv_id);
  2256. $course_id = intval($course_id);
  2257. $sql = "SELECT count(*) FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
  2258. $res = Database::query($sql);
  2259. $res = 0;
  2260. if (Database::num_rows($res)) {
  2261. $row = Database::fetch_array($res);
  2262. $num = $row[0];
  2263. }
  2264. return $num;
  2265. }
  2266. /**
  2267. * Return the interactions 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 Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
  2272. */
  2273. public function get_iv_interactions_array($lp_iv_id = 0) {
  2274. $course_id = api_get_course_int_id();
  2275. $list = array ();
  2276. $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
  2277. $sql = "SELECT * FROM $table WHERE c_id = ".$course_id." AND lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2278. $res = Database::query($sql);
  2279. $num = Database :: num_rows($res);
  2280. if ($num > 0) {
  2281. $list[] = array (
  2282. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2283. 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
  2284. 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
  2285. 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
  2286. 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
  2287. 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
  2288. 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
  2289. 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES)
  2290. );
  2291. while ($row = Database :: fetch_array($res)) {
  2292. $list[] = array (
  2293. 'order_id' => ($row['order_id'] + 1),
  2294. 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
  2295. 'type' => $row['interaction_type'],
  2296. 'time' => $row['completion_time'],
  2297. //'correct_responses' => $row['correct_responses'],
  2298. 'correct_responses' => '', // Hide correct responses from students.
  2299. 'student_response' => $row['student_response'],
  2300. 'result' => $row['result'],
  2301. 'latency' => $row['latency']
  2302. );
  2303. }
  2304. }
  2305. return $list;
  2306. }
  2307. /**
  2308. * Return the number of objectives for the given learnpath Item View ID.
  2309. * This method can be used as static.
  2310. * @param integer Item View ID
  2311. * @return integer Number of objectives
  2312. */
  2313. public function get_objectives_count_from_db($lp_iv_id, $course_id) {
  2314. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2315. $course_id = intval($course_id);
  2316. $lp_iv_id = intval($lp_iv_id);
  2317. $sql = "SELECT count(*) FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
  2318. $res = Database::query($sql);
  2319. $res = 0;
  2320. if (Database::num_rows($res)) {
  2321. $row = Database :: fetch_array($res);
  2322. $num = $row[0];
  2323. }
  2324. return $num;
  2325. }
  2326. /**
  2327. * Return the objectives as an array for the given lp_iv_id.
  2328. * This method can be used as static.
  2329. * @param integer Learnpath Item View ID
  2330. * @return array
  2331. * @todo Translate labels
  2332. */
  2333. public function get_iv_objectives_array($lp_iv_id = 0) {
  2334. $course_id = api_get_course_int_id();
  2335. $list = array();
  2336. $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
  2337. $sql = "SELECT * FROM $table WHERE c_id = ".$course_id." AND lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
  2338. $res = Database::query($sql);
  2339. $num = Database :: num_rows($res);
  2340. if ($num > 0) {
  2341. $list[] = array (
  2342. 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
  2343. 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
  2344. 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
  2345. 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
  2346. 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
  2347. 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES)
  2348. );
  2349. while ($row = Database :: fetch_array($res)) {
  2350. $list[] = array (
  2351. 'order_id' => ($row['order_id'] + 1),
  2352. 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F or stuff like that.
  2353. 'score_raw' => $row['score_raw'],
  2354. 'score_max' => $row['score_max'],
  2355. 'score_min' => $row['score_min'],
  2356. 'status' => $row['status']
  2357. );
  2358. }
  2359. }
  2360. return $list;
  2361. }
  2362. /**
  2363. * Generate and return the table of contents for this learnpath. The (flat) table returned can be
  2364. * used by get_html_toc() to be ready to display
  2365. * @return array TOC as a table with 4 elements per row: title, link, status and level
  2366. */
  2367. public function get_toc() {
  2368. if ($this->debug > 0) {
  2369. error_log('New LP - In learnpath::get_toc()', 0);
  2370. }
  2371. $toc = array ();
  2372. //echo "<pre>".print_r($this->items,true)."</pre>";
  2373. foreach ($this->ordered_items as $item_id) {
  2374. if ($this->debug > 2) {
  2375. error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
  2376. }
  2377. // TODO: Change this link generation and use new function instead.
  2378. $toc[] = array (
  2379. 'id' => $item_id,
  2380. 'title' => $this->items[$item_id]->get_title(),
  2381. //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
  2382. 'status' => $this->items[$item_id]->get_status(),
  2383. 'level' => $this->items[$item_id]->get_level(),
  2384. 'type' => $this->items[$item_id]->get_type(),
  2385. 'description' => $this->items[$item_id]->get_description(),
  2386. 'path' => $this->items[$item_id]->get_path(),
  2387. );
  2388. }
  2389. if ($this->debug > 2) {
  2390. error_log('New LP - In learnpath::get_toc() - TOC array: ' . print_r($toc, true), 0);
  2391. }
  2392. return $toc;
  2393. }
  2394. /**
  2395. * Generate and return the table of contents for this learnpath. The JS
  2396. * table returned is used inside of scorm_api.php
  2397. * @return string A JS array vairiable construction
  2398. */
  2399. public function get_items_details_as_js($varname = 'olms.lms_item_types') {
  2400. if ($this->debug > 0) {
  2401. error_log('New LP - In learnpath::get_items_details_as_js()', 0);
  2402. }
  2403. $toc = $varname.' = new Array();';
  2404. //echo "<pre>".print_r($this->items,true)."</pre>";
  2405. foreach ($this->ordered_items as $item_id) {
  2406. if ($this->debug > 2) {
  2407. error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0);
  2408. }
  2409. $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
  2410. }
  2411. if ($this->debug > 2) {
  2412. error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0);
  2413. }
  2414. return $toc;
  2415. }
  2416. /**
  2417. * Gets the learning path type
  2418. * @param boolean Return the name? If false, return the ID. Default is false.
  2419. * @return mixed Type ID or name, depending on the parameter
  2420. */
  2421. public function get_type($get_name = false) {
  2422. $res = false;
  2423. if ($this->debug > 0) {
  2424. error_log('New LP - In learnpath::get_type()', 0);
  2425. }
  2426. if (!empty ($this->type)) {
  2427. if ($get_name) {
  2428. // Get it from the lp_type table in main db.
  2429. } else {
  2430. $res = $this->type;
  2431. }
  2432. }
  2433. if ($this->debug > 2) {
  2434. error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
  2435. }
  2436. return $res;
  2437. }
  2438. /**
  2439. * Gets the learning path type as static method
  2440. * @param boolean Return the name? If false, return the ID. Default is false.
  2441. * @return mixed Type ID or name, depending on the parameter
  2442. */
  2443. public function get_type_static($lp_id = 0) {
  2444. $course_id = api_get_course_int_id();
  2445. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  2446. $sql = "SELECT lp_type FROM $tbl_lp WHERE c_id = ".$course_id." AND id = '" . $lp_id . "'";
  2447. $res = Database::query($sql);
  2448. if ($res === false) {
  2449. return null;
  2450. }
  2451. if (Database :: num_rows($res) <= 0) {
  2452. return null;
  2453. }
  2454. $row = Database :: fetch_array($res);
  2455. return $row['lp_type'];
  2456. }
  2457. /**
  2458. * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
  2459. * This method can be used as abstract and is recursive
  2460. * @param integer Learnpath ID
  2461. * @param integer Parent ID of the items to look for
  2462. * @return mixed Ordered list of item IDs or false on error
  2463. */
  2464. public function get_flat_ordered_items_list($lp, $parent = 0, $course_id = null) {
  2465. if (empty($course_id)) {
  2466. $course_id = api_get_course_int_id();
  2467. } else {
  2468. $course_id = intval($course_id);
  2469. }
  2470. $list = array();
  2471. if (empty ($lp)) {
  2472. return false;
  2473. }
  2474. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2475. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
  2476. $res = Database::query($sql);
  2477. while ($row = Database :: fetch_array($res)) {
  2478. $sublist = learnpath :: get_flat_ordered_items_list($lp, $row['id'], $course_id);
  2479. $list[] = $row['id'];
  2480. foreach ($sublist as $item) {
  2481. $list[] = $item;
  2482. }
  2483. }
  2484. return $list;
  2485. }
  2486. /**
  2487. * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
  2488. * @return string HTML TOC ready to display
  2489. */
  2490. public function get_html_toc() {
  2491. $course_id = api_get_course_int_id();
  2492. $course_code = api_get_course_id();
  2493. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  2494. $charset = api_get_system_encoding();
  2495. $display_action_links_with_icons = false;
  2496. if ($this->debug > 0) {
  2497. error_log('New LP - In learnpath::get_html_toc()', 0);
  2498. }
  2499. $list = $this->get_toc();
  2500. //echo $this->current;
  2501. //$parent = $this->items[$this->current]->get_parent();
  2502. //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
  2503. $html = '<div id="scorm_title" class="scorm_title"><div class="scorm_title_text">' . Security::remove_XSS($this->get_name()) . '</div></div>';
  2504. // Build, display.
  2505. if ($is_allowed_to_edit) {
  2506. $gradebook = Security :: remove_XSS($_GET['gradebook']);
  2507. if ($this->get_lp_session_id() == api_get_session_id()) {
  2508. $html .= '<div id="actions_lp" class="actions_lp">';
  2509. if ($display_action_links_with_icons) {
  2510. $html .= '<div style = "text-align:center;">';
  2511. $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>";
  2512. $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>";
  2513. $html .= '<span>' . Display :: return_icon('view_remove_na.png', get_lang('Display'),'','32').'</span><br />';
  2514. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2515. $html .= '</div>';
  2516. } else {
  2517. $html .= '<div style = "text-align:center;">';
  2518. $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>";
  2519. $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>";
  2520. $html .= '<span><b>' . get_lang('Display') . '</b></span><br />';
  2521. $html .= '<a href="lp_controller.php?' . api_get_cidreq() . '">'. get_lang('ReturnToLPList') . '</a>';
  2522. $html .= '</div>';
  2523. }
  2524. $html .= '</div>';
  2525. }
  2526. }
  2527. $html .= '<div id="inner_lp_toc" class="inner_lp_toc">';
  2528. require_once 'resourcelinker.inc.php';
  2529. // Temporary variables.
  2530. $mycurrentitemid = $this->get_current_item_id();
  2531. $color_counter = 0;
  2532. $i = 0;
  2533. foreach ($list as $item) {
  2534. if ($this->debug > 2) {
  2535. error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
  2536. }
  2537. // TODO: Complete this.
  2538. $icon_name = array (
  2539. 'not attempted' => '../img/notattempted.gif',
  2540. 'incomplete' => '../img/incomplete.png',
  2541. 'failed' => '../img/delete.png',
  2542. 'completed' => '../img/completed.png',
  2543. 'passed' => '../img/passed.png',
  2544. 'succeeded' => '../img/succeeded.png',
  2545. 'browsed' => '../img/completed.png',
  2546. );
  2547. $style = 'scorm_item';
  2548. $scorm_color_background = 'scorm_item';
  2549. $style_item = 'scorm_item';
  2550. $current = false;
  2551. if ($item['id'] == $this->current) {
  2552. $style = 'scorm_item_highlight';
  2553. $scorm_color_background = 'scorm_item_highlight';
  2554. } else {
  2555. if ($color_counter % 2 == 0) {
  2556. $scorm_color_background = 'scorm_item_1';
  2557. } else {
  2558. $scorm_color_background = 'scorm_item_2';
  2559. }
  2560. if ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2561. $scorm_color_background =' scorm_item_section ';
  2562. }
  2563. }
  2564. if ($scorm_color_background != '') {
  2565. $html .= '<div id="toc_' . $item['id'] . '" class="' . $scorm_color_background . '">';
  2566. }
  2567. // The anchor will let us center the TOC on the currently viewed item &^D
  2568. if ($item['type'] != 'dokeos_module' && $item['type'] != 'dokeos_chapter') {
  2569. $html .= '<a name="atoc_' . $item['id'] . '" />';
  2570. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 1.5) . 'em; padding-right:' . ($item['level'] / 2) . 'em" title="' . $item['description'] . '" >';
  2571. } else {
  2572. $html .= '<div class="' . $style_item . '" style="padding-left: ' . ($item['level'] * 2) . 'em; padding-right:' . ($item['level'] * 1.5) . 'em" title="' . $item['description'] . '" >';
  2573. }
  2574. $title = $item['title'];
  2575. if (empty ($title)) {
  2576. $title = rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']);
  2577. }
  2578. $title = Security::remove_XSS($title);
  2579. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
  2580. //$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>" ;
  2581. $url = $this->get_link('http', $item['id']);
  2582. //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
  2583. //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
  2584. //<img align="absbottom" width="13" height="13" src="../img/lp_document.png">&nbsp;background:#aaa;
  2585. $html .= '<a href="" onClick="switch_item(' .$mycurrentitemid . ',' .$item['id'] . ');' .'return false;" >' . stripslashes($title) . '</a>';
  2586. } elseif ($item['type'] == 'dokeos_module' || $item['type'] == 'dokeos_chapter') {
  2587. $html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'>&nbsp;" . stripslashes($title);
  2588. } elseif ($item['type'] == 'dir') {
  2589. $html .= stripslashes($title);
  2590. }
  2591. $tbl_track_e_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2592. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  2593. $user_id = api_get_user_id();
  2594. $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item
  2595. WHERE c_id = $course_id AND
  2596. path = '" . $item['path'] . "' AND
  2597. exe_user_id = '$user_id' AND
  2598. exe_cours_id = '$course_code' AND
  2599. path = exe_exo_id AND
  2600. status <> 'incomplete'";
  2601. $result = Database::query($sql);
  2602. $count = Database :: num_rows($result);
  2603. if ($item['type'] == 'quiz') {
  2604. if ($item['status'] == 'completed') {
  2605. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2606. }
  2607. } else {
  2608. if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {
  2609. $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
  2610. }
  2611. }
  2612. $html .= "</div>";
  2613. if ($scorm_color_background != '') {
  2614. $html .= '</div>';
  2615. }
  2616. $color_counter++;
  2617. }
  2618. $html .= "</div>";
  2619. return $html;
  2620. }
  2621. /**
  2622. * Gets the learnpath maker name - generally the editor's name
  2623. * @return string Learnpath maker name
  2624. */
  2625. public function get_maker() {
  2626. if ($this->debug > 0) {
  2627. error_log('New LP - In learnpath::get_maker()', 0);
  2628. }
  2629. if (!empty ($this->maker)) {
  2630. return $this->maker;
  2631. } else {
  2632. return '';
  2633. }
  2634. }
  2635. /**
  2636. * Gets the user-friendly message stored in $this->message
  2637. * @return string Message
  2638. */
  2639. public function get_message() {
  2640. if ($this->debug > 0) {
  2641. error_log('New LP - In learnpath::get_message()', 0);
  2642. }
  2643. return $this->message;
  2644. }
  2645. /**
  2646. * Gets the learnpath name/title
  2647. * @return string Learnpath name/title
  2648. */
  2649. public function get_name() {
  2650. if ($this->debug > 0) {
  2651. error_log('New LP - In learnpath::get_name()', 0);
  2652. }
  2653. if (!empty ($this->name)) {
  2654. return $this->name;
  2655. } else {
  2656. return 'N/A';
  2657. }
  2658. }
  2659. /**
  2660. * Gets a link to the resource from the present location, depending on item ID.
  2661. * @param string Type of link expected
  2662. * @param integer Learnpath item ID
  2663. * @return string Link to the lp_item resource
  2664. */
  2665. public function get_link($type = 'http', $item_id = null) {
  2666. $course_id = api_get_course_int_id();
  2667. if ($this->debug > 0) {
  2668. error_log('New LP - In learnpath::get_link(' . $type . ',' . $item_id . ')', 0);
  2669. }
  2670. if (empty($item_id)) {
  2671. if ($this->debug > 2) {
  2672. error_log('New LP - In learnpath::get_link() - no item id given in learnpath::get_link(), using current: ' . $this->get_current_item_id(), 0);
  2673. }
  2674. $item_id = $this->get_current_item_id();
  2675. }
  2676. if (empty ($item_id)) {
  2677. if ($this->debug > 2) {
  2678. error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
  2679. }
  2680. //still empty, this means there was no item_id given and we are not in an object context or
  2681. //the object property is empty, return empty link
  2682. $item_id = $this->first();
  2683. return '';
  2684. }
  2685. $file = '';
  2686. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  2687. $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
  2688. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  2689. $item_id = Database::escape_string($item_id);
  2690. $sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams
  2691. FROM $lp_table l, $lp_item_table li
  2692. WHERE l.c_id = $course_id AND
  2693. li.c_id = $course_id AND
  2694. li.id = $item_id AND
  2695. li.lp_id = l.id";
  2696. if ($this->debug > 2) {
  2697. error_log('New LP - In learnpath::get_link() - selecting item ' . $sel, 0);
  2698. }
  2699. $res = Database::query($sel);
  2700. if (Database :: num_rows($res) > 0) {
  2701. $row = Database :: fetch_array($res);
  2702. $lp_type = $row['ltype'];
  2703. $lp_path = $row['lpath'];
  2704. $lp_item_type = $row['litype'];
  2705. $lp_item_path = $row['lipath'];
  2706. $lp_item_params = $row['liparams'];
  2707. if (empty ($lp_item_params) && strpos($lp_item_path, '?') !== false) {
  2708. list ($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
  2709. }
  2710. //$lp_item_params = '?'.$lp_item_params;
  2711. //add ? if none - left commented to give freedom to scorm implementation
  2712. //if(substr($lp_item_params,0,1)!='?'){
  2713. // $lp_item_params = '?'.$lp_item_params;
  2714. //}
  2715. $sys_course_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path();
  2716. if ($type == 'http') {
  2717. $course_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path(); //web path
  2718. } else {
  2719. $course_path = $sys_course_path; //system path
  2720. }
  2721. // 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.
  2722. if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
  2723. $lp_type = 1;
  2724. }
  2725. // Now go through the specific cases to get the end of the path.
  2726. // @todo Use constants instead of int values.
  2727. switch ($lp_type) {
  2728. case 1 :
  2729. if ($lp_item_type == 'dokeos_chapter') {
  2730. $file = 'lp_content.php?type=dir';
  2731. } else {
  2732. require_once 'resourcelinker.inc.php';
  2733. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2734. if ($lp_item_type == 'link') {
  2735. require_once api_get_path(LIBRARY_PATH).'link.lib.php';
  2736. if (is_youtube_link($file)) {
  2737. $src = get_youtube_video_id($file);
  2738. $file = 'embed.php?type=youtube&src='.$src;
  2739. }
  2740. } else {
  2741. // check how much attempts of a exercise exits in lp
  2742. $lp_item_id = $this->get_current_item_id();
  2743. $lp_view_id = $this->get_view_id();
  2744. $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
  2745. $list = $this->get_toc();
  2746. $type_quiz = false;
  2747. foreach ($list as $toc) {
  2748. if ($toc['id'] == $lp_item_id && ($toc['type'] == 'quiz')) {
  2749. $type_quiz = true;
  2750. }
  2751. }
  2752. if ($type_quiz) {
  2753. $lp_item_id = Database :: escape_string($lp_item_id);
  2754. $lp_view_id = Database :: escape_string($lp_view_id);
  2755. $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'";
  2756. $result = Database::query($sql);
  2757. $row_count = Database :: fetch_row($result);
  2758. $count_item_view = (int) $row_count[0];
  2759. $not_multiple_attempt = 0;
  2760. if ($prevent_reinit === 1 && $count_item_view > 0) {
  2761. $not_multiple_attempt = 1;
  2762. }
  2763. $file .= '&not_multiple_attempt=' . $not_multiple_attempt;
  2764. }
  2765. $tmp_array = explode('/', $file);
  2766. $document_name = $tmp_array[count($tmp_array) - 1];
  2767. if (strpos($document_name, '_DELETED_')) {
  2768. $file = 'blank.php?error=document_deleted';
  2769. }
  2770. }
  2771. }
  2772. break;
  2773. case 2 :
  2774. if ($this->debug > 2) {
  2775. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2776. }
  2777. if ($lp_item_type != 'dir') {
  2778. // Quite complex here:
  2779. // We want to make sure 'http://' (and similar) links can
  2780. // be loaded as is (withouth the Chamilo path in front) but
  2781. // some contents use this form: resource.htm?resource=http://blablabla
  2782. // which means we have to find a protocol at the path's start, otherwise
  2783. // it should not be considered as an external URL.
  2784. //if ($this->prerequisites_match($item_id)) {
  2785. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2786. if ($this->debug > 2) {
  2787. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2788. }
  2789. // Distant url, return as is.
  2790. $file = $lp_item_path;
  2791. } else {
  2792. if ($this->debug > 2) {
  2793. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2794. }
  2795. // Prevent getting untranslatable urls.
  2796. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2797. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2798. // Prepare the path.
  2799. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2800. // TODO: Fix this for urls with protocol header.
  2801. $file = str_replace('//', '/', $file);
  2802. $file = str_replace(':/', '://', $file);
  2803. if (substr($lp_path, -1) == '/') {
  2804. $lp_path = substr($lp_path, 0, -1);
  2805. }
  2806. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $lp_item_path))) {
  2807. // if file not found.
  2808. $decoded = html_entity_decode($lp_item_path);
  2809. list ($decoded) = explode('?', $decoded);
  2810. if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
  2811. require_once 'resourcelinker.inc.php';
  2812. $file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
  2813. if (empty($file)) {
  2814. $file = 'blank.php?error=document_not_found';
  2815. } else {
  2816. $tmp_array = explode('/', $file);
  2817. $document_name = $tmp_array[count($tmp_array) - 1];
  2818. if (strpos($document_name, '_DELETED_')) {
  2819. $file = 'blank.php?error=document_deleted';
  2820. } else {
  2821. $file = 'blank.php?error=document_not_found';
  2822. }
  2823. }
  2824. } else {
  2825. $file = $course_path . '/scorm/' . $lp_path . '/' . $decoded;
  2826. }
  2827. }
  2828. }
  2829. //}else{
  2830. //prerequisites did not match
  2831. //$file = 'blank.php';
  2832. //}
  2833. // We want to use parameters if they were defined in the imsmanifest.
  2834. if ($file != 'blank.php') {
  2835. $file .= (strstr($file, '?') === false ? '?' : '') . $lp_item_params;
  2836. }
  2837. } else {
  2838. $file = 'lp_content.php?type=dir';
  2839. }
  2840. break;
  2841. case 3 :
  2842. if ($this->debug > 2) {
  2843. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Item type: ' . $lp_item_type, 0);
  2844. }
  2845. // Formatting AICC HACP append URL.
  2846. $aicc_append = '?aicc_sid=' . urlencode(session_id()) . '&aicc_url=' . urlencode(api_get_path(WEB_CODE_PATH) . 'newscorm/aicc_hacp.php') . '&';
  2847. if ($lp_item_type != 'dir') {
  2848. // Quite complex here:
  2849. // We want to make sure 'http://' (and similar) links can
  2850. // be loaded as is (withouth the Chamilo path in front) but
  2851. // some contents use this form: resource.htm?resource=http://blablabla
  2852. // which means we have to find a protocol at the path's start, otherwise
  2853. // it should not be considered as an external URL.
  2854. if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
  2855. if ($this->debug > 2) {
  2856. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - Found match for protocol in ' . $lp_item_path, 0);
  2857. }
  2858. // Distant url, return as is.
  2859. $file = $lp_item_path;
  2860. // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
  2861. /*
  2862. if (stristr($file,'<servername>') !== false) {
  2863. $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
  2864. }
  2865. */
  2866. if (stripos($file, '<servername>') !== false) {
  2867. //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
  2868. $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
  2869. $file = str_replace('<servername>', $web_course_path . '/scorm/' . $lp_path, $lp_item_path);
  2870. }
  2871. //
  2872. $file .= $aicc_append;
  2873. } else {
  2874. if ($this->debug > 2) {
  2875. error_log('New LP - In learnpath::get_link() ' . __LINE__ . ' - No starting protocol in ' . $lp_item_path, 0);
  2876. }
  2877. // Prevent getting untranslatable urls.
  2878. $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
  2879. $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
  2880. // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
  2881. $file = $course_path . '/scorm/' . $lp_path . '/' . $lp_item_path;
  2882. // TODO: Fix this for urls with protocol header.
  2883. $file = str_replace('//', '/', $file);
  2884. $file = str_replace(':/', '://', $file);
  2885. $file .= $aicc_append;
  2886. }
  2887. } else {
  2888. $file = 'lp_content.php?type=dir';
  2889. }
  2890. break;
  2891. case 4 :
  2892. break;
  2893. default :
  2894. break;
  2895. }
  2896. }
  2897. if ($this->debug > 2) {
  2898. error_log('New LP - In learnpath::get_link() - returning "' . $file . '" from get_link', 0);
  2899. }
  2900. return $file;
  2901. }
  2902. /**
  2903. * Gets the latest usable view or generate a new one
  2904. * @param integer Optional attempt number. If none given, takes the highest from the lp_view table
  2905. * @return integer DB lp_view id
  2906. */
  2907. public function get_view($attempt_num = 0) {
  2908. if ($this->debug > 0) {
  2909. error_log('New LP - In learnpath::get_view()', 0);
  2910. }
  2911. $search = '';
  2912. // Use $attempt_num to enable multi-views management (disabled so far).
  2913. if ($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num) {
  2914. $search = 'AND view_count = ' . $attempt_num;
  2915. }
  2916. // When missing $attempt_num, search for a unique lp_view record for this lp and user.
  2917. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  2918. $course_id = api_get_course_int_id();
  2919. $sql = "SELECT id, view_count FROM $lp_view_table
  2920. WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() ." AND user_id = " . $this->get_user_id() . " " .$search .
  2921. " ORDER BY view_count DESC";
  2922. $res = Database::query($sql);
  2923. if (Database :: num_rows($res) > 0) {
  2924. $row = Database :: fetch_array($res);
  2925. $this->lp_view_id = $row['id'];
  2926. } else {
  2927. // There is no database record, create one.
  2928. $sql = "INSERT INTO $lp_view_table (c_id, lp_id,user_id,view_count) VALUES
  2929. ($course_id, " . $this->get_id() . "," . $this->get_user_id() . ",1)";
  2930. $res = Database::query($sql);
  2931. $id = Database :: insert_id();
  2932. $this->lp_view_id = $id;
  2933. }
  2934. return $this->lp_view_id;
  2935. }
  2936. /**
  2937. * Gets the current view id
  2938. * @return integer View ID (from lp_view)
  2939. */
  2940. public function get_view_id() {
  2941. if ($this->debug > 0) {
  2942. error_log('New LP - In learnpath::get_view_id()', 0);
  2943. }
  2944. if (!empty ($this->lp_view_id)) {
  2945. return $this->lp_view_id;
  2946. } else {
  2947. return 0;
  2948. }
  2949. }
  2950. /**
  2951. * Gets the update queue
  2952. * @return array Array containing IDs of items to be updated by JavaScript
  2953. */
  2954. public function get_update_queue() {
  2955. if ($this->debug > 0) {
  2956. error_log('New LP - In learnpath::get_update_queue()', 0);
  2957. }
  2958. return $this->update_queue;
  2959. }
  2960. /**
  2961. * Gets the user ID
  2962. * @return integer User ID
  2963. */
  2964. public function get_user_id() {
  2965. if ($this->debug > 0) {
  2966. error_log('New LP - In learnpath::get_user_id()', 0);
  2967. }
  2968. if (!empty ($this->user_id)) {
  2969. return $this->user_id;
  2970. } else {
  2971. return false;
  2972. }
  2973. }
  2974. /**
  2975. * Checks if any of the items has an audio element attached
  2976. * @return bool True or false
  2977. */
  2978. public function has_audio() {
  2979. if ($this->debug > 1) {
  2980. error_log('New LP - In learnpath::has_audio()', 0);
  2981. }
  2982. $has = false;
  2983. foreach ($this->items as $i => $item) {
  2984. if (!empty ($this->items[$i]->audio)) {
  2985. $has = true;
  2986. break;
  2987. }
  2988. }
  2989. return $has;
  2990. }
  2991. /**
  2992. * Logs a message into a file
  2993. * @param string Message to log
  2994. * @return boolean True on success, false on error or if msg empty
  2995. */
  2996. public function log($msg) {
  2997. if ($this->debug > 0) {
  2998. error_log('New LP - In learnpath::log()', 0);
  2999. }
  3000. // TODO
  3001. $this->error .= $msg;
  3002. return true;
  3003. }
  3004. /**
  3005. * Moves an item up and down at its level
  3006. * @param integer Item to move up and down
  3007. * @param string Direction 'up' or 'down'
  3008. * @return integer New display order, or false on error
  3009. */
  3010. public function move_item($id, $direction) {
  3011. if ($this->debug > 0) {
  3012. error_log('New LP - In learnpath::move_item(' . $id . ',' . $direction . ')', 0);
  3013. }
  3014. if (empty ($id) or empty ($direction)) {
  3015. return false;
  3016. }
  3017. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  3018. $sql_sel = "SELECT *
  3019. FROM " . $tbl_lp_item . "
  3020. WHERE c_id = ".$course_id." AND id = " . $id;
  3021. $res_sel = Database::query($sql_sel);
  3022. // Check if elem exists.
  3023. if (Database :: num_rows($res_sel) < 1) {
  3024. return false;
  3025. }
  3026. // Gather data.
  3027. $row = Database :: fetch_array($res_sel);
  3028. $previous = $row['previous_item_id'];
  3029. $next = $row['next_item_id'];
  3030. $display = $row['display_order'];
  3031. $parent = $row['parent_item_id'];
  3032. $lp = $row['lp_id'];
  3033. // Update the item (switch with previous/next one).
  3034. switch ($direction) {
  3035. case 'up' :
  3036. if ($this->debug > 2) {
  3037. error_log('Movement up detected', 0);
  3038. }
  3039. if ($display <= 1) { /*do nothing*/
  3040. } else {
  3041. $sql_sel2 = "SELECT * FROM $tbl_lp_item
  3042. WHERE c_id = ".$course_id." AND id = $previous";
  3043. if ($this->debug > 2) {
  3044. error_log('Selecting previous: ' . $sql_sel2, 0);
  3045. }
  3046. $res_sel2 = Database::query($sql_sel2);
  3047. if (Database :: num_rows($res_sel2) < 1) {
  3048. $previous_previous = 0;
  3049. }
  3050. // Gather data.
  3051. $row2 = Database :: fetch_array($res_sel2);
  3052. $previous_previous = $row2['previous_item_id'];
  3053. // Update previous_previous item (switch "next" with current).
  3054. if ($previous_previous != 0) {
  3055. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE c_id = ".$course_id." AND id = $previous_previous";
  3056. if ($this->debug > 2) {
  3057. error_log($sql_upd2, 0);
  3058. }
  3059. $res_upd2 = Database::query($sql_upd2);
  3060. }
  3061. // Update previous item (switch with current).
  3062. if ($previous != 0) {
  3063. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1
  3064. WHERE c_id = ".$course_id." AND id = $previous";
  3065. if ($this->debug > 2) {
  3066. error_log($sql_upd2, 0);
  3067. }
  3068. $res_upd2 = Database::query($sql_upd2);
  3069. }
  3070. // Update current item (switch with previous).
  3071. if ($id != 0) {
  3072. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1
  3073. WHERE c_id = ".$course_id." AND id = $id";
  3074. if ($this->debug > 2) {
  3075. error_log($sql_upd2, 0);
  3076. }
  3077. $res_upd2 = Database::query($sql_upd2);
  3078. }
  3079. // Update next item (new previous item).
  3080. if ($next != 0) {
  3081. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous
  3082. WHERE c_id = ".$course_id." AND id = $next";
  3083. if ($this->debug > 2) {
  3084. error_log($sql_upd2, 0);
  3085. }
  3086. $res_upd2 = Database::query($sql_upd2);
  3087. }
  3088. $display = $display -1;
  3089. }
  3090. break;
  3091. case 'down' :
  3092. if ($this->debug > 2) {
  3093. error_log('Movement down detected', 0);
  3094. }
  3095. if ($next == 0) { /* Do nothing. */
  3096. } else {
  3097. $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND id = $next";
  3098. if ($this->debug > 2) {
  3099. error_log('Selecting next: ' . $sql_sel2, 0);
  3100. }
  3101. $res_sel2 = Database::query($sql_sel2);
  3102. if (Database :: num_rows($res_sel2) < 1) {
  3103. $next_next = 0;
  3104. }
  3105. // Gather data.
  3106. $row2 = Database :: fetch_array($res_sel2);
  3107. $next_next = $row2['next_item_id'];
  3108. // Update previous item (switch with current).
  3109. if ($previous != 0) {
  3110. $sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next
  3111. WHERE c_id = ".$course_id." AND id = $previous";
  3112. $res_upd2 = Database::query($sql_upd2);
  3113. }
  3114. // Update current item (switch with previous).
  3115. if ($id != 0) {
  3116. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1
  3117. WHERE c_id = ".$course_id." AND id = $id";
  3118. $res_upd2 = Database::query($sql_upd2);
  3119. }
  3120. // Update next item (new previous item).
  3121. if ($next != 0) {
  3122. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1
  3123. WHERE c_id = ".$course_id." AND id = $next";
  3124. $res_upd2 = Database::query($sql_upd2);
  3125. }
  3126. // Update next_next item (switch "previous" with current).
  3127. if ($next_next != 0) {
  3128. $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id
  3129. WHERE c_id = ".$course_id." AND id = $next_next";
  3130. $res_upd2 = Database::query($sql_upd2);
  3131. }
  3132. $display = $display +1;
  3133. }
  3134. break;
  3135. default :
  3136. return false;
  3137. }
  3138. return $display;
  3139. }
  3140. /**
  3141. * Move a learnpath up (display_order)
  3142. * @param integer Learnpath ID
  3143. */
  3144. public function move_up($lp_id) {
  3145. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3146. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." ORDER BY display_order";
  3147. $res = Database::query($sql);
  3148. if ($res === false)
  3149. return false;
  3150. $lps = array ();
  3151. $lp_order = array ();
  3152. $num = Database :: num_rows($res);
  3153. // First check the order is correct, globally (might be wrong because
  3154. // of versions < 1.8.4)
  3155. if ($num > 0) {
  3156. $i = 1;
  3157. while ($row = Database :: fetch_array($res)) {
  3158. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3159. $need_fix = true;
  3160. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = " . $row['id'];
  3161. $res_u = Database::query($sql_u);
  3162. }
  3163. $row['display_order'] = $i;
  3164. $lps[$row['id']] = $row;
  3165. $lp_order[$i] = $row['id'];
  3166. $i++;
  3167. }
  3168. }
  3169. if ($num > 1) { // If there's only one element, no need to sort.
  3170. $order = $lps[$lp_id]['display_order'];
  3171. if ($order > 1) { // If it's the first element, no need to move up.
  3172. $sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE c_id = ".$course_id." AND id = " . $lp_order[$order - 1];
  3173. $res_u1 = Database::query($sql_u1);
  3174. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order - 1) . " WHERE c_id = ".$course_id." AND id = " . $lp_id;
  3175. $res_u2 = Database::query($sql_u2);
  3176. }
  3177. }
  3178. }
  3179. /**
  3180. * Move a learnpath down (display_order)
  3181. * @param integer Learnpath ID
  3182. */
  3183. public function move_down($lp_id) {
  3184. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3185. $sql = "SELECT * FROM $lp_table ORDER BY display_order";
  3186. $res = Database::query($sql);
  3187. if ($res === false)
  3188. return false;
  3189. $lps = array ();
  3190. $lp_order = array ();
  3191. $num = Database :: num_rows($res);
  3192. $max = 0;
  3193. // First check the order is correct, globally (might be wrong because
  3194. // of versions < 1.8.4).
  3195. if ($num > 0) {
  3196. $i = 1;
  3197. while ($row = Database :: fetch_array($res)) {
  3198. $max = $i;
  3199. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  3200. $need_fix = true;
  3201. $sql_u = "UPDATE $lp_table SET display_order = $i
  3202. WHERE c_id = ".$course_id." AND id = " . $row['id'];
  3203. $res_u = Database::query($sql_u);
  3204. }
  3205. $row['display_order'] = $i;
  3206. $lps[$row['id']] = $row;
  3207. $lp_order[$i] = $row['id'];
  3208. $i++;
  3209. }
  3210. }
  3211. if ($num > 1) { // If there's only one element, no need to sort.
  3212. $order = $lps[$lp_id]['display_order'];
  3213. if ($order < $max) { // If it's the first element, no need to move up.
  3214. $sql_u1 = "UPDATE $lp_table SET display_order = $order
  3215. WHERE c_id = ".$course_id." AND id = " . $lp_order[$order + 1];
  3216. $res_u1 = Database::query($sql_u1);
  3217. $sql_u2 = "UPDATE $lp_table SET display_order = " . ($order + 1) . "
  3218. WHERE c_id = ".$course_id." AND id = " . $lp_id;
  3219. $res_u2 = Database::query($sql_u2);
  3220. }
  3221. }
  3222. }
  3223. /**
  3224. * Updates learnpath attributes to point to the next element
  3225. * The last part is similar to set_current_item but processing the other way around
  3226. */
  3227. public function next() {
  3228. if ($this->debug > 0) {
  3229. error_log('New LP - In learnpath::next()', 0);
  3230. }
  3231. $this->last = $this->get_current_item_id();
  3232. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3233. $this->autocomplete_parents($this->last);
  3234. $new_index = $this->get_next_index();
  3235. if ($this->debug > 2) {
  3236. error_log('New LP - New index: ' . $new_index, 0);
  3237. }
  3238. $this->index = $new_index;
  3239. if ($this->debug > 2) {
  3240. error_log('New LP - Now having orderedlist[' . $new_index . '] = ' . $this->ordered_items[$new_index], 0);
  3241. }
  3242. $this->current = $this->ordered_items[$new_index];
  3243. if ($this->debug > 2) {
  3244. error_log('New LP - new item id is ' . $this->current . '-' . $this->get_current_item_id(), 0);
  3245. }
  3246. }
  3247. /**
  3248. * Open a resource = initialise all local variables relative to this resource. Depending on the child
  3249. * class, this might be redefined to allow several behaviours depending on the document type.
  3250. * @param integer Resource ID
  3251. * @return boolean True on success, false otherwise
  3252. */
  3253. public function open($id) {
  3254. if ($this->debug > 0) {
  3255. error_log('New LP - In learnpath::open()', 0);
  3256. }
  3257. // TODO:
  3258. // set the current resource attribute to this resource
  3259. // switch on element type (redefine in child class?)
  3260. // set status for this item to "opened"
  3261. // start timer
  3262. // initialise score
  3263. $this->index = 0; //or = the last item seen (see $this->last)
  3264. }
  3265. /**
  3266. * Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
  3267. * and the prerequisite string on error.
  3268. * This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
  3269. * @param integer Optional item ID. If none given, uses the current open item.
  3270. * @return boolean True if prerequisites are matched, false otherwise - Empty string if true returned, prerequisites string otherwise.
  3271. */
  3272. public function prerequisites_match($item = null) {
  3273. if ($this->debug > 0) {
  3274. error_log('New LP - In learnpath::prerequisites_match()', 0);
  3275. }
  3276. if (empty ($item)) {
  3277. $item = $this->current;
  3278. }
  3279. if (is_object($this->items[$item])) {
  3280. $prereq_string = $this->items[$item]->get_prereq_string();
  3281. if (empty ($prereq_string)) {
  3282. return true;
  3283. }
  3284. // Clean spaces.
  3285. $prereq_string = str_replace(' ', '', $prereq_string);
  3286. if ($this->debug > 0) {
  3287. error_log('Found prereq_string: ' . $prereq_string, 0);
  3288. }
  3289. // Now send to the parse_prereq() function that will check this component's prerequisites.
  3290. $result = $this->items[$item]->parse_prereq($prereq_string, $this->items, $this->refs_list, $this->get_user_id());
  3291. if ($result === false) {
  3292. $this->set_error_msg($this->items[$item]->prereq_alert);
  3293. }
  3294. } else {
  3295. $result = true;
  3296. if ($this->debug > 1) {
  3297. error_log('New LP - $this->items[' . $item . '] was not an object', 0);
  3298. }
  3299. }
  3300. if ($this->debug > 1) {
  3301. error_log('New LP - End of prerequisites_match(). Error message is now ' . $this->error, 0);
  3302. }
  3303. return $result;
  3304. }
  3305. /**
  3306. * Updates learnpath attributes to point to the previous element
  3307. * The last part is similar to set_current_item but processing the other way around
  3308. */
  3309. public function previous() {
  3310. if ($this->debug > 0) {
  3311. error_log('New LP - In learnpath::previous()', 0);
  3312. }
  3313. $this->last = $this->get_current_item_id();
  3314. $this->items[$this->last]->save(false, $this->prerequisites_match($this->last));
  3315. $this->autocomplete_parents($this->last);
  3316. $new_index = $this->get_previous_index();
  3317. $this->index = $new_index;
  3318. $this->current = $this->ordered_items[$new_index];
  3319. }
  3320. /**
  3321. * Publishes a learnpath. This basically means show or hide the learnpath
  3322. * to normal users.
  3323. * Can be used as abstract
  3324. * @param integer Learnpath ID
  3325. * @param string New visibility
  3326. */
  3327. public function toggle_visibility($lp_id, $set_visibility = 1) {
  3328. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_visibility()', 0); }
  3329. $action = 'visible';
  3330. if ($set_visibility != 1) {
  3331. $action = 'invisible';
  3332. }
  3333. return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id());
  3334. }
  3335. /**
  3336. * Publishes a learnpath. This basically means show or hide the learnpath
  3337. * on the course homepage
  3338. * Can be used as abstract
  3339. * @param integer Learnpath id
  3340. * @param string New visibility (v/s - visible/invisible)
  3341. */
  3342. public function toggle_publish($lp_id, $set_visibility = 'v') {
  3343. //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
  3344. $course_id = api_get_course_int_id();
  3345. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3346. $sql = "SELECT * FROM $tbl_lp where c_id = ".$course_id." AND id=$lp_id";
  3347. $result = Database::query($sql);
  3348. $row = Database :: fetch_array($result);
  3349. $name = domesticate($row['name']);
  3350. if ($set_visibility == 'i') {
  3351. $s = $name . " " . get_lang('_no_published');
  3352. $dialogBox = $s;
  3353. $v = 0;
  3354. }
  3355. if ($set_visibility == 'v') {
  3356. $s = $name . " " . get_lang('_published');
  3357. $dialogBox = $s;
  3358. $v = 1;
  3359. }
  3360. $session_id = api_get_session_id();
  3361. $session_condition = api_get_session_condition($session_id);
  3362. $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
  3363. $course_id = api_get_course_int_id();
  3364. $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id.'&id_session='.$session_id;
  3365. $sql = "SELECT * FROM $tbl_tool WHERE c_id = ".$course_id." AND name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition";
  3366. $result = Database::query($sql);
  3367. $num = Database :: num_rows($result);
  3368. $row2 = Database :: fetch_array($result);
  3369. //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
  3370. if (($set_visibility == 'i') && ($num > 0)) {
  3371. $sql = "DELETE FROM $tbl_tool WHERE c_id = ".$course_id." AND (name='$name' and image='scormbuilder.gif' and link LIKE '$link%' $session_condition)";
  3372. } elseif (($set_visibility == 'v') && ($num == 0)) {
  3373. $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id) VALUES
  3374. ($course_id, '$name','$link','scormbuilder.gif','$v','0','pastillegris.gif',0, $session_id)";
  3375. } else {
  3376. // Parameter and database incompatible, do nothing.
  3377. }
  3378. $result = Database::query($sql);
  3379. //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
  3380. }
  3381. /**
  3382. * Restart the whole learnpath. Return the URL of the first element.
  3383. * Make sure the results are saved with anoter method. This method should probably be
  3384. * redefined in children classes.
  3385. * To use a similar method statically, use the create_new_attempt() method
  3386. * @return string URL to load in the viewer
  3387. */
  3388. public function restart() {
  3389. if ($this->debug > 0) {
  3390. error_log('New LP - In learnpath::restart()', 0);
  3391. }
  3392. // TODO
  3393. // Call autosave method to save the current progress.
  3394. //$this->index = 0;
  3395. $session_id = api_get_session_id();
  3396. $course_id = api_get_course_int_id();
  3397. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
  3398. $sql = "INSERT INTO $lp_view_table (c_id, lp_id, user_id, view_count, session_id) " .
  3399. "VALUES ($course_id, " . $this->lp_id . "," . $this->get_user_id() . "," . ($this->attempt + 1) . ", $session_id)";
  3400. if ($this->debug > 2) {
  3401. error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
  3402. }
  3403. $res = Database::query($sql);
  3404. if ($view_id = Database :: insert_id($res)) {
  3405. $this->lp_view_id = $view_id;
  3406. $this->attempt = $this->attempt + 1;
  3407. } else {
  3408. $this->error = 'Could not insert into item_view table...';
  3409. return false;
  3410. }
  3411. $this->autocomplete_parents($this->current);
  3412. foreach ($this->items as $index => $dummy) {
  3413. $this->items[$index]->restart();
  3414. $this->items[$index]->set_lp_view($this->lp_view_id);
  3415. }
  3416. $this->first();
  3417. return true;
  3418. }
  3419. /**
  3420. * Saves the current item
  3421. * @return boolean
  3422. */
  3423. public function save_current() {
  3424. if ($this->debug > 0) {
  3425. error_log('New LP - In learnpath::save_current()', 0);
  3426. }
  3427. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3428. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3429. if ($this->debug > 2) {
  3430. error_log('New LP - save_current() saving item ' . $this->current, 0);
  3431. }
  3432. if ($this->debug > 2) {
  3433. error_log('' . print_r($this->items, true), 0);
  3434. }
  3435. if (is_object($this->items[$this->current])) {
  3436. //$res = $this->items[$this->current]->save(false);
  3437. $res = $this->items[$this->current]->save(false, $this->prerequisites_match($this->current));
  3438. $this->autocomplete_parents($this->current);
  3439. $status = $this->items[$this->current]->get_status();
  3440. $this->append_message('new_item_status: ' . $status);
  3441. $this->update_queue[$this->current] = $status;
  3442. return $res;
  3443. }
  3444. return false;
  3445. }
  3446. /**
  3447. * Saves the given item
  3448. * @param integer Item ID. Optional (will take from $_REQUEST if null)
  3449. * @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
  3450. * @return boolean
  3451. */
  3452. public function save_item($item_id = null, $from_outside = true) {
  3453. $course_id = api_get_course_int_id();
  3454. if ($this->debug > 0) {
  3455. error_log('New LP - In learnpath::save_item(' . $item_id . ',' . $from_outside . ')', 0);
  3456. }
  3457. // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
  3458. // on $ordered_items[] but not sure it's always safe to use with $items[]).
  3459. if (empty ($item_id)) {
  3460. $item_id = $this->escape_string($_REQUEST['id']);
  3461. }
  3462. if (empty ($item_id)) {
  3463. $item_id = $this->get_current_item_id();
  3464. }
  3465. if ($this->debug > 2) {
  3466. error_log('New LP - save_current() saving item ' . $item_id, 0);
  3467. }
  3468. if (is_object($this->items[$item_id])) {
  3469. $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id));
  3470. //$res = $this->items[$item_id]->save($from_outside);
  3471. $this->autocomplete_parents($item_id);
  3472. $status = $this->items[$item_id]->get_status();
  3473. $this->append_message('new_item_status: ' . $status);
  3474. $this->update_queue[$item_id] = $status;
  3475. return $res;
  3476. }
  3477. return false;
  3478. }
  3479. /**
  3480. * Saves the last item seen's ID only in case
  3481. */
  3482. public function save_last() {
  3483. $course_id = api_get_course_int_id();
  3484. if ($this->debug > 0) {
  3485. error_log('New LP - In learnpath::save_last()', 0);
  3486. }
  3487. $session_condition = api_get_session_condition(api_get_session_id(), true, false);
  3488. $table = Database :: get_course_table(TABLE_LP_VIEW);
  3489. if (isset ($this->current)) {
  3490. if ($this->debug > 2) {
  3491. error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
  3492. }
  3493. $sql = "UPDATE $table SET last_item = " . Database::escape_string($this->get_current_item_id()). " " .
  3494. "WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND user_id = " . $this->get_user_id().' '.$session_condition;
  3495. if ($this->debug > 2) {
  3496. error_log('New LP - Saving last item seen : ' . $sql, 0);
  3497. }
  3498. $res = Database::query($sql);
  3499. }
  3500. // Save progress.
  3501. list($progress, $text) = $this->get_progress_bar_text('%');
  3502. if ($progress >= 0 && $progress <= 100) {
  3503. $progress = (int) $progress;
  3504. $sql = "UPDATE $table SET progress = $progress " .
  3505. "WHERE c_id = ".$course_id." AND lp_id = " . $this->get_id() . " AND " .
  3506. "user_id = " . $this->get_user_id().' '.$session_condition;
  3507. $res = Database::query($sql); // Ignore errors as some tables might not have the progress field just yet.
  3508. $this->progress_db = $progress;
  3509. }
  3510. }
  3511. /**
  3512. * Sets the current item ID (checks if valid and authorized first)
  3513. * @param integer New item ID. If not given or not authorized, defaults to current
  3514. */
  3515. public function set_current_item($item_id = null) {
  3516. if ($this->debug > 0) {
  3517. error_log('New LP - In learnpath::set_current_item(' . $item_id . ')', 0);
  3518. }
  3519. if (empty ($item_id)) {
  3520. if ($this->debug > 2) {
  3521. error_log('New LP - No new current item given, ignore...', 0);
  3522. }
  3523. // Do nothing.
  3524. } else {
  3525. if ($this->debug > 2) {
  3526. error_log('New LP - New current item given is ' . $item_id . '...', 0);
  3527. }
  3528. if (is_numeric($item_id)) {
  3529. $item_id = $this->escape_string($item_id);
  3530. // TODO: Check in database here.
  3531. $this->last = $this->current;
  3532. $this->current = $item_id;
  3533. // TODO: Update $this->index as well.
  3534. foreach ($this->ordered_items as $index => $item) {
  3535. if ($item == $this->current) {
  3536. $this->index = $index;
  3537. break;
  3538. }
  3539. }
  3540. if ($this->debug > 2) {
  3541. error_log('New LP - set_current_item(' . $item_id . ') done. Index is now : ' . $this->index, 0);
  3542. }
  3543. } else {
  3544. error_log('New LP - set_current_item(' . $item_id . ') failed. Not a numeric value: ', 0);
  3545. }
  3546. }
  3547. }
  3548. /**
  3549. * Sets the encoding
  3550. * @param string New encoding
  3551. * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed.
  3552. */
  3553. public function set_encoding($enc = 'UTF-8') {
  3554. if ($this->debug > 0) {
  3555. error_log('New LP - In learnpath::set_encoding()', 0);
  3556. }
  3557. /* // Deprecated code (Chamilo 1.8.8).
  3558. $enc = strtoupper($enc);
  3559. $encodings = array (
  3560. 'UTF-8',
  3561. 'ISO-8859-1',
  3562. 'ISO-8859-15',
  3563. 'cp1251',
  3564. 'cp1252',
  3565. 'KOI8-R',
  3566. 'BIG5',
  3567. 'GB2312',
  3568. 'Shift_JIS',
  3569. 'EUC-JP',
  3570. ''
  3571. );
  3572. if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it.
  3573. $lp = $this->get_id();
  3574. if ($lp != 0) {
  3575. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3576. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp;
  3577. $res = Database::query($sql);
  3578. return $res;
  3579. }
  3580. }
  3581. return false;
  3582. */
  3583. $enc = api_refine_encoding_id($enc);
  3584. if (empty($enc)) {
  3585. $enc = api_get_system_encoding();
  3586. }
  3587. if (api_is_encoding_supported($enc)) {
  3588. $lp = $this->get_id();
  3589. if ($lp != 0) {
  3590. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3591. $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE c_id = ".$course_id." AND id = " . $lp;
  3592. $res = Database::query($sql);
  3593. return $res;
  3594. }
  3595. }
  3596. return false;
  3597. }
  3598. /**
  3599. * Sets the JS lib setting in the database directly.
  3600. * This is the JavaScript library file this lp needs to load on startup
  3601. * @param string Proximity setting
  3602. * @return boolean True on update success. False otherwise.
  3603. */
  3604. public function set_jslib($lib = '') {
  3605. if ($this->debug > 0) {
  3606. error_log('New LP - In learnpath::set_jslib()', 0);
  3607. }
  3608. $lp = $this->get_id();
  3609. if ($lp != 0) {
  3610. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  3611. $sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE c_id = ".$course_id." AND id = " . $lp;
  3612. $res = Database::query($sql);
  3613. return $res;
  3614. } else {
  3615. return false;
  3616. }
  3617. }
  3618. /**
  3619. * Sets the name of the LP maker (publisher) (and save)
  3620. * @param string Optional string giving the new content_maker of this learnpath
  3621. * @return boolean True
  3622. */
  3623. public function set_maker($name = '') {
  3624. if ($this->debug > 0) {
  3625. error_log('New LP - In learnpath::set_maker()', 0);
  3626. }
  3627. if (empty ($name))
  3628. return false;
  3629. $this->maker = $this->escape_string($name);
  3630. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3631. $lp_id = $this->get_id();
  3632. $sql = "UPDATE $lp_table SET content_maker = '" . $this->maker . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3633. if ($this->debug > 2) {
  3634. error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
  3635. }
  3636. $res = Database::query($sql);
  3637. return true;
  3638. }
  3639. /**
  3640. * Sets the name of the current learnpath (and save)
  3641. * @param string Optional string giving the new name of this learnpath
  3642. * @return boolean True/False
  3643. */
  3644. public function set_name($name = '') {
  3645. if ($this->debug > 0) {
  3646. error_log('New LP - In learnpath::set_name()', 0);
  3647. }
  3648. if (empty ($name))
  3649. return false;
  3650. $this->name = $this->escape_string($name);
  3651. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3652. $lp_id = $this->get_id();
  3653. $sql = "UPDATE $lp_table SET name = '" . $this->name . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3654. if ($this->debug > 2) {
  3655. error_log('New LP - lp updated with new name : ' . $this->name, 0);
  3656. }
  3657. $res = Database::query($sql);
  3658. // If the lp is visible on the homepage, change his name there.
  3659. if (Database::affected_rows()) {
  3660. $table = Database :: get_course_table(TABLE_TOOL_LIST);
  3661. $sql = 'UPDATE ' . $table . ' SET
  3662. name = "' . $this->name . '"
  3663. WHERE c_id = '.$course_id.' AND link = "newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '"';
  3664. Database::query($sql);
  3665. }
  3666. return true;
  3667. }
  3668. /**
  3669. * Set index specified prefix terms for all items in this path
  3670. * @param string Comma-separated list of terms
  3671. * @param char Xapian term prefix
  3672. * @return boolean False on error, true otherwise
  3673. */
  3674. public function set_terms_by_prefix($terms_string, $prefix) {
  3675. if (api_get_setting('search_enabled') !== 'true')
  3676. return false;
  3677. if (!extension_loaded('xapian')) {
  3678. return false;
  3679. }
  3680. $terms_string = trim($terms_string);
  3681. $terms = explode(',', $terms_string);
  3682. array_walk($terms, 'trim_value');
  3683. $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
  3684. // Don't do anything if no change, verify only at DB, not the search engine.
  3685. if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0))
  3686. return false;
  3687. require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
  3688. require_once api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php';
  3689. require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
  3690. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  3691. $items_table = Database :: get_course_table(TABLE_LP_ITEM);
  3692. // TODO: Make query secure agains XSS : use member attr instead of post var.
  3693. $lp_id = intval($_POST['lp_id']);
  3694. $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
  3695. $result = Database::query($sql);
  3696. $di = new DokeosIndexer();
  3697. while ($lp_item = Database :: fetch_array($result)) {
  3698. // Get search_did.
  3699. $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  3700. $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';
  3701. $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
  3702. //echo $sql; echo '<br>';
  3703. $res = Database::query($sql);
  3704. if (Database::num_rows($res) > 0) {
  3705. $se_ref = Database :: fetch_array($res);
  3706. // Compare terms.
  3707. $doc = $di->get_document($se_ref['search_did']);
  3708. $xapian_terms = xapian_get_doc_terms($doc, $prefix);
  3709. $xterms = array ();
  3710. foreach ($xapian_terms as $xapian_term) {
  3711. $xterms[] = substr($xapian_term['name'], 1);
  3712. }
  3713. $dterms = $terms;
  3714. $missing_terms = array_diff($dterms, $xterms);
  3715. $deprecated_terms = array_diff($xterms, $dterms);
  3716. // Save it to search engine.
  3717. foreach ($missing_terms as $term) {
  3718. $doc->add_term($prefix . $term, 1);
  3719. }
  3720. foreach ($deprecated_terms as $term) {
  3721. $doc->remove_term($prefix . $term);
  3722. }
  3723. $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
  3724. $di->getDb()->flush();
  3725. } else {
  3726. //@todo What we should do here?
  3727. }
  3728. }
  3729. return true;
  3730. }
  3731. /**
  3732. * Sets the theme of the LP (local/remote) (and save)
  3733. * @param string Optional string giving the new theme of this learnpath
  3734. * @return bool Returns true if theme name is not empty
  3735. */
  3736. public function set_theme($name = '') {
  3737. if ($this->debug > 0) {
  3738. error_log('New LP - In learnpath::set_theme()', 0);
  3739. }
  3740. $this->theme = $this->escape_string($name);
  3741. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3742. $lp_id = $this->get_id();
  3743. $sql = "UPDATE $lp_table SET theme = '" . $this->theme . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3744. if ($this->debug > 2) {
  3745. error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
  3746. }
  3747. //$res = Database::query($sql);
  3748. $res = Database::query($sql);
  3749. return true;
  3750. }
  3751. /**
  3752. * Sets the image of an LP (and save)
  3753. * @param string Optional string giving the new image of this learnpath
  3754. * @return bool Returns true if theme name is not empty
  3755. */
  3756. public function set_preview_image($name = '') {
  3757. if ($this->debug > 0) {
  3758. error_log('New LP - In learnpath::set_preview_image()', 0);
  3759. }
  3760. $this->preview_image = $this->escape_string($name);
  3761. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3762. $lp_id = $this->get_id();
  3763. $sql = "UPDATE $lp_table SET preview_image = '" . $this->preview_image . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3764. if ($this->debug > 2) {
  3765. error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
  3766. }
  3767. $res = Database::query($sql);
  3768. return true;
  3769. }
  3770. /**
  3771. * Sets the author of a LP (and save)
  3772. * @param string Optional string giving the new author of this learnpath
  3773. * @return bool Returns true if author's name is not empty
  3774. */
  3775. public function set_author($name = '') {
  3776. if ($this->debug > 0) {
  3777. error_log('New LP - In learnpath::set_author()', 0);
  3778. }
  3779. $this->author = $this->escape_string($name);
  3780. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3781. $lp_id = $this->get_id();
  3782. $sql = "UPDATE $lp_table SET author = '" . $this->author . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3783. if ($this->debug > 2) {
  3784. error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
  3785. }
  3786. $res = Database::query($sql);
  3787. return true;
  3788. }
  3789. /**
  3790. * Sets the hide_toc_frame parameter of a LP (and save)
  3791. * @param int 1 if frame is hiddent 0 thenelse
  3792. * @return bool Returns true if author's name is not empty
  3793. */
  3794. public function set_hide_toc_frame($hide) {
  3795. if ($this->debug > 0) {
  3796. error_log('New LP - In learnpath::set_hide_toc_frame()', 0);
  3797. }
  3798. if (intval($hide) == $hide){
  3799. $this->hide_toc_frame = $hide;
  3800. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3801. $lp_id = $this->get_id();
  3802. $sql = "UPDATE $lp_table SET hide_toc_frame = '" . $this->hide_toc_frame . "'
  3803. WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3804. if ($this->debug > 2) {
  3805. error_log('New LP - lp updated with new preview hide_toc_frame : ' . $this->author, 0);
  3806. }
  3807. $res = Database::query($sql);
  3808. return true;
  3809. }
  3810. else {
  3811. return false;
  3812. }
  3813. }
  3814. /**
  3815. * Sets the prerequisite of a LP (and save)
  3816. * @param int integer giving the new prerequisite of this learnpath
  3817. * @return bool returns true if prerequisite is not empty
  3818. */
  3819. public function set_prerequisite($prerequisite) {
  3820. if ($this->debug > 0) {
  3821. error_log('New LP - In learnpath::set_prerequisite()', 0);
  3822. }
  3823. $this->prerequisite = intval($prerequisite);
  3824. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3825. $lp_id = $this->get_id();
  3826. $sql = "UPDATE $lp_table SET prerequisite = '".$this->prerequisite."'
  3827. WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3828. if ($this->debug > 2) {
  3829. error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0);
  3830. }
  3831. $res = Database::query($sql);
  3832. return true;
  3833. }
  3834. /**
  3835. * Sets the location/proximity of the LP (local/remote) (and save)
  3836. * @param string Optional string giving the new location of this learnpath
  3837. * @return boolean True on success / False on error
  3838. */
  3839. public function set_proximity($name = '') {
  3840. if ($this->debug > 0) {
  3841. error_log('New LP - In learnpath::set_proximity()', 0);
  3842. }
  3843. if (empty ($name))
  3844. return false;
  3845. $this->proximity = $this->escape_string($name);
  3846. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3847. $lp_id = $this->get_id();
  3848. $sql = "UPDATE $lp_table SET content_local = '" . $this->proximity . "'
  3849. WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3850. if ($this->debug > 2) {
  3851. error_log('New LP - lp updated with new proximity : ' . $this->proximity, 0);
  3852. }
  3853. $res = Database::query($sql);
  3854. return true;
  3855. }
  3856. /**
  3857. * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
  3858. * @param integer DB ID of the item
  3859. */
  3860. public function set_previous_item($id) {
  3861. if ($this->debug > 0) {
  3862. error_log('New LP - In learnpath::set_previous_item()', 0);
  3863. }
  3864. $this->last = $id;
  3865. }
  3866. /**
  3867. * Sets use_max_score
  3868. * @param string Optional string giving the new location of this learnpath
  3869. * @return boolean True on success / False on error
  3870. */
  3871. public function set_use_max_score($use_max_score = 1) {
  3872. if ($this->debug > 0) {
  3873. error_log('New LP - In learnpath::set_use_max_score()', 0);
  3874. }
  3875. $use_max_score = intval($use_max_score);
  3876. $this->use_max_score = $use_max_score;
  3877. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3878. $lp_id = $this->get_id();
  3879. $sql = "UPDATE $lp_table SET use_max_score = '" . $this->use_max_score . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3880. if ($this->debug > 2) {
  3881. error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
  3882. }
  3883. $res = Database::query($sql);
  3884. return true;
  3885. }
  3886. /**
  3887. * Sets and saves the expired_on date
  3888. * @param string Optional string giving the new author of this learnpath
  3889. * @return bool Returns true if author's name is not empty
  3890. */
  3891. public function set_expired_on($expired_on) {
  3892. if ($this->debug > 0) {
  3893. error_log('New LP - In learnpath::set_expired_on()', 0);
  3894. }
  3895. if (!empty($expired_on)) {
  3896. $this->expired_on = $this->escape_string(api_get_utc_datetime($expired_on));
  3897. } else {
  3898. $this->expired_on = '';
  3899. }
  3900. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3901. $lp_id = $this->get_id();
  3902. $sql = "UPDATE $lp_table SET expired_on = '" . $this->expired_on . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3903. if ($this->debug > 2) {
  3904. error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
  3905. }
  3906. $res = Database::query($sql);
  3907. return true;
  3908. }
  3909. /**
  3910. * Sets and saves the publicated_on date
  3911. * @param string Optional string giving the new author of this learnpath
  3912. * @return bool Returns true if author's name is not empty
  3913. */
  3914. public function set_publicated_on($publicated_on) {
  3915. if ($this->debug > 0) {
  3916. error_log('New LP - In learnpath::set_expired_on()', 0);
  3917. }
  3918. if (!empty($publicated_on)) {
  3919. $this->publicated_on = $this->escape_string(api_get_utc_datetime($publicated_on));
  3920. } else {
  3921. $this->publicated_on = '';
  3922. }
  3923. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3924. $lp_id = $this->get_id();
  3925. $sql = "UPDATE $lp_table SET publicated_on = '" . $this->publicated_on . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3926. if ($this->debug > 2) {
  3927. error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
  3928. }
  3929. $res = Database::query($sql);
  3930. return true;
  3931. }
  3932. /**
  3933. * Sets and saves the expired_on date
  3934. * @param string Optional string giving the new author of this learnpath
  3935. * @return bool Returns true if author's name is not empty
  3936. */
  3937. public function set_modified_on() {
  3938. $course_id = api_get_course_int_id();
  3939. if ($this->debug > 0) {
  3940. error_log('New LP - In learnpath::set_expired_on()', 0);
  3941. }
  3942. $this->modified_on = api_get_utc_datetime();
  3943. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  3944. $lp_id = $this->get_id();
  3945. $sql = "UPDATE $lp_table SET modified_on = '" . $this->modified_on . "' WHERE c_id = ".$course_id." AND id = '$lp_id'";
  3946. if ($this->debug > 2) {
  3947. error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0);
  3948. }
  3949. $res = Database::query($sql);
  3950. return true;
  3951. }
  3952. /**
  3953. * Sets the object's error message
  3954. * @param string Error message. If empty, reinits the error string
  3955. * @return void
  3956. */
  3957. public function set_error_msg($error = '') {
  3958. if ($this->debug > 0) {
  3959. error_log('New LP - In learnpath::set_error_msg()', 0);
  3960. }
  3961. if (empty ($error)) {
  3962. $this->error = '';
  3963. } else {
  3964. $this->error .= $error;
  3965. }
  3966. }
  3967. /**
  3968. * Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
  3969. * @param boolean Whether to allow a new attempt or not
  3970. * @return boolean True
  3971. */
  3972. public function start_current_item($allow_new_attempt = false) {
  3973. if ($this->debug > 0) {
  3974. error_log('New LP - In learnpath::start_current_item()', 0);
  3975. }
  3976. if ($this->current != 0 AND is_object($this->items[$this->current])) {
  3977. $type = $this->get_type();
  3978. $item_type = $this->items[$this->current]->get_type();
  3979. if (($type == 2 && $item_type != 'sco') OR ($type == 3 && $item_type != 'au') OR ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)) {
  3980. $this->items[$this->current]->open($allow_new_attempt);
  3981. $this->autocomplete_parents($this->current);
  3982. $prereq_check = $this->prerequisites_match($this->current);
  3983. $this->items[$this->current]->save(false, $prereq_check);
  3984. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  3985. } else {
  3986. // If sco, then it is supposed to have been updated by some other call.
  3987. }
  3988. if ($item_type == 'sco') {
  3989. $this->items[$this->current]->restart();
  3990. }
  3991. }
  3992. if ($this->debug > 0) {
  3993. error_log('New LP - End of learnpath::start_current_item()', 0);
  3994. }
  3995. return true;
  3996. }
  3997. /**
  3998. * Stops the processing and counters for the old item (as held in $this->last)
  3999. * @return boolean True/False
  4000. */
  4001. public function stop_previous_item() {
  4002. if ($this->debug > 0) {
  4003. error_log('New LP - In learnpath::stop_previous_item()', 0);
  4004. }
  4005. if ($this->last != 0 && $this->last != $this->current && is_object($this->items[$this->last])) {
  4006. if ($this->debug > 2) {
  4007. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' is object', 0);
  4008. }
  4009. switch ($this->get_type()) {
  4010. case '3' :
  4011. if ($this->items[$this->last]->get_type() != 'au') {
  4012. if ($this->debug > 2) {
  4013. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 3 is <> au', 0);
  4014. }
  4015. $this->items[$this->last]->close();
  4016. //$this->autocomplete_parents($this->last);
  4017. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  4018. } else {
  4019. if ($this->debug > 2) {
  4020. error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals', 0);
  4021. }
  4022. }
  4023. case '2' :
  4024. if ($this->items[$this->last]->get_type() != 'sco') {
  4025. if ($this->debug > 2) {
  4026. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 2 is <> sco', 0);
  4027. }
  4028. $this->items[$this->last]->close();
  4029. //$this->autocomplete_parents($this->last);
  4030. //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
  4031. } else {
  4032. if ($this->debug > 2) {
  4033. error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals', 0);
  4034. }
  4035. }
  4036. break;
  4037. case '1' :
  4038. default :
  4039. if ($this->debug > 2) {
  4040. error_log('New LP - In learnpath::stop_previous_item() - ' . $this->last . ' in lp_type 1 is asset', 0);
  4041. }
  4042. $this->items[$this->last]->close();
  4043. break;
  4044. }
  4045. } else {
  4046. if ($this->debug > 2) {
  4047. error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...', 0);
  4048. }
  4049. return false;
  4050. }
  4051. return true;
  4052. }
  4053. /**
  4054. * Updates the default view mode from fullscreen to embedded and inversely
  4055. * @return string The current default view mode ('fullscreen' or 'embedded')
  4056. */
  4057. public function update_default_view_mode() {
  4058. if ($this->debug > 0) {
  4059. error_log('New LP - In learnpath::update_default_view_mode()', 0);
  4060. }
  4061. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4062. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4063. $res = Database::query($sql);
  4064. if (Database :: num_rows($res) > 0) {
  4065. $row = Database :: fetch_array($res);
  4066. $view_mode = $row['default_view_mod'];
  4067. if ($view_mode == 'fullscreen') {
  4068. $view_mode = 'embedded';
  4069. } elseif ($view_mode == 'embedded') {
  4070. $view_mode = 'embedframe';
  4071. } elseif ($view_mode == 'embedframe') {
  4072. $view_mode = 'fullscreen';
  4073. }
  4074. $sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4075. $res = Database::query($sql);
  4076. $this->mode = $view_mode;
  4077. return $view_mode;
  4078. } else {
  4079. if ($this->debug > 2) {
  4080. error_log('New LP - Problem in update_default_view() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4081. }
  4082. }
  4083. return -1;
  4084. }
  4085. /**
  4086. * Updates the default behaviour about auto-commiting SCORM updates
  4087. * @return boolean True if auto-commit has been set to 'on', false otherwise
  4088. */
  4089. public function update_default_scorm_commit() {
  4090. if ($this->debug > 0) {
  4091. error_log('New LP - In learnpath::update_default_scorm_commit()', 0);
  4092. }
  4093. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4094. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4095. $res = Database::query($sql);
  4096. if (Database :: num_rows($res) > 0) {
  4097. $row = Database :: fetch_array($res);
  4098. $force = $row['force_commit'];
  4099. if ($force == 1) {
  4100. $force = 0;
  4101. $force_return = false;
  4102. } elseif ($force == 0) {
  4103. $force = 1;
  4104. $force_return = true;
  4105. }
  4106. $sql = "UPDATE $lp_table SET force_commit = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4107. $res = Database::query($sql);
  4108. $this->force_commit = $force_return;
  4109. return $force_return;
  4110. } else {
  4111. if ($this->debug > 2) {
  4112. error_log('New LP - Problem in update_default_scorm_commit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4113. }
  4114. }
  4115. return -1;
  4116. }
  4117. /**
  4118. * Updates the order of learning paths (goes through all of them by order and fills the gaps)
  4119. * @return bool True on success, false on failure
  4120. */
  4121. public function update_display_order() {
  4122. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4123. $course_id = api_get_course_int_id();
  4124. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." ORDER BY display_order";
  4125. $res = Database::query($sql);
  4126. if ($res === false)
  4127. return false;
  4128. $lps = array ();
  4129. $lp_order = array ();
  4130. $num = Database :: num_rows($res);
  4131. // First check the order is correct, globally (might be wrong because
  4132. // of versions < 1.8.4).
  4133. if ($num > 0) {
  4134. $i = 1;
  4135. while ($row = Database :: fetch_array($res)) {
  4136. if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
  4137. $need_fix = true;
  4138. $sql_u = "UPDATE $lp_table SET display_order = $i WHERE c_id = ".$course_id." AND id = " . $row['id'];
  4139. $res_u = Database::query($sql_u);
  4140. }
  4141. $i++;
  4142. }
  4143. }
  4144. return true;
  4145. }
  4146. /**
  4147. * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
  4148. * @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
  4149. */
  4150. public function update_reinit() {
  4151. if ($this->debug > 0) {
  4152. error_log('New LP - In learnpath::update_reinit()', 0);
  4153. }
  4154. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4155. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4156. $res = Database::query($sql);
  4157. if (Database :: num_rows($res) > 0) {
  4158. $row = Database :: fetch_array($res);
  4159. $force = $row['prevent_reinit'];
  4160. if ($force == 1) {
  4161. $force = 0;
  4162. } elseif ($force == 0) {
  4163. $force = 1;
  4164. }
  4165. $sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4166. $res = Database::query($sql);
  4167. $this->prevent_reinit = $force;
  4168. return $force;
  4169. } else {
  4170. if ($this->debug > 2) {
  4171. error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4172. }
  4173. }
  4174. return -1;
  4175. }
  4176. /**
  4177. * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag
  4178. *
  4179. * @return string 'single', 'multi' or 'seriousgame'
  4180. * @author ndiechburg <noel@cblue.be>
  4181. **/
  4182. public function get_attempt_mode() {
  4183. if (!isset($this->seriousgame_mode)) { //Set default value for seriousgame_mode
  4184. $this->seriousgame_mode=0;
  4185. }
  4186. if (!isset($this->prevent_reinit)) { // Set default value for prevent_reinit
  4187. $this->prevent_reinit =1;
  4188. }
  4189. if ($this->seriousgame_mode == 1 && $this->prevent_reinit == 1) {
  4190. return 'seriousgame';
  4191. }
  4192. if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 1) {
  4193. return 'single';
  4194. }
  4195. if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 0) {
  4196. return 'multiple';
  4197. }
  4198. return 'single';
  4199. }
  4200. /**
  4201. * Register the attempt mode into db thanks to flags prevent_reinit and seriousgame_mode flags
  4202. *
  4203. * @param string 'seriousgame', 'single' or 'multiple'
  4204. * @return boolean
  4205. * @author ndiechburg <noel@cblue.be>
  4206. **/
  4207. public function set_attempt_mode($mode) {
  4208. switch ($mode) {
  4209. case 'seriousgame' :
  4210. $sg_mode = 1;
  4211. $prevent_reinit = 1;
  4212. break;
  4213. case 'single' :
  4214. $sg_mode = 0;
  4215. $prevent_reinit = 1;
  4216. break;
  4217. case 'multiple' :
  4218. $sg_mode = 0;
  4219. $prevent_reinit = 0;
  4220. break;
  4221. default :
  4222. $sg_mode = 0;
  4223. $prevent_reinit = 0;
  4224. break;
  4225. }
  4226. $this->prevent_reinit = $prevent_reinit;
  4227. $this->seriousgame_mode = $sg_mode;
  4228. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4229. $sql = "UPDATE $lp_table SET prevent_reinit = $prevent_reinit , seriousgame_mode = $sg_mode WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4230. $res = Database::query($sql);
  4231. if ($res) {
  4232. return true;
  4233. }
  4234. else {
  4235. return false;
  4236. }
  4237. }
  4238. /**
  4239. * switch between multiple attempt, single attempt or serious_game mode (only for scorm)
  4240. *
  4241. * @return boolean
  4242. * @author ndiechburg <noel@cblue.be>
  4243. **/
  4244. public function switch_attempt_mode()
  4245. {
  4246. if ($this->debug > 0) {
  4247. error_log('New LP - In learnpath::switch_attempt_mode()', 0);
  4248. }
  4249. $mode = $this->get_attempt_mode();
  4250. switch ($mode) {
  4251. case 'single' :
  4252. $next_mode = 'multiple';
  4253. break;
  4254. case 'multiple' :
  4255. $next_mode = 'seriousgame';
  4256. break;
  4257. case 'seriousgame' :
  4258. $next_mode = 'single';
  4259. break;
  4260. default :
  4261. $next_mode = 'single';
  4262. break;
  4263. }
  4264. $this->set_attempt_mode($next_mode);
  4265. }
  4266. /**
  4267. * Swithc the lp in ktm mode. This is a special scorm mode with unique attempt but possibility to do again a completed item.
  4268. *
  4269. * @return boolean true if seriousgame_mode has been set to 1, false otherwise
  4270. * @author ndiechburg <noel@cblue.be>
  4271. **/
  4272. public function set_seriousgame_mode()
  4273. {
  4274. if ($this->debug > 0) {
  4275. error_log('New LP - In learnpath::set_seriousgame_mode()', 0);
  4276. }
  4277. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4278. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4279. $res = Database::query($sql);
  4280. if (Database :: num_rows($res) > 0) {
  4281. $row = Database :: fetch_array($res);
  4282. $force = $row['seriousgame_mode'];
  4283. if ($force == 1) {
  4284. $force = 0;
  4285. } elseif ($force == 0) {
  4286. $force = 1;
  4287. }
  4288. $sql = "UPDATE $lp_table SET seriousgame_mode = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4289. $res = Database::query($sql);
  4290. $this->seriousgame_mode = $force;
  4291. return $force;
  4292. } else {
  4293. if ($this->debug > 2) {
  4294. error_log('New LP - Problem in set_seriousgame_mode() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4295. }
  4296. }
  4297. return -1;
  4298. }
  4299. /**
  4300. * Updates the "scorm_debug" value that shows or hide the debug window
  4301. * @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
  4302. */
  4303. public function update_scorm_debug() {
  4304. if ($this->debug > 0) {
  4305. error_log('New LP - In learnpath::update_scorm_debug()', 0);
  4306. }
  4307. $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
  4308. $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4309. $res = Database::query($sql);
  4310. if (Database :: num_rows($res) > 0) {
  4311. $row = Database :: fetch_array($res);
  4312. $force = $row['debug'];
  4313. if ($force == 1) {
  4314. $force = 0;
  4315. } elseif ($force == 0) {
  4316. $force = 1;
  4317. }
  4318. $sql = "UPDATE $lp_table SET debug = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
  4319. $res = Database::query($sql);
  4320. $this->scorm_debug = $force;
  4321. return $force;
  4322. } else {
  4323. if ($this->debug > 2) {
  4324. error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
  4325. }
  4326. }
  4327. return -1;
  4328. }
  4329. /**
  4330. * Function that makes a call to the function sort_tree_array and create_tree_array
  4331. * @author Kevin Van Den Haute
  4332. * @param array
  4333. */
  4334. public function tree_array($array) {
  4335. if ($this->debug > 1) {
  4336. error_log('New LP - In learnpath::tree_array()', 0);
  4337. }
  4338. $array = $this->sort_tree_array($array);
  4339. $this->create_tree_array($array);
  4340. }
  4341. /**
  4342. * Creates an array with the elements of the learning path tree in it
  4343. *
  4344. * @author Kevin Van Den Haute
  4345. * @param array $array
  4346. * @param int $parent
  4347. * @param int $depth
  4348. * @param array $tmp
  4349. */
  4350. public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = array ()) {
  4351. if ($this->debug > 1) {
  4352. error_log('New LP - In learnpath::create_tree_array())', 0);
  4353. }
  4354. if (is_array($array)) {
  4355. for ($i = 0; $i < count($array); $i++) {
  4356. if ($array[$i]['parent_item_id'] == $parent) {
  4357. if (!in_array($array[$i]['parent_item_id'], $tmp)) {
  4358. $tmp[] = $array[$i]['parent_item_id'];
  4359. $depth++;
  4360. }
  4361. $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
  4362. $audio = isset($array[$i]['audio']) ? $array[$i]['audio'] : null;
  4363. $this->arrMenu[] = array (
  4364. 'id' => $array[$i]['id'],
  4365. 'item_type' => $array[$i]['item_type'],
  4366. 'title' => $array[$i]['title'],
  4367. 'path' => $array[$i]['path'],
  4368. 'description' => $array[$i]['description'],
  4369. 'parent_item_id' => $array[$i]['parent_item_id'],
  4370. 'previous_item_id' => $array[$i]['previous_item_id'],
  4371. 'next_item_id' => $array[$i]['next_item_id'],
  4372. 'min_score' => $array[$i]['min_score'],
  4373. 'max_score' => $array[$i]['max_score'],
  4374. 'mastery_score' => $array[$i]['mastery_score'],
  4375. 'display_order' => $array[$i]['display_order'],
  4376. 'prerequisite' => $preq,
  4377. 'depth' => $depth,
  4378. 'audio' => $audio
  4379. );
  4380. $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
  4381. }
  4382. }
  4383. }
  4384. }
  4385. /**
  4386. * Sorts a multi dimensional array by parent id and display order
  4387. * @author Kevin Van Den Haute
  4388. *
  4389. * @param array $array (array with al the learning path items in it)
  4390. *
  4391. * @return array
  4392. */
  4393. public function sort_tree_array($array) {
  4394. foreach ($array as $key => $row) {
  4395. $parent[$key] = $row['parent_item_id'];
  4396. $position[$key] = $row['display_order'];
  4397. }
  4398. if (count($array) > 0)
  4399. array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
  4400. return $array;
  4401. }
  4402. /**
  4403. * Function that creates a table structure with a learning path his modules, chapters and documents.
  4404. * Also the actions for the modules, chapters and documents are in this table.
  4405. * @author Kevin Van Den Haute
  4406. * @param int $lp_id
  4407. * @return string
  4408. */
  4409. public function overview() {
  4410. $course_id = api_get_course_int_id();
  4411. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  4412. if ($this->debug > 0) {
  4413. error_log('New LP - In learnpath::overview()', 0);
  4414. }
  4415. global $charset, $_course;
  4416. $_SESSION['gradebook'] = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4417. $return = '';
  4418. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4419. $sql = "SELECT * FROM " . $tbl_lp_item . "
  4420. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  4421. $result = Database::query($sql);
  4422. $arrLP = array ();
  4423. while ($row = Database :: fetch_array($result)) {
  4424. $row['title'] = Security :: remove_XSS($row['title']);
  4425. $row['description'] = Security :: remove_XSS($row['description']);
  4426. $arrLP[] = array (
  4427. 'id' => $row['id'],
  4428. 'item_type' => $row['item_type'],
  4429. 'title' => $row['title'],
  4430. 'path' => $row['path'],
  4431. 'description' => $row['description'],
  4432. 'parent_item_id' => $row['parent_item_id'],
  4433. 'previous_item_id' => $row['previous_item_id'],
  4434. 'next_item_id' => $row['next_item_id'],
  4435. 'max_score' => $row['max_score'],
  4436. 'min_score' => $row['min_score'],
  4437. 'mastery_score' => $row['mastery_score'],
  4438. 'prerequisite' => $row['prerequisite'],
  4439. 'display_order' => $row['display_order'],
  4440. 'audio' => $row['audio']
  4441. );
  4442. }
  4443. $this->tree_array($arrLP);
  4444. $arrLP = $this->arrMenu;
  4445. unset ($this->arrMenu);
  4446. $update_audio = isset($_GET['updateaudio']) ? $_GET['updateaudio'] : null;
  4447. if ($is_allowed_to_edit) {
  4448. $token = Security::get_token();
  4449. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4450. $return .= '<div class="actions">';
  4451. $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>';
  4452. if ($update_audio == 'true') {
  4453. $return .='<a href="lp_controller.php?cidReq='.Security::remove_XSS($_GET['cidReq']) .'&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang('BasicOverview').'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'),'','32').'</a>';
  4454. } else {
  4455. $return .= Display :: return_icon('move_learnpath_na.png', get_lang('BasicOverview'),'',32);
  4456. }
  4457. $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>';
  4458. $return .= ' '.Display :: return_icon('i.gif');
  4459. $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') . '">
  4460. '. Display :: return_icon('new_learnigpath_object.png', get_lang('NewStep'),'','32').'</a>';
  4461. $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') . '">
  4462. '. Display :: return_icon('add_learnpath_section.png', get_lang('NewChapter'),'','32').'</a>';
  4463. if ($update_audio == 'true') {
  4464. $return .= Display::url(Display :: return_icon('upload_audio_na.png', get_lang('UpdateAllAudioFragments'),'','32'),'#');
  4465. } else {
  4466. $return .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4467. }
  4468. $return .= '<a href="lp_controller.php?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4469. $return .= '</div>';
  4470. }
  4471. // we need to start a form when we want to update all the mp3 files
  4472. if ($update_audio == 'true' AND count($arrLP) <> 0) {
  4473. $return .= '<form action="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;updateaudio=' . Security :: remove_XSS($_GET['updateaudio']) .'&amp;action=' . Security :: remove_XSS($_GET['action']) . '&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
  4474. //$return .= Display::return_message(get_lang('LeaveEmptyToKeepCurrentFile'), 'warning');
  4475. }
  4476. $return .= '<div id="message"></div>';
  4477. $return_audio = '<table class="data_table">';
  4478. $return_audio .= '<tr>';
  4479. $return_audio .= '<th width="60%">' . get_lang('Title') . '</th>';
  4480. $return_audio .= '<th>' . get_lang('Audio') . '</th>';
  4481. //$return_audio .= '<th>' . get_lang('Actions') . '</th>';
  4482. $return_audio .= '</tr>';
  4483. $elements = array();
  4484. for ($i = 0; $i < count($arrLP); $i++) {
  4485. $title = $arrLP[$i]['title'];
  4486. if (($i % 2) == 0) {
  4487. $oddclass = 'row_odd';
  4488. } else {
  4489. $oddclass = 'row_even';
  4490. }
  4491. $return_audio .= '<tr id ="lp_item_'.$arrLP[$i]['id'] .'" class="' . $oddclass . '">';
  4492. // "lp_item_'.$i.' is important for the drag and drop otherwise the LP will not work
  4493. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4494. /*
  4495. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4496. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />' . $title . '</td>';
  4497. } else {
  4498. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4499. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />' . $title . '</td>';
  4500. } else {
  4501. //$return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;">' . Display::display_icon('folder_document.gif','',array('style'=>'margin-right:3px;')) . $title . '</td>';
  4502. $return .= '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />' . $title . '</td>';
  4503. }
  4504. }*/
  4505. $icon = '';
  4506. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4507. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.png" style="margin-right:3px;" />';
  4508. } else {
  4509. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4510. $icon = '<img align="left" src="../img/lp_' . $icon_name . '.gif" style="margin-right:3px;" />';
  4511. } else {
  4512. $icon = '<img align="left" src="../img/folder_document.gif" style="margin-right:3px;" />';
  4513. }
  4514. }
  4515. // The audio column.
  4516. $return_audio .= '<td align="center">';
  4517. $audio = '';
  4518. if (!$update_audio OR $update_audio <> 'true') {
  4519. if (!empty ($arrLP[$i]['audio'])) {
  4520. $audio .= '<span id="container'.$i.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>';
  4521. $audio .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  4522. $audio .= '<script type="text/javascript">
  4523. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  4524. s1.addParam("allowscriptaccess","always");
  4525. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $arrLP[$i]['audio'] . '");
  4526. s1.write("container' . $i . '");
  4527. </script>';
  4528. } else {
  4529. $audio .= '';
  4530. }
  4531. } else {
  4532. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
  4533. $audio .= '<input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
  4534. if (!empty ($arrLP[$i]['audio'])) {
  4535. $audio .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
  4536. }
  4537. }
  4538. }
  4539. $return_audio .= Display::span($title.$icon).Display::tag('td', $audio, array('style'=>'text-align:right'));
  4540. $return_audio .= '</td>';
  4541. $move_icon = '';
  4542. $edit_icon = '';
  4543. $delete_icon = '';
  4544. if ($is_allowed_to_edit) {
  4545. if (!$update_audio OR $update_audio <> 'true') {
  4546. $move_icon .= '<a class="moved" href="#">';
  4547. $move_icon .= Display::return_icon('move.png', get_lang('Move'), array(), 24);
  4548. $move_icon .= '</a>';
  4549. }
  4550. if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module') {
  4551. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;view=build&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4552. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4553. $edit_icon .= '</a>';
  4554. } else {
  4555. $edit_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=edit_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '&amp;path_item=' . $arrLP[$i]['path'] . '">';
  4556. $edit_icon .= '<img style="margin:1px;" alt="" src="../img/edit.png" title="' . get_lang('_edit_learnpath_module') . '" />';
  4557. $edit_icon .= '</a>';
  4558. }
  4559. $delete_icon .= '<a href="' . api_get_self() . '?cidReq=' . Security :: remove_XSS($_GET['cidReq']) . '&amp;action=delete_item&amp;id=' . $arrLP[$i]['id'] . '&amp;lp_id=' . $this->lp_id . '" onClick="return confirmation(\'' . addslashes($title) . '\');">';
  4560. $delete_icon .= '<img style="margin:1px;" alt="" src="../img/delete.png" title="' . get_lang('_delete_learnpath_module') . '" />';
  4561. $delete_icon .= '</a>';
  4562. }
  4563. if ($update_audio != 'true') {
  4564. $row = $move_icon.Display::span($title.$icon).Display::span($audio.$edit_icon.$delete_icon, array('class'=>'button_actions'));
  4565. } else {
  4566. $row = Display::span($title.$icon).Display::span($audio, array('class'=>'button_actions'));
  4567. }
  4568. $parent_id = $arrLP[$i]['parent_item_id'];
  4569. $default_data[$arrLP[$i]['id']] = $row;
  4570. $default_content[$arrLP[$i]['id']] = $arrLP[$i];
  4571. if (empty($parent_id)) {
  4572. $elements[$arrLP[$i]['id']]['data'] = $row;
  4573. $elements[$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4574. } else {
  4575. $parent_arrays = array();
  4576. if ($arrLP[$i]['depth'] > 1) {
  4577. //Getting list of parents
  4578. for($j = 0; $j < $arrLP[$i]['depth']; $j++) {
  4579. foreach($arrLP as $item) {
  4580. if ($item['id'] == $parent_id) {
  4581. if ($item['parent_item_id'] == 0) {
  4582. $parent_id = $item['id'];
  4583. //$parent_arrays[] = $parent_id;
  4584. break;
  4585. } else {
  4586. $parent_id = $item['parent_item_id'];
  4587. if (empty($parent_arrays)) {
  4588. $parent_arrays[] = intval($item['id']);
  4589. }
  4590. $parent_arrays[] = $parent_id;
  4591. break;
  4592. }
  4593. }
  4594. }
  4595. }
  4596. }
  4597. if (!empty($parent_arrays)) {
  4598. $parent_arrays = array_reverse($parent_arrays);
  4599. $value_to_insert = array();
  4600. $val = '$elements';
  4601. $x = 0;
  4602. foreach($parent_arrays as $item) {
  4603. if ($x != count($parent_arrays) -1) {
  4604. $val .= '["'.$item.'"]["children"]';
  4605. } else {
  4606. $val .= '["'.$item.'"]["children"]';
  4607. }
  4608. $x++;
  4609. }
  4610. $val .= "";
  4611. $generated_array = null;
  4612. $code_str = $val."[".$arrLP[$i]['id']."][\"load_data\"] = '".$arrLP[$i]['id']."' ; ";
  4613. eval($code_str);
  4614. } else {
  4615. $elements[$parent_id]['children'][$arrLP[$i]['id']]['data'] = $row;
  4616. $elements[$parent_id]['children'][$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
  4617. }
  4618. }
  4619. }
  4620. //@todo move this somewhere else
  4621. function print_recursive($elements, $default_data, $default_content) {
  4622. $return = '';
  4623. foreach($elements as $key => $item) {
  4624. if (isset($item['load_data']) || empty($item['data'])) {
  4625. $item['data'] = $default_data[$item['load_data']];
  4626. $item['type'] = $default_content[$item['load_data']]['item_type'];
  4627. }
  4628. $sub_list = '';
  4629. if (isset($item['type']) && $item['type'] == 'dokeos_chapter') {
  4630. $sub_list = Display::tag('li', '', array('class'=>'sub_item empty')); // empty value
  4631. }
  4632. if (empty($item['children'])) {
  4633. $sub_list = Display::tag('ul', $sub_list, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4634. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4635. } else {
  4636. //sections
  4637. if (isset($item['children'])) {
  4638. $data = print_recursive($item['children'], $default_data, $default_content);
  4639. }
  4640. /*foreach($item['children'] as $my_key => $sub_item) {
  4641. $sub_list .= Display::tag('li', $sub_item['data'], array('id'=>$my_key,'class'=>'record item'));
  4642. }*/
  4643. $sub_list = Display::tag('ul', $sub_list.$data, array('id'=>'UL_'.$key, 'class'=>'record container'));
  4644. $return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record container'));
  4645. }
  4646. }
  4647. return $return;
  4648. }
  4649. if ($update_audio != 'true') {
  4650. $return .= '<div style="width:90%;"><ul id="lp_item_list">';
  4651. $return .= print_recursive($elements, $default_data, $default_content);
  4652. $return .='</ul></div>';
  4653. $return .= Display::div(Display::url(get_lang('Save'), '#', array('id'=>'listSubmit', 'class'=>'a_button orange medium')), array('style'=>'float:left; margin-top:15px;width:100%'));
  4654. } else {
  4655. $return .= $return_audio.'</table>';
  4656. }
  4657. /*
  4658. if (count($arrLP) == 0) {
  4659. $return .= '<tr>';
  4660. $return .= '<td colspan="4">' . get_lang('NoItemsInLp') . '</td>';
  4661. $return .= '</tr>';
  4662. }*/
  4663. // We need to close the form when we are updating the mp3 files.
  4664. if ($update_audio == 'true') {
  4665. $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?
  4666. }
  4667. // We need to close the form when we are updating the mp3 files.
  4668. if ($update_audio == 'true' && count($arrLP) != 0) {
  4669. $return .= '</form>';
  4670. }
  4671. return $return;
  4672. }
  4673. /**
  4674. * This function builds the action menu
  4675. * @return void
  4676. */
  4677. public function build_action_menu() {
  4678. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  4679. echo '<div class="actions">';
  4680. echo Display :: return_icon('build_learnpath_na.png', get_lang('Build'),'','32');
  4681. echo '<a href="' . api_get_self().'?'.api_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>';
  4682. echo '<a href="lp_controller.php?'.api_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> ';
  4683. Display :: display_icon('i.gif');
  4684. echo '<a href="'.api_get_self().'?'.api_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>';
  4685. echo '<a href="'.api_get_self().'?'.api_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>';
  4686. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '&amp;updateaudio=true">' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'','32').'</a>';
  4687. echo '<a href="lp_controller.php?'.api_get_cidreq().'&amp;action=edit&amp;lp_id=' . $_SESSION['oLP']->lp_id . '">' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'','32').'</a>';
  4688. echo '</div>';
  4689. }
  4690. /**
  4691. * This functions builds the LP tree based on data from the database.
  4692. * @return string
  4693. * @uses dtree.js :: necessary javascript for building this tree
  4694. */
  4695. public function build_tree() {
  4696. $course_id = api_get_course_int_id();
  4697. $return = "<script type=\"text/javascript\">\n";
  4698. $return .= "\tm = new dTree('m');\n\n";
  4699. $return .= "\tm.config.folderLinks = true;\n";
  4700. $return .= "\tm.config.useCookies = true;\n";
  4701. $return .= "\tm.config.useIcons = true;\n";
  4702. $return .= "\tm.config.useLines = true;\n";
  4703. $return .= "\tm.config.useSelection = true;\n";
  4704. $return .= "\tm.config.useStatustext = false;\n\n";
  4705. $menu = 0;
  4706. $parent = '';
  4707. $return .= "\tm.add(" . $menu . ", -1, '" . addslashes(Security::remove_XSS(($this->name))) . "');\n";
  4708. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4709. $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
  4710. FROM $tbl_lp_item
  4711. WHERE c_id = ".$course_id." AND lp_id = " . Database :: escape_string($this->lp_id);
  4712. $result = Database::query($sql);
  4713. $arrLP = array ();
  4714. while ($row = Database :: fetch_array($result)) {
  4715. $row['title'] = Security :: remove_XSS($row['title']);
  4716. $row['description'] = Security :: remove_XSS($row['description']);
  4717. $arrLP[] = array (
  4718. 'id' => $row['id'],
  4719. 'item_type' => $row['item_type'],
  4720. 'title' => $row['title'],
  4721. 'path' => $row['path'],
  4722. 'description' => $row['description'],
  4723. 'parent_item_id' => $row['parent_item_id'],
  4724. 'previous_item_id' => $row['previous_item_id'],
  4725. 'next_item_id' => $row['next_item_id'],
  4726. 'max_score' => $row['max_score'],
  4727. 'min_score' => $row['min_score'],
  4728. 'mastery_score' => $row['mastery_score'],
  4729. 'display_order' => $row['display_order']
  4730. );
  4731. }
  4732. $this->tree_array($arrLP);
  4733. $arrLP = $this->arrMenu;
  4734. unset ($this->arrMenu);
  4735. $title = '';
  4736. for ($i = 0; $i < count($arrLP); $i++) {
  4737. $title = addslashes($arrLP[$i]['title']);
  4738. $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;
  4739. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  4740. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  4741. $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";
  4742. } else
  4743. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  4744. $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";
  4745. } else {
  4746. $return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/folder_document.gif', '../img/folder_document.gif');\n";
  4747. }
  4748. if ($menu < $arrLP[$i]['id'])
  4749. $menu = $arrLP[$i]['id'];
  4750. }
  4751. $return .= "\n\tdocument.write(m);\n";
  4752. $return .= "\t if(!m.selectedNode) m.s(1);";
  4753. $return .= "</script>\n";
  4754. return $return;
  4755. }
  4756. public function generate_lp_folder($course, $dir) {
  4757. $filepath = '';
  4758. //Creating learning_path folder
  4759. $dir = '/learning_path';
  4760. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
  4761. $folder = null;
  4762. if (!is_dir($filepath.'/'.$dir)) {
  4763. $folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , get_lang('LearningPaths'));
  4764. } else {
  4765. $folder = true;
  4766. }
  4767. $dir = '/learning_path/';
  4768. //Creating LP folder
  4769. if ($folder) {
  4770. //Limits title size
  4771. $title = api_substr(replace_dangerous_char($this->name), 0 , 80);
  4772. $dir = $dir.$title;
  4773. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
  4774. if (!is_dir($filepath.'/'.$dir)) {
  4775. $folder = create_unexisting_directory($course, api_get_user_id(), api_get_session_id(), 0, 0, $filepath, $dir , $this->name);
  4776. } else {
  4777. $folder = true;
  4778. }
  4779. $dir = $dir.'/';
  4780. if ($folder) {
  4781. $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'.$dir;
  4782. }
  4783. }
  4784. $array = array('dir' => $dir, 'filepath' => $filepath);
  4785. return $array;
  4786. }
  4787. /**
  4788. * Create a new document //still needs some finetuning
  4789. * @param array $_course
  4790. * @return string
  4791. */
  4792. public function create_document($_course) {
  4793. $course_id = api_get_course_int_id();
  4794. global $charset;
  4795. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4796. if (strstr($dir, '..'))
  4797. $dir = '/';
  4798. if ($dir[0] == '.')
  4799. $dir = substr($dir, 1);
  4800. if ($dir[0] != '/')
  4801. $dir = '/' . $dir;
  4802. if ($dir[strlen($dir) - 1] != '/')
  4803. $dir .= '/';
  4804. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4805. if (empty($_POST['dir']) && empty($_GET['dir'])) {
  4806. $result = $this->generate_lp_folder($_course, $dir);
  4807. $dir = $result['dir'];
  4808. $filepath = $result['filepath'];
  4809. }
  4810. if (!is_dir($filepath)) {
  4811. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4812. $dir = '/';
  4813. }
  4814. // stripslashes() before calling replace_dangerous_char() because $_POST['title']
  4815. // is already escaped twice when it gets here.
  4816. $title = replace_dangerous_char(stripslashes($_POST['title']));
  4817. $title = disable_dangerous_file($title);
  4818. $filename = $title;
  4819. $content = $_POST['content_lp'];
  4820. $tmp_filename = $filename;
  4821. $i = 0;
  4822. while (file_exists($filepath . $tmp_filename . '.html'))
  4823. $tmp_filename = $filename . '_' . ++ $i;
  4824. $filename = $tmp_filename . '.html';
  4825. $content = stripslashes($content);
  4826. $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH).'courses/', $content);
  4827. // Change the path of mp3 to absolute.
  4828. // The first regexp deals with ../../../ urls.
  4829. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4830. // The second regexp deals with audio/ urls.
  4831. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4832. // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
  4833. $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
  4834. if (!file_exists($filepath . $filename)) {
  4835. if ($fp = @ fopen($filepath . $filename, 'w')) {
  4836. fputs($fp, $content);
  4837. fclose($fp);
  4838. $file_size = filesize($filepath . $filename);
  4839. $save_file_path = $dir.$filename;
  4840. $document_id = add_document($_course, $save_file_path, 'file', $file_size, $tmp_filename);
  4841. if ($document_id) {
  4842. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
  4843. $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : '';
  4844. $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : '';
  4845. if ($new_comment || $new_title) {
  4846. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4847. $ct = '';
  4848. if ($new_comment)
  4849. $ct .= ", comment='" . Database::escape_string($new_comment). "'";
  4850. if ($new_title)
  4851. $ct .= ", title='" . Database :: escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset))."' ";
  4852. $sql_update = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." WHERE c_id = ".$course_id." AND id = " . $document_id;
  4853. Database::query($sql_update);
  4854. }
  4855. }
  4856. return $document_id;
  4857. }
  4858. }
  4859. }
  4860. /**
  4861. * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'
  4862. * @param array $_course array
  4863. * @return void
  4864. */
  4865. public function edit_document($_course) {
  4866. $course_id = api_get_course_int_id();
  4867. global $_configuration;
  4868. $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
  4869. if (strstr($dir, '..'))
  4870. $dir = '/';
  4871. if ($dir[0] == '.')
  4872. $dir = substr($dir, 1);
  4873. if ($dir[0] != '/')
  4874. $dir = '/' . $dir;
  4875. if ($dir[strlen($dir) - 1] != '/')
  4876. $dir .= '/';
  4877. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
  4878. if (!is_dir($filepath)) {
  4879. $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
  4880. $dir = '/';
  4881. }
  4882. $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4883. if (isset($_POST['path']) && !empty($_POST['path'])) {
  4884. $document_id = intval($_POST['path']);
  4885. $sql = "SELECT path FROM " . $table_doc . " WHERE c_id = $course_id AND id = " . $document_id;
  4886. $res = Database::query($sql);
  4887. $row = Database :: fetch_array($res);
  4888. $content = stripslashes($_POST['content_lp']);
  4889. $file = $filepath . $row['path'];
  4890. if ($fp = @ fopen($file, 'w')) {
  4891. $content = text_filter($content);
  4892. $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
  4893. // Change the path of mp3 to absolute.
  4894. // The first regexp deals with ../../../ urls.
  4895. $content = preg_replace("|(flashvars=\"file=)(\.+/)+|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
  4896. // The second regexp deals with audio/ urls.
  4897. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
  4898. fputs($fp, $content);
  4899. fclose($fp);
  4900. $sql_update = "UPDATE " . $table_doc ." SET title='".Database::escape_string($_POST['title'])."' WHERE c_id = ".$course_id." AND id = " . $document_id;
  4901. Database::query($sql_update);
  4902. }
  4903. }
  4904. }
  4905. /**
  4906. * Displays the selected item, with a panel for manipulating the item
  4907. * @param int $item_id
  4908. * @param string $msg
  4909. * @return string
  4910. */
  4911. public function display_item($item_id, $iframe = true, $msg = '') {
  4912. $course_id = api_get_course_int_id();
  4913. global $_course; // It will disappear.
  4914. $return = '';
  4915. if (is_numeric($item_id)) {
  4916. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4917. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4918. $sql = "SELECT lp.* FROM " . $tbl_lp_item . " as lp
  4919. WHERE c_id = ".$course_id." AND lp.id = " . Database :: escape_string($item_id);
  4920. $result = Database::query($sql);
  4921. while ($row = Database :: fetch_array($result)) {
  4922. $_SESSION['parent_item_id'] = ($row['item_type'] == 'dokeos_chapter' || $row['item_type'] == 'dokeos_module' || $row['item_type'] == 'dir') ? $item_id : 0;
  4923. // Prevents wrong parent selection for document, see Bug#1251.
  4924. if ($row['item_type'] != 'dokeos_chapter' || $row['item_type'] != 'dokeos_module') {
  4925. $_SESSION['parent_item_id'] = $row['parent_item_id'];
  4926. }
  4927. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4928. $return .= '<div style="padding:10px;">';
  4929. if ($msg != '')
  4930. $return .= $msg;
  4931. $return .= '<p class="lp_title">' . $row['title'] . '</p>';
  4932. //$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
  4933. //$return .= '<hr />';
  4934. switch ($row['item_type']) {
  4935. case TOOL_QUIZ:
  4936. if (!empty($row['path'])) {
  4937. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  4938. $exercise = new Exercise();
  4939. $exercise->read($row['path']);
  4940. // $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exercise->id.'&'.api_get_cidReq().'&id_session='.api_get_session_id();
  4941. $return .=$exercise->description.'<br />';
  4942. //$return .=Display::url($exercise_url, $exercise_url).'<br />';*/
  4943. }
  4944. break;
  4945. case TOOL_DOCUMENT:
  4946. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  4947. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($row['path']);
  4948. $result = Database::query($sql_doc);
  4949. $path_file = Database :: result($result, 0, 0);
  4950. $path_parts = pathinfo($path_file);
  4951. // TODO: Correct the following naive comparisons, also, htm extension is missing.
  4952. if (in_array($path_parts['extension'], array (
  4953. 'html',
  4954. 'txt',
  4955. 'png',
  4956. 'jpg',
  4957. 'JPG',
  4958. 'jpeg',
  4959. 'JPEG',
  4960. 'gif',
  4961. 'swf'
  4962. ))) {
  4963. $return .= $this->display_document($row['path'], true, true);
  4964. }
  4965. break;
  4966. }
  4967. $return .= '</div>';
  4968. }
  4969. }
  4970. return $return;
  4971. }
  4972. /**
  4973. * Shows the needed forms for editing a specific item
  4974. * @param int $item_id
  4975. * @return string
  4976. */
  4977. public function display_edit_item($item_id) {
  4978. global $_course; // It will disappear.
  4979. $course_id = api_get_course_int_id();
  4980. $return = '';
  4981. if (is_numeric($item_id)) {
  4982. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  4983. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($item_id);
  4984. $res = Database::query($sql);
  4985. $row = Database::fetch_array($res);
  4986. switch ($row['item_type']) {
  4987. case 'dokeos_chapter' :
  4988. case 'dir' :
  4989. case 'asset' :
  4990. case 'sco' :
  4991. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  4992. $return .= $this->display_manipulate($item_id, $row['item_type']);
  4993. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', 'edit', $item_id, $row);
  4994. } else {
  4995. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentChapter') . ' :', $row);
  4996. }
  4997. break;
  4998. case TOOL_DOCUMENT :
  4999. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5000. $sql_step = " SELECT lp.*, doc.path as dir
  5001. FROM " . $tbl_lp_item . " as lp
  5002. LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
  5003. WHERE lp.c_id = $course_id AND
  5004. doc.c_id = $course_id AND
  5005. lp.id = " . Database :: escape_string($item_id);
  5006. $res_step = Database::query($sql_step);
  5007. $row_step = Database :: fetch_array($res_step);
  5008. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5009. $return .= $this->display_document_form('edit', $item_id, $row_step);
  5010. break;
  5011. case TOOL_LINK :
  5012. $link_id = (string) $row['path'];
  5013. if (ctype_digit($link_id)) {
  5014. $tbl_link = Database :: get_course_table(TABLE_LINK);
  5015. $sql_select = 'SELECT url FROM ' . $tbl_link . ' WHERE c_id = '.$course_id.' AND id = ' . Database :: escape_string($link_id);
  5016. $res_link = Database::query($sql_select);
  5017. $row_link = Database :: fetch_array($res_link);
  5018. if (is_array($row_link)) {
  5019. $row['url'] = $row_link['url'];
  5020. }
  5021. }
  5022. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5023. $return .= $this->display_link_form('edit', $item_id, $row);
  5024. break;
  5025. case 'dokeos_module' :
  5026. if (isset ($_GET['view']) && $_GET['view'] == 'build') {
  5027. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5028. $return .= $this->display_item_form($row['item_type'], get_lang('EditCurrentModule') . ' :', 'edit', $item_id, $row);
  5029. } else {
  5030. $return .= $this->display_item_small_form($row['item_type'], get_lang('EditCurrentModule') . ' :', $row);
  5031. }
  5032. break;
  5033. case TOOL_QUIZ :
  5034. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5035. $return .= $this->display_quiz_form('edit', $item_id, $row);
  5036. break;
  5037. case TOOL_HOTPOTATOES :
  5038. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5039. $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
  5040. break;
  5041. case TOOL_STUDENTPUBLICATION :
  5042. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5043. $return .= $this->display_student_publication_form('edit', $item_id, $row);
  5044. break;
  5045. case TOOL_FORUM :
  5046. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5047. $return .= $this->display_forum_form('edit', $item_id, $row);
  5048. break;
  5049. case TOOL_THREAD :
  5050. $return .= $this->display_manipulate($item_id, $row['item_type']);
  5051. $return .= $this->display_thread_form('edit', $item_id, $row);
  5052. break;
  5053. }
  5054. }
  5055. return $return;
  5056. }
  5057. /**
  5058. * Function that displays a list with al the resources that could be added to the learning path
  5059. * @return string
  5060. */
  5061. public function display_resources() {
  5062. global $_course; // TODO: Don't use globals.
  5063. $course_code = api_get_course_id();
  5064. /*$return .= '<div class="sectiontitle">' . get_lang('CreateNewStep') . '</div>';
  5065. $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>';
  5066. $return .= '<div class="sectiontitle">' . get_lang('UseAnExistingResource') . '</div>';*/
  5067. //Get all the docs
  5068. $documents = $this->get_documents();
  5069. //Get all the exercises
  5070. $exercises = $this->get_exercises();
  5071. // Get all the links
  5072. $links = $this->get_links();
  5073. //Get al the student publications
  5074. $works = $this->get_student_publications();
  5075. //Get al the forums
  5076. $forums = $this->get_forums(null, $course_code);
  5077. $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), 64),
  5078. Display::return_icon('quiz.png', get_lang('Quiz'), array(), 64),
  5079. Display::return_icon('links.png', get_lang('Links'), array(), 64),
  5080. Display::return_icon('works.png', get_lang('Works'), array(), 64),
  5081. Display::return_icon('forum.png', get_lang('Forums'), array(), 64),
  5082. );
  5083. echo Display::tabs($headers, array($documents, $exercises, $links, $works, $forums), 'resource_tab');
  5084. return true;
  5085. }
  5086. /**
  5087. * Returns the extension of a document
  5088. * @param string filename
  5089. * @return string Extension (part after the last dot)
  5090. */
  5091. public function get_extension($filename) {
  5092. $explode = explode('.', $filename);
  5093. return $explode[count($explode) - 1];
  5094. }
  5095. /**
  5096. * Displays a document by id
  5097. *
  5098. * @param unknown_type $id
  5099. * @return unknown
  5100. */
  5101. public function display_document($id, $show_title = false, $iframe = true, $edit_link = false) {
  5102. global $_course; // It is temporary.
  5103. $course_id = api_get_course_int_id();
  5104. $return = '';
  5105. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  5106. $sql_doc = "SELECT * FROM " . $tbl_doc . "
  5107. WHERE c_id = ".$course_id." AND id = " . $id;
  5108. $res_doc = Database::query($sql_doc);
  5109. $row_doc = Database :: fetch_array($res_doc);
  5110. //if ($show_title)
  5111. //$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>';
  5112. // TODO: Add a path filter.
  5113. if ($iframe) {
  5114. $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>';
  5115. } else {
  5116. $return .= file_get_contents(api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $row_doc['path']);
  5117. }
  5118. return $return;
  5119. }
  5120. /**
  5121. * Return HTML form to add/edit a quiz
  5122. * @param string Action (add/edit)
  5123. * @param integer Item ID if already exists
  5124. * @param mixed Extra information (quiz ID if integer)
  5125. * @return string HTML form
  5126. */
  5127. public function display_quiz_form($action = 'add', $id = 0, $extra_info = '') {
  5128. $course_id = api_get_course_int_id();
  5129. global $charset;
  5130. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5131. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  5132. if ($id != 0 && is_array($extra_info)) {
  5133. $item_title = $extra_info['title'];
  5134. $item_description = $extra_info['description'];
  5135. } elseif (is_numeric($extra_info)) {
  5136. $sql_quiz = "SELECT title, description FROM " . $tbl_quiz . " WHERE c_id = ".$course_id." AND id = " . $extra_info;
  5137. $result = Database::query($sql_quiz);
  5138. $row = Database :: fetch_array($result);
  5139. $item_title = $row['title'];
  5140. $item_description = $row['description'];
  5141. } else {
  5142. $item_title = '';
  5143. $item_description = '';
  5144. }
  5145. $item_title = Security::remove_XSS($item_title);
  5146. $item_description = Security::remove_XSS($item_description);
  5147. $return = ' <div class="row">
  5148. <div class="form_header">';
  5149. if ($id != 0 && is_array($extra_info))
  5150. $parent = $extra_info['parent_item_id'];
  5151. else
  5152. $parent = 0;
  5153. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  5154. $result = Database::query($sql);
  5155. $arrLP = array ();
  5156. while ($row = Database :: fetch_array($result)) {
  5157. $arrLP[] = array (
  5158. 'id' => $row['id'],
  5159. 'item_type' => $row['item_type'],
  5160. 'title' => $row['title'],
  5161. 'path' => $row['path'],
  5162. 'description' => $row['description'],
  5163. 'parent_item_id' => $row['parent_item_id'],
  5164. 'previous_item_id' => $row['previous_item_id'],
  5165. 'next_item_id' => $row['next_item_id'],
  5166. 'display_order' => $row['display_order'],
  5167. 'max_score' => $row['max_score'],
  5168. 'min_score' => $row['min_score'],
  5169. 'mastery_score' => $row['mastery_score'],
  5170. 'prerequisite' => $row['prerequisite'],
  5171. 'max_time_allowed' => $row['max_time_allowed']
  5172. );
  5173. }
  5174. $this->tree_array($arrLP);
  5175. $arrLP = $this->arrMenu;
  5176. unset ($this->arrMenu);
  5177. if ($action == 'add')
  5178. $return .= get_lang('CreateTheExercise') . '&nbsp;:';
  5179. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentExercise') . '&nbsp;:';
  5180. else
  5181. $return .= get_lang('EditCurrentExecice') . '&nbsp;:';
  5182. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5183. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5184. }
  5185. $return .= ' </div>
  5186. </div>';
  5187. $return .= '<div class="sectioncomment">';
  5188. $return .= '<form method="POST">';
  5189. $return .= '<table class="lp_form">';
  5190. if ($action != 'move') {
  5191. $return .= '<tr>';
  5192. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5193. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" class="learnpath_item_form" value="' . $item_title . '" /></td>';
  5194. $return .= '</tr>';
  5195. }
  5196. $return .= '<tr>';
  5197. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5198. $return .= '<td class="input">';
  5199. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  5200. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  5201. $arrHide = array (
  5202. $id
  5203. );
  5204. //$parent_item_id = $_SESSION['parent_item_id'];
  5205. for ($i = 0; $i < count($arrLP); $i++) {
  5206. if ($action != 'add') {
  5207. 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)) {
  5208. $return .= '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5209. } else {
  5210. $arrHide[] = $arrLP[$i]['id'];
  5211. }
  5212. } else {
  5213. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5214. $return .= '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</option>';
  5215. }
  5216. }
  5217. if (is_array($arrLP)) {
  5218. reset($arrLP);
  5219. }
  5220. $return .= '</select>';
  5221. $return .= '</td>';
  5222. $return .= '</tr>';
  5223. $return .= '<tr>';
  5224. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5225. $return .= '<td class="input">';
  5226. $return .= '<select class="learnpath_item_form" style="width:100%;" id="previous" name="previous" size="1">';
  5227. $return .= '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5228. for ($i = 0; $i < count($arrLP); $i++) {
  5229. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5230. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5231. $selected = 'selected="selected" ';
  5232. elseif ($action == 'add') $selected = 'selected="selected" ';
  5233. else
  5234. $selected = '';
  5235. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5236. }
  5237. }
  5238. $return .= '</select>';
  5239. $return .= '</td>';
  5240. $return .= '</tr>';
  5241. if ($action != 'move') {
  5242. $id_prerequisite = 0;
  5243. if (is_array($arrLP)) {
  5244. foreach ($arrLP as $key => $value) {
  5245. if ($value['id'] == $id) {
  5246. $id_prerequisite = $value['prerequisite'];
  5247. break;
  5248. }
  5249. }
  5250. }
  5251. $arrHide = array ();
  5252. for ($i = 0; $i < count($arrLP); $i++) {
  5253. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5254. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5255. $s_selected_position = $arrLP[$i]['id'];
  5256. elseif ($action == 'add') $s_selected_position = 0;
  5257. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5258. }
  5259. }
  5260. /*// Commented the prerequisites, only visible in edit (exercise).
  5261. $return .= '<tr>';
  5262. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  5263. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5264. foreach($arrHide as $key => $value){
  5265. if($key==$s_selected_position && $action == 'add'){
  5266. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5267. }
  5268. elseif($key==$id_prerequisite && $action == 'edit'){
  5269. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  5270. }
  5271. else{
  5272. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  5273. }
  5274. }
  5275. $return .= "</select></td>";
  5276. */
  5277. $return .= '</tr>';
  5278. /*$return .= '<tr>';
  5279. $return .= '<td class="label"><label for="maxTimeAllowed">' . get_lang('MaxTimeAllowed') . '</label></td>';
  5280. $return .= '<td class="input"><input name="maxTimeAllowed" style="width:98%;" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
  5281. // Remove temporarily the test description.
  5282. //$return .= '<td class="label"><label for="idDescription">'.get_lang('Description').' :</label></td>';
  5283. //$return .= '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>';
  5284. $return .= '</tr>'; */
  5285. }
  5286. $return .= '<tr>';
  5287. if ($action == 'add') {
  5288. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddExercise') . '</button></td>';
  5289. } else {
  5290. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentExecice') . '</button></td>';
  5291. }
  5292. $return .= '</tr>';
  5293. $return .= '</table>';
  5294. if ($action == 'move') {
  5295. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5296. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5297. }
  5298. if (is_numeric($extra_info)) {
  5299. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5300. }
  5301. elseif (is_array($extra_info)) {
  5302. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5303. }
  5304. $return .= '<input name="type" type="hidden" value="' . TOOL_QUIZ . '" />';
  5305. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5306. $return .= '</form>';
  5307. $return .= '</div>';
  5308. return $return;
  5309. }
  5310. /**
  5311. * Addition of Hotpotatoes tests
  5312. * @param string Action
  5313. * @param integer Internal ID of the item
  5314. * @param mixed Extra information - can be an array with title and description indexes
  5315. * @return string HTML structure to display the hotpotatoes addition formular
  5316. */
  5317. public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
  5318. $course_id = api_get_course_int_id();
  5319. global $charset;
  5320. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  5321. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5322. if ($id != 0 && is_array($extra_info)) {
  5323. $item_title = stripslashes($extra_info['title']);
  5324. $item_description = stripslashes($extra_info['description']);
  5325. } elseif (is_numeric($extra_info)) {
  5326. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  5327. $sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
  5328. WHERE c_id = ".$course_id." AND
  5329. path LIKE '" . $uploadPath . "/%/%htm%' AND
  5330. id = " . (int) $extra_info . "
  5331. ORDER BY id ASC";
  5332. $res_hot = Database::query($sql_hot);
  5333. $row = Database::fetch_array($res_hot);
  5334. $item_title = $row['title'];
  5335. $item_description = $row['description'];
  5336. if (!empty ($row['comment'])) {
  5337. $item_title = $row['comment'];
  5338. }
  5339. } else {
  5340. $item_title = '';
  5341. $item_description = '';
  5342. }
  5343. if ($id != 0 && is_array($extra_info))
  5344. $parent = $extra_info['parent_item_id'];
  5345. else
  5346. $parent = 0;
  5347. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  5348. $result = Database::query($sql);
  5349. $arrLP = array ();
  5350. while ($row = Database :: fetch_array($result)) {
  5351. $arrLP[] = array (
  5352. 'id' => $row['id'],
  5353. 'item_type' => $row['item_type'],
  5354. 'title' => $row['title'],
  5355. 'path' => $row['path'],
  5356. 'description' => $row['description'],
  5357. 'parent_item_id' => $row['parent_item_id'],
  5358. 'previous_item_id' => $row['previous_item_id'],
  5359. 'next_item_id' => $row['next_item_id'],
  5360. 'display_order' => $row['display_order'],
  5361. 'max_score' => $row['max_score'],
  5362. 'min_score' => $row['min_score'],
  5363. 'mastery_score' => $row['mastery_score'],
  5364. 'prerequisite' => $row['prerequisite'],
  5365. 'max_time_allowed' => $row['max_time_allowed']
  5366. );
  5367. }
  5368. /*
  5369. $this->tree_array($arrLP);
  5370. $arrLP = $this->arrMenu;
  5371. unset ($this->arrMenu);*/
  5372. if ($action == 'add')
  5373. $return .= '<div class="row"><div class="form_header">' . get_lang('CreateTheExercise') . '&nbsp;:</div></div>';
  5374. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentExercise') . '&nbsp;:</p>';
  5375. else
  5376. //$return .= '<p class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</p>';
  5377. $return .= '<div class="row"><div class="form_header">' . get_lang('EditCurrentExecice') . '&nbsp;:</div></div>';
  5378. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  5379. $return .= Display :: return_warning_message('<p class="lp_title">' . get_lang('Warning') . ' !</p>' . get_lang('WarningEditingDocument'));
  5380. }
  5381. $return .= '<form method="POST">';
  5382. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5383. $return .= '<tr>';
  5384. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . ' :</label></td>';
  5385. $return .= '<td class="input">';
  5386. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5387. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5388. $arrHide = array (
  5389. $id
  5390. );
  5391. if (count($arrLP) > 0) {
  5392. for ($i = 0; $i < count($arrLP); $i++) {
  5393. if ($action != 'add') {
  5394. 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)) {
  5395. $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>';
  5396. } else {
  5397. $arrHide[] = $arrLP[$i]['id'];
  5398. }
  5399. } else {
  5400. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5401. $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>';
  5402. }
  5403. }
  5404. reset($arrLP);
  5405. }
  5406. $return .= "\t\t\t\t" . '</select>';
  5407. $return .= '</td>';
  5408. $return .= '</tr>';
  5409. $return .= '<tr>';
  5410. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . ' :</label></td>';
  5411. $return .= '<td class="input">';
  5412. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5413. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5414. for ($i = 0; $i < count($arrLP); $i++) {
  5415. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5416. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5417. $selected = 'selected="selected" ';
  5418. elseif ($action == 'add') $selected = 'selected="selected" ';
  5419. else
  5420. $selected = '';
  5421. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5422. }
  5423. }
  5424. $return .= "\t\t\t\t" . '</select>';
  5425. $return .= '</td>';
  5426. $return .= '</tr>';
  5427. if ($action != 'move') {
  5428. $return .= '<tr>';
  5429. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . ' :</label></td>';
  5430. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5431. $return .= '</tr>';
  5432. $id_prerequisite = 0;
  5433. if (is_array($arrLP) && count($arrLP) > 0) {
  5434. foreach ($arrLP as $key => $value) {
  5435. if ($value['id'] == $id) {
  5436. $id_prerequisite = $value['prerequisite'];
  5437. break;
  5438. }
  5439. }
  5440. $arrHide = array ();
  5441. for ($i = 0; $i < count($arrLP); $i++) {
  5442. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5443. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5444. $s_selected_position = $arrLP[$i]['id'];
  5445. elseif ($action == 'add') $s_selected_position = 0;
  5446. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5447. }
  5448. }
  5449. }
  5450. //$return .= '<tr>';
  5451. //$return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').' :</label></td>';
  5452. //$return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  5453. /*
  5454. foreach ($arrHide as $key => $value) {
  5455. if ($key == $s_selected_position && $action == 'add') {
  5456. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5457. }
  5458. elseif ($key == $id_prerequisite && $action == 'edit') {
  5459. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5460. } else {
  5461. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5462. }
  5463. }
  5464. */
  5465. //$return .= "</select></td>";
  5466. //$return .= '</tr>';
  5467. //$return .= '<tr>';
  5468. //$return .= '</tr>';
  5469. }
  5470. $return .= '<tr>';
  5471. $return .= '<td>&nbsp; </td><td><button class="save" name="submit_button" action="edit" type="submit">' . get_lang('SaveHotpotatoes') . '</button></td>';
  5472. $return .= '</tr>';
  5473. $return .= '</table>';
  5474. if ($action == 'move') {
  5475. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5476. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5477. }
  5478. if (is_numeric($extra_info)) {
  5479. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5480. }
  5481. elseif (is_array($extra_info)) {
  5482. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5483. }
  5484. $return .= '<input name="type" type="hidden" value="' . TOOL_HOTPOTATOES . '" />';
  5485. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5486. $return .= '</form>';
  5487. return $return;
  5488. }
  5489. /**
  5490. * Return the form to display the forum edit/add option
  5491. * @param string Action (add/edit)
  5492. * @param integer ID of the lp_item if already exists
  5493. * @param mixed Forum ID or title
  5494. * @return string HTML form
  5495. */
  5496. public function display_forum_form($action = 'add', $id = 0, $extra_info = '') {
  5497. $course_id = api_get_course_int_id();
  5498. global $charset;
  5499. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5500. $tbl_forum = Database :: get_course_table(TABLE_FORUM);
  5501. if ($id != 0 && is_array($extra_info)) {
  5502. $item_title = stripslashes($extra_info['title']);
  5503. }
  5504. elseif (is_numeric($extra_info)) {
  5505. $sql_forum = "SELECT forum_title as title, forum_comment as comment
  5506. FROM " . $tbl_forum . "
  5507. WHERE c_id = ".$course_id." AND forum_id = " . $extra_info;
  5508. $result = Database::query($sql_forum);
  5509. $row = Database :: fetch_array($result);
  5510. $item_title = $row['title'];
  5511. $item_description = $row['comment'];
  5512. } else {
  5513. $item_title = '';
  5514. $item_description = '';
  5515. }
  5516. $return = ' <div class="row">
  5517. <div class="form_header">';
  5518. if ($id != 0 && is_array($extra_info))
  5519. $parent = $extra_info['parent_item_id'];
  5520. else
  5521. $parent = 0;
  5522. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5523. WHERE c_id = ".$course_id." AND
  5524. lp_id = " . $this->lp_id;
  5525. $result = Database::query($sql);
  5526. $arrLP = array ();
  5527. while ($row = Database :: fetch_array($result)) {
  5528. $arrLP[] = array (
  5529. 'id' => $row['id'],
  5530. 'item_type' => $row['item_type'],
  5531. 'title' => $row['title'],
  5532. 'path' => $row['path'],
  5533. 'description' => $row['description'],
  5534. 'parent_item_id' => $row['parent_item_id'],
  5535. 'previous_item_id' => $row['previous_item_id'],
  5536. 'next_item_id' => $row['next_item_id'],
  5537. 'display_order' => $row['display_order'],
  5538. 'max_score' => $row['max_score'],
  5539. 'min_score' => $row['min_score'],
  5540. 'mastery_score' => $row['mastery_score'],
  5541. 'prerequisite' => $row['prerequisite']
  5542. );
  5543. }
  5544. $this->tree_array($arrLP);
  5545. $arrLP = $this->arrMenu;
  5546. unset ($this->arrMenu);
  5547. if ($action == 'add')
  5548. $return .= get_lang('CreateTheForum') . '&nbsp;:';
  5549. elseif ($action == 'move') $return .= get_lang('MoveTheCurrentForum') . '&nbsp;:';
  5550. else
  5551. $return .= get_lang('EditCurrentForum') . '&nbsp;:';
  5552. $return .= ' </div>
  5553. </div>';
  5554. $return .= '<div class="sectioncomment">';
  5555. $return .= '<form method="POST">';
  5556. $return .= '<table class="lp_form">';
  5557. if ($action != 'move') {
  5558. $return .= '<tr>';
  5559. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  5560. $return .= '<td class="input"><input id="idTitle" size="44" name="title" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  5561. $return .= '</tr>';
  5562. }
  5563. $return .= '<tr>';
  5564. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  5565. $return .= '<td class="input">';
  5566. $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">';
  5567. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5568. $arrHide = array (
  5569. $id
  5570. );
  5571. //$parent_item_id = $_SESSION['parent_item_id'];
  5572. for ($i = 0; $i < count($arrLP); $i++) {
  5573. if ($action != 'add') {
  5574. 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)) {
  5575. $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>';
  5576. } else {
  5577. $arrHide[] = $arrLP[$i]['id'];
  5578. }
  5579. } else {
  5580. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5581. $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>';
  5582. }
  5583. }
  5584. if (is_array($arrLP)) {
  5585. reset($arrLP);
  5586. }
  5587. $return .= "\t\t\t\t" . '</select>';
  5588. $return .= '</td>';
  5589. $return .= '</tr>';
  5590. $return .= '<tr>';
  5591. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  5592. $return .= '<td class="input">';
  5593. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  5594. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5595. for ($i = 0; $i < count($arrLP); $i++) {
  5596. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5597. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5598. $selected = 'selected="selected" ';
  5599. elseif ($action == 'add') $selected = 'selected="selected" ';
  5600. else
  5601. $selected = '';
  5602. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5603. }
  5604. }
  5605. $return .= "\t\t\t\t" . '</select>';
  5606. $return .= '</td>';
  5607. $return .= '</tr>';
  5608. if ($action != 'move') {
  5609. $return .= '<tr>';
  5610. $return .= '</tr>';
  5611. $id_prerequisite = 0;
  5612. if (is_array($arrLP)) {
  5613. foreach ($arrLP as $key => $value) {
  5614. if ($value['id'] == $id) {
  5615. $id_prerequisite = $value['prerequisite'];
  5616. break;
  5617. }
  5618. }
  5619. }
  5620. $arrHide = array ();
  5621. for ($i = 0; $i < count($arrLP); $i++) {
  5622. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5623. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5624. $s_selected_position = $arrLP[$i]['id'];
  5625. elseif ($action == 'add') $s_selected_position = 0;
  5626. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5627. }
  5628. }
  5629. $return .= '</tr>';
  5630. }
  5631. $return .= '<tr>';
  5632. if ($action == 'add') {
  5633. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('AddForumToCourse') . ' </button></td>';
  5634. } else {
  5635. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit"> ' . get_lang('EditCurrentForum') . ' </button></td>';
  5636. }
  5637. $return .= '</tr>';
  5638. $return .= '</table>';
  5639. if ($action == 'move') {
  5640. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5641. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5642. }
  5643. if (is_numeric($extra_info)) {
  5644. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5645. }
  5646. elseif (is_array($extra_info)) {
  5647. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5648. }
  5649. $return .= '<input name="type" type="hidden" value="' . TOOL_FORUM . '" />';
  5650. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5651. $return .= '</form>';
  5652. $return .= '</div>';
  5653. return $return;
  5654. }
  5655. /**
  5656. * Return HTML form to add/edit forum threads
  5657. * @param string Action (add/edit)
  5658. * @param integer Item ID if already exists in learning path
  5659. * @param mixed Extra information (thread ID if integer)
  5660. * @return string HTML form
  5661. */
  5662. public function display_thread_form($action = 'add', $id = 0, $extra_info = '') {
  5663. $course_id = api_get_course_int_id();
  5664. global $charset;
  5665. echo '<style>
  5666. div.row div.label {
  5667. width:110px;
  5668. }
  5669. div.row div.formw {
  5670. width: 82%;
  5671. }
  5672. </style>';
  5673. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5674. $tbl_forum = Database :: get_course_table(TABLE_FORUM_THREAD);
  5675. if ($id != 0 && is_array($extra_info)) {
  5676. $item_title = stripslashes($extra_info['title']);
  5677. }
  5678. elseif (is_numeric($extra_info)) {
  5679. $sql_forum = "SELECT thread_title as title
  5680. FROM " . $tbl_forum . "
  5681. WHERE c_id = ".$course_id." AND thread_id = " . $extra_info;
  5682. $result = Database::query($sql_forum);
  5683. $row = Database :: fetch_array($result);
  5684. $item_title = $row['title'];
  5685. $item_description = '';
  5686. } else {
  5687. $item_title = '';
  5688. $item_description = '';
  5689. }
  5690. $return = '<div style="margin:3px 12px;">';
  5691. if ($id != 0 && is_array($extra_info))
  5692. $parent = $extra_info['parent_item_id'];
  5693. else
  5694. $parent = 0;
  5695. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5696. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  5697. $result = Database::query($sql);
  5698. $arrLP = array ();
  5699. while ($row = Database :: fetch_array($result)) {
  5700. $arrLP[] = array (
  5701. 'id' => $row['id'],
  5702. 'item_type' => $row['item_type'],
  5703. 'title' => $row['title'],
  5704. 'path' => $row['path'],
  5705. 'description' => $row['description'],
  5706. 'parent_item_id' => $row['parent_item_id'],
  5707. 'previous_item_id' => $row['previous_item_id'],
  5708. 'next_item_id' => $row['next_item_id'],
  5709. 'display_order' => $row['display_order'],
  5710. 'max_score' => $row['max_score'],
  5711. 'min_score' => $row['min_score'],
  5712. 'mastery_score' => $row['mastery_score'],
  5713. 'prerequisite' => $row['prerequisite']
  5714. );
  5715. }
  5716. $this->tree_array($arrLP);
  5717. $arrLP = $this->arrMenu;
  5718. unset ($this->arrMenu);
  5719. if ($action == 'add')
  5720. $return .= '<p class="lp_title">' . get_lang('CreateTheForum') . '&nbsp;:</p>';
  5721. elseif ($action == 'move') $return .= '<p class="lp_title">' . get_lang('MoveTheCurrentForum') . '&nbsp;:</p>';
  5722. else
  5723. $return .= '<p class="lp_title">' . get_lang('EditCurrentForum') . '&nbsp;:</p>';
  5724. $return .= '<form method="POST">';
  5725. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  5726. $return .= '<tr>';
  5727. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '&nbsp;:</label></td>';
  5728. $return .= '<td class="input">';
  5729. $return .= "\t\t\t\t" . '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
  5730. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  5731. $arrHide = array (
  5732. $id
  5733. );
  5734. for ($i = 0; $i < count($arrLP); $i++) {
  5735. if ($action != 'add') {
  5736. 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)) {
  5737. $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>';
  5738. } else {
  5739. $arrHide[] = $arrLP[$i]['id'];
  5740. }
  5741. } else {
  5742. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  5743. $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>';
  5744. }
  5745. }
  5746. if ($arrLP != null) {
  5747. reset($arrLP);
  5748. }
  5749. $return .= "\t\t\t\t" . '</select>';
  5750. $return .= '</td>';
  5751. $return .= '</tr>';
  5752. $return .= '<tr>';
  5753. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '&nbsp;:</label></td>';
  5754. $return .= '<td class="input">';
  5755. $return .= "\t\t\t\t" . '<select id="previous" name="previous" size="1">';
  5756. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  5757. for ($i = 0; $i < count($arrLP); $i++) {
  5758. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5759. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5760. $selected = 'selected="selected" ';
  5761. elseif ($action == 'add') $selected = 'selected="selected" ';
  5762. else
  5763. $selected = '';
  5764. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  5765. }
  5766. }
  5767. $return .= "\t\t\t\t" . '</select>';
  5768. $return .= '</td>';
  5769. $return .= '</tr>';
  5770. if ($action != 'move') {
  5771. $return .= '<tr>';
  5772. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '&nbsp;:</label></td>';
  5773. $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>';
  5774. $return .= '</tr>';
  5775. $return .= '<tr>';
  5776. $return .= '</tr>';
  5777. $id_prerequisite = 0;
  5778. if ($arrLP != null) {
  5779. foreach ($arrLP as $key => $value) {
  5780. if ($value['id'] == $id) {
  5781. $id_prerequisite = $value['prerequisite'];
  5782. break;
  5783. }
  5784. }
  5785. }
  5786. $arrHide = array();
  5787. for ($i = 0; $i < count($arrLP); $i++) {
  5788. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  5789. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5790. $s_selected_position = $arrLP[$i]['id'];
  5791. elseif ($action == 'add') $s_selected_position = 0;
  5792. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5793. }
  5794. }
  5795. $return .= '<tr>';
  5796. $return .= '<td class="label"><label for="idPrerequisites">' . get_lang('Prerequisites') . '&nbsp;:</label></td>';
  5797. $return .= '<td class="input"><select name="prerequisites" id="prerequisites"><option value="0">' . get_lang('NoPrerequisites') . '</option>';
  5798. foreach ($arrHide as $key => $value) {
  5799. if ($key == $s_selected_position && $action == 'add') {
  5800. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5801. }
  5802. elseif ($key == $id_prerequisite && $action == 'edit') {
  5803. $return .= '<option value="' . $key . '" selected="selected">' . $value['value'] . '</option>';
  5804. } else {
  5805. $return .= '<option value="' . $key . '">' . $value['value'] . '</option>';
  5806. }
  5807. }
  5808. $return .= "</select></td>";
  5809. $return .= '</tr>';
  5810. }
  5811. $return .= '<tr>';
  5812. $return .= '<td colspan="2">
  5813. <button class="save" name="submit_button" type="submit" value="'.get_lang('Ok').'" />'.get_lang('Ok').'</button></td>';
  5814. $return .= '</tr>';
  5815. $return .= '</table>';
  5816. if ($action == 'move') {
  5817. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  5818. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  5819. }
  5820. if (is_numeric($extra_info)) {
  5821. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  5822. }
  5823. elseif (is_array($extra_info)) {
  5824. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  5825. }
  5826. $return .= '<input name="type" type="hidden" value="' . TOOL_THREAD . '" />';
  5827. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  5828. $return .= '</form>';
  5829. $return .= '</div>';
  5830. return $return;
  5831. }
  5832. /**
  5833. * Return the HTML form to display an item (generally a section/module item)
  5834. * @param string Item type (module/dokeos_module)
  5835. * @param string Title (optional, only when creating)
  5836. * @param string Action ('add'/'edit')
  5837. * @param integer lp_item ID
  5838. * @param mixed Extra info
  5839. * @return string HTML form
  5840. */
  5841. public function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new') {
  5842. $course_id = api_get_course_int_id();
  5843. global $_course;
  5844. global $charset;
  5845. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  5846. if ($id != 0 && is_array($extra_info)) {
  5847. $item_title = $extra_info['title'];
  5848. $item_description = $extra_info['description'];
  5849. $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5850. $item_path_fck = '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
  5851. } else {
  5852. $item_title = '';
  5853. $item_description = '';
  5854. $item_path_fck = '';
  5855. }
  5856. $return = '<div class="row">
  5857. <div class="form_header">';
  5858. if ($id != 0 && is_array($extra_info))
  5859. $parent = $extra_info['parent_item_id'];
  5860. else
  5861. $parent = 0;
  5862. $id = intval($id);
  5863. $sql = "SELECT * FROM " . $tbl_lp_item . "
  5864. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id . " AND id != $id";
  5865. if ($item_type == 'module')
  5866. $sql .= " AND parent_item_id = 0";
  5867. $result = Database::query($sql);
  5868. $arrLP = array ();
  5869. while ($row = Database :: fetch_array($result)) {
  5870. $arrLP[] = array (
  5871. 'id' => $row['id'],
  5872. 'item_type' => $row['item_type'],
  5873. 'title' => $row['title'],
  5874. 'path' => $row['path'],
  5875. 'description' => $row['description'],
  5876. 'parent_item_id' => $row['parent_item_id'],
  5877. 'previous_item_id' => $row['previous_item_id'],
  5878. 'next_item_id' => $row['next_item_id'],
  5879. 'max_score' => $row['max_score'],
  5880. 'min_score' => $row['min_score'],
  5881. 'mastery_score' => $row['mastery_score'],
  5882. 'prerequisite' => $row['prerequisite'],
  5883. 'display_order' => $row['display_order']
  5884. );
  5885. }
  5886. $this->tree_array($arrLP);
  5887. $arrLP = $this->arrMenu;
  5888. unset ($this->arrMenu);
  5889. $return .= $title;
  5890. $return .= '</div>
  5891. </div>';
  5892. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  5893. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING']);
  5894. $defaults['title'] = api_html_entity_decode($item_title, ENT_QUOTES, $charset);
  5895. $defaults['description'] = $item_description;
  5896. $form->addElement('html', $return);
  5897. //$arrHide = array($id);
  5898. $arrHide[0]['value'] = Security :: remove_XSS($this->name);
  5899. $arrHide[0]['padding'] = 3;
  5900. $charset = api_get_system_encoding();
  5901. if ($item_type != 'module' && $item_type != 'dokeos_module') {
  5902. for ($i = 0; $i < count($arrLP); $i++) {
  5903. if ($action != 'add') {
  5904. 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)) {
  5905. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5906. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5907. if ($parent == $arrLP[$i]['id']) {
  5908. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5909. }
  5910. }
  5911. } else {
  5912. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  5913. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  5914. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  5915. if ($parent == $arrLP[$i]['id']) {
  5916. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  5917. }
  5918. }
  5919. }
  5920. }
  5921. if ($action != 'move') {
  5922. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_chapter_form" size="40%"');
  5923. $form->applyFilter('title', 'html_filter');
  5924. $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
  5925. //$form->addElement('textarea', 'description', get_lang('Description').' :', 'id="idDescription"');
  5926. } else {
  5927. $form->addElement('hidden', 'title');
  5928. }
  5929. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_chapter_form" style="width:37%;" id="idParent" onchange="javascript: load_cbo(this.value);"');
  5930. foreach ($arrHide as $key => $value) {
  5931. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  5932. }
  5933. if (!empty($s_selected_parent)) {
  5934. $parent_select->setSelected($s_selected_parent);
  5935. }
  5936. }
  5937. if (is_array($arrLP)) {
  5938. reset($arrLP);
  5939. }
  5940. $arrHide = array ();
  5941. // POSITION
  5942. for ($i = 0; $i < count($arrLP); $i++) {
  5943. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  5944. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  5945. $s_selected_position = $arrLP[$i]['id'];
  5946. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  5947. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  5948. }
  5949. }
  5950. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_chapter_form" style="width:37%;"');
  5951. $padding = isset($value['padding']) ? $value['padding'] : 0;
  5952. $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $padding . 'px;"');
  5953. foreach ($arrHide as $key => $value) {
  5954. $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $padding . 'px;"');
  5955. }
  5956. if (!empty ($s_selected_position)) {
  5957. $position->setSelected($s_selected_position);
  5958. }
  5959. if (is_array($arrLP)) {
  5960. reset($arrLP);
  5961. }
  5962. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveSection'), 'class="save"');
  5963. if ($item_type == 'module' || $item_type == 'dokeos_module') {
  5964. $form->addElement('hidden', 'parent', '0');
  5965. }
  5966. $extension = null;
  5967. if (!empty($item_path)) {
  5968. $extension = pathinfo($item_path, PATHINFO_EXTENSION);
  5969. }
  5970. if (($item_type == 'asset' || $item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
  5971. if ($item_type == 'sco') {
  5972. $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
  5973. }
  5974. $renderer = $form->defaultRenderer();
  5975. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  5976. $relative_prefix = '';
  5977. $editor_config = array( 'ToolbarSet' => 'LearningPathDocuments',
  5978. 'Width' => '100%',
  5979. 'Height' => '500',
  5980. 'FullPage' => true,
  5981. 'CreateDocumentDir' => $relative_prefix,
  5982. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/scorm/',
  5983. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().$item_path_fck
  5984. );
  5985. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  5986. $defaults['content_lp'] = file_get_contents($item_path);
  5987. }
  5988. $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
  5989. $form->addElement('hidden', 'post_time', time());
  5990. $form->setDefaults($defaults);
  5991. return $form->return_form();
  5992. }
  5993. /**
  5994. * Returns the form to update or create a document
  5995. * @param string Action (add/edit)
  5996. * @param integer ID of the lp_item (if already exists)
  5997. * @param mixed Integer if document ID, string if info ('new')
  5998. * @return string HTML form
  5999. */
  6000. public function display_document_form($action = 'add', $id = 0, $extra_info = 'new') {
  6001. $course_id = api_get_course_int_id();
  6002. global $charset;
  6003. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6004. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  6005. $path_parts = pathinfo($extra_info['dir']);
  6006. $no_display_edit_textarea = false;
  6007. //If action==edit document
  6008. //We don't display the document form if it's not an editable document (html or txt file)
  6009. if ($action == "edit") {
  6010. if (is_array($extra_info)) {
  6011. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  6012. $no_display_edit_textarea = true;
  6013. }
  6014. }
  6015. }
  6016. $no_display_add = false;
  6017. // If action==add an existing document
  6018. // We don't display the document form if it's not an editable document (html or txt file).
  6019. if ($action == "add") {
  6020. if (is_numeric($extra_info)) {
  6021. $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($extra_info);
  6022. $result = Database::query($sql_doc);
  6023. $path_file = Database :: result($result, 0, 0);
  6024. $path_parts = pathinfo($path_file);
  6025. if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
  6026. $no_display_add = true;
  6027. }
  6028. }
  6029. }
  6030. if ($id != 0 && is_array($extra_info)) {
  6031. $item_title = stripslashes($extra_info['title']);
  6032. $item_description = stripslashes($extra_info['description']);
  6033. $item_terms = stripslashes($extra_info['terms']);
  6034. if (empty ($item_title)) {
  6035. $path_parts = pathinfo($extra_info['path']);
  6036. $item_title = stripslashes($path_parts['filename']);
  6037. }
  6038. } elseif (is_numeric($extra_info)) {
  6039. $sql_doc = "SELECT path, title FROM " . $tbl_doc . "
  6040. WHERE c_id = ".$course_id." AND id = " . Database :: escape_string($extra_info);
  6041. $result = Database::query($sql_doc);
  6042. $row = Database::fetch_array($result);
  6043. $explode = explode('.', $row['title']);
  6044. if (count($explode) > 1) {
  6045. for ($i = 0; $i < count($explode) - 1; $i++)
  6046. $item_title .= $explode[$i];
  6047. } else {
  6048. $item_title = $row['title'];
  6049. }
  6050. $item_title = str_replace('_', ' ', $item_title);
  6051. if (empty ($item_title)) {
  6052. $path_parts = pathinfo($row['path']);
  6053. $item_title = stripslashes($path_parts['filename']);
  6054. }
  6055. } else {
  6056. $item_title = '';
  6057. $item_description = '';
  6058. }
  6059. $return = '<div class="row">
  6060. <div class="form_header">';
  6061. if ($id != 0 && is_array($extra_info))
  6062. $parent = $extra_info['parent_item_id'];
  6063. else
  6064. $parent = 0;
  6065. $sql = "SELECT * FROM " . $tbl_lp_item . "
  6066. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6067. $result = Database::query($sql);
  6068. $arrLP = array ();
  6069. while ($row = Database :: fetch_array($result)) {
  6070. $arrLP[] = array (
  6071. 'id' => $row['id'],
  6072. 'item_type' => $row['item_type'],
  6073. 'title' => $row['title'],
  6074. 'path' => $row['path'],
  6075. 'description' => $row['description'],
  6076. 'parent_item_id' => $row['parent_item_id'],
  6077. 'previous_item_id' => $row['previous_item_id'],
  6078. 'next_item_id' => $row['next_item_id'],
  6079. 'display_order' => $row['display_order'],
  6080. 'max_score' => $row['max_score'],
  6081. 'min_score' => $row['min_score'],
  6082. 'mastery_score' => $row['mastery_score'],
  6083. 'prerequisite' => $row['prerequisite']
  6084. );
  6085. }
  6086. $this->tree_array($arrLP);
  6087. $arrLP = $this->arrMenu;
  6088. unset ($this->arrMenu);
  6089. if ($action == 'add') {
  6090. $return .= get_lang('CreateTheDocument');
  6091. } elseif ($action == 'move') {
  6092. $return .= get_lang('MoveTheCurrentDocument');
  6093. } else {
  6094. $return .= get_lang('EditTheCurrentDocument');
  6095. }
  6096. $return .= '</div>
  6097. </div>';
  6098. if (isset ($_GET['edit']) && $_GET['edit'] == 'true') {
  6099. $return .= Display :: return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
  6100. }
  6101. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  6102. $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', 'enctype="multipart/form-data"');
  6103. $defaults['title'] = Security :: remove_XSS($item_title);
  6104. if (empty($item_title)) {
  6105. $defaults['title'] = Security::remove_XSS($item_title);
  6106. }
  6107. $defaults['description'] = $item_description;
  6108. $form->addElement('html', $return);
  6109. if ($action != 'move') {
  6110. $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
  6111. $form->applyFilter('title', 'html_filter');
  6112. }
  6113. //$arrHide = array($id);
  6114. $arrHide[0]['value'] = $this->name;
  6115. $arrHide[0]['padding'] = 3;
  6116. for ($i = 0; $i < count($arrLP); $i++) {
  6117. if ($action != 'add') {
  6118. 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)) {
  6119. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6120. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  6121. if ($parent == $arrLP[$i]['id']) {
  6122. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  6123. }
  6124. }
  6125. } else {
  6126. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
  6127. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6128. $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
  6129. if ($parent == $arrLP[$i]['id']) {
  6130. $s_selected_parent = $arrHide[$arrLP[$i]['id']];
  6131. }
  6132. }
  6133. }
  6134. }
  6135. $parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
  6136. $my_count=0;
  6137. foreach ($arrHide as $key => $value) {
  6138. if ($my_count!=0) {
  6139. // The LP name is also the first section and is not in the same charset like the other sections.
  6140. $value['value'] = Security :: remove_XSS($value['value']);
  6141. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  6142. } else {
  6143. $value['value'] = Security :: remove_XSS($value['value']);
  6144. $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
  6145. }
  6146. $my_count++;
  6147. }
  6148. if (!empty($id)) {
  6149. $parent_select->setSelected($parent);
  6150. } else {
  6151. $parent_item_id = $_SESSION['parent_item_id'];
  6152. $parent_select->setSelected($parent_item_id);
  6153. }
  6154. if (is_array($arrLP)) {
  6155. reset($arrLP);
  6156. }
  6157. $arrHide = array ();
  6158. //POSITION
  6159. for ($i = 0; $i < count($arrLP); $i++) {
  6160. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6161. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6162. $s_selected_position = $arrLP[$i]['id'];
  6163. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  6164. $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
  6165. }
  6166. }
  6167. $position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
  6168. $position->addOption(get_lang('FirstPosition'), 0);
  6169. foreach ($arrHide as $key => $value) {
  6170. $padding = isset($value['padding']) ? $value['padding']: 0;
  6171. $position->addOption($value['value'], $key, 'style="padding-left:' . $padding . 'px;"');
  6172. }
  6173. $position->setSelected($s_selected_position);
  6174. if (is_array($arrLP)) {
  6175. reset($arrLP);
  6176. }
  6177. if ($action != 'move') {
  6178. $id_prerequisite = 0;
  6179. if (is_array($arrLP)) {
  6180. foreach ($arrLP as $key => $value) {
  6181. if ($value['id'] == $id) {
  6182. $id_prerequisite = $value['prerequisite'];
  6183. break;
  6184. }
  6185. }
  6186. }
  6187. $arrHide = array ();
  6188. for ($i = 0; $i < count($arrLP); $i++) {
  6189. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6190. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6191. $s_selected_position = $arrLP[$i]['id'];
  6192. elseif ($action == 'add') $s_selected_position = $arrLP[$i]['id'];
  6193. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6194. }
  6195. }
  6196. if (!$no_display_add) {
  6197. if (($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true')) {
  6198. if (isset ($_POST['content']))
  6199. $content = stripslashes($_POST['content']);
  6200. elseif (is_array($extra_info)) {
  6201. //If it's an html document or a text file
  6202. if (!$no_display_edit_textarea) {
  6203. $content = $this->display_document($extra_info['path'], false, false);
  6204. }
  6205. } elseif (is_numeric($extra_info))
  6206. $content = $this->display_document($extra_info, false, false);
  6207. else
  6208. $content = '';
  6209. if (!$no_display_edit_textarea) {
  6210. // We need to calculate here some specific settings for the online editor.
  6211. // The calculated settings work for documents in the Documents tool
  6212. // (on the root or in subfolders).
  6213. // For documents in native scorm packages it is unclear whether the
  6214. // online editor should be activated or not.
  6215. // A new document, it is in the root of the repository.
  6216. $relative_path = '';
  6217. $relative_prefix = '';
  6218. if (is_array($extra_info) && $extra_info != 'new') {
  6219. // The document already exists. Whe have to determine its relative path towards the repository root.
  6220. $relative_path = explode('/', $extra_info['dir']);
  6221. $cnt = count($relative_path) - 2;
  6222. if ($cnt < 0) {
  6223. $cnt = 0;
  6224. }
  6225. $relative_prefix = str_repeat('../', $cnt);
  6226. $relative_path = array_slice($relative_path, 1, $cnt);
  6227. $relative_path = implode('/', $relative_path);
  6228. if (strlen($relative_path) > 0) {
  6229. $relative_path = $relative_path . '/';
  6230. }
  6231. } else {
  6232. global $_course;
  6233. $result = $this->generate_lp_folder($_course, '');
  6234. $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
  6235. $relative_prefix = '../../';
  6236. }
  6237. $editor_config = array( 'ToolbarSet' => 'LearningPathDocuments',
  6238. 'Width' => '100%',
  6239. 'Height' => '500',
  6240. 'FullPage' => true,
  6241. 'CreateDocumentDir' => $relative_prefix,
  6242. 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/document/',
  6243. 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path().'/document/'.$relative_path
  6244. );
  6245. if ($_GET['action'] == 'add_item') {
  6246. $class = 'add';
  6247. $text = get_lang('LPCreateDocument');
  6248. } else
  6249. if ($_GET['action'] == 'edit_item') {
  6250. $class = 'save';
  6251. $text = get_lang('SaveDocument');
  6252. }
  6253. $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
  6254. $renderer = $form->defaultRenderer();
  6255. $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
  6256. $form->addElement('html', '<div style="margin:3px 12px">');
  6257. $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
  6258. $form->addElement('html', '</div>');
  6259. $defaults['content_lp'] = $content;
  6260. }
  6261. } elseif (is_numeric($extra_info)) {
  6262. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6263. $return = $this->display_document($extra_info, true, true, true);
  6264. $form->addElement('html', $return);
  6265. }
  6266. }
  6267. }
  6268. if ($action == 'move') {
  6269. $form->addElement('hidden', 'title', $item_title);
  6270. $form->addElement('hidden', 'description', $item_description);
  6271. }
  6272. if (is_numeric($extra_info)) {
  6273. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
  6274. $form->addElement('hidden', 'path', $extra_info);
  6275. }
  6276. elseif (is_array($extra_info)) {
  6277. $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
  6278. $form->addElement('hidden', 'path', $extra_info['path']);
  6279. }
  6280. $form->addElement('hidden', 'type', TOOL_DOCUMENT);
  6281. $form->addElement('hidden', 'post_time', time());
  6282. $form->setDefaults($defaults);
  6283. return $form->return_form();
  6284. }
  6285. /**
  6286. * Return HTML form to add/edit a link item
  6287. * @param string Action (add/edit)
  6288. * @param integer Item ID if exists
  6289. * @param mixed Extra info
  6290. * @return string HTML form
  6291. */
  6292. public function display_link_form($action = 'add', $id = 0, $extra_info = '') {
  6293. $course_id = api_get_course_int_id();
  6294. global $charset;
  6295. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6296. $tbl_link = Database :: get_course_table(TABLE_LINK);
  6297. if ($id != 0 && is_array($extra_info)) {
  6298. $item_title = stripslashes($extra_info['title']);
  6299. $item_description = stripslashes($extra_info['description']);
  6300. $item_url = stripslashes($extra_info['url']);
  6301. } elseif (is_numeric($extra_info)) {
  6302. $sql_link = "SELECT title, description, url FROM " . $tbl_link . " WHERE c_id = ".$course_id." AND id = " . $extra_info;
  6303. $result = Database::query($sql_link);
  6304. $row = Database :: fetch_array($result);
  6305. $item_title = $row['title'];
  6306. $item_description = $row['description'];
  6307. $item_url = $row['url'];
  6308. } else {
  6309. $item_title = '';
  6310. $item_description = '';
  6311. $item_url = '';
  6312. }
  6313. $return = ' <div class="row">
  6314. <div class="form_header">';
  6315. if ($id != 0 && is_array($extra_info))
  6316. $parent = $extra_info['parent_item_id'];
  6317. else
  6318. $parent = 0;
  6319. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6320. $result = Database::query($sql);
  6321. $arrLP = array ();
  6322. while ($row = Database :: fetch_array($result)) {
  6323. $arrLP[] = array (
  6324. 'id' => $row['id'],
  6325. 'item_type' => $row['item_type'],
  6326. 'title' => $row['title'],
  6327. 'path' => $row['path'],
  6328. 'description' => $row['description'],
  6329. 'parent_item_id' => $row['parent_item_id'],
  6330. 'previous_item_id' => $row['previous_item_id'],
  6331. 'next_item_id' => $row['next_item_id'],
  6332. 'display_order' => $row['display_order'],
  6333. 'max_score' => $row['max_score'],
  6334. 'min_score' => $row['min_score'],
  6335. 'mastery_score' => $row['mastery_score'],
  6336. 'prerequisite' => $row['prerequisite']
  6337. );
  6338. }
  6339. $this->tree_array($arrLP);
  6340. $arrLP = $this->arrMenu;
  6341. unset ($this->arrMenu);
  6342. if ($action == 'add')
  6343. $return .= get_lang('CreateTheLink') . '&nbsp;:';
  6344. elseif ($action == 'move') $return .= get_lang('MoveCurrentLink') . '&nbsp;:';
  6345. else
  6346. $return .= get_lang('EditCurrentLink') . '&nbsp;:';
  6347. $return .= ' </div>
  6348. </div>';
  6349. $return .= '<div class="sectioncomment">';
  6350. $return .= '<form method="POST">';
  6351. $return .= '<table>';
  6352. if ($action != 'move') {
  6353. $return .= '<tr>';
  6354. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6355. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form"/></td>';
  6356. $return .= '</tr>';
  6357. }
  6358. $return .= '<tr>';
  6359. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6360. $return .= '<td class="input">';
  6361. $return .= '<select id="idParent" style="width:100%;" name="parent" onChange="javascript: load_cbo(this.value);" class="learnpath_item_form" size="1">';
  6362. $return .= '<option class="top" value="0">' . $this->name . '</option>';
  6363. $arrHide = array (
  6364. $id
  6365. );
  6366. $parent_item_id = $_SESSION['parent_item_id'];
  6367. for ($i = 0; $i < count($arrLP); $i++) {
  6368. if ($action != 'add') {
  6369. 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)) {
  6370. $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>';
  6371. } else {
  6372. $arrHide[] = $arrLP[$i]['id'];
  6373. }
  6374. } else {
  6375. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6376. $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>';
  6377. }
  6378. }
  6379. if (is_array($arrLP)) {
  6380. reset($arrLP);
  6381. }
  6382. $return .= "\t\t\t\t" . '</select>';
  6383. $return .= '</td>';
  6384. $return .= '</tr>';
  6385. $return .= '<tr>';
  6386. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6387. $return .= '<td class="input">';
  6388. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6389. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6390. for ($i = 0; $i < count($arrLP); $i++) {
  6391. if ($arrLP[$i]['parent_item_id'] == $parent_item_id && $arrLP[$i]['id'] != $id) {
  6392. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6393. $selected = 'selected="selected" ';
  6394. elseif ($action == 'add')
  6395. $selected = 'selected="selected" ';
  6396. else
  6397. $selected = '';
  6398. $return .= '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6399. }
  6400. }
  6401. $return .= '</select>';
  6402. $return .= '</td>';
  6403. $return .= '</tr>';
  6404. if ($action != 'move') {
  6405. $return .= '<tr>';
  6406. $return .= '<td class="label"><label for="idURL">' . get_lang('Url') . '</label></td>';
  6407. $return .= '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" style="width:99%;" type="text" value="' . $item_url . '" class="learnpath_item_form" /></td>';
  6408. $return .= '</tr>';
  6409. $id_prerequisite = 0;
  6410. if (is_array($arrLP)) {
  6411. foreach ($arrLP as $key => $value) {
  6412. if ($value['id'] == $id) {
  6413. $id_prerequisite = $value['prerequisite'];
  6414. break;
  6415. }
  6416. }
  6417. }
  6418. $arrHide = array ();
  6419. for ($i = 0; $i < count($arrLP); $i++) {
  6420. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6421. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6422. $s_selected_position = $arrLP[$i]['id'];
  6423. elseif ($action == 'add') $s_selected_position = 0;
  6424. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6425. }
  6426. }
  6427. /*// Commented the prerequisites, only visible in edit (link).
  6428. $return .= '<tr>';
  6429. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6430. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6431. foreach($arrHide as $key => $value) {
  6432. if ($key == $s_selected_position && $action == 'add') {
  6433. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6434. }
  6435. elseif ($key == $id_prerequisite && $action == 'edit') {
  6436. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6437. }
  6438. else {
  6439. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6440. }
  6441. }
  6442. $return .= "</select></td>";
  6443. */
  6444. $return .= '</tr>';
  6445. }
  6446. $return .= '<tr>';
  6447. if ($action == 'add') {
  6448. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddLinkToCourse') . '</button></td>';
  6449. } else {
  6450. $return .= '<td>&nbsp;</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentLink') . '</button></td>';
  6451. }
  6452. $return .= '</tr>';
  6453. $return .= '</table>';
  6454. if ($action == 'move') {
  6455. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6456. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6457. }
  6458. if (is_numeric($extra_info)) {
  6459. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6460. }
  6461. elseif (is_array($extra_info)) {
  6462. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6463. }
  6464. $return .= '<input name="type" type="hidden" value="' . TOOL_LINK . '" />';
  6465. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6466. $return .= '</form>';
  6467. $return .= '</div>';
  6468. return $return;
  6469. }
  6470. /**
  6471. * Return HTML form to add/edit a student publication (work)
  6472. * @param string Action (add/edit)
  6473. * @param integer Item ID if already exists
  6474. * @param mixed Extra info (work ID if integer)
  6475. * @return string HTML form
  6476. */
  6477. public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '') {
  6478. $course_id = api_get_course_int_id();
  6479. global $charset;
  6480. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6481. $tbl_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  6482. if ($id != 0 && is_array($extra_info)) {
  6483. $item_title = stripslashes($extra_info['title']);
  6484. $item_description = stripslashes($extra_info['description']);
  6485. }
  6486. elseif (is_numeric($extra_info)) {
  6487. $sql_publication = "SELECT title, description FROM " . $tbl_publication . "
  6488. WHERE c_id = ".$course_id." AND id = " . $extra_info;
  6489. $result = Database::query($sql_publication);
  6490. $row = Database :: fetch_array($result);
  6491. $item_title = $row['title'];
  6492. } else {
  6493. $item_title = get_lang('Student_publication');
  6494. }
  6495. $return = ' <div class="row">
  6496. <div class="form_header">';
  6497. if ($id != 0 && is_array($extra_info))
  6498. $parent = $extra_info['parent_item_id'];
  6499. else
  6500. $parent = 0;
  6501. $sql = "SELECT * FROM " . $tbl_lp_item . "
  6502. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6503. $result = Database::query($sql);
  6504. $arrLP = array ();
  6505. while ($row = Database :: fetch_array($result)) {
  6506. $arrLP[] = array (
  6507. 'id' => $row['id'],
  6508. 'item_type' => $row['item_type'],
  6509. 'title' => $row['title'],
  6510. 'path' => $row['path'],
  6511. 'description' => $row['description'],
  6512. 'parent_item_id' => $row['parent_item_id'],
  6513. 'previous_item_id' => $row['previous_item_id'],
  6514. 'next_item_id' => $row['next_item_id'],
  6515. 'display_order' => $row['display_order'],
  6516. 'max_score' => $row['max_score'],
  6517. 'min_score' => $row['min_score'],
  6518. 'mastery_score' => $row['mastery_score'],
  6519. 'prerequisite' => $row['prerequisite']
  6520. );
  6521. }
  6522. $this->tree_array($arrLP);
  6523. $arrLP = $this->arrMenu;
  6524. unset ($this->arrMenu);
  6525. if ($action == 'add')
  6526. $return .= get_lang('Student_publication') . '&nbsp;:' . "\n";
  6527. elseif ($action == 'move') $return .= get_lang('MoveCurrentStudentPublication') . '&nbsp;:' . "\n";
  6528. else
  6529. $return .= get_lang('EditCurrentStudentPublication') . '&nbsp;:' . "\n";
  6530. $return .= ' </div>
  6531. </div>';
  6532. $return .= '<div class="sectioncomment">';
  6533. $return .= '<form method="POST">';
  6534. $return .= '<table class="lp_form">';
  6535. if ($action != 'move') {
  6536. $return .= '<tr>';
  6537. $return .= '<td class="label"><label for="idTitle">' . get_lang('Title') . '</label></td>';
  6538. $return .= '<td class="input"><input id="idTitle" name="title" size="44" type="text" value="' . $item_title . '" class="learnpath_item_form" /></td>';
  6539. $return .= '</tr>';
  6540. }
  6541. $return .= '<tr>';
  6542. $return .= '<td class="label"><label for="idParent">' . get_lang('Parent') . '</label></td>';
  6543. $return .= '<td class="input">';
  6544. $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">';
  6545. //$parent_item_id = $_SESSION['parent_item_id'];
  6546. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
  6547. $arrHide = array (
  6548. $id
  6549. );
  6550. for ($i = 0; $i < count($arrLP); $i++) {
  6551. if ($action != 'add') {
  6552. 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)) {
  6553. $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>';
  6554. } else {
  6555. $arrHide[] = $arrLP[$i]['id'];
  6556. }
  6557. } else {
  6558. if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
  6559. $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>';
  6560. }
  6561. }
  6562. if (is_array($arrLP)) {
  6563. reset($arrLP);
  6564. }
  6565. $return .= "\t\t\t\t" . '</select>';
  6566. $return .= '</td>';
  6567. $return .= '</tr>';
  6568. $return .= '<tr>';
  6569. $return .= '<td class="label"><label for="previous">' . get_lang('Position') . '</label></td>';
  6570. $return .= '<td class="input">';
  6571. $return .= "\t\t\t\t" . '<select id="previous" name="previous" style="width:100%;" size="1" class="learnpath_item_form">';
  6572. $return .= "\t\t\t\t\t" . '<option class="top" value="0">' . get_lang('FirstPosition') . '</option>';
  6573. for ($i = 0; $i < count($arrLP); $i++) {
  6574. if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
  6575. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6576. $selected = 'selected="selected" ';
  6577. elseif ($action == 'add') $selected = 'selected="selected" ';
  6578. else
  6579. $selected = '';
  6580. $return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"</option>';
  6581. }
  6582. }
  6583. $return .= "\t\t\t\t" . '</select>';
  6584. $return .= '</td>';
  6585. $return .= '</tr>';
  6586. if ($action != 'move') {
  6587. $id_prerequisite = 0;
  6588. if (is_array($arrLP)) {
  6589. foreach ($arrLP as $key => $value) {
  6590. if ($value['id'] == $id) {
  6591. $id_prerequisite = $value['prerequisite'];
  6592. break;
  6593. }
  6594. }
  6595. }
  6596. $arrHide = array ();
  6597. for ($i = 0; $i < count($arrLP); $i++) {
  6598. if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
  6599. if ($extra_info['previous_item_id'] == $arrLP[$i]['id'])
  6600. $s_selected_position = $arrLP[$i]['id'];
  6601. elseif ($action == 'add') $s_selected_position = 0;
  6602. $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
  6603. }
  6604. }
  6605. // Commented the prerequisites, only visible in edit (work).
  6606. /*
  6607. $return .= '<tr>';
  6608. $return .= '<td class="label"><label for="idPrerequisites">'.get_lang('Prerequisites').'</label></td>';
  6609. $return .= '<td class="input"><select name="prerequisites" id="prerequisites" class="learnpath_item_form"><option value="0">'.get_lang('NoPrerequisites').'</option>';
  6610. foreach($arrHide as $key => $value) {
  6611. if ($key == $s_selected_position && $action == 'add') {
  6612. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6613. }
  6614. elseif ($key == $id_prerequisite && $action == 'edit') {
  6615. $return .= '<option value="'.$key.'" selected="selected">'.$value['value'].'</option>';
  6616. }
  6617. else {
  6618. $return .= '<option value="'.$key.'">'.$value['value'].'</option>';
  6619. }
  6620. }
  6621. $return .= "</select></td>";
  6622. */
  6623. $return .= '</tr>';
  6624. }
  6625. $return .= '<tr>';
  6626. if ($action == 'add') {
  6627. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('AddAssignmentToCourse') . '</button></td>';
  6628. } else {
  6629. $return .= '<td>&nbsp</td><td><button class="save" name="submit_button" type="submit">' . get_lang('EditCurrentStudentPublication') . '</button></td>';
  6630. }
  6631. $return .= '</tr>';
  6632. $return .= '</table>';
  6633. if ($action == 'move') {
  6634. $return .= '<input name="title" type="hidden" value="' . $item_title . '" />';
  6635. $return .= '<input name="description" type="hidden" value="' . $item_description . '" />';
  6636. }
  6637. if (is_numeric($extra_info)) {
  6638. $return .= '<input name="path" type="hidden" value="' . $extra_info . '" />';
  6639. } elseif (is_array($extra_info)) {
  6640. $return .= '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />';
  6641. }
  6642. $return .= '<input name="type" type="hidden" value="' . TOOL_STUDENTPUBLICATION . '" />';
  6643. $return .= '<input name="post_time" type="hidden" value="' . time() . '" />';
  6644. $return .= '</form>';
  6645. $return .= '</div>';
  6646. return $return;
  6647. }
  6648. /**
  6649. * Displays the menu for manipulating a step
  6650. * @return string html
  6651. */
  6652. public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT) {
  6653. $course_id = api_get_course_int_id();
  6654. global $charset, $_course;
  6655. $return = '<div class="actions">';
  6656. switch ($item_type) {
  6657. case 'dokeos_chapter' :
  6658. case 'chapter' :
  6659. // Commented the message cause should not show it.
  6660. //$lang = get_lang('TitleManipulateChapter');
  6661. break;
  6662. case 'dokeos_module' :
  6663. case 'module' :
  6664. // Commented the message cause should not show it.
  6665. //$lang = get_lang('TitleManipulateModule');
  6666. break;
  6667. case TOOL_DOCUMENT :
  6668. // Commented the message cause should not show it.
  6669. //$lang = get_lang('TitleManipulateDocument');
  6670. break;
  6671. case TOOL_LINK :
  6672. case 'link' :
  6673. // Commented the message cause should not show it.
  6674. //$lang = get_lang('TitleManipulateLink');
  6675. break;
  6676. case TOOL_QUIZ :
  6677. // Commented the message cause should not show it.
  6678. //$lang = get_lang('TitleManipulateQuiz');
  6679. break;
  6680. case TOOL_STUDENTPUBLICATION :
  6681. // Commented the message cause should not show it.
  6682. //$lang = get_lang('TitleManipulateStudentPublication');
  6683. break;
  6684. }
  6685. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6686. $item_id = intval($item_id);
  6687. $sql = "SELECT * FROM " . $tbl_lp_item . " as lp WHERE lp.c_id = ".$course_id." AND lp.id = " . $item_id;
  6688. $result = Database::query($sql);
  6689. $row = Database::fetch_assoc($result);
  6690. $s_title = $row['title'];
  6691. // We display an audio player if needed.
  6692. if (!empty ($row['audio'])) {
  6693. $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>';
  6694. $return .= '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
  6695. $return .= '<script type="text/javascript">
  6696. var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
  6697. s1.addParam("allowscriptaccess","always");
  6698. s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $row['audio'] . '&autostart=true");
  6699. s1.write("container");
  6700. </script>';
  6701. }
  6702. // Commented ":" for message in step.
  6703. //$return .= $lang.': ';
  6704. $url = api_get_self() . '?cidReq='.Security::remove_XSS($_GET['cidReq']).'&view=build&id='.$item_id .'&lp_id='.$this->lp_id;
  6705. $return .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), $url.'&action=edit_item&path_item=' . $row['path']);
  6706. $return .= Display::url(Display::return_icon('move.png', get_lang('Move'), array(), 22), $url.'&action=move_item');
  6707. // Commented for now as prerequisites cannot be added to chapters.
  6708. if ($item_type != 'dokeos_chapter' && $item_type != 'chapter') {
  6709. $return .= Display::url(Display::return_icon('accept.png', get_lang('Prerequisites'), array(), 22), $url.'&action=edit_item_prereq');
  6710. }
  6711. $return .= Display::url(Display::return_icon('delete.png', get_lang('Delete'), array(), 22), $url.'&action=delete_item');
  6712. /*
  6713. // Get the audiorecorder. Use of ob_* functions since there are echos in the file.
  6714. ob_start();
  6715. $audio_recorder_studentview = 'false';
  6716. $audio_recorder_item_id = $item_id;
  6717. if (api_get_setting('service_visio', 'active') == 'true') {
  6718. require_once 'audiorecorder.inc.php';
  6719. }
  6720. $return .= ob_get_contents();
  6721. ob_end_clean();
  6722. // End of audiorecorder include
  6723. */
  6724. $return .= '</div>';
  6725. return $return;
  6726. }
  6727. /**
  6728. * Creates the javascript needed for filling up the checkboxes without page reload
  6729. *
  6730. * @return string
  6731. */
  6732. public function get_js_dropdown_array() {
  6733. $course_id = api_get_course_int_id();
  6734. $return = 'var child_name = new Array();' . "\n";
  6735. $return .= 'var child_value = new Array();' . "\n\n";
  6736. $return .= 'child_name[0] = new Array();' . "\n";
  6737. $return .= 'child_value[0] = new Array();' . "\n\n";
  6738. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6739. $sql_zero = "SELECT * FROM " . $tbl_lp_item . "
  6740. WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id . " AND parent_item_id = 0
  6741. ORDER BY display_order ASC";
  6742. $res_zero = Database::query($sql_zero);
  6743. global $charset;
  6744. $i = 0;
  6745. while ($row_zero = Database :: fetch_array($res_zero)) {
  6746. $js_var = json_encode(get_lang('After').' '.$row_zero['title']);
  6747. $return .= 'child_name[0][' . $i . '] = '.$js_var.' ;' . "\n";
  6748. $return .= 'child_value[0][' . $i++ . '] = "' . $row_zero['id'] . '";' . "\n";
  6749. }
  6750. $return .= "\n";
  6751. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
  6752. $res = Database::query($sql);
  6753. while ($row = Database :: fetch_array($res)) {
  6754. $sql_parent = "
  6755. SELECT * FROM " . $tbl_lp_item . "
  6756. WHERE c_id = ".$course_id." AND parent_item_id = " . $row['id'] . "
  6757. ORDER BY display_order ASC";
  6758. $res_parent = Database::query($sql_parent);
  6759. $i = 0;
  6760. $return .= 'child_name[' . $row['id'] . '] = new Array();' . "\n";
  6761. $return .= 'child_value[' . $row['id'] . '] = new Array();' . "\n\n";
  6762. while ($row_parent = Database :: fetch_array($res_parent)) {
  6763. $js_var = json_encode(get_lang('After').' '.$row_parent['title']);
  6764. $return .= 'child_name[' . $row['id'] . '][' . $i . '] = '.$js_var.' ;' . "\n";
  6765. $return .= 'child_value[' . $row['id'] . '][' . $i++ . '] = "' . $row_parent['id'] . '";' . "\n";
  6766. }
  6767. $return .= "\n";
  6768. }
  6769. return $return;
  6770. }
  6771. /**
  6772. * Display the form to allow moving an item
  6773. * @param integer Item ID
  6774. * @return string HTML form
  6775. */
  6776. public function display_move_item($item_id) {
  6777. $course_id = api_get_course_int_id();
  6778. global $_course; //will disappear
  6779. global $charset;
  6780. $return = '';
  6781. if (is_numeric($item_id)) {
  6782. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6783. $sql = "SELECT *
  6784. FROM " . $tbl_lp_item . "
  6785. WHERE c_id = ".$course_id." AND id = " . $item_id;
  6786. $res = Database::query($sql);
  6787. $row = Database :: fetch_array($res);
  6788. switch ($row['item_type']) {
  6789. case 'dokeos_chapter' :
  6790. case 'dir' :
  6791. case 'asset' :
  6792. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6793. $return .= $this->display_item_form($row['item_type'], get_lang('MoveCurrentChapter'), 'move', $item_id, $row);
  6794. break;
  6795. case 'dokeos_module' :
  6796. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6797. $return .= $this->display_item_form($row['item_type'], 'Move th current module:', 'move', $item_id, $row);
  6798. break;
  6799. case TOOL_DOCUMENT :
  6800. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6801. $return .= $this->display_document_form('move', $item_id, $row);
  6802. break;
  6803. case TOOL_LINK :
  6804. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6805. $return .= $this->display_link_form('move', $item_id, $row);
  6806. break;
  6807. case TOOL_HOTPOTATOES :
  6808. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6809. $return .= $this->display_link_form('move', $item_id, $row);
  6810. break;
  6811. case TOOL_QUIZ :
  6812. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6813. $return .= $this->display_quiz_form('move', $item_id, $row);
  6814. break;
  6815. case TOOL_STUDENTPUBLICATION :
  6816. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6817. $return .= $this->display_student_publication_form('move', $item_id, $row);
  6818. break;
  6819. case TOOL_FORUM :
  6820. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6821. $return .= $this->display_forum_form('move', $item_id, $row);
  6822. break;
  6823. case TOOL_THREAD :
  6824. $return .= $this->display_manipulate($item_id, $row['item_type']);
  6825. $return .= $this->display_forum_form('move', $item_id, $row);
  6826. break;
  6827. }
  6828. }
  6829. return $return;
  6830. }
  6831. /**
  6832. * Displays a basic form on the overview page for changing the item title and the item description.
  6833. * @param string $item_type
  6834. * @param string $title
  6835. * @param array $data
  6836. * @return string
  6837. */
  6838. public function display_item_small_form($item_type, $title = '', $data) {
  6839. $return = '<div class="lp_small_form">';
  6840. $return .= '<p class="lp_title">' . $title . '</p>';
  6841. $return .= '<form method="post">';
  6842. $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
  6843. $return .= '<tr>';
  6844. $return .= '<td class="label"><label for="idTitle">Title&nbsp;:</label></td>';
  6845. $return .= '<td class="input"><input class="small_form" id="idTitle" name="title" type="text" value="' . api_html_entity_decode($data['title'], ENT_QUOTES) . '" /></td>';
  6846. $return .= '</tr>';
  6847. // It said these lines of code - see SVN#11724 and SVN#10770
  6848. //$return .= '<tr>';
  6849. //$return .= '<td class="label"><label for="idDescription">Description&nbsp;:</label></td>';
  6850. //$return .= '<td class="input"><textarea class="small_form" id="idDescription" name="description" rows="4">' . $data['description'] . '</textarea></td>';
  6851. //$return .= '</tr>';
  6852. $return .= '<tr>';
  6853. $return .= '<td colspan="2"><button class="save" name="submit_button" type="submit">' . get_lang('Save') . '</button></td>';
  6854. $return .= '</tr>';
  6855. $return .= '</table>';
  6856. $return .= '<input name="parent" type="hidden" value="' . $data['parent_item_id'] . '"/>';
  6857. $return .= '<input name="previous" type="hidden" value="' . $data['previous_item_id'] . '"/>';
  6858. $return .= '</form>';
  6859. $return .= '</div>';
  6860. return $return;
  6861. }
  6862. /**
  6863. * Return HTML form to allow prerequisites selection
  6864. * @param integer Item ID
  6865. * @return string HTML form
  6866. */
  6867. public function display_item_prerequisites_form($item_id) {
  6868. $course_id = api_get_course_int_id();
  6869. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  6870. $item_id = intval($item_id);
  6871. /* Current prerequisite */
  6872. $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND id = " . $item_id;
  6873. $result = Database::query($sql);
  6874. $row = Database::fetch_array($result);
  6875. $preq_id = $row['prerequisite'];
  6876. //$preq_mastery = $row['mastery_score'];
  6877. //$preq_max = $row['max_score'];
  6878. $return = $this->display_manipulate($item_id, TOOL_DOCUMENT);
  6879. $return = ' <div class="row">
  6880. <div class="form_header">';
  6881. $return .= get_lang('AddEditPrerequisites');
  6882. $return .= '</div></div>';
  6883. $return .= '<div class="sectioncomment">';
  6884. $return .= '<form method="POST">';
  6885. $return .= '<table class="data_table" style="width:650px">';
  6886. $return .= '<tr>';
  6887. $return .= '<th height="24">' . get_lang('Prerequisites') . '</th>';
  6888. $return .= '<th width="70" height="24">' . get_lang('Minimum') . '</th>';
  6889. $return .= '<th width="70" height="24">' . get_lang('Maximum') . '</th>';
  6890. $return .= '</tr>';
  6891. // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
  6892. $return .= '<tr >';
  6893. $return .= '<td colspan="3" class="radio">';
  6894. $return .= '<input checked="checked" id="idNone" name="prerequisites" style="margin-left:0px; margin-right:10px;" type="radio" />';
  6895. $return .= '<label for="idNone">' . get_lang('None') . '</label>';
  6896. $return .= '</tr>';
  6897. $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
  6898. $result = Database::query($sql);
  6899. $arrLP = array ();
  6900. while ($row = Database :: fetch_array($result)) {
  6901. $arrLP[] = array (
  6902. 'id' => $row['id'],
  6903. 'item_type' => $row['item_type'],
  6904. 'title' => $row['title'],
  6905. 'ref' => $row['ref'],
  6906. 'description' => $row['description'],
  6907. 'parent_item_id' => $row['parent_item_id'],
  6908. 'previous_item_id' => $row['previous_item_id'],
  6909. 'next_item_id' => $row['next_item_id'],
  6910. 'max_score' => $row['max_score'],
  6911. 'min_score' => $row['min_score'],
  6912. 'mastery_score' => $row['mastery_score'],
  6913. 'prerequisite' => $row['prerequisite'],
  6914. 'next_item_id' => $row['next_item_id'],
  6915. 'display_order' => $row['display_order']
  6916. );
  6917. if ($row['ref'] == $preq_id) {
  6918. $preq_mastery = $row['mastery_score'];
  6919. $preq_max = $row['max_score'];
  6920. }
  6921. }
  6922. $this->tree_array($arrLP);
  6923. $arrLP = $this->arrMenu;
  6924. unset ($this->arrMenu);
  6925. for ($i = 0; $i < count($arrLP); $i++) {
  6926. if ($arrLP[$i]['id'] == $item_id)
  6927. break;
  6928. $return .= '<tr>';
  6929. $return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_QUIZ && $arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . '>';
  6930. $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'] . '" />';
  6931. $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
  6932. if (file_exists('../img/lp_' . $icon_name . '.png')) {
  6933. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.png" style="margin-right:5px;" title="" />';
  6934. } else
  6935. if (file_exists('../img/lp_' . $icon_name . '.gif')) {
  6936. $return .= '<img alt="" src="../img/lp_' . $icon_name . '.gif" style="margin-right:5px;" title="" />';
  6937. } else {
  6938. $return .= Display::return_icon('folder_document.gif','',array('style'=>'margin-right:5px;'));
  6939. }
  6940. $return .= '<label for="id' . $arrLP[$i]['id'] . '">' . $arrLP[$i]['title'] . '</label>';
  6941. $return .= '</td>';
  6942. //$return .= '<td class="radio"' . (($arrLP[$i]['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '') . ' />';
  6943. if ($arrLP[$i]['item_type'] == TOOL_QUIZ) {
  6944. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6945. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6946. $return .= '</td>';
  6947. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6948. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6949. $return .= '</td>';
  6950. }
  6951. if ($arrLP[$i]['item_type'] == TOOL_HOTPOTATOES) {
  6952. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6953. $return .= '<center><input size="4" maxlength="3" name="min_' . $arrLP[$i]['id'] . '" type="text" value="' . (($arrLP[$i]['id'] == $preq_id) ? $preq_mastery : 0) . '" /></center>';
  6954. $return .= '</td>';
  6955. $return .= '<td class="exercise" style="border:1px solid #ccc;">';
  6956. $return .= '<center><input size="4" maxlength="3" name="max_' . $arrLP[$i]['id'] . '" type="text" value="' . $arrLP[$i]['max_score'] . '" disabled="true" /></center>';
  6957. $return .= '</td>';
  6958. }
  6959. $return .= '</tr>';
  6960. }
  6961. $return .= '<tr>';
  6962. $return .= '</tr>';
  6963. $return .= '</table>';
  6964. $return .= '<div style="padding-top:3px;">';
  6965. $return .= '<button class="save" name="submit_button" type="submit">' . get_lang('ModifyPrerequisites') . ' </button></td>';
  6966. $return .= '</div>';
  6967. $return .= '</form>';
  6968. $return .= '</div>';
  6969. return $return;
  6970. }
  6971. /**
  6972. * Return HTML list to allow prerequisites selection for lp
  6973. * @param integer Item ID
  6974. * @return string HTML form
  6975. */
  6976. public function display_lp_prerequisites_list() {
  6977. $course_id = api_get_course_int_id();
  6978. $lp_id = $this->lp_id;
  6979. $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
  6980. // get current prerequisite
  6981. $sql = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $lp_id ";
  6982. $result = Database::query($sql);
  6983. $row = Database :: fetch_array($result);
  6984. $preq_id = $row['prerequisite'];
  6985. $session_id = api_get_session_id();
  6986. $session_condition = api_get_session_condition($session_id);
  6987. $sql = "SELECT * FROM $tbl_lp WHERE c_id = $course_id $session_condition ORDER BY display_order ";
  6988. $rs = Database::query($sql);
  6989. $return = '';
  6990. $return .= '<select name="prerequisites" >';
  6991. $return .= '<option value="0">'.get_lang('None').'</option>';
  6992. if (Database::num_rows($rs) > 0) {
  6993. while ($row = Database::fetch_array($rs)) {
  6994. if ($row['id'] == $lp_id) {
  6995. continue;
  6996. }
  6997. $return .= '<option value="'.$row['id'].'" '.(($row['id']==$preq_id)?' selected ' : '').'>'.$row['name'].'</option>';
  6998. }
  6999. }
  7000. $return .= '</select>';
  7001. return $return;
  7002. }
  7003. /**
  7004. * Creates a list with all the documents in it
  7005. * @return string
  7006. */
  7007. public function get_documents() {
  7008. $course_info = api_get_course_info();
  7009. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7010. $document_tree = DocumentManager::get_document_preview($course_info, $this->lp_id);
  7011. return $document_tree;
  7012. }
  7013. /**
  7014. * Creates a list with all the exercises (quiz) in it
  7015. * @return string
  7016. */
  7017. public function get_exercises() {
  7018. $course_id = api_get_course_int_id();
  7019. // New for hotpotatoes.
  7020. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  7021. $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
  7022. $tbl_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  7023. $session_id = api_get_session_id();
  7024. $condition_session = api_get_session_condition($session_id);
  7025. $sql_quiz = "SELECT * FROM $tbl_quiz WHERE c_id = $course_id AND active<>'-1' $condition_session ORDER BY title ASC";
  7026. $sql_hot = "SELECT * FROM $tbl_doc WHERE c_id = $course_id AND path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
  7027. $res_quiz = Database::query($sql_quiz);
  7028. $res_hot = Database::query($sql_hot);
  7029. //$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>';
  7030. $return = '<div class="lp_resource">';
  7031. $return .= '<div class="lp_resource_element">';
  7032. $return .= '<img alt="" src="../img/new_test_small.gif" style="margin-right:5px;" title="" />';
  7033. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'exercice/exercise_admin.php?lp_id=' . $this->lp_id . '">' . get_lang('NewExercise') . '</a>';
  7034. $return .= '</div>';
  7035. while ($row_hot = Database :: fetch_array($res_hot)) {
  7036. $return .= '<div class="lp_resource_element">';
  7037. // Display quizhotpotatoes.
  7038. $return .= '<img alt="hp" src="../img/hotpotatoes_s.png" style="margin-right:5px;" title="" width="18px" height="18px" />';
  7039. $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>';
  7040. //$return .= $row_quiz['title'];
  7041. $return .= '</div>';
  7042. }
  7043. while ($row_quiz = Database :: fetch_array($res_quiz)) {
  7044. $return .= '<div class="lp_resource_element">';
  7045. $return .= '<img alt="" src="../img/quizz_small.gif" style="margin-right:5px;" title="" />';
  7046. $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>';
  7047. //$return .= $row_quiz['title'];
  7048. $return .= '</div>';
  7049. }
  7050. $return .= '</div>';
  7051. return $return;
  7052. }
  7053. /**
  7054. * Creates a list with all the links in it
  7055. * @return string
  7056. */
  7057. public function get_links() {
  7058. $course_id = api_get_course_int_id();
  7059. $tbl_link = Database :: get_course_table(TABLE_LINK);
  7060. $session_id = api_get_session_id();
  7061. $condition_session = api_get_session_condition($session_id);
  7062. $sql_link = "SELECT * FROM $tbl_link WHERE c_id = ".$course_id." $condition_session ORDER BY title ASC";
  7063. $res_link = Database::query($sql_link);
  7064. //$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>';
  7065. $return = '<div class="lp_resource">';
  7066. $return .= '<div class="lp_resource_element">';
  7067. $return .= '<img alt="" src="../img/linksnew.gif" style="margin-right:5px;width:16px" title="" />';
  7068. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'link/link.php?' . api_get_cidreq() . '&action=addlink&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('LinkAdd') . '">' . get_lang('LinkAdd') . '</a>';
  7069. $return .= '</div>';
  7070. while ($row_link = Database :: fetch_array($res_link)) {
  7071. $return .= '<div class="lp_resource_element">';
  7072. $return .= '<img alt="" src="../img/lp_link.gif" style="margin-right:5px;" title="" />';
  7073. $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>';
  7074. $return .= '</div>';
  7075. }
  7076. /*if (Database :: num_rows($res_link) == 0)
  7077. $return .= '<div class="lp_resource_element">' . get_lang('NoLinksAvailable') . '</div>';
  7078. */
  7079. $return .= '</div>';
  7080. return $return;
  7081. }
  7082. /**
  7083. * Creates a list with all the student publications in it
  7084. * @return unknown
  7085. */
  7086. public function get_student_publications() {
  7087. $course_id = api_get_course_int_id();
  7088. $tbl_student = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  7089. $session_id = api_get_session_id();
  7090. $condition_session = api_get_session_condition($session_id);
  7091. $sql_student = "SELECT * FROM $tbl_student WHERE c_id = ".$course_id." $condition_session ORDER BY title ASC";
  7092. $res_student = Database::query($sql_student);
  7093. //$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>';
  7094. $return = '<div class="lp_resource" >';
  7095. $return .= '<div class="lp_resource_element">';
  7096. $return .= '<img align="left" alt="" src="../img/works_small.gif" style="margin-right:5px;" title="" />';
  7097. $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>';
  7098. $return .= '</div>';
  7099. $return .= '</div>';
  7100. return $return;
  7101. }
  7102. /**
  7103. * Creates a list with all the forums in it
  7104. * @return string
  7105. */
  7106. public function get_forums() {
  7107. require_once '../forum/forumfunction.inc.php';
  7108. require_once '../forum/forumconfig.inc.php';
  7109. global $table_forums, $table_threads, $table_posts, $table_item_property, $table_users;
  7110. $table_forums = Database :: get_course_table(TABLE_FORUM);
  7111. $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
  7112. $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
  7113. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  7114. $table_users = Database :: get_main_table(TABLE_MAIN_USER);
  7115. $a_forums = get_forums();
  7116. //$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>';
  7117. $return = '<div class="lp_resource">';
  7118. $return .= '<div class="lp_resource_element">';
  7119. $return .= '<img alt="" src="../img/forum_new_small.gif" style="margin-right:5px;" title="" />';
  7120. $return .= '<a href="' . api_get_path(REL_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&action=add&amp;content=forum&amp;origin=learnpath&amp;lp_id=' . $this->lp_id . '" title="' . get_lang('CreateANewForum') . '">' . get_lang('CreateANewForum') . '</a>';
  7121. $return .= '</div>';
  7122. foreach ($a_forums as $forum) {
  7123. $return .= '<div class="lp_resource_element_no_link">';
  7124. $return .= '<script type="text/javascript">
  7125. function toggle_forum(forum_id){
  7126. if(document.getElementById("forum_"+forum_id+"_content").style.display == "none"){
  7127. document.getElementById("forum_"+forum_id+"_content").style.display = "block";
  7128. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'remove.gif";
  7129. }
  7130. else {
  7131. document.getElementById("forum_"+forum_id+"_content").style.display = "none";
  7132. document.getElementById("forum_"+forum_id+"_opener").src = "' . api_get_path(WEB_IMG_PATH) . 'add.gif";
  7133. }
  7134. }
  7135. </script>';
  7136. if (!empty($forum['forum_id'])) {
  7137. $return .= '<img alt="" src="../img/lp_forum.gif" style="margin-right:5px;" title="" />';
  7138. $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>
  7139. <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">';
  7140. }
  7141. $a_threads = get_threads($forum['forum_id']);
  7142. if (is_array($a_threads)) {
  7143. foreach ($a_threads as $thread) {
  7144. $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>';
  7145. }
  7146. }
  7147. $return .= '</ul></div>';
  7148. }
  7149. return $return;
  7150. }
  7151. /**
  7152. * // TODO: The output encoding should be equal to the system encoding.
  7153. *
  7154. * Exports the learning path as a SCORM package. This is the main function that
  7155. * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
  7156. * whole thing and returns the zip.
  7157. *
  7158. * This method needs to be called in PHP5, as it will fail with non-adequate
  7159. * XML package (like the ones for PHP4), and it is *not* a static method, so
  7160. * you need to call it on a learnpath object.
  7161. * @TODO The method might be redefined later on in the scorm class itself to avoid
  7162. * creating a SCORM structure if there is one already. However, if the initial SCORM
  7163. * path has been modified, it should use the generic method here below.
  7164. * @TODO link this function with the export_lp() function in the same class
  7165. * @param string Optional name of zip file. If none, title of learnpath is
  7166. * domesticated and trailed with ".zip"
  7167. * @return string Returns the zip package string, or null if error
  7168. */
  7169. public function scorm_export() {
  7170. global $_course;
  7171. // Remove memory and time limits as much as possible as this might be a long process...
  7172. if (function_exists('ini_set')) {
  7173. $mem = ini_get('memory_limit');
  7174. if (substr($mem, -1, 1) == 'M') {
  7175. $mem_num = substr($mem, 0, -1);
  7176. if ($mem_num < 128) {
  7177. ini_set('memory_limit', '128M');
  7178. }
  7179. } else {
  7180. ini_set('memory_limit', '128M');
  7181. }
  7182. ini_set('max_execution_time', 600);
  7183. //} else {
  7184. //error_log('Scorm export: could not change memory and time limits', 0);
  7185. }
  7186. // Create the zip handler (this will remain available throughout the method).
  7187. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  7188. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  7189. $temp_dir_short = uniqid();
  7190. $temp_zip_dir = $archive_path.'/'.$temp_dir_short;
  7191. $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
  7192. $zip_folder = new PclZip($temp_zip_file);
  7193. $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
  7194. $root_path = $main_path = api_get_path(SYS_PATH);
  7195. $files_cleanup = array();
  7196. // Place to temporarily stash the zipfiles.
  7197. // create the temp dir if it doesn't exist
  7198. // or do a cleanup befor creating the zipfile.
  7199. if (!is_dir($temp_zip_dir)) {
  7200. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  7201. } else {
  7202. // Cleanup: Check the temp dir for old files and delete them.
  7203. $handle = opendir($temp_zip_dir);
  7204. while (false !== ($file = readdir($handle))) {
  7205. if ($file != '.' && $file != '..') {
  7206. unlink("$temp_zip_dir/$file");
  7207. }
  7208. }
  7209. closedir($handle);
  7210. }
  7211. $zip_files = $zip_files_abs = $zip_files_dist = array();
  7212. if (is_dir($current_course_path.'/scorm/'.$this->path) && is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')) {
  7213. // Remove the possible . at the end of the path.
  7214. $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
  7215. $dest_path_to_scorm_folder = str_replace('//','/',$temp_zip_dir.'/scorm/'.$dest_path_to_lp);
  7216. mkdir($dest_path_to_scorm_folder, api_get_permissions_for_new_directories(), true);
  7217. $zip_files_dist = copyr($current_course_path.'/scorm/'.$this->path, $dest_path_to_scorm_folder, array('imsmanifest'), $zip_files);
  7218. }
  7219. // Build a dummy imsmanifest structure. Do not add to the zip yet (we still need it).
  7220. // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
  7221. // Aggregation Model official document, secion "2.3 Content Packaging".
  7222. $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.
  7223. $root = $xmldoc->createElement('manifest');
  7224. $root->setAttribute('identifier', 'SingleCourseManifest');
  7225. $root->setAttribute('version', '1.1');
  7226. $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
  7227. $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
  7228. $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  7229. $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');
  7230. // Build mandatory sub-root container elements.
  7231. $metadata = $xmldoc->createElement('metadata');
  7232. $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
  7233. $metadata->appendChild($md_schema);
  7234. $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
  7235. $metadata->appendChild($md_schemaversion);
  7236. $root->appendChild($metadata);
  7237. $organizations = $xmldoc->createElement('organizations');
  7238. $resources = $xmldoc->createElement('resources');
  7239. // Build the only organization we will use in building our learnpaths.
  7240. $organizations->setAttribute('default', 'chamilo_scorm_export');
  7241. $organization = $xmldoc->createElement('organization');
  7242. $organization->setAttribute('identifier', 'chamilo_scorm_export');
  7243. // To set the title of the SCORM entity (=organization), we take the name given
  7244. // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
  7245. // learning path charset) as it is the encoding that defines how it is stored
  7246. // in the database. Then we convert it to HTML entities again as the "&" character
  7247. // alone is not authorized in XML (must be &amp;).
  7248. // The title is then decoded twice when extracting (see scorm::parse_manifest).
  7249. $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
  7250. $organization->appendChild($org_title);
  7251. // For each element, add it to the imsmanifest structure, then add it to the zip.
  7252. // Always call the learnpathItem->scorm_export() method to change it to the SCORM format.
  7253. $link_updates = array();
  7254. foreach ($this->items as $index => $item) {
  7255. if (!in_array($item->type, array(TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION))) {
  7256. // Get included documents from this item.
  7257. if ($item->type == 'sco')
  7258. $inc_docs = $item->get_resources_from_source(null, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.'scorm/'.$this->path.'/'.$item->get_path());
  7259. else
  7260. $inc_docs = $item->get_resources_from_source();
  7261. // Give a child element <item> to the <organization> element.
  7262. $my_item_id = $item->get_id();
  7263. $my_item = $xmldoc->createElement('item');
  7264. $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
  7265. $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
  7266. $my_item->setAttribute('isvisible', 'true');
  7267. // Give a child element <title> to the <item> element.
  7268. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7269. $my_item->appendChild($my_title);
  7270. // Give a child element <adlcp:prerequisites> to the <item> element.
  7271. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $this->get_scorm_prereq_string($my_item_id));
  7272. $my_prereqs->setAttribute('type', 'aicc_script');
  7273. $my_item->appendChild($my_prereqs);
  7274. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7275. //$xmldoc->createElement('adlcp:maxtimeallowed','');
  7276. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7277. //$xmldoc->createElement('adlcp:timelimitaction','');
  7278. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7279. //$xmldoc->createElement('adlcp:datafromlms','');
  7280. // Give a child element <adlcp:masteryscore> to the <item> element.
  7281. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7282. $my_item->appendChild($my_masteryscore);
  7283. // Attach this item to the organization element or hits parent if there is one.
  7284. if (!empty($item->parent) && $item->parent != 0) {
  7285. $children = $organization->childNodes;
  7286. $possible_parent = &$this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
  7287. if (is_object($possible_parent)) {
  7288. $possible_parent->appendChild($my_item);
  7289. } else {
  7290. if ($this->debug > 0) { error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found'); }
  7291. }
  7292. } else {
  7293. if ($this->debug > 0) { error_log('No parent'); }
  7294. $organization->appendChild($my_item);
  7295. }
  7296. // Get the path of the file(s) from the course directory root.
  7297. $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7298. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7299. $my_xml_file_path = $my_file_path;
  7300. $my_sub_dir = dirname($my_file_path);
  7301. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7302. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7303. $my_xml_sub_dir = $my_sub_dir;
  7304. // Give a <resource> child to the <resources> element
  7305. $my_resource = $xmldoc->createElement('resource');
  7306. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7307. $my_resource->setAttribute('type', 'webcontent');
  7308. $my_resource->setAttribute('href', $my_xml_file_path);
  7309. // adlcp:scormtype can be either 'sco' or 'asset'.
  7310. if ($item->type == 'sco') {
  7311. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7312. } else {
  7313. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7314. }
  7315. // xml:base is the base directory to find the files declared in this resource.
  7316. $my_resource->setAttribute('xml:base', '');
  7317. // Give a <file> child to the <resource> element.
  7318. $my_file = $xmldoc->createElement('file');
  7319. $my_file->setAttribute('href', $my_xml_file_path);
  7320. $my_resource->appendChild($my_file);
  7321. // Dependency to other files - not yet supported.
  7322. $i = 1;
  7323. foreach ($inc_docs as $doc_info) {
  7324. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7325. $my_dep = $xmldoc->createElement('resource');
  7326. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7327. $my_dep->setAttribute('identifier', $res_id);
  7328. $my_dep->setAttribute('type', 'webcontent');
  7329. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7330. $my_dep_file = $xmldoc->createElement('file');
  7331. // Check type of URL.
  7332. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7333. if ($doc_info[1] == 'remote') {
  7334. // Remote file. Save url as is.
  7335. $my_dep_file->setAttribute('href', $doc_info[0]);
  7336. $my_dep->setAttribute('xml:base', '');
  7337. } elseif ($doc_info[1] == 'local') {
  7338. switch ($doc_info[2]) {
  7339. case 'url': // Local URL - save path as url for now, don't zip file.
  7340. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7341. $current_dir = dirname($abs_path);
  7342. $current_dir = str_replace('\\', '/', $current_dir);
  7343. $file_path = realpath($abs_path);
  7344. $file_path = str_replace('\\', '/', $file_path);
  7345. $my_dep_file->setAttribute('href', $file_path);
  7346. $my_dep->setAttribute('xml:base', '');
  7347. if (strstr($file_path, $main_path) !== false) {
  7348. // The calculated real path is really inside Chamilo's root path.
  7349. // Reduce file path to what's under the DocumentRoot.
  7350. $file_path = substr($file_path, strlen($root_path) - 1);
  7351. //echo $file_path;echo '<br /><br />';
  7352. //error_log(__LINE__.'Reduced url path: '.$file_path, 0);
  7353. $zip_files_abs[] = $file_path;
  7354. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7355. $my_dep_file->setAttribute('href', $file_path);
  7356. $my_dep->setAttribute('xml:base', '');
  7357. }
  7358. elseif (empty($file_path)) {
  7359. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7360. if (strpos($document_root, -1) == '/') {
  7361. $document_root = substr(0, -1, $document_root);
  7362. }*/
  7363. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7364. $file_path = str_replace('//', '/', $file_path);
  7365. if (file_exists($file_path)) {
  7366. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7367. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7368. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7369. $my_dep_file->setAttribute('href', $file_path);
  7370. $my_dep->setAttribute('xml:base', '');
  7371. }
  7372. }
  7373. break;
  7374. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7375. $my_dep_file->setAttribute('href', $doc_info[0]);
  7376. $my_dep->setAttribute('xml:base', '');
  7377. //$current_dir = str_replace('\\', '/', dirname($current_course_path.'/'.$item->get_file_path())).'/';
  7378. // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
  7379. // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
  7380. $abs_img_path_without_subdir = $doc_info[0];
  7381. $relp = api_get_path(REL_PATH); // The url-append config param.
  7382. $pos = strpos($abs_img_path_without_subdir, $relp);
  7383. if ($pos === 0) {
  7384. $abs_img_path_without_subdir = '/'.substr($abs_img_path_without_subdir, strlen($relp));
  7385. }
  7386. //$file_path = realpath(api_get_path(SYS_PATH).$doc_info[0]);
  7387. $file_path = realpath(api_get_path(SYS_PATH).$abs_img_path_without_subdir);
  7388. $file_path = str_replace('\\', '/', $file_path);
  7389. $file_path = str_replace('//', '/', $file_path);
  7390. //error_log(__LINE__.'Abs path: '.$file_path, 0);
  7391. // Prepare the current directory path (until just under 'document') with a trailing slash.
  7392. $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
  7393. // Check if the current document is in that path.
  7394. if (strstr($file_path, $cur_path) !== false) {
  7395. // The document is in that path, now get the relative path
  7396. // to the containing document.
  7397. $orig_file_path = dirname($cur_path.$my_file_path).'/';
  7398. $orig_file_path = str_replace('\\', '/', $orig_file_path);
  7399. $relative_path = '';
  7400. if (strstr($file_path, $cur_path) !== false) {
  7401. $relative_path = substr($file_path, strlen($orig_file_path));
  7402. $file_path = substr($file_path, strlen($cur_path));
  7403. } else {
  7404. // This case is still a problem as it's difficult to calculate a relative path easily
  7405. // might still generate wrong links.
  7406. //$file_path = substr($file_path,strlen($cur_path));
  7407. // Calculate the directory path to the current file (without trailing slash).
  7408. $my_relative_path = dirname($file_path);
  7409. $my_relative_path = str_replace('\\', '/', $my_relative_path);
  7410. $my_relative_file = basename($file_path);
  7411. // Calculate the directory path to the containing file (without trailing slash).
  7412. $my_orig_file_path = substr($orig_file_path, 0, -1);
  7413. $dotdot = '';
  7414. $subdir = '';
  7415. while (strstr($my_relative_path, $my_orig_file_path) === false && (strlen($my_orig_file_path) > 1) && (strlen($my_relative_path) > 1)) {
  7416. $my_relative_path2 = dirname($my_relative_path);
  7417. $my_relative_path2 = str_replace('\\', '/', $my_relative_path2);
  7418. $my_orig_file_path = dirname($my_orig_file_path);
  7419. $my_orig_file_path = str_replace('\\', '/', $my_orig_file_path);
  7420. $subdir = substr($my_relative_path, strlen($my_relative_path2) + 1).'/'.$subdir;
  7421. $dotdot += '../';
  7422. $my_relative_path = $my_relative_path2;
  7423. }
  7424. $relative_path = $dotdot.$subdir.$my_relative_file;
  7425. }
  7426. // Put the current document in the zip (this array is the array
  7427. // that will manage documents already in the course folder - relative).
  7428. $zip_files[] = $file_path;
  7429. // Update the links to the current document in the containing document (make them relative).
  7430. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $relative_path);
  7431. $my_dep_file->setAttribute('href', $file_path);
  7432. $my_dep->setAttribute('xml:base', '');
  7433. }
  7434. elseif (strstr($file_path,$main_path) !== false) {
  7435. // The calculated real path is really inside Chamilo's root path.
  7436. // Reduce file path to what's under the DocumentRoot.
  7437. $file_path = substr($file_path, strlen($root_path));
  7438. //echo $file_path;echo '<br /><br />';
  7439. //error_log('Reduced path: '.$file_path, 0);
  7440. $zip_files_abs[] = $file_path;
  7441. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7442. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7443. $my_dep->setAttribute('xml:base', '');
  7444. }
  7445. elseif (empty($file_path)) {
  7446. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7447. if(strpos($document_root,-1) == '/') {
  7448. $document_root = substr(0, -1, $document_root);
  7449. }*/
  7450. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7451. $file_path = str_replace('//', '/', $file_path);
  7452. if (file_exists($file_path)) {
  7453. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7454. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7455. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7456. $my_dep_file->setAttribute('href','document/'.$file_path);
  7457. $my_dep->setAttribute('xml:base', '');
  7458. }
  7459. }
  7460. break;
  7461. 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
  7462. if (substr($doc_info[0], 0, 2) == '..') {
  7463. // Relative path going up.
  7464. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7465. $current_dir = str_replace('\\', '/', $current_dir);
  7466. $file_path = realpath($current_dir.$doc_info[0]);
  7467. $file_path = str_replace('\\', '/', $file_path);
  7468. //error_log($file_path.' <-> '.$main_path,0);
  7469. if (strstr($file_path, $main_path) !== false) {
  7470. // The calculated real path is really inside Chamilo's root path.
  7471. // Reduce file path to what's under the DocumentRoot.
  7472. $file_path = substr($file_path, strlen($root_path));
  7473. //error_log('Reduced path: '.$file_path, 0);
  7474. $zip_files_abs[] = $file_path;
  7475. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7476. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7477. $my_dep->setAttribute('xml:base', '');
  7478. }
  7479. } else {
  7480. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7481. $my_dep_file->setAttribute('href', $doc_info[0]);
  7482. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7483. }
  7484. break;
  7485. default:
  7486. $my_dep_file->setAttribute('href', $doc_info[0]);
  7487. $my_dep->setAttribute('xml:base', '');
  7488. break;
  7489. }
  7490. }
  7491. $my_dep->appendChild($my_dep_file);
  7492. $resources->appendChild($my_dep);
  7493. $dependency = $xmldoc->createElement('dependency');
  7494. $dependency->setAttribute('identifierref', $res_id);
  7495. $my_resource->appendChild($dependency);
  7496. $i++;
  7497. }
  7498. //$my_dependency = $xmldoc->createElement('dependency');
  7499. //$my_dependency->setAttribute('identifierref', '');
  7500. $resources->appendChild($my_resource);
  7501. $zip_files[] = $my_file_path;
  7502. //error_log('File '.$my_file_path. ' added to $zip_files', 0);
  7503. } else {
  7504. // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
  7505. if ($item->type == TOOL_LINK) {
  7506. $my_item = $xmldoc->createElement('item');
  7507. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7508. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7509. $my_item->setAttribute('isvisible', 'true');
  7510. // Give a child element <title> to the <item> element.
  7511. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7512. $my_item->appendChild($my_title);
  7513. // Give a child element <adlcp:prerequisites> to the <item> element.
  7514. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7515. $my_prereqs->setAttribute('type', 'aicc_script');
  7516. $my_item->appendChild($my_prereqs);
  7517. // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
  7518. //$xmldoc->createElement('adlcp:maxtimeallowed', '');
  7519. // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
  7520. //$xmldoc->createElement('adlcp:timelimitaction', '');
  7521. // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
  7522. //$xmldoc->createElement('adlcp:datafromlms', '');
  7523. // Give a child element <adlcp:masteryscore> to the <item> element.
  7524. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7525. $my_item->appendChild($my_masteryscore);
  7526. // Attach this item to the organization element or its parent if there is one.
  7527. if (!empty($item->parent) && $item->parent != 0) {
  7528. $children = $organization->childNodes;
  7529. for ($i = 0; $i < $children->length; $i++) {
  7530. $item_temp = $children->item($i);
  7531. if ($item_temp -> nodeName == 'item') {
  7532. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7533. $item_temp -> appendChild($my_item);
  7534. }
  7535. }
  7536. }
  7537. } else {
  7538. $organization->appendChild($my_item);
  7539. }
  7540. $my_file_path = 'link_'.$item->get_id().'.html';
  7541. $sql = 'SELECT url, title FROM '.Database :: get_course_table(TABLE_LINK).' WHERE id='.$item->path;
  7542. $rs = Database::query($sql);
  7543. if ($link = Database :: fetch_array($rs)) {
  7544. $url = $link['url'];
  7545. $title = stripslashes($link['title']);
  7546. $links_to_create[$my_file_path] = array('title' => $title, 'url' => $url);
  7547. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7548. $my_xml_file_path = $my_file_path;
  7549. $my_sub_dir = dirname($my_file_path);
  7550. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7551. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7552. $my_xml_sub_dir = $my_sub_dir;
  7553. // Give a <resource> child to the <resources> element.
  7554. $my_resource = $xmldoc->createElement('resource');
  7555. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7556. $my_resource->setAttribute('type', 'webcontent');
  7557. $my_resource->setAttribute('href', $my_xml_file_path);
  7558. // adlcp:scormtype can be either 'sco' or 'asset'.
  7559. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7560. // xml:base is the base directory to find the files declared in this resource.
  7561. $my_resource->setAttribute('xml:base', '');
  7562. // give a <file> child to the <resource> element.
  7563. $my_file = $xmldoc->createElement('file');
  7564. $my_file->setAttribute('href', $my_xml_file_path);
  7565. $my_resource->appendChild($my_file);
  7566. $resources->appendChild($my_resource);
  7567. }
  7568. }
  7569. elseif ($item->type == TOOL_QUIZ) {
  7570. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  7571. $exe_id = $item->path; // Should be using ref when everything will be cleaned up in this regard.
  7572. $exe = new Exercise();
  7573. $exe->read($exe_id);
  7574. $my_item = $xmldoc->createElement('item');
  7575. $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
  7576. $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
  7577. $my_item->setAttribute('isvisible', 'true');
  7578. // Give a child element <title> to the <item> element.
  7579. $my_title = $xmldoc->createElement('title', htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES, 'UTF-8'));
  7580. $my_item->appendChild($my_title);
  7581. $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
  7582. //$my_item->appendChild($my_max_score);
  7583. // Give a child element <adlcp:prerequisites> to the <item> element.
  7584. $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
  7585. $my_prereqs->setAttribute('type','aicc_script');
  7586. $my_item->appendChild($my_prereqs);
  7587. // Give a child element <adlcp:masteryscore> to the <item> element.
  7588. $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
  7589. $my_item->appendChild($my_masteryscore);
  7590. // Attach this item to the organization element or hits parent if there is one.
  7591. if (!empty($item->parent) && $item->parent != 0) {
  7592. $children = $organization->childNodes;
  7593. for ($i = 0; $i < $children->length; $i++) {
  7594. $item_temp = $children->item($i);
  7595. if ($item_temp -> nodeName == 'item') {
  7596. if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
  7597. $item_temp -> appendChild($my_item);
  7598. }
  7599. }
  7600. }
  7601. } else {
  7602. $organization->appendChild($my_item);
  7603. }
  7604. // Include export scripts.
  7605. require_once api_get_path(SYS_CODE_PATH).'exercice/export/scorm/scorm_export.php';
  7606. // Get the path of the file(s) from the course directory root
  7607. //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
  7608. $my_file_path = 'quiz_'.$item->get_id().'.html';
  7609. // Write the contents of the exported exercise into a (big) html file
  7610. // to later pack it into the exported SCORM. The file will be removed afterwards.
  7611. $contents = export_exercise($exe_id,true);
  7612. $tmp_file_path = $archive_path.$temp_dir_short.'/'.$my_file_path;
  7613. $res = file_put_contents($tmp_file_path, $contents);
  7614. if ($res === false) { error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0); }
  7615. $files_cleanup[] = $tmp_file_path;
  7616. //error_log($tmp_path); die();
  7617. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_QUOTES, 'UTF-8');
  7618. $my_xml_file_path = $my_file_path;
  7619. $my_sub_dir = dirname($my_file_path);
  7620. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7621. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_QUOTES, 'UTF-8');
  7622. $my_xml_sub_dir = $my_sub_dir;
  7623. // Give a <resource> child to the <resources> element.
  7624. $my_resource = $xmldoc->createElement('resource');
  7625. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7626. $my_resource->setAttribute('type', 'webcontent');
  7627. $my_resource->setAttribute('href', $my_xml_file_path);
  7628. // adlcp:scormtype can be either 'sco' or 'asset'.
  7629. $my_resource->setAttribute('adlcp:scormtype', 'sco');
  7630. // xml:base is the base directory to find the files declared in this resource.
  7631. $my_resource->setAttribute('xml:base', '');
  7632. // Give a <file> child to the <resource> element.
  7633. $my_file = $xmldoc->createElement('file');
  7634. $my_file->setAttribute('href', $my_xml_file_path);
  7635. $my_resource->appendChild($my_file);
  7636. // Get included docs.
  7637. $inc_docs = $item->get_resources_from_source(null,$tmp_file_path);
  7638. // Dependency to other files - not yet supported.
  7639. $i = 1;
  7640. foreach ($inc_docs as $doc_info) {
  7641. if (count($doc_info) < 1 || empty($doc_info[0])) { continue; }
  7642. $my_dep = $xmldoc->createElement('resource');
  7643. $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
  7644. $my_dep->setAttribute('identifier', $res_id);
  7645. $my_dep->setAttribute('type', 'webcontent');
  7646. $my_dep->setAttribute('adlcp:scormtype', 'asset');
  7647. $my_dep_file = $xmldoc->createElement('file');
  7648. // Check type of URL.
  7649. //error_log(__LINE__.'Now dealing with '.$doc_info[0].' of type '.$doc_info[1].'-'.$doc_info[2], 0);
  7650. if ($doc_info[1] == 'remote') {
  7651. // Remote file. Save url as is.
  7652. $my_dep_file->setAttribute('href', $doc_info[0]);
  7653. $my_dep->setAttribute('xml:base', '');
  7654. } elseif ($doc_info[1] == 'local') {
  7655. switch ($doc_info[2]) {
  7656. case 'url': // Local URL - save path as url for now, don't zip file.
  7657. // Save file but as local file (retrieve from URL).
  7658. $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
  7659. $current_dir = dirname($abs_path);
  7660. $current_dir = str_replace('\\', '/', $current_dir);
  7661. $file_path = realpath($abs_path);
  7662. $file_path = str_replace('\\', '/', $file_path);
  7663. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7664. $my_dep->setAttribute('xml:base', '');
  7665. if (strstr($file_path, $main_path) !== false) {
  7666. // The calculated real path is really inside the chamilo root path.
  7667. // Reduce file path to what's under the DocumentRoot.
  7668. $file_path = substr($file_path, strlen($root_path));
  7669. //echo $file_path;echo '<br /><br />';
  7670. //error_log('Reduced path: '.$file_path, 0);
  7671. $zip_files_abs[] = $file_path;
  7672. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7673. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7674. $my_dep->setAttribute('xml:base', '');
  7675. }
  7676. elseif (empty($file_path)) {
  7677. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH),api_get_path(REL_PATH)));
  7678. if (strpos($document_root,-1) == '/') {
  7679. $document_root = substr(0, -1, $document_root);
  7680. }*/
  7681. $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
  7682. $file_path = str_replace('//', '/', $file_path);
  7683. if (file_exists($file_path)) {
  7684. $file_path = substr($file_path, strlen($current_dir)); // We get the relative path.
  7685. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7686. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => 'document/'.$file_path);
  7687. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7688. $my_dep->setAttribute('xml:base', '');
  7689. }
  7690. }
  7691. break;
  7692. case 'abs': // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
  7693. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7694. $current_dir = str_replace('\\', '/', $current_dir);
  7695. $file_path = realpath($doc_info[0]);
  7696. $file_path = str_replace('\\', '/', $file_path);
  7697. $my_dep_file->setAttribute('href', $file_path);
  7698. $my_dep->setAttribute('xml:base', '');
  7699. if (strstr($file_path,$main_path) !== false) {
  7700. // The calculated real path is really inside the chamilo root path.
  7701. // Reduce file path to what's under the DocumentRoot.
  7702. $file_path = substr($file_path, strlen($root_path));
  7703. //echo $file_path;echo '<br /><br />';
  7704. //error_log('Reduced path: '.$file_path, 0);
  7705. $zip_files_abs[] = $file_path;
  7706. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7707. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7708. $my_dep->setAttribute('xml:base', '');
  7709. }
  7710. elseif (empty($file_path)) {
  7711. /*$document_root = substr(api_get_path(SYS_PATH), 0, strpos(api_get_path(SYS_PATH), api_get_path(REL_PATH)));
  7712. if (strpos($document_root,-1) == '/') {
  7713. $document_root = substr(0, -1, $document_root);
  7714. }*/
  7715. $file_path = $_SERVER['DOCUMENT_ROOT'].$doc_info[0];
  7716. $file_path = str_replace('//', '/', $file_path);
  7717. if (file_exists($file_path)) {
  7718. $file_path = substr($file_path,strlen($current_dir)); // We get the relative path.
  7719. $zip_files[] = $my_sub_dir.'/'.$file_path;
  7720. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path);
  7721. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7722. $my_dep->setAttribute('xml:base', '');
  7723. }
  7724. }
  7725. break;
  7726. 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
  7727. if (substr($doc_info[0], 0, 2) == '..') {
  7728. // Relative path going up.
  7729. $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
  7730. $current_dir = str_replace('\\', '/', $current_dir);
  7731. $file_path = realpath($current_dir.$doc_info[0]);
  7732. $file_path = str_replace('\\', '/', $file_path);
  7733. //error_log($file_path.' <-> '.$main_path, 0);
  7734. if (strstr($file_path, $main_path) !== false) {
  7735. // The calculated real path is really inside Chamilo's root path.
  7736. // Reduce file path to what's under the DocumentRoot.
  7737. $file_path = substr($file_path, strlen($root_path));
  7738. $file_path_dest = $file_path;
  7739. // File path is courses/CHAMILO/document/....
  7740. $info_file_path = explode('/', $file_path);
  7741. if ($info_file_path[0] == 'courses') { // Add character "/" in file path.
  7742. $file_path_dest = 'document/'.$file_path;
  7743. }
  7744. //error_log('Reduced path: '.$file_path, 0);
  7745. $zip_files_abs[] = $file_path;
  7746. $link_updates[$my_file_path][] = array('orig' => $doc_info[0], 'dest' => $file_path_dest);
  7747. $my_dep_file->setAttribute('href', 'document/'.$file_path);
  7748. $my_dep->setAttribute('xml:base', '');
  7749. }
  7750. } else {
  7751. $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
  7752. $my_dep_file->setAttribute('href', $doc_info[0]);
  7753. $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
  7754. }
  7755. break;
  7756. default:
  7757. $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
  7758. $my_dep->setAttribute('xml:base', '');
  7759. break;
  7760. }
  7761. }
  7762. $my_dep->appendChild($my_dep_file);
  7763. $resources->appendChild($my_dep);
  7764. $dependency = $xmldoc->createElement('dependency');
  7765. $dependency->setAttribute('identifierref', $res_id);
  7766. $my_resource->appendChild($dependency);
  7767. $i++;
  7768. }
  7769. $resources->appendChild($my_resource);
  7770. $zip_files[] = $my_file_path;
  7771. } else {
  7772. // Get the path of the file(s) from the course directory root
  7773. $my_file_path = 'non_exportable.html';
  7774. //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
  7775. $my_xml_file_path = $my_file_path;
  7776. $my_sub_dir = dirname($my_file_path);
  7777. $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
  7778. //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
  7779. $my_xml_sub_dir = $my_sub_dir;
  7780. // Give a <resource> child to the <resources> element.
  7781. $my_resource = $xmldoc->createElement('resource');
  7782. $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
  7783. $my_resource->setAttribute('type', 'webcontent');
  7784. $my_resource->setAttribute('href', 'document/'.$my_xml_file_path);
  7785. // adlcp:scormtype can be either 'sco' or 'asset'.
  7786. $my_resource->setAttribute('adlcp:scormtype', 'asset');
  7787. // xml:base is the base directory to find the files declared in this resource.
  7788. $my_resource->setAttribute('xml:base', '');
  7789. // Give a <file> child to the <resource> element.
  7790. $my_file = $xmldoc->createElement('file');
  7791. $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
  7792. $my_resource->appendChild($my_file);
  7793. $resources->appendChild($my_resource);
  7794. }
  7795. }
  7796. }
  7797. $organizations->appendChild($organization);
  7798. $root->appendChild($organizations);
  7799. $root->appendChild($resources);
  7800. $xmldoc->appendChild($root);
  7801. // TODO: Add a readme file here, with a short description and a link to the Reload player
  7802. // then add the file to the zip, then destroy the file (this is done automatically).
  7803. // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
  7804. //error_log(print_r($zip_files,true), 0);
  7805. foreach ($zip_files as $file_path) {
  7806. if (empty($file_path)) { continue; }
  7807. //error_log(__LINE__.'getting document from '.$sys_course_path.$_course['path'].'/'.$file_path.' removing '.$sys_course_path.$_course['path'].'/',0);
  7808. $dest_file = $archive_path.$temp_dir_short.'/'.$file_path;
  7809. $this->create_path($dest_file);
  7810. //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);
  7811. //echo $main_path.$file_path.'<br />';
  7812. @copy($sys_course_path.$_course['path'].'/'.$file_path, $dest_file);
  7813. // Check if the file needs a link update.
  7814. if (in_array($file_path, array_keys($link_updates))) {
  7815. $string = file_get_contents($dest_file);
  7816. unlink($dest_file);
  7817. foreach ($link_updates[$file_path] as $old_new) {
  7818. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7819. // This is an ugly hack that allows .flv files to be found by the flv player that
  7820. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7821. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7822. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7823. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7824. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7825. }
  7826. elseif (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 6) == 'video/') {
  7827. $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
  7828. }
  7829. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7830. }
  7831. file_put_contents($dest_file, $string);
  7832. }
  7833. }
  7834. foreach ($zip_files_abs as $file_path) {
  7835. if (empty($file_path)) { continue; }
  7836. //error_log(__LINE__.'checking existence of '.$main_path.$file_path.'', 0);
  7837. if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) { continue; }
  7838. //error_log(__LINE__.'getting document from '.$main_path.$file_path.' removing '.api_get_path(SYS_COURSE_PATH).$_course['path'].'/', 0);
  7839. $dest_file = $archive_path.$temp_dir_short.'/document/'.$file_path;
  7840. $this->create_path($dest_file);
  7841. //error_log('Created path '.api_get_path(SYS_ARCHIVE_PATH).$temp_dir_short.'/document/'.$file_path, 0);
  7842. //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);
  7843. //echo $main_path.$file_path.' - '.$dest_file.'<br />';
  7844. copy($main_path.$file_path, $dest_file);
  7845. // Check if the file needs a link update.
  7846. if (in_array($file_path, array_keys($link_updates))) {
  7847. $string = file_get_contents($dest_file);
  7848. unlink($dest_file);
  7849. foreach ($link_updates[$file_path] as $old_new) {
  7850. //error_log('Replacing '.$old_new['orig'].' by '.$old_new['dest'].' in '.$file_path, 0);
  7851. // This is an ugly hack that allows .flv files to be found by the flv player that
  7852. // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
  7853. // to find the flv to play in document/main/, so we replace main/ in the flv path by
  7854. // ../../.. to return from inc/lib/flv_player to the document/main path.
  7855. if (substr($old_new['dest'], -3) == 'flv' && substr($old_new['dest'], 0, 5) == 'main/') {
  7856. $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
  7857. }
  7858. $string = str_replace($old_new['orig'], $old_new['dest'], $string);
  7859. }
  7860. file_put_contents($dest_file, $string);
  7861. }
  7862. }
  7863. if (is_array($links_to_create)) {
  7864. foreach ($links_to_create as $file => $link) {
  7865. $file_content = '<!DOCTYPE html
  7866. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7867. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7868. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7869. <head>
  7870. <title>'.$link['title'].'</title>
  7871. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7872. </head>
  7873. <body dir="'.api_get_text_direction().'">
  7874. <div style="text-align:center"><a href="'.$link['url'].'">'.$link['title'].'</a></div>
  7875. </body>
  7876. </html>';
  7877. file_put_contents($archive_path.$temp_dir_short.'/'.$file, $file_content);
  7878. }
  7879. }
  7880. // Add non exportable message explanation.
  7881. $lang_not_exportable = get_lang('ThisItemIsNotExportable');
  7882. $file_content = '<!DOCTYPE html
  7883. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  7884. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7885. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">
  7886. <head>
  7887. <title>'.$lang_not_exportable.'</title>
  7888. <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
  7889. </head>
  7890. <body dir="'.api_get_text_direction().'">
  7891. ';
  7892. $file_content .=
  7893. <<<EOD
  7894. <style>
  7895. .error-message {
  7896. font-family: arial, verdana, helvetica, sans-serif;
  7897. border-width: 1px;
  7898. border-style: solid;
  7899. left: 50%;
  7900. margin: 10px auto;
  7901. min-height: 30px;
  7902. padding: 5px;
  7903. right: 50%;
  7904. width: 500px;
  7905. background-color: #FFD1D1;
  7906. border-color: #FF0000;
  7907. color: #000;
  7908. }
  7909. </style>
  7910. <body>
  7911. <div class="error-message">
  7912. $lang_not_exportable
  7913. </div>
  7914. </body>
  7915. </html>
  7916. EOD;
  7917. if (!is_dir($archive_path.$temp_dir_short.'/document')) {
  7918. @mkdir($archive_path.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
  7919. }
  7920. file_put_contents($archive_path.$temp_dir_short.'/document/non_exportable.html', $file_content);
  7921. // Add the extra files that go along with a SCORM package.
  7922. $main_code_path = api_get_path(SYS_CODE_PATH).'newscorm/packaging/';
  7923. $extra_files = scandir($main_code_path);
  7924. foreach ($extra_files as $extra_file) {
  7925. if (strpos($extra_file, '.') === 0)
  7926. continue;
  7927. else {
  7928. $dest_file = $archive_path . $temp_dir_short . '/' . $extra_file;
  7929. $this->create_path($dest_file);
  7930. copy($main_code_path.$extra_file, $dest_file);
  7931. }
  7932. }
  7933. // Finalize the imsmanifest structure, add to the zip, then return the zip.
  7934. $manifest = @$xmldoc->saveXML();
  7935. $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
  7936. file_put_contents($archive_path.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
  7937. $zip_folder->add($archive_path.'/'.$temp_dir_short, PCLZIP_OPT_REMOVE_PATH, $archive_path.'/'.$temp_dir_short.'/');
  7938. // Clean possible temporary files.
  7939. foreach ($files_cleanup as $file) {
  7940. $res = unlink($file);
  7941. if ($res === false) { error_log('Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__, 0); }
  7942. }
  7943. // Send file to client.
  7944. //$name = 'scorm_export_'.$this->lp_id.'.zip';
  7945. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  7946. $name = replace_dangerous_char($this->get_name()).'.zip';
  7947. DocumentManager::file_send_for_download($temp_zip_file, true, $name);
  7948. }
  7949. public function scorm_export_to_pdf($lp_id) {
  7950. $lp_id = intval($lp_id);
  7951. $files_to_export = array();
  7952. $course_data = api_get_course_info($this->cc);
  7953. if (!empty($course_data)) {
  7954. $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
  7955. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  7956. $list = $this->get_flat_ordered_items_list($lp_id);
  7957. foreach($list as $item_id) {
  7958. $item = $this->items[$item_id];
  7959. //Getting documents from a LP with chamilo documents
  7960. switch ($item->type) {
  7961. case 'document':
  7962. $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
  7963. $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
  7964. if (file_exists($file_path)) {
  7965. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7966. }
  7967. break;
  7968. case 'sco':
  7969. $file_path = $scorm_path.'/'.$item->path;
  7970. if (file_exists($file_path)) {
  7971. $files_to_export[] = array('title'=>$item->get_title(),'path'=>$file_path);
  7972. }
  7973. break;
  7974. case 'dokeos_chapter':
  7975. case 'dir':
  7976. case 'chapter':
  7977. $files_to_export[] = array('title'=>$item->get_title(),'path'=>null);
  7978. break;
  7979. }
  7980. }
  7981. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  7982. $pdf = new PDF();
  7983. $result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
  7984. return $result;
  7985. }
  7986. return false;
  7987. }
  7988. /**
  7989. * Temp function to be moved in main_api or the best place around for this. Creates a file path
  7990. * if it doesn't exist
  7991. */
  7992. public function create_path($path) {
  7993. $path_bits = split('/', dirname($path));
  7994. // IS_WINDOWS_OS has been defined in main_api.lib.php
  7995. $path_built = IS_WINDOWS_OS ? '' : '/';
  7996. foreach ($path_bits as $bit) {
  7997. if (!empty ($bit)) {
  7998. $new_path = $path_built . $bit;
  7999. if (is_dir($new_path)) {
  8000. $path_built = $new_path . '/';
  8001. } else {
  8002. mkdir($new_path, api_get_permissions_for_new_directories());
  8003. $path_built = $new_path . '/';
  8004. }
  8005. }
  8006. }
  8007. }
  8008. /**
  8009. * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
  8010. * @return boolean The results of the unlink function, or false if there was no image to start with
  8011. */
  8012. public function delete_lp_image() {
  8013. $img = $this->get_preview_image();
  8014. if ($img != '') {
  8015. $del_file = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $img;
  8016. $this->set_preview_image('');
  8017. return @ unlink($del_file);
  8018. } else {
  8019. return false;
  8020. }
  8021. }
  8022. /**
  8023. * Uploads an author image to the upload/learning_path/images directory
  8024. * @param array The image array, coming from the $_FILES superglobal
  8025. * @return boolean True on success, false on error
  8026. */
  8027. public function upload_image($image_array) {
  8028. $image_moved = false;
  8029. if (!empty ($image_array['name'])) {
  8030. $upload_ok = process_uploaded_file($image_array);
  8031. $has_attachment = true;
  8032. } else {
  8033. $image_moved = true;
  8034. }
  8035. if ($upload_ok) {
  8036. if ($has_attachment) {
  8037. $courseDir = api_get_course_path() . '/upload/learning_path/images';
  8038. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  8039. $updir = $sys_course_path . $courseDir;
  8040. // Try to add an extension to the file if it hasn't one.
  8041. $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
  8042. if (!filter_extension($new_file_name)) {
  8043. //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  8044. $image_moved = false;
  8045. } else {
  8046. $file_extension = explode('.', $image_array['name']);
  8047. $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
  8048. $new_file_name = uniqid('') . '.' . $file_extension;
  8049. $new_path = $updir . '/' . $new_file_name;
  8050. // Resize the image.
  8051. $temp = new Image($image_array['tmp_name']);
  8052. $picture_infos = $temp->get_image_info();
  8053. if ($picture_infos['width'] > 104) {
  8054. $thumbwidth = 104;
  8055. } else {
  8056. $thumbwidth = $picture_infos['width'];
  8057. }
  8058. if ($picture_infos['height'] > 96) {
  8059. $new_height = 96;
  8060. } else {
  8061. $new_height = $picture_infos['height'];
  8062. }
  8063. $temp->resize($thumbwidth, $new_height, 0);
  8064. $result = $temp->send_image($new_path);
  8065. // Storing the image filename.
  8066. if ($result) {
  8067. $image_moved = true;
  8068. $this->set_preview_image($new_file_name);
  8069. return true;
  8070. }
  8071. }
  8072. }
  8073. }
  8074. return false;
  8075. }
  8076. public function set_autolunch($lp_id, $status) {
  8077. $course_id = api_get_course_int_id();
  8078. $lp_id = intval($lp_id);
  8079. $status = intval($status);
  8080. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  8081. //Setting everything to autolunch = 0
  8082. $attributes['autolunch'] = 0;
  8083. $where = array('session_id = ? AND c_id = ? '=> array(api_get_session_id(), $course_id));
  8084. Database::update($lp_table, $attributes,$where);
  8085. if ($status == 1) {
  8086. //Setting my lp_id to autolunch = 1
  8087. $attributes['autolunch'] = 1;
  8088. $where = array('id = ? AND session_id = ? AND c_id = ?'=> array($lp_id, api_get_session_id(), $course_id));
  8089. Database::update($lp_table, $attributes, $where );
  8090. }
  8091. }
  8092. /**
  8093. * Gets previous_item_id for the next element of the lp_item table
  8094. * @author Isaac flores paz
  8095. * @return integer Previous item ID
  8096. */
  8097. function select_previous_item_id() {
  8098. $course_id = api_get_course_int_id();
  8099. if ($this->debug > 0) {
  8100. error_log('New LP - In learnpath::select_previous_item_id()', 0);
  8101. }
  8102. $table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  8103. // Get the max order of the items
  8104. $sql_max_order = "SELECT max(display_order) AS display_order FROM $table_lp_item WHERE c_id = ".$course_id." AND lp_id = '" . $this->lp_id . "'";
  8105. $rs_max_order = Database::query($sql_max_order);
  8106. $row_max_order = Database::fetch_object($rs_max_order);
  8107. $max_order = $row_max_order->display_order;
  8108. // Get the previous item ID
  8109. $sql_max = "SELECT id as previous FROM $table_lp_item WHERE c_id = ".$course_id." AND lp_id = '" . $this->lp_id . "' AND display_order = '".$max_order."' ";
  8110. $rs_max = Database::query($sql_max, __FILE__, __LINE__);
  8111. $row_max = Database::fetch_object($rs_max);
  8112. // Return the previous item ID
  8113. return $row_max->previous;
  8114. }
  8115. }
  8116. if (!function_exists('trim_value')) {
  8117. function trim_value(& $value) {
  8118. $value = trim($value);
  8119. }
  8120. }