12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899 |
- <?php
- define('REQUIRED_PHP_VERSION', '5.3');
- define('REQUIRED_MIN_MEMORY_LIMIT', '32');
- define('REQUIRED_MIN_UPLOAD_MAX_FILESIZE', '10');
- define('REQUIRED_MIN_POST_MAX_SIZE', '10');
- use \ChamiloSession as Session;
- define('COURSEMANAGER', 1);
- define('SESSIONADMIN', 3);
- define('DRH', 4);
- define('STUDENT', 5);
- define('ANONYMOUS', 6);
- define('COURSEMANAGERLOWSECURITY', 10);
- define('TEACHER', 1);
- define('PLATFORM_ADMIN', 11);
- define('SESSION_COURSE_COACH', 12);
- define('SESSION_GENERAL_COACH', 13);
- define('COURSE_STUDENT', 14);
- define('SESSION_STUDENT', 15);
- define('COURSE_TUTOR', 16);
- $_status_list[COURSEMANAGER] = 'teacher';
- $_status_list[SESSIONADMIN] = 'session_admin';
- $_status_list[DRH] = 'drh';
- $_status_list[STUDENT] = 'user';
- $_status_list[ANONYMOUS] = 'anonymous';
- define('COURSE_VISIBILITY_CLOSED', 0);
- define('COURSE_VISIBILITY_REGISTERED', 1);
- define('COURSE_VISIBILITY_OPEN_PLATFORM', 2);
- define('COURSE_VISIBILITY_OPEN_WORLD', 3);
- define('SESSION_VISIBLE_READ_ONLY', 1);
- define('SESSION_VISIBLE', 2);
- define('SESSION_INVISIBLE', 3);
- define('SESSION_AVAILABLE', 4);
- define('SUBSCRIBE_ALLOWED', 1);
- define('SUBSCRIBE_NOT_ALLOWED', 0);
- define('UNSUBSCRIBE_ALLOWED', 1);
- define('UNSUBSCRIBE_NOT_ALLOWED', 0);
- define('TOOL_DOCUMENT','document');
- define('TOOL_THUMBNAIL', 'thumbnail');
- define('TOOL_HOTPOTATOES', 'hotpotatoes');
- define('TOOL_CALENDAR_EVENT', 'calendar_event');
- define('TOOL_LINK', 'link');
- define('TOOL_COURSE_DESCRIPTION', 'course_description');
- define('TOOL_SEARCH', 'search');
- define('TOOL_LEARNPATH', 'learnpath');
- define('TOOL_ANNOUNCEMENT', 'announcement');
- define('TOOL_FORUM', 'forum');
- define('TOOL_FORUM_CATEGORY','forum_category');
- define('TOOL_FORUM_THREAD','forum_thread');
- define('TOOL_FORUM_POST','forum_post');
- define('TOOL_FORUM_ATTACH','forum_attachment');
- define('TOOL_FORUM_THREAD_QUALIFY','forum_thread_qualify');
- define('TOOL_THREAD', 'thread');
- define('TOOL_POST', 'post');
- define('TOOL_DROPBOX', 'dropbox');
- define('TOOL_QUIZ', 'quiz');
- define('TOOL_USER', 'user');
- define('TOOL_GROUP', 'group');
- define('TOOL_BLOGS', 'blog_management');
- define('TOOL_CHAT', 'chat');
- define('TOOL_CONFERENCE', 'conference');
- define('TOOL_STUDENTPUBLICATION', 'student_publication');
- define('TOOL_TRACKING', 'tracking');
- define('TOOL_HOMEPAGE_LINK', 'homepage_link');
- define('TOOL_COURSE_SETTING', 'course_setting');
- define('TOOL_BACKUP', 'backup');
- define('TOOL_COPY_COURSE_CONTENT', 'copy_course_content');
- define('TOOL_RECYCLE_COURSE', 'recycle_course');
- define('TOOL_COURSE_HOMEPAGE', 'course_homepage');
- define('TOOL_COURSE_RIGHTS_OVERVIEW', 'course_rights');
- define('TOOL_UPLOAD','file_upload');
- define('TOOL_COURSE_MAINTENANCE','course_maintenance');
- define('TOOL_VISIO','visio');
- define('TOOL_VISIO_CONFERENCE','visio_conference');
- define('TOOL_VISIO_CLASSROOM','visio_classroom');
- define('TOOL_SURVEY','survey');
- define('TOOL_WIKI','wiki');
- define('TOOL_GLOSSARY','glossary');
- define('TOOL_GRADEBOOK','gradebook');
- define('TOOL_NOTEBOOK','notebook');
- define('TOOL_ATTENDANCE','attendance');
- define('TOOL_COURSE_PROGRESS','course_progress');
- define('SECTION_CAMPUS', 'mycampus');
- define('SECTION_COURSES', 'mycourses');
- define('SECTION_MYPROFILE', 'myprofile');
- define('SECTION_MYAGENDA', 'myagenda');
- define('SECTION_COURSE_ADMIN', 'course_admin');
- define('SECTION_PLATFORM_ADMIN', 'platform_admin');
- define('SECTION_MYGRADEBOOK', 'mygradebook');
- define('SECTION_TRACKING','session_my_space');
- define('SECTION_SOCIAL', 'social');
- define('SECTION_DASHBOARD', 'dashboard');
- define('SECTION_REPORTS', 'reports');
- define('SECTION_GLOBAL', 'global');
- define('PLATFORM_AUTH_SOURCE', 'platform');
- define('CAS_AUTH_SOURCE', 'cas');
- define('LDAP_AUTH_SOURCE', 'extldap');
- define('DIR_HOTPOTATOES','/HotPotatoes_files');
- define('LOG_COURSE_DELETE', 'course_deleted');
- define('LOG_COURSE_CREATE', 'course_created');
- define('LOG_USER_CREATE', 'user_created');
- define('LOG_USER_UPDATED', 'user_updated');
- define('LOG_USER_DELETE', 'user_deleted');
- define('LOG_USER_ACTIVATED', 'user_activated');
- define('LOG_USER_DEACTIVATED', 'user_deactivated');
- define('LOG_SESSION_CREATE', 'session_created');
- define('LOG_SESSION_DELETE', 'session_deleted');
- define('LOG_SESSION_CATEGORY_CREATE', 'session_category_created');
- define('LOG_SESSION_CATEGORY_DELETE', 'session_category_deleted');
- define('LOG_CONFIGURATION_SETTINGS_CHANGE', 'settings_changed');
- define('LOG_PLATFORM_LANGUAGE_CHANGE', 'platform_language_changed');
- define('LOG_SUBSCRIBE_USER_TO_COURSE', 'user_subscribed');
- define('LOG_UNSUBSCRIBE_USER_FROM_COURSE', 'user_unsubscribed');
- define('LOG_ATTEMPTED_FORCED_LOGIN', 'attempted_forced_login');
- define('LOG_HOMEPAGE_CHANGED', 'homepage_changed');
- define('LOG_PROMOTION_CREATE', 'promotion_created');
- define('LOG_PROMOTION_DELETE', 'promotion_deleted');
- define('LOG_CAREER_CREATE', 'career_created');
- define('LOG_CAREER_DELETE', 'career_deleted');
- define('LOG_COURSE_CODE', 'course_code');
- define('LOG_USER_ID', 'user_id');
- define('LOG_USER_OBJECT', 'user_object');
- define('LOG_SESSION_ID', 'session_id');
- define('LOG_SESSION_CATEGORY_ID', 'session_category_id');
- define('LOG_CONFIGURATION_SETTINGS_CATEGORY', 'settings_category');
- define('LOG_CONFIGURATION_SETTINGS_VARIABLE', 'settings_variable');
- define('LOG_PLATFORM_LANGUAGE', 'default_platform_language');
- define('LOG_CAREER_ID', 'career_id');
- define('LOG_PROMOTION_ID', 'promotion_id');
- define('LOG_GRADEBOOK_LOCKED', 'gradebook_locked');
- define('LOG_GRADEBOOK_UNLOCKED', 'gradebook_unlocked');
- define('LOG_GRADEBOOK_ID', 'gradebook_id');
- define('USERNAME_PURIFIER', '/[^0-9A-Za-z_\.]/');
- define('USERNAME_PURIFIER_MAIL', '/[^0-9A-Za-z_\.@]/');
- define('USERNAME_PURIFIER_SHALLOW', '/\s/');
- $php_version = (float) PHP_VERSION;
- define('IS_PHP_52', !((float)$php_version < 5.2));
- define('IS_PHP_53', !((float)$php_version < 5.3));
- define('IS_PHP_SUP_OR_EQ_53', ($php_version >= 5.3));
- define('IS_PHP_SUP_OR_EQ_52', ($php_version >= 5.2 && !IS_PHP_53));
- define('IS_PHP_SUP_OR_EQ_51', ($php_version >= 5.1 && !IS_PHP_52 && !IS_PHP_53));
- define('IS_WINDOWS_OS', api_is_windows_os());
- define('INTL_INSTALLED', function_exists('intl_get_error_code'));
- define('ICONV_INSTALLED', function_exists('iconv'));
- define('MBSTRING_INSTALLED', function_exists('mb_strlen'));
- define('DATE_TIME_INSTALLED', class_exists('DateTime'));
- define('REPEATED_SLASHES_PURIFIER', '/\/{2,}/');
- define('VALID_WEB_PATH', '/https?:\/\/[^\/]*(\/.*)?/i');
- define('VALID_WEB_SERVER_BASE', '/https?:\/\/[^\/]*/i');
- define('WEB_PATH', 'WEB_PATH');
- define('WEB_PUBLIC_PATH', 'WEB_PUBLIC_PATH');
- define('SYS_PATH', 'SYS_PATH');
- define('SYS_PATH_APP', 'SYS_PATH_APP');
- define('SYS_DATA_PATH', 'SYS_DATA_PATH');
- define('SYS_LOG_PATH', 'SYS_LOG_PATH');
- define('SYS_CONFIG_PATH', 'SYS_CONFIG_PATH');
- define('REL_PATH', 'REL_PATH');
- define('WEB_SERVER_ROOT_PATH', 'WEB_SERVER_ROOT_PATH');
- define('SYS_SERVER_ROOT_PATH', 'SYS_SERVER_ROOT_PATH');
- define('WEB_COURSE_PATH', 'WEB_COURSE_PATH');
- define('SYS_COURSE_PATH', 'SYS_COURSE_PATH');
- define('REL_COURSE_PATH', 'REL_COURSE_PATH');
- define('REL_CODE_PATH', 'REL_CODE_PATH');
- define('WEB_CODE_PATH', 'WEB_CODE_PATH');
- define('SYS_CODE_PATH', 'SYS_CODE_PATH');
- define('SYS_CSS_PATH', 'SYS_CSS_PATH');
- define('SYS_LANG_PATH', 'SYS_LANG_PATH');
- define('WEB_IMG_PATH', 'WEB_IMG_PATH');
- define('WEB_CSS_PATH', 'WEB_CSS_PATH');
- define('SYS_PLUGIN_PATH', 'SYS_PLUGIN_PATH');
- define('PLUGIN_PATH', 'SYS_PLUGIN_PATH');
- define('WEB_PLUGIN_PATH', 'WEB_PLUGIN_PATH');
- define('SYS_ARCHIVE_PATH', 'SYS_ARCHIVE_PATH');
- define('WEB_ARCHIVE_PATH', 'WEB_ARCHIVE_PATH');
- define('INCLUDE_PATH', 'INCLUDE_PATH');
- define('LIBRARY_PATH', 'LIBRARY_PATH');
- define('CONFIGURATION_PATH', 'CONFIGURATION_PATH');
- define('WEB_LIBRARY_PATH', 'WEB_LIBRARY_PATH');
- define('WEB_AJAX_PATH', 'WEB_AJAX_PATH');
- define('SYS_TEST_PATH', 'SYS_TEST_PATH');
- define('WEB_TEMPLATE_PATH', 'WEB_TEMPLATE_PATH');
- define('SYS_TEMPLATE_PATH', 'SYS_TEMPLATE_PATH');
- define('TO_WEB', 'TO_WEB');
- define('TO_SYS', 'TO_SYS');
- define('TO_REL', 'TO_REL');
- define('FLASH_PLAYER_AUDIO', '{FLASH_PLAYER_AUDIO}');
- define('FLASH_PLAYER_VIDEO', '{FLASH_PLAYER_VIDEO}');
- define('SCRIPT_SWFOBJECT', '{SCRIPT_SWFOBJECT}');
- define('SCRIPT_ASCIIMATHML', '{SCRIPT_ASCIIMATHML}');
- define('DRAWING_ASCIISVG', '{DRAWING_ASCIISVG}');
- define('COURSE_RELATION_TYPE_RRHH', 1);
- define('SESSION_RELATION_TYPE_RRHH', 1);
- define('USER_IMAGE_SIZE_ORIGINAL', 1);
- define('USER_IMAGE_SIZE_BIG', 2);
- define('USER_IMAGE_SIZE_MEDIUM', 3);
- define('USER_IMAGE_SIZE_SMALL', 4);
- define('USER_UNKNOW', 0);
- define('USER_RELATION_TYPE_UNKNOW', 1);
- define('USER_RELATION_TYPE_PARENT', 2);
- define('USER_RELATION_TYPE_FRIEND', 3);
- define('USER_RELATION_TYPE_GOODFRIEND', 4);
- define('USER_RELATION_TYPE_ENEMY', 5);
- define('USER_RELATION_TYPE_DELETED', 6);
- define('USER_RELATION_TYPE_RRHH', 7);
- define('LINK_EXERCISE', 1);
- define('LINK_DROPBOX', 2);
- define('LINK_STUDENTPUBLICATION', 3);
- define('LINK_LEARNPATH', 4);
- define('LINK_FORUM_THREAD', 5);
- define('LINK_ATTENDANCE', 7);
- define('LINK_SURVEY', 8);
- define('COURSE_REQUEST_PENDING', 0);
- define('COURSE_REQUEST_ACCEPTED', 1);
- define('COURSE_REQUEST_REJECTED', 2);
- define('SHORTCUTS_HORIZONTAL', 0);
- define('SHORTCUTS_VERTICAL', 1);
- define ('CAREER_STATUS_ACTIVE', 1);
- define ('CAREER_STATUS_INACTIVE',0);
- define('MAX_LENGTH_BREADCRUMB', 100);
- define('ICON_SIZE_TINY', 16);
- define('ICON_SIZE_SMALL', 22);
- define('ICON_SIZE_MEDIUM', 32);
- define('ICON_SIZE_LARGE', 48);
- define('ICON_SIZE_BIG', 64);
- define('ICON_SIZE_HUGE', 128);
- define('SHOW_TEXT_NEAR_ICONS', false);
- define ('EVENT_EMAIL_TEMPLATE_ACTIVE', 1);
- define ('EVENT_EMAIL_TEMPLATE_INACTIVE',0);
- define('GROUP_PERMISSION_OPEN' , '1');
- define('GROUP_PERMISSION_CLOSED', '2');
- define('GROUP_USER_PERMISSION_ADMIN' , '1');
- define('GROUP_USER_PERMISSION_READER', '2');
- define('GROUP_USER_PERMISSION_PENDING_INVITATION', '3');
- define('GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER', '4');
- define('GROUP_USER_PERMISSION_MODERATOR', '5');
- define('GROUP_USER_PERMISSION_ANONYMOUS' , '6');
- define('GROUP_USER_PERMISSION_HRM', '7');
- define('GROUP_IMAGE_SIZE_ORIGINAL', 1);
- define('GROUP_IMAGE_SIZE_BIG', 2);
- define('GROUP_IMAGE_SIZE_MEDIUM', 3);
- define('GROUP_IMAGE_SIZE_SMALL', 4);
- define('GROUP_TITLE_LENGTH', 50);
- define('MESSAGE_STATUS_NEW', '0');
- define('MESSAGE_STATUS_UNREAD', '1');
- define('MESSAGE_STATUS_DELETED', '3');
- define('MESSAGE_STATUS_OUTBOX', '4');
- define('MESSAGE_STATUS_INVITATION_PENDING', '5');
- define('MESSAGE_STATUS_INVITATION_ACCEPTED', '6');
- define('MESSAGE_STATUS_INVITATION_DENIED', '7');
- define('SESSION_LINK_TARGET', '_self');
- define('NO_HTML', 1);
- define('STUDENT_HTML', 2);
- define('TEACHER_HTML', 3);
- define('STUDENT_HTML_FULLPAGE', 4);
- define('TEACHER_HTML_FULLPAGE', 5);
- define('EXERCISE_NUMBER_OF_DECIMALS', 2);
- define('_PCRE_XML_ENCODING', '/<\?xml.*encoding=[\'"](.*?)[\'"].*\?>/m');
- define('SOCIAL_LEFT_PLUGIN', 1);
- define('SOCIAL_CENTER_PLUGIN', 2);
- define('SOCIAL_RIGHT_PLUGIN', 3);
- define('CUT_GROUP_NAME', 50);
- function api_get_path($path_type, $path = null) {
- static $paths = array(
- WEB_PATH => '',
- SYS_PATH => '',
- SYS_PATH_APP => 'app/',
- SYS_DATA_PATH => 'data/',
- SYS_CONFIG_PATH => 'config/',
- SYS_LOG_PATH => 'logs/',
- REL_PATH => '',
- WEB_SERVER_ROOT_PATH => '',
- SYS_SERVER_ROOT_PATH => '',
- WEB_COURSE_PATH => '',
- SYS_COURSE_PATH => '',
- REL_COURSE_PATH => '',
- REL_CODE_PATH => '',
- WEB_CODE_PATH => '',
- SYS_CODE_PATH => '',
- SYS_CSS_PATH => 'css/',
- SYS_LANG_PATH => 'lang/',
- WEB_IMG_PATH => 'img/',
- WEB_CSS_PATH => 'css/',
- SYS_PLUGIN_PATH => 'plugin/',
- WEB_PLUGIN_PATH => 'plugin/',
- SYS_ARCHIVE_PATH => 'temp/',
- WEB_ARCHIVE_PATH => 'temp/',
- INCLUDE_PATH => 'inc/',
- LIBRARY_PATH => 'inc/lib/',
- CONFIGURATION_PATH => 'inc/conf/',
- WEB_LIBRARY_PATH => 'inc/lib/',
- WEB_AJAX_PATH => 'inc/ajax/',
- SYS_TEST_PATH => 'tests/',
- WEB_TEMPLATE_PATH => 'template/',
- SYS_TEMPLATE_PATH => 'template/'
- );
- static $resource_paths = array(
- FLASH_PLAYER_AUDIO => 'inc/lib/mediaplayer/player.swf',
- FLASH_PLAYER_VIDEO => 'inc/lib/mediaplayer/player.swf',
- SCRIPT_SWFOBJECT => 'inc/lib/swfobject/swfobject.js',
- SCRIPT_ASCIIMATHML => 'inc/lib/javascript/asciimath/ASCIIMathML.js',
- DRAWING_ASCIISVG => 'inc/lib/javascript/asciimath/d.svg'
- );
- static $is_this_function_initialized;
- static $server_base_web;
- static $server_base_sys;
- static $root_web;
- static $root_sys;
- static $root_rel;
- static $code_folder;
- static $course_folder;
-
- global $_configuration;
-
- $root_web = isset($_configuration['root_web']) ? $_configuration['root_web'] : null;
-
- $root_sys = isset($_configuration['root_sys']) ? $_configuration['root_sys'] : realpath(dirname(__FILE__).'/../../../');
- $load_new_config = false;
-
- if ($path_type == WEB_PATH) {
- if (isset($_configuration['access_url']) && $_configuration['access_url'] != 1) {
-
- $url_info = api_get_access_url($_configuration['access_url']);
- $root_web = $url_info['active'] == 1 ? $url_info['url'] : $_configuration['root_web'];
- $load_new_config = true;
- }
- }
- if (!$is_this_function_initialized) {
-
- $root_rel = "/".basename($root_sys);
- $code_folder = 'main/';
-
- $course_folder = "courses/";
-
-
-
-
- if (empty($root_web)) {
-
- $pos = strpos(($requested_page_rel = api_get_self()), 'web/index');
- $pos_install = strpos(($requested_page_rel = api_get_self()), 'main/install');
- if ($pos_install) {
- $pos = $pos_install;
- }
-
- $root_rel = substr($requested_page_rel, 0, $pos);
-
- $server_protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
- $server_name =
- isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME']
- : (isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME']
- : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']
- : (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR']
- : 'localhost')));
- if (isset($_SERVER['SERVER_PORT']) && !strpos($server_name, ':')
- && (($server_protocol == 'http'
- && $_SERVER['SERVER_PORT'] != 80 ) || ($server_protocol == 'https' && $_SERVER['SERVER_PORT'] != 443 ))) {
- $server_name .= ":" . $_SERVER['SERVER_PORT'];
- }
- $root_web = $server_protocol.'://'.$server_name.$root_rel;
- $root_sys = str_replace('\\', '/', realpath(dirname(__FILE__).'/../../../')).'/';
- $code_folder = 'main/';
- $course_folder = 'courses/';
-
-
- }
-
- $root_web = api_add_trailing_slash($root_web);
- $root_sys = api_add_trailing_slash($root_sys);
- $root_rel = api_add_trailing_slash($root_rel);
- $code_folder = api_add_trailing_slash($code_folder);
- $course_folder = api_add_trailing_slash($course_folder);
-
- $server_base_web = preg_replace('@'.$root_rel.'$@', '', $root_web);
- $server_base_sys = preg_replace('@'.$root_rel.'$@', '', $root_sys);
-
- $paths[WEB_PATH] = $root_web;
- $paths[WEB_PUBLIC_PATH] = $root_web."web/";
- $paths[SYS_PATH] = $root_sys;
- $paths[SYS_PATH_APP] = $root_sys.'app/';
- $paths[SYS_DATA_PATH] = $root_sys.'data/';
- $paths[SYS_LOG_PATH] = $root_sys.'logs/';
- $paths[SYS_CONFIG_PATH] = $root_sys.'config/';
- $paths[REL_PATH] = $root_rel;
- $paths[WEB_SERVER_ROOT_PATH] = $server_base_web.'/';
- $paths[SYS_SERVER_ROOT_PATH] = $server_base_sys.'/';
- $paths[WEB_COURSE_PATH] = $root_web.$course_folder;
- $paths[SYS_COURSE_PATH] = $root_sys.$course_folder;
- $paths[REL_COURSE_PATH] = $root_rel.$course_folder;
- $paths[REL_CODE_PATH] = $root_rel.$code_folder;
- $paths[WEB_CODE_PATH] = $root_web.$code_folder;
- $paths[SYS_CODE_PATH] = $root_sys.$code_folder;
-
- $paths[SYS_LANG_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_LANG_PATH];
- $paths[SYS_PLUGIN_PATH] = $paths[SYS_PATH].$paths[SYS_PLUGIN_PATH];
- $paths[SYS_ARCHIVE_PATH] = $paths[SYS_PATH].$paths[SYS_ARCHIVE_PATH];
- $paths[SYS_TEST_PATH] = $paths[SYS_PATH].$paths[SYS_TEST_PATH];
- $paths[SYS_TEMPLATE_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_TEMPLATE_PATH];
- $paths[SYS_CSS_PATH] = $paths[SYS_CODE_PATH].$paths[SYS_CSS_PATH];
- $paths[WEB_CSS_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_CSS_PATH];
- $paths[WEB_IMG_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_IMG_PATH];
- $paths[WEB_LIBRARY_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_LIBRARY_PATH];
- $paths[WEB_AJAX_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_AJAX_PATH];
- $paths[WEB_PLUGIN_PATH] = $paths[WEB_PATH].$paths[WEB_PLUGIN_PATH];
- $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH].$paths[WEB_ARCHIVE_PATH];
- $paths[WEB_TEMPLATE_PATH] = $paths[WEB_CODE_PATH].$paths[WEB_TEMPLATE_PATH];
- $paths[INCLUDE_PATH] = $paths[SYS_CODE_PATH].$paths[INCLUDE_PATH];
- $paths[LIBRARY_PATH] = $paths[SYS_CODE_PATH].$paths[LIBRARY_PATH];
- $paths[CONFIGURATION_PATH] = $paths[SYS_CODE_PATH].$paths[CONFIGURATION_PATH];
- $is_this_function_initialized = true;
- } else {
- if ($load_new_config) {
-
-
- $web_paths = array(
- WEB_PATH => '',
- WEB_SERVER_ROOT_PATH => '',
- WEB_COURSE_PATH => '',
- WEB_CODE_PATH => '',
- WEB_IMG_PATH => 'img/',
- WEB_CSS_PATH => 'css/',
- WEB_PLUGIN_PATH => 'plugin/',
- WEB_ARCHIVE_PATH => 'archive/',
- WEB_LIBRARY_PATH => 'inc/lib/',
- WEB_AJAX_PATH => 'inc/ajax/',
- );
- $root_web = api_add_trailing_slash($root_web);
-
- $server_base_web = preg_replace('@'.$root_rel.'$@', '', $root_web);
-
- $paths[WEB_PATH] = $root_web;
- $paths[WEB_SERVER_ROOT_PATH] = $server_base_web.'/';
- $paths[WEB_COURSE_PATH] = $root_web.$course_folder;
- $paths[WEB_CODE_PATH] = $root_web.$code_folder;
- $paths[WEB_IMG_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_IMG_PATH];
- $paths[WEB_CSS_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_CSS_PATH];
- $paths[WEB_PLUGIN_PATH] = $paths[WEB_PATH].$web_paths[WEB_PLUGIN_PATH];
- $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH].$web_paths[WEB_ARCHIVE_PATH];
- $paths[WEB_LIBRARY_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_LIBRARY_PATH];
- $paths[WEB_AJAX_PATH] = $paths[WEB_CODE_PATH].$web_paths[WEB_AJAX_PATH];
- }
- }
-
- $path_type = trim($path_type);
- $path = trim($path);
- if (empty($path_type)) {
- return null;
- }
-
- if (isset($paths[$path_type])) {
- return $paths[$path_type];
- }
-
- if (isset($resource_paths[$path])) {
- switch ($path_type) {
- case TO_WEB:
- return $paths[WEB_CODE_PATH].$resource_paths[$path];
- case TO_SYS:
- return $paths[SYS_CODE_PATH].$resource_paths[$path];
- case TO_REL:
- return $paths[REL_CODE_PATH].$resource_paths[$path];
- default:
- return null;
- }
- }
-
- if (isset($paths[$path])) {
- $path = $paths[$path];
- }
-
-
- $path = str_replace('\\', '/', $path);
-
-
- if (($pos = strpos($path, '?')) !== false) {
- $path = substr($path, 0, $pos);
- }
-
- if (preg_match(VALID_WEB_PATH, $path)) {
-
-
-
-
-
-
-
- if (strpos($path, 'download.php') !== false) {
- $path = urldecode($path);
- if (preg_match('/(.*)main\/document\/download.php\?doc_url=\/(.*)&cDir=\/(.*)?/', $path, $matches)) {
- $sys_course_code =
- isset($_SESSION['_course']['sysCode'])
- ? $_SESSION['_course']['sysCode']
- : '{SYS_COURSE_CODE}';
- $path = $matches[1].'courses/'.$sys_course_code.'/document/'.str_replace('//', '/', $matches[3].'/'.$matches[2]);
- }
- }
-
- $path = preg_replace(VALID_WEB_SERVER_BASE, '/', $path);
- } elseif (strpos($path, $server_base_sys) === 0) {
- $path = preg_replace('@^'.$server_base_sys.'@', '', $path);
- } elseif (strpos($path, '/') === 0) {
-
-
- } else {
- return null;
- }
-
- $path = preg_replace(REPEATED_SLASHES_PURIFIER, '/', $path);
-
- switch ($path_type) {
- case TO_WEB:
- return $server_base_web.$path;
- case TO_SYS:
- return $server_base_sys.$path;
- case TO_REL:
- return $path;
- }
- return null;
- }
- function api_get_cdn_path($web_path) {
- global $_configuration;
- $web_root = api_get_path(WEB_PATH);
- $ext = substr($web_path,strrpos($web_path,'.'));
- if (isset($ext[2])) {
-
- if (!empty($_configuration['cdn_enable']) && !empty($ext)) {
- foreach ($_configuration['cdn'] as $host => $exts) {
- if (in_array($ext,$exts)) {
-
-
- return str_replace($web_root,$host.'/',$web_path);
- }
- }
- }
- }
- return $web_path;
- }
- function api_is_cas_activated() {
- return api_get_setting(cas_activate) == "true";
- }
- function api_is_ldap_activated() {
- global $extAuthSource;
- return is_array($extAuthSource[LDAP_AUTH_SOURCE]);
- }
- function api_is_facebook_auth_activated() {
- global $_configuration;
- return (isset($_configuration['facebook_auth']) && $_configuration['facebook_auth'] == 1);
- }
- function api_is_internal_path($path) {
- $path = str_replace('\\', '/', trim($path));
- if (empty($path)) {
- return false;
- }
- if (strpos($path, api_remove_trailing_slash(api_get_path(WEB_PATH))) === 0) {
- return true;
- }
- if (strpos($path, api_remove_trailing_slash(api_get_path(SYS_PATH))) === 0) {
- return true;
- }
- $server_base_web = api_remove_trailing_slash(api_get_path(REL_PATH));
- $server_base_web = empty($server_base_web) ? '/' : $server_base_web;
- if (strpos($path, $server_base_web) === 0) {
- return true;
- }
- return false;
- }
- function api_add_trailing_slash($path) {
- return substr($path, -1) == '/' ? $path : $path.'/';
- }
- function api_remove_trailing_slash($path) {
- return substr($path, -1) == '/' ? substr($path, 0, -1) : $path;
- }
- function api_valid_url($url, $absolute = false) {
- if ($absolute) {
- if (preg_match("
- /^ # Start at the beginning of the text
- (?:ftp|https?|feed):\/\/ # Look for ftp, http, https or feed schemes
- (?: # Userinfo (optional) which is typically
- (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)* # a username or a username and password
- (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@ # combination
- )?
- (?:
- (?:[a-z0-9\-\.]|%[0-9a-f]{2})+ # A domain name or a IPv4 address
- |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]) # or a well formed IPv6 address
- )
- (?::[0-9]+)? # Server port number (optional)
- (?:[\/|\?]
- (?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2}) # The path and query (optional)
- *)?
- $/xi", $url)) {
- return $url;
- }
- return false;
- } else {
- return preg_match("/^(?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})+$/i", $url) ? $url : false;
- }
- }
- function api_valid_email($address) {
-
- if (function_exists('filter_var')) {
- return filter_var($address, FILTER_VALIDATE_EMAIL);
- } else {
- return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address) ? $address : false;
- }
- }
- function api_protect_course_script($print_headers = false, $allow_session_admins = false, $allow_drh = false) {
- global $is_allowed_in_course;
- $is_visible = false;
- $course_info = api_get_course_info();
-
- if (empty($course_info)) {
- api_not_allowed($print_headers);
- }
- if (api_is_drh()) {
- return true;
- }
- if (api_is_platform_admin($allow_session_admins)) {
- return true;
- }
- if (isset($course_info) && isset($course_info['visibility'])) {
- switch ($course_info['visibility']) {
- default:
- case COURSE_VISIBILITY_CLOSED:
- if (api_get_user_id() && !api_is_anonymous() && (api_is_allowed_to_edit())) {
- $is_visible = true;
- }
- break;
- case COURSE_VISIBILITY_REGISTERED:
- if (api_get_user_id() && !api_is_anonymous() && $is_allowed_in_course) {
- $is_visible = true;
- }
- break;
- case COURSE_VISIBILITY_OPEN_PLATFORM:
- if (api_get_user_id() && !api_is_anonymous()) {
- $is_visible = true;
- }
- break;
- case COURSE_VISIBILITY_OPEN_WORLD:
- $is_visible = true;
- break;
- }
-
- if ($is_allowed_in_course == false & isset($course_info['registration_code']) && !empty($course_info['registration_code'])) {
- $is_visible = false;
- }
- }
-
- $session_id = api_get_session_id();
- if (!empty($session_id)) {
-
- if (!$is_allowed_in_course) {
- $is_visible = false;
- }
- }
- if (!$is_visible) {
- api_not_allowed($print_headers);
- return false;
- }
- return true;
- }
- function api_protect_admin_script($allow_sessions_admins = false) {
- if (!api_is_platform_admin($allow_sessions_admins)) {
- api_not_allowed(true);
- return false;
- }
- return true;
- }
- function api_block_anonymous_users($print_headers = true) {
- global $_user;
- if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'], true)) {
- api_not_allowed($print_headers);
- return false;
- }
- return true;
- }
- function api_get_navigator() {
- $navigator = 'Unknown';
- $version = 0;
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false) {
- $navigator = 'Opera';
- list (, $version) = explode('Opera', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
- $navigator = 'Internet Explorer';
- list (, $version) = explode('MSIE', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false) {
- $navigator = 'Chrome';
- list (, $version) = explode('Chrome', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false) {
- $navigator = 'Mozilla';
- list (, $version) = explode('; rv:', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape') !== false) {
- $navigator = 'Netscape';
- list (, $version) = explode('Netscape', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false) {
- $navigator = 'Konqueror';
- list (, $version) = explode('Konqueror', $_SERVER['HTTP_USER_AGENT']);
- } elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'applewebkit') !== false) {
- $navigator = 'AppleWebKit';
- list (, $version) = explode('Version/', $_SERVER['HTTP_USER_AGENT']);
- } elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) {
- $navigator = 'Safari';
- list (, $version) = explode('Version/', $_SERVER['HTTP_USER_AGENT']);
- }
- $version = str_replace('/', '', $version);
- if (strpos($version, '.') === false) {
- $version = number_format(doubleval($version), 1);
- }
- $return_array = array ('name' => $navigator, 'version' => $version);
- return $return_array;
- }
- function api_is_self_registration_allowed() {
- return isset($GLOBALS['allowSelfReg']) ? $GLOBALS['allowSelfReg'] : false;
- }
- function api_get_user_id() {
- return empty($GLOBALS['_user']['user_id']) ? 0 : intval($GLOBALS['_user']['user_id']);
- }
- function api_get_user_courses($userid, $fetch_session = true) {
- if ($userid != strval(intval($userid))) { return array(); }
- $t_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $t_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $t_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $t_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
- $t_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $sql_select_courses = "SELECT cc.code code, cc.db_name db, cc.directory dir, cu.status status
- FROM $t_course cc,
- $t_course_user cu
- WHERE cc.code = cu.course_code
- AND cu.user_id = '".$userid."' AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH." ";
- $result = Database::query($sql_select_courses);
- if ($result === false) { return array(); }
- while ($row = Database::fetch_array($result)) {
-
- $courses[] = $row;
- }
- return $courses;
- }
- function _api_format_user($user, $add_password = false) {
- $result = array();
-
- $firstname = $lastname = null;
- if (isset($user['firstname']) && isset($user['lastname'])) {
- $firstname = $user['firstname'];
- $lastname = $user['lastname'];
- } elseif (isset($user['firstName']) && isset($user['lastName'])) {
- $firstname = $user['firstName'];
- $lastname = $user['lastName'];
- }
- $result['phone']= $user['phone'];
- $result['complete_name'] = api_get_person_name($firstname, $lastname);
- $result['complete_name_with_username'] = $result['complete_name'];
- if (!empty($user['username'])) {
- $result['complete_name_with_username'] = $result['complete_name'].' ('.$user['username'].')';
- }
- $result['complete_name_login_as']= $result['complete_name'];
- if (!empty($user['username'])) {
- $result['complete_name_login_as'] = $result['complete_name'].' ('.sprintf(get_lang('LoginX'), $user['username']).')';
- }
- $result['firstname'] = $firstname;
- $result['lastname'] = $lastname;
-
- $result['firstName'] = $firstname;
- $result['lastName'] = $lastname;
- if (isset($user['email'])) {
- $result['mail'] = $user['email'];
- $result['email'] = $user['email'];
- } else {
- $result['mail'] = $user['mail'];
- $result['email'] = $user['mail'];
- }
- $user_id = intval($user['user_id']);
- $result['picture_uri'] = $user['picture_uri'];
- $result['user_id'] = $user_id;
- $result['official_code'] = $user['official_code'];
- $result['status'] = $user['status'];
- $result['auth_source'] = $user['auth_source'];
- $result['active'] = $user['active'];
- if (isset($user['username'])) {
- $result['username'] = $user['username'];
- }
- $result['theme'] = $user['theme'];
- $result['language'] = $user['language'];
- if (!isset($user['lastLogin']) && !isset($user['last_login'])) {
- $timestamp = Tracking::get_last_connection_date($result['user_id'], false, true);
-
-
- $last_login = date('Y-m-d H:i:s', $timestamp);
- } else {
- if (isset($user['lastLogin'])) {
- $last_login = $user['lastLogin'];
- } else {
- $last_login = $user['last_login'];
- }
- }
- $result['last_login'] = $last_login;
-
- $result['lastLogin'] = $last_login;
-
- $picture_filename = trim($user['picture_uri']);
- $avatar = api_get_path(WEB_CODE_PATH).'img/unknown.jpg';
- $avatar_small = api_get_path(WEB_CODE_PATH).'img/unknown_22.jpg';
- $avatar_sys_path = api_get_path(SYS_CODE_PATH).'img/unknown.jpg';
- $dir = 'upload/users/'.$user_id.'/';
-
- if (!empty($picture_filename)) {
- if (api_get_setting('split_users_upload_directory') === 'true') {
- $dir = 'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/';
- }
- }
- $image_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename;
- if (file_exists($image_sys_path) && !is_dir($image_sys_path)) {
- $avatar = api_get_path(WEB_CODE_PATH).$dir.$picture_filename;
- $avatar_small = api_get_path(WEB_CODE_PATH).$dir.'small_'.$picture_filename;
- $avatar_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename;
- }
- $result['avatar'] = $avatar;
- $result['avatar_sys_path'] = $avatar_sys_path;
- $result['avatar_small'] = $avatar_small;
- if (isset($user['user_is_online'])) {
- $result['user_is_online'] = $user['user_is_online'] == true ? 1 : 0;
- }
- if (isset($user['user_is_online_in_chat'])) {
- $result['user_is_online_in_chat'] = intval($user['user_is_online_in_chat']);
- }
- if ($add_password) {
- $result['password'] = $user['password'];
- }
- return $result;
- }
- function api_get_user_info($user_id = '', $check_if_user_is_online = false, $show_password = false, $add_extra_values = false) {
- if (empty($user_id)) {
- global $_user;
- return _api_format_user($_user);
- }
- $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_USER)." WHERE user_id='".Database::escape_string($user_id)."'";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
- $result_array = Database::fetch_array($result);
- if ($check_if_user_is_online) {
- $use_status_in_platform = Online::user_is_online($user_id);
- $result_array['user_is_online'] = $use_status_in_platform;
- $user_online_in_chat = 0;
- if ($use_status_in_platform) {
- $user_status = UserManager::get_extra_user_data_by_field($user_id, 'user_chat_status', false, true);
- if (intval($user_status['user_chat_status']) == 1) {
- $user_online_in_chat = 1;
- }
- }
- $result_array['user_is_online_in_chat'] = $user_online_in_chat;
- }
- $user = _api_format_user($result_array, $show_password);
- if ($add_extra_values) {
- $extra_field_values = new ExtraField('user');
- $user['extra_fields'] = $extra_field_values->get_handler_extra_data($user_id);
- }
- return $user;
- }
- return false;
- }
- function api_get_user_info_from_username($username = '') {
- if (empty($username)) { return false; }
- $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_USER)." WHERE username='".Database::escape_string($username)."'";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
- $result_array = Database::fetch_array($result);
- return _api_format_user($result_array);
- }
- return false;
- }
- function api_get_course_id() {
- return isset($GLOBALS['_cid']) ? $GLOBALS['_cid'] : null;
- }
- function api_get_real_course_id() {
- return isset($_SESSION['_real_cid']) ? intval($_SESSION['_real_cid']) : 0;
- }
- function api_get_course_int_id() {
- return isset($_SESSION['_real_cid']) ? intval($_SESSION['_real_cid']) : 0;
- }
- function api_get_course_path($course_code = null) {
- $info = !empty($course_code) ? api_get_course_info($course_code) : api_get_course_info();
- return $info['path'];
- }
- function api_get_course_setting($setting_name, $course_code = null) {
- $course_info = api_get_course_info($course_code);
- $table = Database::get_course_table(TABLE_COURSE_SETTING);
- $setting_name = Database::escape_string($setting_name);
- if (!empty($course_info['real_id']) && !empty($setting_name)) {
- $sql = "SELECT value FROM $table WHERE c_id = {$course_info['real_id']} AND variable = '$setting_name'";
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- return $row['value'];
- }
- }
- return -1;
- }
- function api_get_anonymous_id() {
- $table = Database::get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT user_id FROM $table WHERE status = 6";
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- return $row['user_id'];
- }
-
- return 0;
- }
- function api_get_cidreq($add_session_id = true, $add_group_id = true) {
- $url = empty($GLOBALS['_cid']) ? '' : 'cidReq='.htmlspecialchars($GLOBALS['_cid']);
- if ($add_session_id) {
- if (!empty($url)) {
- $url .= api_get_session_id() == 0 ? '&id_session=0' : '&id_session='.api_get_session_id();
- }
- }
- if ($add_group_id) {
- if (!empty($url)) {
- $url .= api_get_group_id() == 0 ? '&gidReq=0' : '&gidReq='.api_get_group_id();
- }
- }
- return $url;
- }
- function api_get_course_info($course_code = null, $add_extra_values = false) {
- if (!empty($course_code)) {
- $course_code = Database::escape_string($course_code);
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
- $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
- $sql = "SELECT course.*, course_category.code faCode, course_category.name faName
- FROM $course_table
- LEFT JOIN $course_cat_table
- ON course.category_code = course_category.code
- WHERE course.code = '$course_code'";
- $result = Database::query($sql);
- $_course = array();
- if (Database::num_rows($result) > 0) {
- $course_data = Database::fetch_array($result);
- if ($add_extra_values) {
- $extra_field_values = new ExtraField('course');
- $course_data['extra_fields'] = $extra_field_values->get_handler_extra_data($course_code);
- }
- $_course = api_format_course_array($course_data);
- }
- return $_course;
- }
- global $_course;
- if ($_course == '-1') {
- $_course = array();
- }
- return $_course;
- }
- function api_get_course_info_by_id($id = null, $add_extra_values = false) {
- if (!empty($id)) {
- $id = intval($id);
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
- $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
- $sql = "SELECT course.*, course_category.code faCode, course_category.name faName
- FROM $course_table
- LEFT JOIN $course_cat_table
- ON course.category_code = course_category.code
- WHERE course.id = $id";
- $result = Database::query($sql);
- $_course = array();
- if (Database::num_rows($result) > 0) {
- $course_data = Database::fetch_array($result);
- if ($add_extra_values) {
- $extra_field_values = new ExtraField('course');
- $course_data['extra_fields'] = $extra_field_values->get_handler_extra_data($course_data['code']);
- }
- $_course = api_format_course_array($course_data);
- }
- return $_course;
- }
-
- global $_course;
- if ($_course == '-1') $_course = array();
- return $_course;
- }
- function api_format_course_array($course_data) {
- global $_configuration;
- if (empty($course_data)) {
- return array();
- }
- $_course = array();
- $_course['id' ] = $course_data['code'];
- $_course['real_id' ] = $course_data['id'];
-
- $_course['code' ] = $course_data['code' ];
- $_course['name' ] = $course_data['title' ];
- $_course['title' ] = $course_data['title' ];
- $_course['official_code'] = $course_data['visual_code' ];
- $_course['visual_code'] = $course_data['visual_code' ];
- $_course['sysCode' ] = $course_data['code' ];
- $_course['path' ] = $course_data['directory' ];
- $_course['directory' ] = $course_data['directory' ];
-
- $_course['dbName' ] = $course_data['db_name' ];
- $_course['db_name' ] = $course_data['db_name' ];
-
- $_course['titular' ] = $course_data['tutor_name' ];
- $_course['language' ] = $course_data['course_language'];
- $_course['extLink' ]['url' ] = $course_data['department_url' ];
- $_course['extLink' ]['name'] = $course_data['department_name'];
- $_course['categoryCode' ] = $course_data['faCode' ];
- $_course['categoryName' ] = $course_data['faName' ];
- $_course['visibility' ] = $course_data['visibility' ];
- $_course['subscribe_allowed'] = $course_data['subscribe' ];
- $_course['subscribe'] = $course_data['subscribe'];
- $_course['unsubscribe'] = $course_data['unsubscribe' ];
- $_course['course_language'] = $course_data['course_language'];
- $_course['activate_legal'] = isset($course_data['activate_legal']) ? $course_data['activate_legal'] : false;;
- $_course['legal'] = $course_data['legal' ];
- $_course['show_score'] = $course_data['show_score'];
- $_course['department_name'] = $course_data['department_name'];
- $_course['department_url'] = $course_data['department_url' ];
-
- $_course['registration_code'] = !empty($course_data['registration_code']) ? sha1($course_data['registration_code']) : null;
- $_course['disk_quota'] = $course_data['disk_quota'];
- $_course['course_public_url'] = api_get_path(WEB_COURSE_PATH).$course_data['directory'].'/index.php';
- $_course['user_status_in_course'] = CourseManager::get_user_in_course_status(api_get_user_id(), $_course['code']);
- if (file_exists(api_get_path(SYS_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png')) {
- $url_image = api_get_path(WEB_COURSE_PATH).$course_data['directory'].'/course-pic85x85.png';
- } else {
- $url_image = api_get_path(WEB_IMG_PATH).'without_picture.png';
- }
- $_course['course_image'] = $url_image;
- return $_course;
- }
- function api_add_url_param($url, $param, $filter_xss = true) {
- if (empty($param)) {
- return $url;
- }
- if (strpos($url, '?') !== false) {
- if ($param[0] != '&') {
- $param = '&'.$param;
- }
- list (, $query_string) = explode('?', $url);
- $param_list1 = explode('&', $param);
- $param_list2 = explode('&', $query_string);
- $param_list1_keys = $param_list1_vals = array();
- foreach ($param_list1 as $key => $enreg) {
- list ($param_list1_keys[$key], $param_list1_vals[$key]) = explode('=', $enreg);
- }
- $param_list1 = array ('keys' => $param_list1_keys, 'vals' => $param_list1_vals);
- foreach ($param_list2 as $enreg) {
- $enreg = explode('=', $enreg);
- $key = array_search($enreg[0], $param_list1['keys']);
- if (!is_null($key) && !is_bool($key)) {
- $url = str_replace($enreg[0].'='.$enreg[1], $enreg[0].'='.$param_list1['vals'][$key], $url);
- $param = str_replace('&'.$enreg[0].'='.$param_list1['vals'][$key], '', $param);
- }
- }
- $url .= $param;
- } else {
- $url = $url.'?'.$param;
- }
- if ($filter_xss === true) {
- $url = Security::remove_XSS(urldecode($url));
- }
- return $url;
- }
- function api_generate_password($length = 8) {
- $characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
- if ($length < 2) {
- $length = 2;
- }
- $password = '';
- for ($i = 0; $i < $length; $i ++) {
- $password .= $characters[rand() % strlen($characters)];
- }
- return $password;
- }
- function api_check_password($password) {
- $password_length = api_strlen($password);
- if ($password_length < 5) {
- return false;
- }
- $password = api_strtolower($password);
- $letters = 0;
- $digits = 0;
- $consequent_characters = 0;
- $previous_character_code = 0;
- for ($i = 0; $i < $password_length; $i ++) {
- $current_character_code = api_ord(api_substr($password, $i, 1));
- if ($i && abs($current_character_code - $previous_character_code) <= 1) {
- $consequent_characters ++;
- if ($consequent_characters == 3) {
- return false;
- }
- } else {
- $consequent_characters = 1;
- }
- if ($current_character_code >= 97 && $current_character_code <= 122) {
- $letters ++;
- } elseif ($current_character_code >= 48 && $current_character_code <= 57) {
- $digits ++;
- } else {
- return false;
- }
- $previous_character_code = $current_character_code;
- }
- return ($letters >= 3 && $digits >= 2);
- }
- function api_clear_anonymous($db_check = false) {
- global $_user;
- if (api_is_anonymous($_user['user_id'], $db_check)) {
- unset($_user['user_id']);
- Session::erase('_uid');
- return true;
- }
- return false;
- }
- function get_status_from_code($status_code) {
- switch ($status_code) {
- case STUDENT:
- return get_lang('Student', '');
- case TEACHER:
- return get_lang('Teacher', '');
- case COURSEMANAGER:
- return get_lang('Manager', '');
- case SESSIONADMIN:
- return get_lang('SessionsAdmin', '');
- case DRH:
- return get_lang('Drh', '');
-
- case PLATFORM_ADMIN:
- return get_lang('Admin');
- case SESSION_COURSE_COACH:
- return get_lang('SessionCourseCoach');
- case SESSION_GENERAL_COACH:
- return get_lang('SessionGeneralCoach');
- case COURSE_STUDENT:
- return get_lang('StudentInCourse');
- case SESSION_STUDENT:
- return get_lang('StudentInSessionCourse');
- case COURSE_TUTOR:
- return get_lang('CourseTutor');
- }
- }
- $api_failureList = array();
- function api_set_failure($failure_type) {
- global $api_failureList;
- $api_failureList[] = $failure_type;
- return false;
- }
- function api_set_anonymous() {
- global $_user;
- if (!empty($_user['user_id'])) {
- return false;
- }
- $user_id = api_get_anonymous_id();
- if ($user_id == 0) {
- return false;
- }
- Session::erase('_user');
- $_user['user_id'] = $user_id;
- $_user['is_anonymous'] = true;
- Session::write('_user',$_user);
- $GLOBALS['_user'] = $_user;
- return true;
- }
- function api_get_last_failure() {
- global $api_failureList;
- return $api_failureList[count($api_failureList) - 1];
- }
- class api_failure {
-
-
- public $api_failureList = array();
-
- static function set_failure($failure_type) {
- global $api_failureList;
- $api_failureList[] = $failure_type;
- return false;
- }
-
- static function get_last_failure() {
- global $api_failureList;
- if (count($api_failureList) == 0) { return ''; }
- return $api_failureList[count($api_failureList) - 1];
- }
- }
- function api_get_session_id() {
- return empty($_SESSION['id_session']) ? 0 : intval($_SESSION['id_session']);
- }
- function api_get_group_id() {
- return empty($_SESSION['_gid']) ? 0 : intval($_SESSION['_gid']);
- }
- function api_get_session_name($session_id) {
- if (empty($session_id)) {
- $session_id = api_get_session_id();
- if (empty($session_id)) { return null; }
- }
- $t = Database::get_main_table(TABLE_MAIN_SESSION);
- $s = "SELECT name FROM $t WHERE id = ".(int)$session_id;
- $r = Database::query($s);
- $c = Database::num_rows($r);
- if ($c > 0) {
-
- $rec = Database::fetch_array($r);
- return $rec['name'];
- }
- return null;
- }
- function api_get_session_info($session_id, $add_extra_values = false) {
- $data = array();
- if (!empty($session_id)) {
- $session_id = intval($session_id);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $sql = "SELECT * FROM $tbl_session WHERE id = $session_id";
- $result = Database::query($sql);
- if (Database::num_rows($result)>0) {
- $data = Database::fetch_array($result, 'ASSOC');
- if ($add_extra_values) {
- $extra_field_values = new ExtraField('session');
- $data['extra_fields'] = $extra_field_values->get_handler_extra_data($session_id);
- }
- }
- }
- return $data;
- }
- function api_get_session_date_validation($session_info, $course_code, $ignore_visibility_for_admins = true, $check_coach_dates = true) {
- if (api_is_platform_admin()) {
- if ($ignore_visibility_for_admins) {
- return true;
- }
- }
- $session_id = $session_info['id'];
- $now = time();
- $access = false;
- if ($session_info) {
-
- if ($session_info['access_start_date'] == '0000-00-00 00:00:00' && $session_info['access_end_date'] == '0000-00-00 00:00:00') {
- return true;
- } else {
-
- if (!empty($session_info['access_start_date']) && $session_info['access_start_date'] != '0000-00-00 00:00:00') {
- if ($now > api_strtotime($session_info['access_start_date'], 'UTC')) {
- $access = true;
- } else {
- $access = false;
- }
- }
-
- if (!empty($session_info['access_end_date']) && $session_info['access_end_date'] != '0000-00-00 00:00:00') {
-
- if ($now <= api_strtotime($session_info['access_end_date'], 'UTC')) {
-
- $access = true;
- } else {
-
- $access = false;
- }
- }
- }
- if ($check_coach_dates) {
-
- $is_coach = api_is_coach($session_id, $course_code);
- if ($is_coach) {
- if (isset($session_info['access_end_date']) && !empty($session_info['access_end_date']) && $session_info['access_end_date'] != '0000-00-00 00:00:00' &&
- isset($session_info['coach_access_end_date']) && !empty($session_info['coach_access_end_date']) && $session_info['coach_access_end_date'] != '0000-00-00 00:00:00') {
- $end_date_extra_for_coach = api_strtotime($session_info['coach_access_end_date'], 'UTC');
- if ($now <= $end_date_extra_for_coach) {
- $access = true;
- } else {
- $access = false;
- }
- }
-
- if (isset($session_info['access_start_date']) && !empty($session_info['access_start_date']) && $session_info['access_start_date'] != '0000-00-00 00:00:00' &&
- isset($session_info['coach_start_date']) && !empty($session_info['coach_start_date']) && $session_info['coach_start_date'] != '0000-00-00 00:00:00') {
- $start_date_for_coach = api_strtotime($session_info['coach_start_date'], 'UTC');
- if ($now > $start_date_for_coach) {
- $access = true;
- } else {
- $access = false;
- }
- }
- }
- }
- return $access;
- }
- }
- function api_get_session_visibility($session_id, $course_code = null, $ignore_visibility_for_admins = true) {
- if (api_is_platform_admin()) {
- if ($ignore_visibility_for_admins) {
- return SESSION_AVAILABLE;
- }
- }
- $session_info = api_get_session_info($session_id);
- $visibility = SESSION_AVAILABLE;
- if (!empty($session_info)) {
- $visibility = $session_info['visibility'];
-
- $date_validation = api_get_session_date_validation($session_info, $course_code, $ignore_visibility_for_admins);
- if ($date_validation) {
- return SessionManager::DEFAULT_VISIBILITY;
- } else {
-
- return $visibility;
- }
- }
- return $visibility;
- }
- function api_get_session_image($session_id, $status_id) {
- $session_id = (int)$session_id;
- $session_img = '';
- if ((int)$status_id != STUDENT) {
- if ($session_id > 0) {
- $session_img = " ".Display::return_icon('star.png', get_lang('SessionSpecificResource'), array('align' => 'absmiddle'), ICON_SIZE_SMALL);
- }
- }
- return $session_img;
- }
- function api_get_session_condition($session_id, $and = true, $with_base_content = false, $session_field = "session_id") {
- $session_id = intval($session_id);
- if (empty($session_field)) {
- $session_field = "session_id";
- }
-
- $condition_session = '';
- $condition_add = $and ? " AND " : " WHERE ";
- if ($with_base_content) {
- $condition_session = $condition_add." ( $session_field = $session_id OR $session_field = 0) ";
- } else {
- $condition_session = $condition_add." $session_field = $session_id ";
- }
- return $condition_session;
- }
- function api_get_coachs_from_course($session_id=0,$course_code='') {
- if (!empty($session_id)) {
- $session_id = intval($session_id);
- } else {
- $session_id = api_get_session_id();
- }
- if (!empty($course_code)) {
- $course_code = Database::escape_string($course_code);
- } else {
- $course_code = api_get_course_id();
- }
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $coaches = array();
- $sql = "SELECT u.user_id,u.lastname,u.firstname,u.username FROM $tbl_user u,$tbl_session_course_user scu
- WHERE u.user_id = scu.id_user AND scu.id_session = '$session_id' AND scu.course_code = '$course_code' AND scu.status = 2";
- $rs = Database::query($sql);
- if (Database::num_rows($rs) > 0) {
- while ($row = Database::fetch_array($rs)) {
- $coaches[] = $row;
- }
- return $coaches;
- } else {
- return false;
- }
- }
- function api_get_setting($variable, $key = null) {
- global $_setting;
- if ($variable == 'header_extra_content') {
- $filename = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';
- if (file_exists($filename)) {
- $value = file_get_contents($filename);
- return $value ;
- } else {
- return '';
- }
- }
- if ($variable == 'footer_extra_content') {
- $filename = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt';
- if (file_exists($filename)) {
- $value = file_get_contents($filename);
- return $value ;
- } else {
- return '';
- }
- }
- $value = null;
- if (is_null($key)) {
- $value = ((isset($_setting[$variable]) && $_setting[$variable] != '') ? $_setting[$variable] : null);
- } else {
- if (isset($_setting[$variable][$key])) {
- $value = $_setting[$variable][$key];
- }
- }
- return $value;
- }
- function api_get_settings_params($params) {
- $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $result = Database::select('*', $table, array('where' => $params));
- return $result;
- }
- function api_get_settings_params_simple($params) {
- $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $result = Database::select('*', $table, array('where' => $params), 'one');
- return $result;
- }
- function api_delete_settings_params($params) {
- $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $result = Database::delete($table, $params);
- return $result;
- }
- function api_get_self() {
- return htmlentities($_SERVER['PHP_SELF']);
- }
- function api_is_platform_admin($allow_sessions_admins = false) {
- if (isset($_SESSION['is_platformAdmin']) && $_SESSION['is_platformAdmin']) {
- return true;
- }
- global $_user;
- return $allow_sessions_admins && isset($_user['status']) && $_user['status'] == SESSIONADMIN;
- }
- function api_is_platform_admin_by_id($user_id = null, $url = null) {
- $user_id = intval($user_id);
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
- $sql = "SELECT * FROM $admin_table WHERE user_id = $user_id";
- $res = Database::query($sql);
- $is_admin = Database::num_rows($res) === 1;
- if (!$is_admin or !isset($url)) {
- return $is_admin;
- }
-
- $url = intval($url);
- $url_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
- $sql = "SELCT * FROM $url_user_table WHERE access_url_id = $url AND user_id = $user_id";
- $res = Database::query($sql);
- $is_on_url = Database::num_rows($res) === 1;
- return $is_on_url;
- }
- function api_get_user_status($user_id = null) {
- $user_id = intval($user_id);
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $table = Database::get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT status FROM $table WHERE user_id = $user_id ";
- $result = Database::query($sql);
- $status = null;
- if (Database::num_rows($result)) {
- $row = Database::fetch_array($result);
- $status = $row['status'];
- }
- return $status;
- }
- function api_is_allowed_to_create_course() {
- return isset($_SESSION['is_allowedCreateCourse']) ? $_SESSION['is_allowedCreateCourse'] : false;
- }
- function api_is_course_admin() {
- return isset($_SESSION['is_courseAdmin']) ? $_SESSION['is_courseAdmin'] : false;
- }
- function api_is_course_coach() {
- return $_SESSION['is_courseCoach'];
- }
- function api_is_course_tutor() {
- return $_SESSION['is_courseTutor'];
- }
- function api_get_user_platform_status($user_id = false) {
- $status = array();
- $user_id = intval($user_id);
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- if (empty($user_id)) {
- return false;
- }
- $group_id = api_get_group_id();
- $course_id = api_get_course_int_id();
- $course_code= api_get_course_id();
- $session_id = api_get_session_id();
-
- if ($group_id && $course_id) {
- $group_status = array();
- $is_subscribed = GroupManager::is_subscribed($user_id, $group_id);
- if ($is_subscribed) {
- $group_status = array('id'=> $group_id , 'status' => 'student');
- $is_tutor = GroupManager::is_tutor_of_group($user_id, $group_id);
- if ($is_tutor) {
- $group_status['status'] = 'tutor';
- } else {
- $group_status['status'] = 'student';
- }
- }
- $status['group'] = $group_status;
- }
-
- if ($session_id && $course_id) {
- $session_status = array();
- $session_status = array('id' => $session_id, 'course_id' => $course_id);
- $session_user_status = SessionManager::get_user_status_in_course_session($user_id, $course_code, $session_id);
- switch ($session_user_status) {
- case 0:
- $session_status['status'] = 'student';
- break;
- case 2:
- $session_status['status'] = 'coach';
- break;
- }
- $is_general_coach = SessionManager::user_is_general_coach($user_id, $session_id);
- if ($is_general_coach) {
- $session_status['status'] = 'general_coach';
- }
- $status['session'] = $session_status;
- } elseif($course_id) {
-
- $course_status = array();
- if ($course_id) {
- $user_course_status = CourseManager::get_user_in_course_status($user_id, $course_code);
- if ($user_course_status) {
- $course_status = array('id'=> $course_id);
- switch($user_course_status) {
- case COURSEMANAGER;
- $course_status['status'] = 'teacher';
- break;
- case STUDENT;
- $course_status['status'] = 'student';
-
- $tutor_course_status = CourseManager::get_tutor_in_course_status($user_id, $course_code);
- if ($tutor_course_status) {
- $course_status['status'] = 'tutor';
- }
- break;
- }
- }
- }
- $status['course'] = $course_status;
- }
- return $status;
- }
- function api_is_course_session_coach($user_id, $course_code, $session_id) {
- $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
- $session_rel_course_rel_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $user_id = intval($user_id);
- $session_id = intval($session_id);
- $course_code = Database::escape_string($course_code);
- $sql = "SELECT DISTINCT id
- FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru
- ON session.id = session_rc_ru.id_session
- WHERE session_rc_ru.id_user = '".$user_id."' AND
- session_rc_ru.course_code = '$course_code' AND
- session_rc_ru.status = 2 AND
- session_rc_ru.id_session = '$session_id'";
- $result = Database::query($sql);
- return Database::num_rows($result) > 0;
- }
- function api_is_coach($session_id = 0, $course_code = null) {
- if (!empty($session_id)) {
- $session_id = intval($session_id);
- } else {
- $session_id = api_get_session_id();
- }
- if (!empty($course_code)) {
- $course_code = Database::escape_string($course_code);
- } else {
- $course_code = api_get_course_id();
- }
- $user_id = api_get_user_id();
- $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
- $session_rel_course_rel_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $sessionIsCoach = null;
- if (!empty($course_code)) {
- $sql = "SELECT DISTINCT id
- FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru
- ON session.id = session_rc_ru.id_session
- WHERE session_rc_ru.id_user = '".$user_id."' AND
- session_rc_ru.course_code = '$course_code' AND
- session_rc_ru.status = 2 AND
- session_rc_ru.id_session = '$session_id'";
- $result = Database::query($sql);
- $sessionIsCoach = Database::store_result($result);
- } else {
-
- $sql = "SELECT DISTINCT session.id
- FROM $session_table session INNER JOIN $session_rel_course_rel_user_table session_rc_ru
- ON session.id = session_rc_ru.id_session
- WHERE session_rc_ru.id_user = '".$user_id."' AND
- session_rc_ru.status = 2 AND
- session_rc_ru.id_session = '$session_id'";
- $result = Database::query($sql);
- $sessionIsCoach = Database::store_result($result);
- }
-
- if (!empty($session_id)) {
- $sql = "SELECT DISTINCT id
- FROM $session_table
- WHERE session.id_coach = '".$user_id."' AND
- id = '$session_id'";
- $result = Database::query($sql);
- if (!empty($sessionIsCoach)) {
- $sessionIsCoach = array_merge($sessionIsCoach , Database::store_result($result));
- } else {
- $sessionIsCoach = Database::store_result($result);
- }
- }
- return (count($sessionIsCoach) > 0);
- }
- function api_is_session_admin() {
- global $_user;
- return isset($_user['status']) && $_user['status'] == SESSIONADMIN;
- }
- function api_is_drh() {
- global $_user;
- return isset($_user['status']) && $_user['status'] == DRH;
- }
- function api_is_student() {
- global $_user;
- return isset($_user['status']) && $_user['status'] == STUDENT;
- }
- function api_is_teacher() {
- global $_user;
- return isset($_user['status']) && $_user['status'] == COURSEMANAGER;
- }
- function api_is_session_in_category($session_id, $category_name) {
- $session_id = intval($session_id);
- $category_name = Database::escape_string($category_name);
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
- $sql = "select 1 FROM $tbl_session WHERE $session_id IN (SELECT s.id FROM $tbl_session s, $tbl_session_category sc WHERE s.session_category_id = sc.id AND sc.name LIKE '%$category_name' )";
- $rs = Database::query($sql);
- if (Database::num_rows($rs) > 0) {
- return true;
- } else {
- return false;
- }
- }
- function api_display_tool_title($title_element) {
- if (is_string($title_element)) {
- $tit = $title_element;
- unset ($title_element);
- $title_element['mainTitle'] = $tit;
- }
- echo '<h2>';
- if (!empty($title_element['supraTitle'])) {
- echo '<small>'.$title_element['supraTitle'].'</small><br />';
- }
- if (!empty($title_element['mainTitle'])) {
- echo $title_element['mainTitle'];
- }
- if (!empty($title_element['subTitle'])) {
- echo '<br /><small>'.$title_element['subTitle'].'</small>';
- }
- echo '</h2>';
- }
- function api_display_tool_view_option() {
- if (api_get_setting('student_view_enabled') != 'true') {
- return '';
- }
- $sourceurl = '';
- $is_framed = false;
-
- if (strpos($_SERVER['REQUEST_URI'], 'chat/chat_banner.php') !== false) {
- $is_framed = true;
- return '';
- }
-
-
- if (strpos($_SERVER['REQUEST_URI'], 'newscorm/lp_header.php') !== false) {
- if (empty($_GET['lp_id'])) {
- return '';
- }
- $sourceurl = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
- $sourceurl = str_replace('newscorm/lp_header.php', 'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.intval($_GET['lp_id']).'&isStudentView='.($_SESSION['studentview']=='studentview' ? 'false' : 'true'), $sourceurl);
-
-
- $is_framed = true;
- }
-
- if (!$is_framed) {
- if (strpos($_SERVER['REQUEST_URI'], '?') === false) {
- $sourceurl = api_get_self().'?'.api_get_cidreq();
- } else {
- $sourceurl = $_SERVER['REQUEST_URI'];
-
- }
- }
- $output_string = '';
- if (!empty($_SESSION['studentview'])) {
- if ($_SESSION['studentview'] == 'studentview') {
-
- $sourceurl = str_replace('&isStudentView=true', '', $sourceurl);
- $sourceurl = str_replace('&isStudentView=false', '', $sourceurl);
- $output_string .= '<a class="btn btn-mini btn-success" href="'.$sourceurl.'&isStudentView=false" target="_self">'.get_lang('CourseManagerview').'</a>';
- } elseif ($_SESSION['studentview'] == 'teacherview') {
-
- $sourceurl = str_replace('&isStudentView=true', '', $sourceurl);
- $sourceurl = str_replace('&isStudentView=false', '', $sourceurl);
- $output_string .= '<a class="btn btn-mini" href="'.$sourceurl.'&isStudentView=true" target="_self">'.get_lang('StudentView').'</a>';
- }
- } else {
- $output_string .= '<a class="btn btn-mini" href="'.$sourceurl.'&isStudentView=true" target="_self">'.get_lang('StudentView').'</a>';
- }
- return $output_string;
- }
- function api_display_array($info_array) {
- $message = '';
- if(is_array($info_array)) {
- foreach ($info_array as $element) {
- $message .= $element.'<br />';
- }
- }
- Display :: display_normal_message($message);
- }
- function api_display_debug_info($debug_info) {
- $message = '<i>Debug info</i><br />';
- $message .= $debug_info;
- Display :: display_normal_message($message);
- }
- function api_is_allowed_to_edit($tutor = false, $coach = false, $session_coach = false, $check_student_view = true) {
- $my_session_id = api_get_session_id();
- $is_allowed_coach_to_edit = api_is_coach();
- $session_visibility = api_get_session_visibility($my_session_id);
-
- if (api_is_platform_admin(false)) {
-
- if ($check_student_view && isset($_SESSION['studentview']) && $_SESSION['studentview'] == "studentview") {
- return false;
- } else {
- return true;
- }
- }
- $is_courseAdmin = api_is_course_admin();
- if (!$is_courseAdmin && $tutor) {
- $is_courseAdmin = $is_courseAdmin || api_is_course_tutor();
- }
- if (!$is_courseAdmin && $coach) {
-
- if ($session_visibility == SESSION_VISIBLE_READ_ONLY) {
- $is_allowed_coach_to_edit = false;
- }
- if (api_get_setting('allow_coach_to_edit_course_session') == 'true') {
- $is_courseAdmin = $is_courseAdmin || $is_allowed_coach_to_edit;
- } else {
- $is_courseAdmin = $is_courseAdmin;
- }
- }
- if (!$is_courseAdmin && $session_coach) {
- $is_courseAdmin = $is_courseAdmin || api_is_coach();
- }
-
- if (api_get_setting('student_view_enabled') == 'true') {
- if (!empty($my_session_id)) {
-
- if ($session_visibility == SESSION_VISIBLE_READ_ONLY) {
- $is_allowed_coach_to_edit = false;
- }
- if (api_get_setting('allow_coach_to_edit_course_session') == 'true') {
- $is_allowed = $is_allowed_coach_to_edit;
- } else {
- $is_allowed = false;
- }
- if ($check_student_view) {
- $is_allowed = $is_allowed && $_SESSION['studentview'] != 'studentview';
- }
- } else {
- if ($check_student_view) {
- $is_allowed = $is_courseAdmin && $_SESSION['studentview'] != 'studentview';
- } else {
- $is_allowed = $is_courseAdmin;
- }
- }
- return $is_allowed;
- } else {
- return $is_courseAdmin;
- }
- }
- function api_is_allowed_to_session_edit($tutor = false, $coach = false) {
- if (api_is_allowed_to_edit($tutor, $coach)) {
-
- return true;
- } else {
- if (api_get_session_id() == 0) {
-
- return true;
- } else {
-
- $session_id = api_get_session_id();
-
- $session_visibility = api_get_session_visibility($session_id);
- switch ($session_visibility) {
- case SESSION_VISIBLE_READ_ONLY:
- return false;
- case SESSION_VISIBLE:
- return true;
- case SESSION_INVISIBLE:
- return false;
- case SESSION_AVAILABLE:
- return true;
- }
- }
- }
- }
- function api_is_allowed($tool, $action, $task_id = 0) {
- global $_course;
- global $_user;
- if (api_is_course_admin()) {
- return true;
- }
-
- if (is_array($_course) and count($_course) > 0) {
- require_once api_get_path(SYS_CODE_PATH).'permissions/permissions_functions.inc.php';
-
- if ($task_id == 0) {
- $user_permissions = get_permissions('user', $_user['user_id']);
- $_SESSION['total_permissions'][$_course['code']] = $user_permissions;
- }
-
- if ($task_id != 0) {
- $task_permissions = get_permissions('task', $task_id);
- $_SESSION['total_permissions'][$_course['code']] = $task_permissions;
- }
-
-
-
-
-
-
- $user_courserole_permissions = get_roles_permissions('user', $_user['user_id']);
-
-
-
-
-
-
-
-
- }
-
- if (api_get_setting('permissions') == 'limited') {
- if ($action == 'Visibility') {
- $action = 'Edit';
- }
- if ($action == 'Move') {
- $action = 'Edit';
- }
- }
-
-
-
- if (is_array($_SESSION['total_permissions'][$_course['code']][$tool])) {
- if (in_array($action, $_SESSION['total_permissions'][$_course['code']][$tool])) {
- return true;
- } else {
- return false;
- }
- }
- }
- function api_is_anonymous($user_id = null, $db_check = false) {
- if (!isset($user_id)) {
- $user_id = api_get_user_id();
- }
- if ($db_check) {
- $info = api_get_user_info($user_id);
- if ($info['status'] == 6) {
- return true;
- }
- }
- global $_user;
- if (!isset($_user)) {
-
-
- global $use_anonymous;
- if (isset($use_anonymous) && $use_anonymous) {
- api_set_anonymous();
- }
- return true;
- }
- return isset($_user['is_anonymous']) && $_user['is_anonymous'] === true;
- }
- function api_not_found($print_headers = false) {
- global $app;
- $origin = isset($_GET['origin']) ? $_GET['origin'] : '';
- $show_headers = 0;
- if ((!headers_sent() || $print_headers) && $origin != 'learnpath') {
- $show_headers = 1;
- }
- $app['template.show_header'] = $show_headers;
- $app['template.show_footer'] = $show_headers;
- $tpl = new Template(null);
- $msg = get_lang('NotFound');
- $tpl->assign('content', $msg);
- $tpl->display_one_col_template();
- }
- function api_not_allowed($print_headers = false, $message = null) {
- global $app;
- if (api_get_setting('sso_authentication') === 'true') {
- global $osso;
- if ($osso) {
- $osso->logout();
- }
- }
- $home_url = api_get_path(WEB_PATH);
- $user_id = api_get_user_id();
- $course = api_get_course_id();
- global $this_section;
- if (!isset($user_id)) {
-
- $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
- }
- if (CustomPages::enabled() && !isset($user_id)) {
- CustomPages::display(CustomPages::INDEX_UNLOGGED);
- }
- $origin = isset($_GET['origin']) ? $_GET['origin'] : '';
- $msg = null;
- if (isset($message)) {
- $msg = $message;
- } else {
- $msg = Display::return_message(get_lang('NotAllowedClickBack'), 'error', false);
- }
- $msg = Display::div($msg, array('align'=>'center'));
- $show_headers = 0;
- if ($print_headers && $origin != 'learnpath') {
- $show_headers = 1;
- }
- $app['template.show_header'] = $show_headers;
- $app['template.show_footer'] = $show_headers;
- $app['template']->assign('content', $msg);
- $app['allowed'] = true;
- if (($user_id!=0 && !api_is_anonymous()) && (!isset($course) || $course == -1) && empty($_GET['cidReq'])) {
-
-
-
-
-
- $app['allowed'] = false;
- return false;
- }
- if (!empty($_SERVER['REQUEST_URI']) && (!empty($_GET['cidReq']) || $this_section == SECTION_MYPROFILE)) {
-
- if ($user_id != 0 && !api_is_anonymous()) {
-
-
- $app['template']->assign('content', $msg);
- $app['allowed'] = false;
- return false;
- }
-
- $action = api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']);
- $action = str_replace('&', '&', $action);
- $form = new FormValidator('formLogin', 'post', $action, null, array('class'=>'form-stacked'));
-
- $form->addElement('text', 'login', null, array('placeholder' => get_lang('UserName'), 'class' => 'span3 autocapitalize_off'));
-
- $form->addElement('password', 'password', null, array('placeholder' => get_lang('Password'), 'class' => 'span3'));
- $form->addElement('style_submit_button', 'submitAuth', get_lang('LoginEnter'), array('class' => 'btn span3'));
- $content = Display::return_message(get_lang('NotAllowed').'<br />'.get_lang('PleaseLoginAgainFromFormBelow').'<br />', 'error', false);
- $content .= '<div class="well_login">';
- $content .= $form->return_form();
- $content .='</div>';
- $app['template']->assign('content', $content);
- $app['allowed'] = false;
- return false;
-
- }
- if ($user_id != 0 && !api_is_anonymous()) {
- $app['allowed'] = false;
- return false;
- }
- $msg = null;
-
- if( !isset($_COOKIE['TestCookie']) && empty($_COOKIE['TestCookie']) ) {
- $msg = Display::return_message(get_lang('NoCookies').'<br /><br /><a href="'.$home_url.'">'.get_lang('BackTo').' '.get_lang('CampusHomepage').'</a><br />', 'error', false);
- } else {
- $msg = Display::return_message(get_lang('NotAllowed').'<br /><br /><a href="'.$home_url.'">'.get_lang('PleaseLoginAgainFromHomepage').'</a><br />', 'error', false);
- }
- $msg = Display::div($msg, array('align'=>'center'));
- $app['template']->assign('content', $msg);
- $app['allowed'] = false;
- return false;
- }
- function convert_sql_date($last_post_datetime) {
- list ($last_post_date, $last_post_time) = explode(' ', $last_post_datetime);
- list ($year, $month, $day) = explode('-', $last_post_date);
- list ($hour, $min, $sec) = explode(':', $last_post_time);
- return mktime((int)$hour, (int)$min, (int)$sec, (int)$month, (int)$day, (int)$year);
- }
- function api_get_datetime($time = null) {
- if (!isset($time)) { $time = time(); }
- return date('Y-m-d H:i:s', $time);
- }
- function api_get_item_visibility($_course, $tool, $id, $session = 0, $user_id = null, $type = null, $group_id = null) {
- if (!is_array($_course) || count($_course) == 0 || empty($tool) || empty($id)) { return -1; }
- $tool = Database::escape_string($tool);
- $id = Database::escape_string($id);
- $session = (int) $session;
- $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $course_id = $_course['real_id'];
- $user_condition = null;
- if (!empty($user_id)) {
- $user_id = intval($user_id);
- $user_condition = " AND to_user_id = $user_id ";
- }
- $type_condition = null;
- if (!empty($type)) {
- $type = Database::escape_string($type);
- $type_condition = " AND lastedit_type = '$type' ";
- }
- $group_condition = null;
- if (!empty($group_id)) {
- $group_id = intval($group_id);
- $group_condition = " AND to_group_id = '$group_id' ";
- }
- $sql = "SELECT visibility FROM $TABLE_ITEMPROPERTY
- WHERE c_id = $course_id AND
- tool = '$tool' AND
- ref = $id AND
- (id_session = $session OR id_session = 0 OR id_session IS NULL) $user_condition $type_condition $group_condition
- ORDER BY id_session DESC, lastedit_date DESC";
- $res = Database::query($sql);
- if ($res === false || Database::num_rows($res) == 0) { return -1; }
- $row = Database::fetch_array($res);
- return $row['visibility'];
- }
- function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $user_id, $to_group_id = 0, $to_user_id = 0, $start_visible = 0, $end_visible = 0, $session_id = 0) {
-
- $tool = Database::escape_string($tool);
- $item_id = Database::escape_string($item_id);
- $lastedit_type = Database::escape_string($lastedit_type);
- $user_id = Database::escape_string($user_id);
- $to_group_id = Database::escape_string($to_group_id);
- $to_user_id = Database::escape_string($to_user_id);
- $start_visible = $start_visible == 0 ? null : Database::escape_string($start_visible);
- $end_visible = $end_visible == 0 ? null : Database::escape_string($end_visible);
- $to_filter = '';
- $time = api_get_utc_datetime();
- if (!empty($session_id)) {
- $session_id = intval($session_id);
- } else {
- $session_id = api_get_session_id();
- }
-
- $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- if ($to_user_id <= 0) {
- $to_user_id = 0;
- }
-
- $condition_session = '';
- if (!empty($session_id)) {
- $condition_session = " AND id_session = '$session_id' ";
- }
- $course_id = $_course['real_id'];
- $filter = " c_id = $course_id AND tool='$tool' AND ref='$item_id' $condition_session ";
- if ($item_id == '*') {
- $filter = " c_id = $course_id AND tool='$tool' AND visibility<>'2' $condition_session";
- }
-
-
- if (is_null($to_user_id) && is_null($to_group_id)) {
- $to_group_id = 0;
- }
- if (!is_null($to_user_id)) {
- $to_filter = " AND to_user_id='$to_user_id' $condition_session";
- } else {
- if (($to_group_id != 0) && $to_group_id == strval(intval($to_group_id))) {
- $to_filter = " AND to_group_id='$to_group_id' $condition_session";
- }
- }
-
- $set_type = '';
- switch ($lastedit_type) {
- case 'delete' :
- $visibility = '2';
- if (!empty($session_id)) {
-
- $sql = "SELECT id_session FROM $TABLE_ITEMPROPERTY
- WHERE c_id = $course_id AND tool = '$tool' AND ref='$item_id' AND id_session = '$session_id'";
- $rs = Database::query($sql);
- if (Database::num_rows($rs) > 0) {
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_type = '".str_replace('_', '', ucwords($tool))."Deleted',
- lastedit_date = '$time',
- lastedit_user_id = '$user_id',
- visibility = '$visibility',
- id_session = '$session_id' $set_type
- WHERE $filter";
- } else {
- $sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, to_user_id, to_group_id, visibility, start_visible, end_visible, id_session)
- VALUES ($course_id, '$tool','$item_id','$time', '$user_id', '$time', '$lastedit_type','$user_id', '$to_user_id', '$to_group_id', '$visibility', '$start_visible','$end_visible', '$session_id')";
- }
- } else {
- $sql = "UPDATE $TABLE_ITEMPROPERTY SET lastedit_type='".str_replace('_', '', ucwords($tool))."Deleted', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
- WHERE $filter";
- }
- break;
- case 'visible' :
- $visibility = '1';
- if (!empty($session_id)) {
-
- $sql = "SELECT id_session FROM $TABLE_ITEMPROPERTY WHERE c_id=$course_id AND tool = '$tool' AND ref='$item_id' AND id_session = '$session_id'";
- $rs = Database::query($sql);
- if (Database::num_rows($rs) > 0) {
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_type='".str_replace('_', '', ucwords($tool))."Visible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility', id_session = '$session_id' $set_type
- WHERE $filter";
- } else {
- $sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, to_user_id, to_group_id, visibility, start_visible, end_visible, id_session)
- VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_user_id', '$to_group_id', '$visibility', '$start_visible', '$end_visible', '$session_id')";
- }
- } else {
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_type='".str_replace('_', '', ucwords($tool))."Visible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
- WHERE $filter";
- }
- break;
- case 'invisible' :
- $visibility = '0';
- if (!empty($session_id)) {
-
- $sql = "SELECT id_session FROM $TABLE_ITEMPROPERTY WHERE c_id=$course_id AND tool = '$tool' AND ref='$item_id' AND id_session = '$session_id'";
- $rs = Database::query($sql);
- if (Database::num_rows($rs) > 0) {
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_type='".str_replace('_', '', ucwords($tool))."Invisible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility', id_session = '$session_id' $set_type
- WHERE $filter";
- } else {
- $sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id, to_user_id, to_group_id, visibility, start_visible, end_visible, id_session)
- VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_user_id', '$to_group_id', '$visibility', '$start_visible', '$end_visible', '$session_id')";
- }
- } else {
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_type='".str_replace('_', '', ucwords($tool))."Invisible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
- WHERE $filter";
- }
- break;
- default :
- $set_type = ", lastedit_type='$lastedit_type' ";
- $visibility = '1';
- $filter .= $to_filter;
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_date = '$time', lastedit_user_id='$user_id' $set_type
- WHERE $filter";
- }
- $res = Database::query($sql);
-
- if (Database::affected_rows() == 0) {
- $sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool,ref,insert_date,insert_user_id,lastedit_date,lastedit_type, lastedit_user_id, to_user_id, to_group_id, visibility, start_visible, end_visible, id_session)
- VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_user_id', '$to_group_id', '$visibility', '$start_visible', '$end_visible', '$session_id')";
- $res = Database::query($sql);
- if (!$res) {
- return false;
- }
- }
- return true;
- }
- function api_get_item_property_by_tool($tool, $course_code, $session_id = null) {
- $course_info = api_get_course_info($course_code);
- $tool = Database::escape_string($tool);
-
- $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $session_condition = '';
- $session_id = intval($session_id);
- $session_condition = ' AND id_session = '.$session_id;
- $course_id = $course_info['real_id'];
- $sql = "SELECT * FROM $item_property_table WHERE c_id = $course_id AND tool = '$tool' $session_condition ";
- $rs = Database::query($sql);
- $list = array();
- if (Database::num_rows($rs) > 0) {
- while ($row = Database::fetch_array($rs, 'ASSOC')) {
- $list[] = $row;
- }
- }
- return $list;
- }
- function api_get_item_property_id($course_code, $tool, $ref) {
- $course_info = api_get_course_info($course_code);
- $tool = Database::escape_string($tool);
- $ref = intval($ref);
-
- $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $course_id = $course_info['real_id'];
- $sql = "SELECT id FROM $TABLE_ITEMPROPERTY WHERE c_id = $course_id AND tool = '$tool' AND ref = '$ref'";
- $rs = Database::query($sql);
- $item_property_id = null;
- if (Database::num_rows($rs) > 0) {
- $row = Database::fetch_array($rs);
- $item_property_id = $row['id'];
- }
- return $item_property_id;
- }
- function api_track_item_property_update($tool, $ref, $title, $content, $progress) {
- $tbl_stats_item_property = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
- $course_id = api_get_real_course_id();
- $course_code = api_get_course_id();
- $item_property_id = api_get_item_property_id($course_code, $tool, $ref);
- if (!empty($item_property_id)) {
- $sql = "INSERT IGNORE INTO $tbl_stats_item_property SET
- course_id = '$course_id',
- item_property_id = '$item_property_id',
- title = '".Database::escape_string($title)."',
- content = '".Database::escape_string($content)."',
- progress = '".intval($progress)."',
- lastedit_date = '".api_get_utc_datetime()."',
- lastedit_user_id = '".api_get_user_id()."',
- session_id = '".api_get_session_id()."'";
- Database::query($sql);
- $affected_rows = Database::affected_rows();
- return $affected_rows;
- }
- return false;
- }
- function api_get_track_item_property_history($tool, $ref) {
- $tbl_stats_item_property = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
- $course_id = api_get_real_course_id();
- $course_code = api_get_course_id();
- $item_property_id = api_get_item_property_id($course_code, $tool, $ref);
- $sql = "SELECT * FROM $tbl_stats_item_property WHERE item_property_id = $item_property_id AND course_id = $course_id ORDER BY lastedit_date DESC";
- $result = Database::query($sql);
- $result = Database::store_result($result,'ASSOC');
- return $result;
- }
- function api_get_item_property_info($course_id, $tool, $ref, $session_id = 0) {
- $course_info = api_get_course_info_by_id($course_id);
- if (empty($course_info)) {
- return false;
- }
- $tool = Database::escape_string($tool);
- $ref = intval($ref);
- $course_id = intval($course_id);
-
- $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $course_id = $course_info['real_id'];
- $sql = "SELECT * FROM $TABLE_ITEMPROPERTY WHERE c_id = $course_id AND tool = '$tool' AND ref = $ref ";
- if (!empty($session_id)) {
- $session_id = intval($session_id);
- $sql .= "AND id_session = $session_id ";
- }
- $rs = Database::query($sql);
- $row = array();
- if (Database::num_rows($rs) > 0) {
- $row = Database::fetch_array($rs,'ASSOC');
- }
- return $row;
- }
- function api_get_languages_combo($name = 'language', $chozen=true) {
- $ret = '';
- $platformLanguage = api_get_setting('platformLanguage');
-
- $language_list = api_get_languages();
- if (count($language_list['name']) < 2) {
- return $ret;
- }
-
- if (isset($_SESSION['user_language_choice'])) {
- $default = $_SESSION['user_language_choice'];
- } else {
- $default = $platformLanguage;
- }
- $languages = $language_list['name'];
- $folder = $language_list['folder'];
- $ret .= '<select name="'.$name.'" id="language_chosen" '.($chozen?'class="chzn-select"':'').' >';
- foreach ($languages as $key => $value) {
- if ($folder[$key] == $default) {
- $selected = ' selected="selected"';
- } else {
- $selected = '';
- }
- $ret .= sprintf('<option value=%s" %s>%s</option>', $folder[$key], $selected, $value);
- }
- $ret .= '</select>';
- return $ret;
- }
- function api_display_language_form($hide_if_no_choice = false) {
-
- $language_list = api_get_languages();
- if (!empty($language_list) && count($language_list['name']) <= 1 && $hide_if_no_choice) {
- return;
- }
-
- if (isset($_SESSION['user_language_choice'])) {
- $user_selected_language = $_SESSION['user_language_choice'];
- }
- if (empty($user_selected_language)) {
- $user_selected_language = api_get_setting('platformLanguage');
- }
- $original_languages = $language_list['name'];
- $folder = $language_list['folder'];
- $html = '
- <script>
- function jumpMenu(targ,selObj,restore){ // v3.0
- eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
- if (restore) selObj.selectedIndex=0;
- }
- </script>';
- $html .= '<form id="lang_form" name="lang_form" method="post" action="'.api_get_self().'">';
- $html .= '<select id="language_list" class="chzn-select" name="language_list" onchange="javascript: jumpMenu(\'parent\',this,0);">';
- foreach ($original_languages as $key => $value) {
- if ($folder[$key] == $user_selected_language) {
- $option_end = ' selected="selected" >';
- } else {
- $option_end = '>';
- }
- $html .= '<option value="'.api_get_self().'?language='.$folder[$key].'"'.$option_end;
- $html .= $value.'</option>';
- }
- $html .= '</select>';
- $html .= '<noscript><input type="submit" name="user_select_language" value="'.get_lang('Ok').'" /></noscript>';
- $html .= '</form>';
- return $html;
- }
- function api_get_languages() {
- global $app;
- if (isset($app['api_get_languages'])) {
- return $app['api_get_languages'];
- }
- $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
- $sql = "SELECT * FROM $tbl_language WHERE available='1' ORDER BY original_name ASC";
- $result = Database::query($sql);
- $language_list = array();
- while ($row = Database::fetch_array($result)) {
- $language_list['name'][] = $row['original_name'];
- $language_list['folder'][] = $row['dokeos_folder'];
- }
- return $language_list;
- }
- function api_get_language_id($language) {
- $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
- if (empty($language)) {
- return null;
- }
- $language = Database::escape_string($language);
- $sql = "SELECT id FROM $tbl_language WHERE available='1' AND dokeos_folder = '$language' LIMIT 1";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return $row['id'];
- }
- function api_get_language_from_type($lang_type){
- global $_user;
- global $_course;
- $toreturn = false;
- switch ($lang_type) {
- case 'platform_lang' :
- $temp_lang = api_get_setting('platformLanguage');
- if (!empty($temp_lang))
- $toreturn = $temp_lang;
- break;
- case 'user_profil_lang' :
- if (isset($_user['language']) && !empty($_user['language']) )
- $toreturn = $_user['language'];
- break;
- case 'user_selected_lang' :
- if (isset($_SESSION['user_language_choice']) && !empty($_SESSION['user_language_choice']) )
- $toreturn = ($_SESSION['user_language_choice']);
- break;
- case 'course_lang' :
- if (isset($_course['language']) && !empty($_course['language']) )
- $toreturn = $_course['language'];
- break;
- default :
- $toreturn = false;
- break;
- }
- return $toreturn;
- }
- function api_get_language_info($language_id) {
- $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
- $sql = 'SELECT * FROM '.$tbl_admin_languages.' WHERE id = "'.intval($language_id).'"';
- $rs = Database::query($sql);
- $language_info = array();
- if (Database::num_rows($rs)) {
- $language_info = Database::fetch_array($rs,'ASSOC');
- }
- return $language_info;
- }
- function api_get_visual_theme() {
- static $visual_theme;
- if (!isset($visual_theme)) {
- $platform_theme = api_get_setting('stylesheets');
- $visual_theme = $platform_theme;
- if (api_get_setting('user_selected_theme') == 'true') {
- $user_info = api_get_user_info();
- if (isset($user_info['theme'])) {
- $user_theme = $user_info['theme'];
- if (!empty($user_theme)) {
- $visual_theme = $user_theme;
- }
- }
- }
- $course_id = api_get_course_id();
- if (!empty($course_id) && $course_id != -1) {
- if (api_get_setting('allow_course_theme') == 'true') {
- $course_theme = api_get_course_setting('course_theme');
- if (!empty($course_theme) && $course_theme != -1) {
- if (!empty($course_theme)) {
- $visual_theme = $course_theme;
- }
- }
- $allow_lp_theme = api_get_course_setting('allow_learning_path_theme');
- if ($allow_lp_theme == 1) {
- global $lp_theme_css, $lp_theme_config;
- if (!$lp_theme_config) {
- if (!empty($lp_theme_css)) {
- $visual_theme = $lp_theme_css;
- }
- }
- }
- }
- }
- if (empty($visual_theme)) {
- $visual_theme = 'chamilo';
- }
- global $lp_theme_log;
- if ($lp_theme_log) {
- $visual_theme = $platform_theme;
- }
- }
- return $visual_theme;
- }
- function api_get_themes() {
- $cssdir = api_get_path(SYS_PATH).'main/css/';
- $list_dir = array();
- $list_name = array();
- if (@is_dir($cssdir)) {
- $themes = @scandir($cssdir);
- if (is_array($themes)) {
- if ($themes !== false) {
- sort($themes);
- foreach ($themes as & $theme) {
- if (substr($theme, 0, 1) == '.') {
- continue;
- } else {
- if (@is_dir($cssdir.$theme)) {
- $list_dir[] = $theme;
- $list_name[] = ucwords(str_replace('_', ' ', $theme));
- }
- }
- }
- }
- }
- }
- return array($list_dir, $list_name);
- }
- function api_disp_html_area($name, $content = '', $height = '', $width = '100%', $attributes = null, $editor_config = null) {
- global $_configuration, $_course, $fck_attribute;
- require_once api_get_path(LIBRARY_PATH).'formvalidator/Element/html_editor.php';
- $editor = new HTML_QuickForm_html_editor($name, null, $attributes, $editor_config);
- $editor->setValue($content);
-
- if( $height != '') {
- $fck_attribute['Height'] = $height;
- }
- if( $width != '') {
- $fck_attribute['Width'] = $width;
- }
- echo $editor->toHtml();
- }
- function api_return_html_area($name, $content = '', $height = '', $width = '100%', $attributes = null, $editor_config = null) {
- global $_configuration, $_course, $fck_attribute;
- require_once api_get_path(LIBRARY_PATH).'formvalidator/Element/html_editor.php';
- $editor = new HTML_QuickForm_html_editor($name, null, $attributes, $editor_config);
- $editor->setValue($content);
-
- if ($height != '') {
- $fck_attribute['Height'] = $height;
- }
- if ($width != '') {
- $fck_attribute['Width'] = $width;
- }
- return $editor->toHtml();
- }
- function api_max_sort_value($user_course_category, $user_id) {
- $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $sql_max = "SELECT max(sort) as max_sort FROM $tbl_course_user WHERE user_id='".intval($user_id)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." AND user_course_cat='".Database::escape_string($user_course_category)."'";
- $result_max = Database::query($sql_max);
- if (Database::num_rows($result_max) == 1) {
- $row_max = Database::fetch_array($result_max);
- return $row_max['max_sort'];
- }
- return 0;
- }
- function string_2_boolean($string) {
- if ($string == 'true') {
- return true;
- }
- if ($string == 'false') {
- return false;
- }
- return false;
- }
- function api_number_of_plugins($location) {
- global $_plugins;
- return isset($_plugins[$location]) && is_array($_plugins[$location]) ? count($_plugins[$location]) : 0;
- }
- function api_plugin($location) {
- global $_plugins;
- if (isset($_plugins[$location]) && is_array($_plugins[$location])) {
- foreach ($_plugins[$location] as $this_plugin) {
- include api_get_path(SYS_PLUGIN_PATH)."$this_plugin/index.php";
- }
- }
- return false;
- }
- function api_is_plugin_installed($plugin_list, $plugin_name) {
- if (is_array($plugin_list)) {
- foreach ($plugin_list as $plugin_location) {
- if (array_search($plugin_name, $plugin_location) !== false) { return true; }
- }
- }
- return false;
- }
- function api_time_to_hms($seconds) {
-
- if ($seconds == -1) {
- return get_lang('Unknown').Display::return_icon('info2.gif', get_lang('WrongDatasForTimeSpentOnThePlatform'), array('align' => 'absmiddle', 'hspace' => '3px'));
- }
-
- $hours = floor($seconds / 3600);
-
- $min = floor(($seconds - ($hours * 3600)) / 60);
-
- $sec = floor($seconds - ($hours * 3600) - ($min * 60));
- if ($sec < 10) {
- $sec = "0$sec";
- }
- if ($min < 10) {
- $min = "0$min";
- }
- return "$hours:$min:$sec";
- }
- function api_get_permissions_for_new_directories() {
- static $permissions;
- if (!isset($permissions)) {
- $permissions = trim(api_get_setting('permissions_for_new_directories'));
-
- $permissions = octdec(!empty($permissions) ? $permissions : '0777');
- }
- return $permissions;
- }
- function api_get_permissions_for_new_files() {
- static $permissions;
- if (!isset($permissions)) {
- $permissions = trim(api_get_setting('permissions_for_new_files'));
-
- $permissions = octdec(!empty($permissions) ? $permissions : '0666');
- }
- return $permissions;
- }
- if (!function_exists('sys_get_temp_dir')) {
- function sys_get_temp_dir() {
-
- if (!empty($_ENV['TMP'])) {
- return realpath($_ENV['TMP']);
- }
- if (!empty($_ENV['TMPDIR'])) {
- return realpath($_ENV['TMPDIR']);
- }
- if (!empty($_ENV['TEMP'])) {
- return realpath($_ENV['TEMP']);
- }
-
-
-
- $temp_file = tempnam(md5(uniqid(rand(), true)), '');
- if ($temp_file) {
- $temp_dir = realpath(dirname($temp_file));
- @unlink( $temp_file );
- return $temp_dir;
- }
- return false;
- }
- }
- function rmdirr($dirname, $delete_only_content_in_folder = false) {
- $res = true;
-
- if (!file_exists($dirname)) {
- return false;
- }
- $php_errormsg = '';
-
- if (is_file($dirname) || is_link($dirname)) {
- $res = unlink($dirname);
- if ($res === false) {
- error_log(__FILE__.' line '.__LINE__.': '.((bool)ini_get('track_errors') ? $php_errormsg : 'Error not recorded because track_errors is off in your php.ini'), 0);
- }
- return $res;
- }
-
- $dir = dir($dirname);
-
- $is_object_dir = is_object($dir);
- if ($is_object_dir) {
- while (false !== $entry = $dir->read()) {
-
- if ($entry == '.' || $entry == '..') {
- continue;
- }
-
- rmdirr("$dirname/$entry");
- }
- }
-
- if ($is_object_dir) {
- $dir->close();
- }
- if ($delete_only_content_in_folder == false) {
- $res = rmdir($dirname);
- if ($res === false) {
- error_log(__FILE__.' line '.__LINE__.': '.((bool)ini_get('track_errors') ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
- }
- }
- return $res;
- }
- function copyr($source, $dest, $exclude = array(), $copied_files = array()) {
- if (empty($dest)) { return false; }
-
- if (is_file($source)) {
- $path_info = pathinfo($source);
- if (!in_array($path_info['filename'], $exclude)) {
- copy($source, $dest);
- }
- return true;
- } elseif (!is_dir($source)) {
-
- return false;
- }
-
- if (!is_dir($dest)) {
- mkdir($dest, api_get_permissions_for_new_directories());
- }
-
- $dir = dir($source);
- while (false !== $entry = $dir->read()) {
-
- if ($entry == '.' || $entry == '..') {
- continue;
- }
-
- if ($dest !== "$source/$entry") {
- $files = copyr("$source/$entry", "$dest/$entry", $exclude, $copied_files);
- }
- }
-
- $dir->close();
- return true;
- }
- function copy_folder_course_session($pathname, $base_path_document, $session_id, $course_info, $document, $source_course_id) {
- $table = Database :: get_course_table(TABLE_DOCUMENT);
- $session_id = intval($session_id);
- $source_course_id = intval($source_course_id);
-
- if (is_dir($pathname) || empty($pathname)) {
- return true;
- }
-
- if (is_file($pathname)) {
- trigger_error('copy_folder_course_session(): File exists', E_USER_WARNING);
- return false;
- }
- $course_id = $course_info['real_id'];
- $folders = explode(DIRECTORY_SEPARATOR,str_replace($base_path_document.DIRECTORY_SEPARATOR,'',$pathname));
- $new_pathname = $base_path_document;
- $path = '';
- foreach ($folders as $folder) {
- $new_pathname .= DIRECTORY_SEPARATOR.$folder;
- $path .= DIRECTORY_SEPARATOR.$folder;
- if (!file_exists($new_pathname)) {
- $path = Database::escape_string($path);
- $sql = "SELECT * FROM $table WHERE c_id = $source_course_id AND path = '$path' AND filetype = 'folder' AND session_id = '$session_id'";
- $rs1 = Database::query($sql);
- $num_rows = Database::num_rows($rs1);
- if ($num_rows == 0) {
- mkdir($new_pathname, api_get_permissions_for_new_directories());
-
- $sql = "INSERT INTO ".$table." SET
- c_id = $course_id,
- path = '$path',
- comment = '".Database::escape_string($document->comment)."',
- title = '".Database::escape_string(basename($new_pathname))."' ,
- filetype='folder',
- size= '0',
- session_id = '$session_id'";
- Database::query($sql);
- $document_id = Database::insert_id();
- api_item_property_update($course_info,TOOL_DOCUMENT,$document_id,'FolderCreated',api_get_user_id(),0,0,null,null,$session_id);
- }
- }
- }
- }
- function api_chmod_R($path, $filemode) {
- if (!is_dir($path)) {
- return chmod($path, $filemode);
- }
- $handler = opendir($path);
- while ($file = readdir($handler)) {
- if ($file != '.' && $file != '..') {
- $fullpath = "$path/$file";
- if (!is_dir($fullpath)) {
- if (!chmod($fullpath, $filemode)) {
- return false;
- }
- } else {
- if (!api_chmod_R($fullpath, $filemode)) {
- return false;
- }
- }
- }
- }
- closedir($handler);
- return chmod($path, $filemode);
- }
- function parse_info_file($filename) {
- $info = array();
- if (!file_exists($filename)) {
- return $info;
- }
- $data = file_get_contents($filename);
- if (preg_match_all('
- @^\s* # Start at the beginning of a line, ignoring leading whitespace
- ((?:
- [^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets,
- \[[^\[\]]*\] # unless they are balanced and not nested
- )+?)
- \s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space)
- (?:
- ("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes
- (\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
- ([^\r\n]*?) # Non-quoted string
- )\s*$ # Stop at the next end of a line, ignoring trailing whitespace
- @msx', $data, $matches, PREG_SET_ORDER)) {
- $key = $value1 = $value2 = $value3 = '';
- foreach ($matches as $match) {
-
- $i = 0;
- foreach (array('key', 'value1', 'value2', 'value3') as $var) {
- $$var = isset($match[++$i]) ? $match[$i] : '';
- }
- $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
-
- $keys = preg_split('/\]?\[/', rtrim($key, ']'));
- $last = array_pop($keys);
- $parent = &$info;
-
- foreach ($keys as $key) {
- if ($key == '') {
- $key = count($parent);
- }
- if (!isset($parent[$key]) || !is_array($parent[$key])) {
- $parent[$key] = array();
- }
- $parent = &$parent[$key];
- }
-
- if (defined($value)) {
- $value = constant($value);
- }
-
- if ($last == '') {
- $last = count($parent);
- }
- $parent[$last] = $value;
- }
- }
- return $info;
- }
- function api_get_version() {
- global $_configuration;
- return (string)$_configuration['system_version'];
- }
- function api_get_software_name() {
- global $_configuration;
- if (isset($_configuration['software_name']) && !empty($_configuration['software_name'])) {
- return $_configuration['software_name'];
- } else {
- return 'Chamilo';
- }
- }
- function api_status_exists($status_asked) {
- global $_status_list;
- return in_array($status_asked, $_status_list) ? true : isset($_status_list[$status_asked]);
- }
- function api_status_key($status) {
- global $_status_list;
- return isset($_status_list[$status]) ? $status : array_search($status, $_status_list);
- }
- function api_get_status_langvars() {
- return array(
- COURSEMANAGER => get_lang('Teacher', ''),
- SESSIONADMIN => get_lang('SessionsAdmin', ''),
- DRH => get_lang('Drh', ''),
- STUDENT => get_lang('Student', ''),
- ANONYMOUS => get_lang('Anonymous', '')
- );
- }
- function api_get_settings_options($var) {
- $table_settings_options = Database :: get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
- $var = Database::escape_string($var);
- $sql = "SELECT * FROM $table_settings_options WHERE variable = '$var' ORDER BY id";
- $result = Database::query($sql);
- $settings_options_array = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
-
- $settings_options_array[] = $row;
- }
- return $settings_options_array;
- }
- function api_set_setting_option($params) {
- $table = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
- if (empty($params['id'])) {
- Database::insert($table, $params);
- } else {
- Database::update($table, $params, array('id = ? '=> $params['id']));
- }
- }
- function api_set_setting_simple($params) {
- $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $url_id = api_get_current_access_url_id();
- if (empty($params['id'])) {
- $params['access_url'] = $url_id;
- Database::insert($table, $params);
- } else {
- Database::update($table, $params, array('id = ? '=> array($params['id'])));
- }
- }
- function api_delete_setting_option($id) {
- $table = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
- if (!empty($id)) {
- Database::delete($table, array('id = ? '=> $id));
- }
- }
- function api_set_setting($var, $value, $subvar = null, $cat = null, $access_url = 1) {
- if (empty($var)) { return false; }
- $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $var = Database::escape_string($var);
- $value = Database::escape_string($value);
- $access_url = (int)$access_url;
- if (empty($access_url)) { $access_url = 1; }
- $select = "SELECT id FROM $t_settings WHERE variable = '$var' ";
- if (!empty($subvar)) {
- $subvar = Database::escape_string($subvar);
- $select .= " AND subkey = '$subvar'";
- }
- if (!empty($cat)) {
- $cat = Database::escape_string($cat);
- $select .= " AND category = '$cat'";
- }
- if ($access_url > 1) {
- $select .= " AND access_url = $access_url";
- } else {
- $select .= " AND access_url = 1 ";
- }
- $res = Database::query($select);
- if (Database::num_rows($res) > 0) {
-
- $row = Database::fetch_array($res);
- $update = "UPDATE $t_settings SET selected_value = '$value' WHERE id = ".$row['id'] ;
- $res = Database::query($update);
- } else {
-
- $select = "SELECT * FROM $t_settings WHERE variable = '$var' AND access_url = 1 ";
-
- if ($access_url == 1) {
- if (!empty($subvar)) {
- $select .= " AND subkey = '$subvar'";
- }
- if (!empty($cat)) {
- $select .= " AND category = '$cat'";
- }
- $res = Database::query($select);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $insert = "INSERT INTO $t_settings " .
- "(variable,subkey," .
- "type,category," .
- "selected_value,title," .
- "comment,scope," .
- "subkeytext,access_url)" .
- " VALUES " .
- "('".$row['variable']."',".(!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL")."," .
- "'".$row['type']."','".$row['category']."'," .
- "'$value','".$row['title']."'," .
- "".(!empty($row['comment']) ? "'".$row['comment']."'" : "NULL").",".(!empty($row['scope']) ? "'".$row['scope']."'" : "NULL")."," .
- "".(!empty($row['subkeytext'])?"'".$row['subkeytext']."'":"NULL").",$access_url)";
- $res = Database::query($insert);
- } else {
- error_log(__FILE__.':'.__LINE__.': Attempting to update setting '.$var.' ('.$subvar.') which does not exist at all', 0);
- }
- } else {
-
- if (!empty($subvar)) {
- $select .= " AND subkey = '$subvar'";
- }
- if (!empty($cat)) {
- $select .= " AND category = '$cat'";
- }
- $res = Database::query($select);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- if ($row['access_url_changeable'] == 1) {
- $insert = "INSERT INTO $t_settings " .
- "(variable,subkey," .
- "type,category," .
- "selected_value,title," .
- "comment,scope," .
- "subkeytext,access_url, access_url_changeable)" .
- " VALUES " .
- "('".$row['variable']."',".
- (!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL")."," .
- "'".$row['type']."','".$row['category']."'," .
- "'$value','".$row['title']."'," .
- "".(!empty($row['comment']) ? "'".$row['comment']."'" : "NULL").",".
- (!empty($row['scope']) ? "'".$row['scope']."'" : "NULL")."," .
- "".(!empty($row['subkeytext']) ? "'".$row['subkeytext']."'" : "NULL").",$access_url,".$row['access_url_changeable'].")";
- $res = Database::query($insert);
- }
- } else {
- error_log(__FILE__.':'.__LINE__.': Attempting to update setting '.$var.' ('.$subvar.') which does not exist at all. The access_url is: '.$access_url.' ',0);
- }
- }
- }
- }
- function api_set_settings_category($category, $value = null, $access_url = 1, $fieldtype = array()) {
- if (empty($category)) { return false; }
- $category = Database::escape_string($category);
- $t_s = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $access_url = (int) $access_url;
- if (empty($access_url)) { $access_url = 1; }
- if (isset($value)) {
- $value = Database::escape_string($value);
- $sql = "UPDATE $t_s SET selected_value = '$value' WHERE category = '$category' AND access_url = $access_url";
- if (is_array($fieldtype) && count($fieldtype)>0) {
- $sql .= " AND ( ";
- $i = 0;
- foreach ($fieldtype as $type){
- if ($i > 0) {
- $sql .= ' OR ';
- }
- $type = Database::escape_string($type);
- $sql .= " type='".$type."' ";
- $i++;
- }
- $sql .= ")";
- }
- $res = Database::query($sql);
- return $res !== false;
- } else {
- $sql = "UPDATE $t_s SET selected_value = NULL WHERE category = '$category' AND access_url = $access_url";
- if (is_array($fieldtype) && count($fieldtype)>0) {
- $sql .= " AND ( ";
- $i = 0;
- foreach ($fieldtype as $type){
- if ($i > 0) {
- $sql .= ' OR ';
- }
- $type = Database::escape_string($type);
- $sql .= " type='".$type."' ";
- $i++;
- }
- $sql .= ")";
- }
- $res = Database::query($sql);
- return $res !== false;
- }
- }
- function api_get_access_urls($from = 0, $to = 1000000, $order = 'url', $direction = 'ASC') {
- $t_au = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
- $from = (int) $from;
- $to = (int) $to;
- $order = Database::escape_string($order);
- $direction = Database::escape_string($direction);
- $sql = "SELECT id, url, description, active, created_by, tms FROM $t_au ORDER BY $order $direction LIMIT $to OFFSET $from";
- $res = Database::query($sql);
- return Database::store_result($res);
- }
- function api_get_access_url($id) {
- global $_configuration;
- $id = Database::escape_string(intval($id));
-
-
- $table = 'access_url';
- $database = $_configuration['main_database'];
- $table_access_url = "".$database.".".$table."";
- $sql = "SELECT url, description, active, created_by, tms
- FROM $table_access_url WHERE id = '$id' ";
- $res = Database::query($sql);
- $result = @Database::fetch_array($res);
- return $result;
- }
- function api_add_access_url($u, $d = '', $a = 1) {
- $t_au = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
- $u = Database::escape_string($u);
- $d = Database::escape_string($d);
- $a = (int) $a;
- $sql = "SELECT id FROM $t_au WHERE url LIKE '$u'";
- $res = Database::query($sql);
- if ($res === false) {
-
- return false;
- }
- if (Database::num_rows($res) > 0) {
- return Database::result($res, 0, 'id');
- }
- $ui = api_get_user_id();
- $sql = "INSERT INTO $t_au (url,description,active,created_by,tms) VALUES ('$u','$d',$a,$ui,'')";
- $res = Database::query($sql);
- return ($res === false) ? false : Database::insert_id();
- }
- function api_get_settings($cat = null, $ordering = 'list', $access_url = 1, $url_changeable = 0) {
- $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $access_url = (int) $access_url;
- $where_condition = '';
- if ($url_changeable == 1) {
- $where_condition = " AND access_url_changeable= '1' ";
- }
- if (empty($access_url) or $access_url == -1) { $access_url = 1; }
- $sql = "SELECT * FROM $t_cs WHERE access_url = $access_url $where_condition ";
- if (!empty($cat)) {
- $cat = Database::escape_string($cat);
- $sql .= " AND category='$cat' ";
- }
- if ($ordering == 'group') {
- $sql .= " GROUP BY variable ORDER BY id ASC";
- } else {
- $sql .= " ORDER BY 1,2 ASC";
- }
- $result = Database::store_result(Database::query($sql));
- return $result;
- }
- function & api_get_settings_categories($exceptions = array(), $access_url = 1) {
- $access_url = (int) $access_url;
- $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $list = "'".implode("','",$exceptions)."'";
- $sql = "SELECT DISTINCT category FROM $t_cs WHERE category is NOT NULL ";
- if ($list != "'',''" and $list != "''" and !empty($list)) {
- $sql .= " AND category NOT IN ($list) ";
- }
- $result = Database::store_result(Database::query($sql));
- return $result;
- }
- function api_delete_setting($v, $s = null, $a = 1) {
- if (empty($v)) { return false; }
- $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $v = Database::escape_string($v);
- $a = (int) $a;
- if (empty($a)) { $a = 1; }
- if (!empty($s)) {
- $s = Database::escape_string($s);
- $sql = "DELETE FROM $t_cs WHERE variable = '$v' AND subkey = '$s' AND access_url = $a";
- $r = Database::query($sql);
- return $r;
- }
- $sql = "DELETE FROM $t_cs WHERE variable = '$v' AND access_url = $a";
- $r = Database::query($sql);
- return $r;
- }
- function api_delete_category_settings_by_subkey($subkey, $access_url_id = 1) {
- if (empty($subkey)) { return false; }
- $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $subkey = Database::escape_string($subkey);
- $access_url_id = intval($access_url_id);
- $sql = "DELETE FROM $t_cs WHERE subkey = '$subkey' AND access_url = $access_url_id";
- $r = Database::query($sql);
- return $r;
- }
- function api_add_setting($val, $var, $sk = null, $type = 'textfield', $c = null, $title = '', $com = '', $sc = null, $skt = null, $a = 1, $v = 0) {
- if (empty($var) || !isset($val)) { return false; }
- $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $var = Database::escape_string($var);
- $val = Database::escape_string($val);
- $a = (int) $a;
- if (empty($a)) { $a = 1; }
-
- $select = "SELECT id FROM $t_settings WHERE variable = '$var' ";
- if (!empty($sk)) {
- $sk = Database::escape_string($sk);
- $select .= " AND subkey = '$sk'";
- }
- if ($a > 1) {
- $select .= " AND access_url = $a";
- } else {
- $select .= " AND access_url = 1 ";
- }
- $res = Database::query($select);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- return $row['id'];
- }
-
-
- $insert = "INSERT INTO $t_settings " .
- "(variable,selected_value," .
- "type,category," .
- "subkey,title," .
- "comment,scope," .
- "subkeytext,access_url,access_url_changeable)" .
- " VALUES ('$var','$val',";
- if (isset($type)) {
- $type = Database::escape_string($type);
- $insert .= "'$type',";
- } else {
- $insert .= "NULL,";
- }
- if (isset($c)) {
- $c = Database::escape_string($c);
- $insert .= "'$c',";
- } else {
- $insert .= "NULL,";
- }
- if (isset($sk)) {
- $sk = Database::escape_string($sk);
- $insert .= "'$sk',";
- } else {
- $insert .= "NULL,";
- }
- if (isset($title)) {
- $title = Database::escape_string($title);
- $insert .= "'$title',";
- } else {
- $insert .= "NULL,";
- }
- if (isset($com)) {
- $com = Database::escape_string($com);
- $insert .= "'$com',";
- } else {
- $insert .= "NULL,";
- }
- if (isset($sc)) {
- $sc = Database::escape_string($sc);
- $insert .= "'$sc',";
- } else {
- $insert .= "NULL,";
- }
- if (isset($skt)) {
- $skt = Database::escape_string($skt);
- $insert .= "'$skt',";
- } else {
- $insert .= "NULL,";
- }
- $insert .= "$a,$v)";
- $res = Database::query($insert);
- return $res;
- }
- function api_is_course_visible_for_user($userid = null, $cid = null) {
- if ($userid == null) {
- $userid = api_get_user_id();
- }
- if (empty($userid) || strval(intval($userid)) != $userid) {
- if (api_is_anonymous()) {
- $userid = api_get_anonymous_id();
- } else {
- return false;
- }
- }
- $cid = Database::escape_string($cid);
- global $is_platformAdmin;
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
- $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
- $sql = "SELECT
- $course_table.category_code,
- $course_table.visibility,
- $course_table.code,
- $course_cat_table.code
- FROM $course_table
- LEFT JOIN $course_cat_table
- ON $course_table.category_code = $course_cat_table.code
- WHERE
- $course_table.code = '$cid'
- LIMIT 1";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
- $visibility = Database::fetch_array($result);
- $visibility = $visibility['visibility'];
- } else {
- $visibility = 0;
- }
-
- if ($visibility === COURSE_VISIBILITY_OPEN_WORLD) {
- return true;
- }
- $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $sql = "SELECT
- tutor_id, status, role
- FROM $tbl_course_user
- WHERE
- user_id = '$userid'
- AND
- relation_type <> '".COURSE_RELATION_TYPE_RRHH."'
- AND
- course_code = '$cid'
- LIMIT 1";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
-
- $cuData = Database::fetch_array($result);
- $_courseUser['role'] = $cuData['role'];
- $is_courseMember = true;
- $is_courseTutor = ($cuData['tutor_id' ] == 1);
- $is_courseAdmin = ($cuData['status'] == 1);
- }
- if (!$is_courseAdmin) {
-
-
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $sql = "SELECT
- session.id_coach, session_admin_id, session.id
- FROM
- $tbl_session as session
- INNER JOIN $tbl_session_course
- ON session_rel_course.id_session = session.id
- AND session_rel_course.course_code = '$cid'
- LIMIT 1";
- $result = Database::query($sql);
- $row = Database::store_result($result);
- if ($row[0]['id_coach'] == $userid) {
- $_courseUser['role'] = 'Professor';
- $is_courseMember = true;
- $is_courseTutor = true;
- $is_courseAdmin = false;
- $is_courseCoach = true;
- $is_sessionAdmin = false;
- Session::write('_courseUser',$_courseUser);
- }
- elseif ($row[0]['session_admin_id'] == $userid) {
- $_courseUser['role'] = 'Professor';
- $is_courseMember = false;
- $is_courseTutor = false;
- $is_courseAdmin = false;
- $is_courseCoach = false;
- $is_sessionAdmin = true;
- } else {
-
- $sql = "SELECT 1
- FROM $tbl_session_course
- WHERE session_rel_course.course_code = '$cid'
- AND session_rel_course.id_coach = '$userid'
- LIMIT 1";
- $result = Database::query($sql);
-
- if (Database::num_rows($result) > 0 ) {
- $_courseUser['role'] = 'Professor';
- $is_courseMember = true;
- $is_courseTutor = true;
- $is_courseCoach = true;
- $is_sessionAdmin = false;
- $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT status FROM $tbl_user
- WHERE user_id = $userid LIMIT 1";
- $result = Database::query($sql);
- if (Database::result($result, 0, 0) == 1) {
- $is_courseAdmin = true;
- } else {
- $is_courseAdmin = false;
- }
- } else {
-
- $sql = "SELECT id
- FROM $tbl_session_course_user
- WHERE id_user = '$userid'
- AND course_code = '$cid'
- LIMIT 1";
- if (Database::num_rows($result) > 0) {
-
- while ($row = Database::fetch_array($result)) {
- $is_courseMember = true;
- $is_courseTutor = false;
- $is_courseAdmin = false;
- $is_sessionAdmin = false;
- }
- }
- }
- }
- }
- switch ($visibility) {
- case COURSE_VISIBILITY_OPEN_WORLD:
- return true;
- case COURSE_VISIBILITY_OPEN_PLATFORM:
- return isset($userid);
- case COURSE_VISIBILITY_REGISTERED:
- case COURSE_VISIBILITY_CLOSED:
- return $is_platformAdmin || $is_courseMember || $is_courseAdmin;
- }
- return false;
- }
- function api_is_element_in_the_session($tool, $element_id, $session_id = null) {
- if (is_null($session_id)) {
- $session_id = intval($_SESSION['id_session']);
- }
-
- switch ($tool) {
- case TOOL_SURVEY :
- $table_tool = Database::get_course_table(TABLE_SURVEY);
- $key_field = 'survey_id';
- break;
- case TOOL_ANNOUNCEMENT :
- $table_tool = Database::get_course_table(TABLE_ANNOUNCEMENT);
- $key_field = 'id';
- break;
- case TOOL_AGENDA :
- $table_tool = Database::get_course_table(TABLE_AGENDA);
- $key_field = 'id';
- break;
- case TOOL_GROUP :
- $table_tool = Database::get_course_table(TABLE_GROUP);
- $key_field = 'id';
- break;
- default: return false;
- }
- $course_id = api_get_course_int_id();
- $sql = "SELECT session_id FROM $table_tool WHERE c_id = $course_id AND $key_field = ".intval($element_id);
- $rs = Database::query($sql);
- if ($element_session_id = Database::result($rs, 0, 0)) {
- if ($element_session_id == intval($session_id)) {
- return true;
- }
- }
- return false;
- }
- function replace_dangerous_char($filename, $strict = 'loose') {
-
- static $search = array("\0", ' ', "\t", "\n", "\r", "\x0B", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
- static $replace = array('', '_', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
-
- $encoding = api_detect_encoding($filename);
-
- $filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding);
-
- $filename = api_transliterate($filename, 'x', $encoding);
-
- $filename = trim($filename);
-
- $filename = trim($filename, '.');
- $filename = trim($filename);
-
- $filename = str_replace($search, $replace, $filename);
- if ($strict == 'strict') {
-
-
-
- $filename = preg_replace('/[^0-9A-Za-z.\-_]/', '', $filename);
- }
-
- $extension = (string)strrchr($filename, '.');
- $extension_len = strlen($extension);
- if ($extension_len > 0 && $extension_len < 250) {
- $filename = substr($filename, 0, -$extension_len);
- return substr($filename, 0, 250 - $extension_len).$extension;
- }
- return substr($filename, 0, 250);
- }
- function api_request_uri() {
- if (!empty($_SERVER['REQUEST_URI'])) {
- return $_SERVER['REQUEST_URI'];
- }
- $uri = $_SERVER['SCRIPT_NAME'];
- if (!empty($_SERVER['QUERY_STRING'])) {
- $uri .= '?'.$_SERVER['QUERY_STRING'];
- }
- $_SERVER['REQUEST_URI'] = $uri;
- return $uri;
- }
- function api_create_include_path_setting() {
- $include_path = ini_get('include_path');
- if (!empty($include_path)) {
- $include_path_array = explode(PATH_SEPARATOR, $include_path);
- $dot_found = array_search('.', $include_path_array);
- if ($dot_found !== false) {
- $result = array();
- foreach ($include_path_array as $path) {
- $result[] = $path;
- if ($path == '.') {
-
- $result[] = api_get_path(LIBRARY_PATH).'pear';
- }
- }
- return implode(PATH_SEPARATOR, $result);
- }
-
- return api_get_path(LIBRARY_PATH).'pear'.PATH_SEPARATOR.$include_path;
- }
-
- return api_get_path(LIBRARY_PATH).'pear';
- }
- function api_get_current_access_url_id() {
- $access_url_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
- $path = Database::escape_string(api_get_path(WEB_PATH));
- $sql = "SELECT id FROM $access_url_table WHERE url = '".$path."'";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
- $access_url_id = Database::result($result, 0, 0);
- return $access_url_id;
- }
-
-
-
-
- return 1;
- }
- function api_get_access_url_from_user($user_id) {
- $user_id = intval($user_id);
- $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
- $table_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
- $sql = "SELECT access_url_id FROM $table_url_rel_user url_rel_user INNER JOIN $table_url u
- ON (url_rel_user.access_url_id = u.id)
- WHERE user_id = ".Database::escape_string($user_id);
- $result = Database::query($sql);
- $url_list = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $url_list[] = $row['access_url_id'];
- }
- return $url_list;
- }
- function api_get_status_of_user_in_course ($user_id, $course_code) {
- $tbl_rel_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- if (!empty($user_id) && !empty($course_code)) {
- $user_id = Database::escape_string(intval($user_id));
- $course_code = Database::escape_string($course_code);
- $sql = 'SELECT status FROM '.$tbl_rel_course_user.'
- WHERE user_id='.$user_id.' AND course_code="'.$course_code.'";';
- $result = Database::query($sql);
- $row_status = Database::fetch_array($result, 'ASSOC');
- return $row_status['status'];
- } else {
- return 0;
- }
- }
- function api_is_in_course($course_code = null) {
- if (isset($_SESSION['_course']['sysCode'])) {
- if (!empty($course_code)) {
- return $course_code == $_SESSION['_course']['sysCode'];
- }
- return true;
- }
- return false;
- }
- function api_is_in_group($group_id = null, $course_code = null) {
- if (!empty($course_code)) {
- if (isset($_SESSION['_course']['sysCode'])) {
- if ($course_code != $_SESSION['_course']['sysCode']) return false;
- } else {
- return false;
- }
- }
- if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
- if (!empty($group_id)) {
- return $group_id == $_SESSION['_gid'];
- } else {
- return true;
- }
- }
- return false;
- }
- function api_get_encrypted_password($password, $salt = '') {
- global $_configuration;
- $password_encryption = isset($_configuration['password_encryption']) ? $_configuration['password_encryption'] : 'sha1';
- switch ($password_encryption) {
- case 'sha1':
- return empty($salt) ? sha1($password) : sha1($password.$salt);
- case 'none':
- return $password;
- case 'md5':
- default:
- return empty($salt) ? md5($password) : md5($password.$salt);
- }
- }
- function api_is_valid_secret_key($original_key_secret, $security_key) {
- return $original_key_secret == sha1($security_key);
- }
- function api_is_user_of_course($course_id, $user_id) {
- $tbl_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $sql = 'SELECT user_id FROM '.$tbl_course_rel_user.' WHERE course_code="'.Database::escape_string($course_id).'" AND user_id="'.Database::escape_string($user_id).'" AND relation_type<>'.COURSE_RELATION_TYPE_RRHH.' ';
- $result = Database::query($sql);
- return Database::num_rows($result) == 1;
- }
- function api_is_windows_os() {
- if (function_exists('php_uname')) {
-
-
- $os = php_uname();
- }
-
- elseif (isset($_ENV['OS'])) {
-
- $os = $_ENV['OS'];
- }
- elseif (defined('PHP_OS')) {
-
-
- $os = PHP_OS;
- } else {
- return false;
- }
- return strtolower(substr((string)$os, 0, 3 )) == 'win';
- }
- function api_is_xml_http_request() {
- return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
- }
- if (!function_exists('json_encode')) {
- function json_encode($a = false) {
- if (is_null($a)) return 'null';
- if ($a === false) return 'false';
- if ($a === true) return 'true';
- if (is_scalar($a)) {
- if (is_float($a)) {
-
- return floatval(str_replace(",", ".", strval($a)));
- }
- if (is_string($a)) {
- static $json_replaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
- return '"' . str_replace($json_replaces[0], $json_replaces[1], $a) . '"';
- }
- else
- return $a;
- }
- $is_list = true;
- for ($i = 0, reset($a); $i < count($a); $i++, next($a)) {
- if (key($a) !== $i) {
- $is_list = false;
- break;
- }
- }
- $result = array();
- if ($is_list) {
- foreach ($a as $v) $result[] = json_encode($v);
- return '[' . join(',', $result) . ']';
- }
- else {
- foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
- return '{' . join(',', $result) . '}';
- }
- }
- }
- function api_getimagesize($path) {
- $image = new Image($path);
- return $image->get_image_size();
- }
- function api_resize_image($image, $target_width, $target_height) {
- $image_properties = api_getimagesize($image);
- return api_calculate_image_size($image_properties['width'], $image_properties['height'], $target_width, $target_height);
- }
- function api_calculate_image_size($image_width, $image_height, $target_width, $target_height) {
-
- $result = array('width' => $image_width, 'height' => $image_height);
- if ($image_width <= 0 || $image_height <= 0) {
- return $result;
- }
- $resize_factor_width = $target_width / $image_width;
- $resize_factor_height = $target_height / $image_height;
- $delta_width = $target_width - $image_width * $resize_factor_height;
- $delta_height = $target_height - $image_height * $resize_factor_width;
- if ($delta_width > $delta_height) {
- $result['width'] = ceil($image_width * $resize_factor_height);
- $result['height'] = ceil($image_height * $resize_factor_height);
- }
- elseif ($delta_width < $delta_height) {
- $result['width'] = ceil($image_width * $resize_factor_width);
- $result['height'] = ceil($image_height * $resize_factor_width);
- }
- else {
- $result['width'] = ceil($target_width);
- $result['height'] = ceil($target_height);
- }
- return $result;
- }
- function api_get_tools_lists($my_tool = null) {
- $tools_list = array(
- TOOL_DOCUMENT, TOOL_THUMBNAIL, TOOL_HOTPOTATOES,
- TOOL_CALENDAR_EVENT, TOOL_LINK, TOOL_COURSE_DESCRIPTION, TOOL_SEARCH,
- TOOL_LEARNPATH, TOOL_ANNOUNCEMENT, TOOL_FORUM, TOOL_THREAD, TOOL_POST,
- TOOL_DROPBOX, TOOL_QUIZ, TOOL_USER, TOOL_GROUP, TOOL_BLOGS, TOOL_CHAT,
- TOOL_CONFERENCE, TOOL_STUDENTPUBLICATION, TOOL_TRACKING, TOOL_HOMEPAGE_LINK,
- TOOL_COURSE_SETTING, TOOL_BACKUP, TOOL_COPY_COURSE_CONTENT, TOOL_RECYCLE_COURSE,
- TOOL_COURSE_HOMEPAGE, TOOL_COURSE_RIGHTS_OVERVIEW, TOOL_UPLOAD, TOOL_COURSE_MAINTENANCE,
- TOOL_VISIO, TOOL_VISIO_CONFERENCE, TOOL_VISIO_CLASSROOM, TOOL_SURVEY, TOOL_WIKI,
- TOOL_GLOSSARY, TOOL_GRADEBOOK, TOOL_NOTEBOOK, TOOL_ATTENDANCE, TOOL_COURSE_PROGRESS
- );
- if (empty($my_tool)) {
- return $tools_list;
- }
- return in_array($my_tool, $tools_list) ? $my_tool : '';
- }
- function api_get_tool_urls() {
- return array(
- TOOL_DOCUMENT => api_get_path(WEB_CODE_PATH).'document/document.php',
- TOOL_QUIZ => api_get_path(WEB_CODE_PATH).'exercice/exercice.php',
- TOOL_ANNOUNCEMENT => api_get_path(WEB_CODE_PATH).'announcements/announcements.php',
- TOOL_CALENDAR_EVENT => api_get_path(WEB_CODE_PATH).'calendar/agenda.php',
- TOOL_STUDENTPUBLICATION => api_get_path(WEB_CODE_PATH).'work/work.php',
- TOOL_LEARNPATH => api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php'
- );
- }
- function api_check_term_condition($user_id) {
- if (api_get_setting('allow_terms_conditions') == 'true') {
- $t_uf = Database::get_main_table(TABLE_MAIN_USER_FIELD);
- $t_ufv = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
-
- if (LegalManager::count() == 0) {
- return true;
- }
-
- $sql = "SELECT field_value FROM $t_ufv ufv inner join $t_uf uf on ufv.field_id= uf.id
- WHERE field_value <> '' AND field_variable = 'legal_accept' AND user_id = ".intval($user_id);
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $rowv = Database::fetch_row($res);
- $rowv = $rowv[0];
- $user_conditions = explode(':', $rowv);
- $version = $user_conditions[0];
- $lang_id = $user_conditions[1];
- $real_version = LegalManager::get_last_version($lang_id);
- return $version >= $real_version;
- }
- return false;
- }
- return false;
- }
- function api_get_tool_information($tool_id) {
- $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $t_tool WHERE c_id = $course_id AND id = ".intval($tool_id);
- $rs = Database::query($sql);
- return Database::fetch_array($rs);
- }
- function api_get_tool_information_by_name($name) {
- $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $t_tool WHERE c_id = $course_id AND name = '".Database::escape_string($name)."' ";
- $rs = Database::query($sql);
- return Database::fetch_array($rs, 'ASSOC');
- }
- function is_allowed_to_edit() {
- return api_is_allowed_to_edit();
- }
- function api_send_mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null) {
- require_once api_get_path(LIBRARY_PATH).'phpmailer/class.phpmailer.php';
- if (empty($platform_email['SMTP_FROM_NAME'])) {
- $platform_email['SMTP_FROM_NAME'] = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
- }
- if (empty($platform_email['SMTP_FROM_EMAIL'])) {
- $platform_email['SMTP_FROM_EMAIL'] = api_get_setting('emailAdministrator');
- }
- $matches = array();
- if (preg_match('/([^<]*)<(.+)>/si', $to, $matches)) {
- $recipient_name = trim($matches[1]);
- $recipient_email = trim($matches[2]);
- } else {
- $recipient_name = '';
- $recipient_email = trim($to);
- }
- $sender_name = '';
- $sender_email = '';
- $extra_headers = $additional_headers;
-
-
-
-
- $mail = new PHPMailer();
- $mail->CharSet = $platform_email['SMTP_CHARSET'];
- $mail->Mailer = $platform_email['SMTP_MAILER'];
- $mail->Host = $platform_email['SMTP_HOST'];
- $mail->Port = $platform_email['SMTP_PORT'];
- if ($platform_email['SMTP_AUTH']) {
- $mail->SMTPAuth = 1;
- $mail->Username = $platform_email['SMTP_USER'];
- $mail->Password = $platform_email['SMTP_PASS'];
- }
- $mail->Priority = 3;
- $mail->AddCustomHeader('Errors-To: '.$platform_email['SMTP_FROM_EMAIL']);
- $mail->IsHTML(0);
- $mail->SMTPKeepAlive = true;
-
-
-
- if ($sender_email != '') {
- $mail->From = $sender_email;
- $mail->Sender = $sender_email;
-
- } else {
- $mail->From = $platform_email['SMTP_FROM_EMAIL'];
- $mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
-
- }
- if ($sender_name != '') {
- $mail->FromName = $sender_name;
- } else {
- $mail->FromName = $platform_email['SMTP_FROM_NAME'];
- }
- $mail->Subject = $subject;
- $mail->Body = $message;
-
-
- if (api_valid_email($recipient_email)) {
- $mail->AddAddress($recipient_email, $recipient_name);
- }
- if ($extra_headers != '') {
- $mail->AddCustomHeader($extra_headers);
- }
-
- if (!$mail->Send()) {
- return 0;
- }
-
- $mail->ClearAddresses();
- return 1;
- }
- function api_is_global_platform_admin($user_id = null) {
- $user_id = intval($user_id);
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- if (api_is_platform_admin_by_id($user_id)) {
- $my_url_list = api_get_access_url_from_user($user_id);
-
- if (in_array(1, $my_url_list)) {
- return true;
- } else {
- return false;
- }
- }
- return false;
- }
- function api_global_admin_can_edit_admin($admin_id_to_check, $my_user_id = null, $allow_session_admin = false) {
- if (empty($my_user_id)) {
- $my_user_id = api_get_user_id();
- }
- $iam_a_global_admin = api_is_global_platform_admin($my_user_id);
- $user_is_global_admin = api_is_global_platform_admin($admin_id_to_check);
- if ($iam_a_global_admin) {
-
- return true;
- } else {
-
- $is_platform_admin = api_is_platform_admin_by_id($my_user_id);
- if ($allow_session_admin) {
- $is_platform_admin = api_is_platform_admin_by_id($my_user_id) || (api_get_user_status($my_user_id) == SESSIONADMIN);
- }
- if ($is_platform_admin) {
- if ($user_is_global_admin) {
- return false;
- } else {
- return true;
- }
- } else {
- return false;
- }
- }
- }
- function api_protect_super_admin($admin_id_to_check, $my_user_id = null, $allow_session_admin = false) {
- if (api_global_admin_can_edit_admin($admin_id_to_check, $my_user_id, $allow_session_admin)) {
- return true;
- } else {
- api_not_allowed();
- }
- }
- function api_protect_global_admin_script() {
- if (!api_is_global_platform_admin()) {
- api_not_allowed();
- return false;
- }
- return true;
- }
- function api_get_template($path_type = 'rel') {
- $path_types = array('rel', 'abs');
- $template_path = '';
- if (in_array($path_type, $path_types)) {
- if ($path_type == 'rel') {
- $template_path = api_get_path(SYS_TEMPLATE_PATH);
- } else {
- $template_path = api_get_path(WEB_TEMPLATE_PATH);
- }
- }
- $actived_theme = 'default';
- if (api_get_setting('active_template')) {
- $actived_theme = api_get_setting('active_template');
- }
- $actived_theme_path = $template_path.$actived_theme.DIRECTORY_SEPARATOR;
- return $actived_theme_path;
- }
- function api_browser_support($format="") {
- require_once api_get_path(LIBRARY_PATH).'browser/Browser.php';
- $browser = new Browser();
-
- $current_browser = $browser->getBrowser();
- $a_versiontemp = explode('.', $browser->getVersion());
- $current_majorver= $a_versiontemp[0];
-
- if ($format=='svg'){
- if (($current_browser == 'Internet Explorer' && $current_majorver >= 9) || ($current_browser == 'Firefox' && $current_majorver > 1) || ($current_browser == 'Safari' && $current_majorver >= 4) || ($current_browser == 'Chrome' && $current_majorver >= 1) || ($current_browser == 'Opera' && $current_majorver >= 9)) {
- return true;
- } else {
- return false;
- }
- } elseif($format=='pdf') {
-
- if($current_browser == 'Chrome' && $current_majorver >= 6){
- return true;
- } else {
- return false;
- }
- } elseif($format=='tif' || $format=='tiff'){
-
- if($current_browser == 'Safari' && $current_majorver >= 5){
- return true;
- } else {
- return false;
- }
- } elseif($format=='ogg' || $format=='ogx'|| $format=='ogv' || $format=='oga'){
-
- if (($current_browser == 'Firefox' && $current_majorver >= 3) || ($current_browser == 'Chrome' && $current_majorver >= 3) || ($current_browser == 'Opera' && $current_majorver >= 9)) {
- return true;
- } else {
- return false;
- }
- } elseif($format=='mpg' || $format=='mpeg'){
-
- if(($current_browser == 'Safari' && $current_majorver >= 5)){
- return true;
- } else {
- return false;
- }
- } elseif($format=='mp4') {
-
- if($current_browser == 'Android' || $current_browser == 'iPhone') {
- return true;
- } else {
- return false;
- }
- } elseif($format=='mov') {
-
- if($current_browser == 'Safari' && $current_majorver >= 5 || $current_browser == 'iPhone'){
- return true;
- } else {
- return false;
- }
- } elseif($format=='avi') {
-
- if($current_browser == 'Safari' && $current_majorver >= 5){
- return true;
- }
- else{
- return false;
- }
- } elseif($format=='wmv') {
-
- if ($current_browser == 'Firefox' && $current_majorver >= 4){
- return true;
- } else {
- return false;
- }
- } elseif($format=='webm') {
-
- if(($current_browser == 'Firefox' && $current_majorver >= 4) || ($current_browser == 'Opera' && $current_majorver >= 9) || ($current_browser == 'Internet Explorer' && $current_majorver >= 9)|| ($current_browser == 'Chrome' && $current_majorver >=9)|| $current_browser == 'Android'){
- return true;
- }
- else{
- return false;
- }
- } elseif($format=='wav') {
-
- if (($current_browser == 'Firefox' && $current_majorver >= 4) || ($current_browser == 'Safari' && $current_majorver >= 5) || ($current_browser == 'Opera' && $current_majorver >= 9) || ($current_browser == 'Internet Explorer' && $current_majorver >= 9)|| ($current_browser == 'Chrome' && $current_majorver > 9)|| $current_browser == 'Android' || $current_browser == 'iPhone'){
- return true;
- }
- else{
- return false;
- }
- } elseif($format=='mid' || $format=='kar') {
-
- if($current_browser == 'Opera'&& $current_majorver >= 9 || $current_browser == 'Android'){
- return true;
- } else {
- return false;
- }
- } elseif($format=='wma') {
-
- if($current_browser == 'Firefox' && $current_majorver >= 4){
- return true;
- }
- else{
- return false;
- }
- } elseif($format=='au') {
-
- if($current_browser == 'Safari' && $current_majorver >= 5){
- return true;
- }
- else{
- return false;
- }
- } elseif($format=='mp3') {
-
- if(($current_browser == 'Safari' && $current_majorver >= 5) || ($current_browser == 'Chrome' && $current_majorver >=6)|| ($current_browser == 'Internet Explorer' && $current_majorver >= 9)|| $current_browser == 'Android' || $current_browser == 'iPhone'){
- return true;
- } else {
- return false;
- }
- } elseif($format=="check_browser") {
- $array_check_browser=array($current_browser, $current_majorver);
- return $array_check_browser;
- } else {
- return false;
- }
- }
- function api_check_browscap() {
- $setting = ini_get('browscap');
- if ($setting) {
- $browser = get_browser($_SERVER['HTTP_USER_AGENT'], true);
- if (strpos($setting, 'browscap.ini') && !empty($browser)) {
- return true;
- }
- }
- return false;
- }
- function api_get_js($file) {
- return '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/'.$file.'"></script>'."\n";
- }
- function api_get_css($file, $media = 'screen') {
- return '<link href="'.$file.'" rel="stylesheet" media="'.$media.'" type="text/css" />'."\n";
- }
- function api_get_jqgrid_js() {
- return api_get_jquery_libraries_js(array('jqgrid'));
- }
- function get_available_jquery_ui_languages() {
-
- return array(
- 'af',
- 'sq',
- 'ar-DZ',
- 'ar',
- 'hy',
- 'az',
- 'eu',
- 'bs',
- 'bg',
- 'ca',
- 'zh-HK',
- 'zh-CN',
- 'zh-TW',
- 'hr',
- 'cs',
- 'da',
- 'nl-BE',
- 'nl',
- 'en-AU',
- 'en-NZ',
- 'en-GB',
- 'eo',
- 'et',
- 'fo',
- 'fa',
- 'fi',
- 'fr',
- 'fr-CH',
- 'gl',
- 'ge',
- 'de',
- 'el',
- 'he',
- 'hi',
- 'hu',
- 'is',
- 'id',
- 'it',
- 'ja',
- 'kk',
- 'km',
- 'ko',
- 'lv',
- 'lt',
- 'lb',
- 'mk',
- 'ml',
- 'ms',
- 'no',
- 'pl',
- 'pt',
- 'pt-BR',
- 'rm',
- 'ro',
- 'ru',
- 'sr',
- 'sr-SR',
- 'sk',
- 'sl',
- 'es',
- 'sv',
- 'ta',
- 'th',
- 'tj',
- 'tr',
- 'uk',
- 'vi',
- 'cy-GB'
- );
- }
- function api_get_jquery_libraries_js($libraries) {
- $js = '';
- $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
- $isocode = api_get_language_isocode();
- if (in_array('jquery-ui-i18n', $libraries)) {
- $js .= api_get_js('jquery-ui/jquery-ui-i18n.min.js');
- if (!in_array($isocode, get_available_jquery_ui_languages())) {
- $isocode = 'en';
- }
- if ($isocode == 'en') {
- $isocode = '';
- }
- $js .= "<script> $(function() { $.datepicker.setDefaults($.datepicker.regional['$isocode']); });</script>";
- }
-
- if (in_array('jqgrid', $libraries)) {
- $languaje = 'en';
- $platform_isocode = strtolower(api_get_language_isocode());
-
- $jqgrid_langs = array('bg', 'bg1251', 'cat','cn','cs','da','de','el','en','es','fa','fi','fr','gl','he','hu','is','it','ja','nl','no','pl','pt-br','pt','ro','ru','sk','sr','sv','tr','ua');
- if (in_array($platform_isocode, $jqgrid_langs)) {
- $languaje = $platform_isocode;
- }
- $js .= api_get_css($js_path.'jqgrid/css/ui.jqgrid.css');
- $js .= api_get_js('jqgrid/js/i18n/grid.locale-'.$languaje.'.js');
- $js .= api_get_js('jqgrid/js/jquery.jqGrid.min.js');
- }
-
- if (in_array('jquery-upload', $libraries)) {
- $js .= api_get_js('jquery-upload/jquery.fileupload.js');
- $js .= api_get_js('jquery-upload/jquery.fileupload-ui.js');
- $js .= api_get_css($js_path.'jquery-upload/jquery.fileupload-ui.css');
- }
- if (in_array('bxslider',$libraries)) {
- $js .= api_get_js('bxslider/jquery.bxSlider.min.js');
- $js .= api_get_css($js_path.'bxslider/bx_styles/bx_styles.css');
- }
- return $js;
- }
- function api_get_course_url($course_code = null, $session_id = null) {
- $session_url = '';
- if (empty($course_code)) {
- $course_info = api_get_course_info();
- } else {
- $course_info = api_get_course_info($course_code);
- }
- if (empty($session_id)) {
- $session_url = '?id_session='.api_get_session_id();
- } else {
- $session_url = '?id_session='.intval($session_id);
- }
-
- if (!empty($course_info['path'])) {
- return api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php'.$session_url;
- }
- return null;
- }
- function api_get_multiple_access_url() {
- global $_configuration;
- if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
- return true;
- }
- return false;
- }
- function api_is_multiple_url_enabled() {
- return api_get_multiple_access_url();
- }
- function api_get_unique_id() {
- $id = md5(time().uniqid().api_get_user_id().api_get_course_id().api_get_session_id());
- return $id;
- }
- function api_get_home_path() {
- $home = 'home/';
- if (api_get_multiple_access_url()) {
- $access_url_id = api_get_current_access_url_id();
- $url_info = api_get_access_url($access_url_id);
- $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
- $clean_url = replace_dangerous_char($url);
- $clean_url = str_replace('/', '-', $clean_url);
- $clean_url .= '/';
-
- if ($clean_url != 'localhost/') {
-
- }
- $home = 'home/'.$clean_url;
- }
- return $home;
- }
- function api_get_course_table_condition($and = true) {
- $course_id = api_get_course_int_id();
- $condition = '';
- $condition_add = $and ? " AND " : " WHERE ";
- if (!empty($course_id)) {
- $condition = " $condition_add c_id = $course_id";
- }
- return $condition;
- }
- function api_resource_is_locked_by_gradebook($item_id, $link_type, $course_code = null) {
- if (api_is_platform_admin()) {
- return false;
- }
- if (api_get_setting('gradebook_locking_enabled') == 'true') {
- if (empty($course_code)) {
- $course_code = api_get_course_id();
- }
- $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
- $item_id = intval($item_id);
- $link_type = intval($link_type);
- $course_code = Database::escape_string($course_code);
- $sql = "SELECT locked FROM $table WHERE locked = 1 AND ref_id = $item_id AND type = $link_type AND course_code = '$course_code' ";
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- return true;
- }
- }
- return false;
- }
- function api_block_course_item_locked_by_gradebook($item_id, $link_type, $course_code = null) {
- if (api_is_platform_admin()) {
- return false;
- }
- if (api_resource_is_locked_by_gradebook($item_id, $link_type, $course_code)) {
- $message = Display::return_message(get_lang('ResourceLockedByGradebook'), 'warning');
- api_not_allowed(true, $message);
- }
- }
- function api_check_php_version() {
- if (!function_exists('version_compare') || version_compare( phpversion(), REQUIRED_PHP_VERSION, '<')) {
- return false;
- }
- return true;
- }
- function api_check_archive_dir() {
- if (is_dir(api_get_path(SYS_ARCHIVE_PATH)) && !is_writable(api_get_path(SYS_ARCHIVE_PATH))) {
- $message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'),'warning');
- api_not_allowed(true, $message);
- }
- }
- function api_get_locked_settings() {
- return array(
- 'server_type',
- 'permanently_remove_deleted_files',
- 'account_valid_duration',
- 'service_visio',
- 'service_ppt2lp',
- 'wcag_anysurfer_public_pages',
- 'upload_extensions_list_type',
- 'upload_extensions_blacklist',
- 'upload_extensions_whitelist',
- 'upload_extensions_skip',
- 'upload_extensions_replace_by',
- 'hide_dltt_markup',
- 'split_users_upload_directory',
- 'permissions_for_new_directories',
- 'permissions_for_new_files',
- 'platform_charset',
- 'service_visio',
- 'ldap_description',
- 'cas_activate',
- 'cas_server',
- 'cas_server_uri',
- 'cas_port',
- 'cas_protocol',
- 'cas_add_user_activate',
- 'update_user_info_cas_with_ldap',
- 'languagePriority1',
- 'languagePriority2',
- 'languagePriority3',
- 'languagePriority4',
- 'login_is_email',
- 'chamilo_database_version'
- );
- }
- function api_user_is_login($user_id = null) {
- $user_id = empty($user_id) ? api_get_user_id() : intval($user_id);
- return $user_id && !api_is_anonymous();
- }
- function api_get_real_ip(){
-
- global $debug;
- $ip = trim($_SERVER['REMOTE_ADDR']);
- if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- list($ip1,$ip2) = split(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
- $ip = trim($ip1);
- }
- if (!empty($debug)) error_log('Real IP: '.$ip);
- return $ip;
- }
- function api_check_ip_in_range($ip,$range) {
- if (empty($ip) or empty($range)) {
- return false;
- }
- $ip_ip = ip2long ($ip);
- $ranges = array();
-
- if (strpos($range,',')!==false) {
- $ranges = explode(',',$range);
- } else {
- $ranges = array($range);
- }
- foreach ($ranges as $range) {
- $range = trim($range);
- if (empty($range)) { continue; }
- if (strpos($range,'/')===false) {
- if (strcmp($ip,$range)===0) {
- return true;
- }
- continue;
- }
-
- list ($net, $mask) = explode("/", $range);
- $ip_net = ip2long ($net);
-
- $ip_mask = ~((1 << (32 - $mask)) - 1);
- $ip_ip_net = $ip_ip & $ip_mask;
- if ($ip_ip_net == $ip_net) {
- return true;
- }
- }
- return false;
- }
- function api_check_user_access_to_legal($course_visibility) {
- $course_visibility_list = array(COURSE_VISIBILITY_OPEN_WORLD, COURSE_VISIBILITY_OPEN_PLATFORM);
- return in_array($course_visibility, $course_visibility_list) || api_is_drh();
- }
- function api_is_global_chat_enabled(){
- $global_chat_is_enabled = !api_is_anonymous() && api_get_setting('allow_global_chat') == 'true' && api_get_setting('allow_social_tool') == 'true';
- return $global_chat_is_enabled;
- }
- function api_set_default_visibility($item_id, $tool_id, $group_id = null) {
- $original_tool_id = $tool_id;
- switch ($tool_id) {
- case TOOL_LINK:
- $tool_id = 'links';
- break;
- case TOOL_DOCUMENT:
- $tool_id = 'documents';
- break;
- case TOOL_LEARNPATH:
- $tool_id = 'learning';
- break;
- case TOOL_ANNOUNCEMENT:
- $tool_id = 'announcements';
- break;
- case TOOL_FORUM:
- case TOOL_FORUM_CATEGORY:
- case TOOL_FORUM_THREAD:
- $tool_id = 'forums';
- break;
- case TOOL_QUIZ:
- $tool_id = 'quiz';
- break;
- }
- $setting = api_get_setting('tool_visible_by_default_at_creation');
- if (isset($setting[$tool_id])) {
- $visibility = 'invisible';
- if ($setting[$tool_id] == 'true') {
- $visibility = 'visible';
- }
- if (empty($group_id)) {
- $group_id = api_get_group_id();
- }
- api_item_property_update(api_get_course_info(), $original_tool_id, $item_id, $visibility, api_get_user_id(), $group_id, null, null, null, api_get_session_id());
-
- switch ($original_tool_id) {
- case TOOL_QUIZ:
- $objExerciseTmp = new Exercise();
- $objExerciseTmp->read($item_id);
- if ($visibility == 'visible') {
- $objExerciseTmp->enable();
- $objExerciseTmp->save();
- } else {
- $objExerciseTmp->disable();
- $objExerciseTmp->save();
- }
- break;
- }
- }
- }
- function api_get_security_key() {
- global $_configuration;
- return $_configuration['security_key'];
- }
- function api_get_datetime_picker_js($htmlHeadXtra) {
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/jquery-ui-timepicker-addon.js" type="text/javascript" language="javascript"></script>';
- $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css" />';
- $isocode = api_get_language_isocode();
- if ($isocode != 'en') {
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/localization/jquery-ui-timepicker-'.$isocode.'.js" type="text/javascript" language="javascript"></script>';
- }
- return $htmlHeadXtra;
- }
- function api_detect_user_roles($user_id, $course_code, $session_id = 0) {
- $user_roles = array();
-
- $url_id = api_get_current_access_url_id();
- if (api_is_platform_admin_by_id($user_id, $url_id)) {
- $user_roles[] = PLATFORM_ADMIN;
- }
-
- if (!empty($session_id)) {
- if (SessionManager::user_is_general_coach($user_id, $session_id)) {
- $user_roles[] = SESSION_GENERAL_COACH;
- }
- }
- if (!empty($course_code)) {
- if (empty($session_id)) {
- if (CourseManager::is_course_teacher($user_id, $course_code)) {
- $user_roles[] = COURSEMANAGER;
- }
- if (CourseManager::get_tutor_in_course_status($user_id, $course_code)) {
- $user_roles[] = COURSE_TUTOR;
- }
- if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
- $user_roles[] = COURSE_STUDENT;
- }
- } else {
- $user_status_in_session = SessionManager::get_user_status_in_course_session($user_id, $course_code, $session_id);
- if (!empty($user_status_in_session)) {
- if ($user_status_in_session == 0) {
- $user_roles[] = SESSION_STUDENT;
- }
- if ($user_status_in_session == 2) {
- $user_roles[] = SESSION_COURSE_COACH;
- }
- }
-
- }
- }
- return $user_roles;
- }
- function api_get_roles_to_string($roles) {
- $role_names = array();
- if (!empty($roles)) {
- foreach ($roles as $role) {
- $role_names[] = get_status_from_code($role);
- }
- }
- if (!empty($role_names)) {
- return implode(', ', $role_names);
- }
- return null;
- }
- function role_actions() {
- return array(
- 'course' => array(
- 'create',
- 'read',
- 'edit',
- 'delete'
- ),
- 'admin' => array(
- 'create',
- 'read',
- 'edit',
- 'delete'
- )
- );
- }
- function api_coach_can_edit_view_results($course_code = null, $session_id = null) {
- $user_id = api_get_user_id();
- if (empty($course_code)) {
- $course_code = api_get_course_id();
- }
- if (empty($session_id)) {
- $session_id = api_get_session_id();
- }
- if (api_is_platform_admin()) {
- return true;
- }
- $roles = api_detect_user_roles($user_id, $course_code, $session_id);
- if (in_array(SESSION_COURSE_COACH, $roles)) {
- return api_get_setting('session_tutor_reports_visibility') == 'true';
- } else {
- if (in_array(COURSEMANAGER, $roles)) {
- return true;
- }
- return false;
- }
- }
- function api_get_js_simple($file) {
- return '<script type="text/javascript" src="'.$file.'"></script>'."\n";
- }
- function api_set_settings_and_plugins() {
- global $_configuration;
- $_setting = array();
- $_plugins = array();
-
- $settings_by_access_list = array();
- $access_url_id = api_get_current_access_url_id();
- if ($access_url_id != 1) {
- $url_info = api_get_access_url($_configuration['access_url']);
- if ($url_info['active'] == 1) {
- $settings_by_access = & api_get_settings(null, 'list', $_configuration['access_url'], 1);
- foreach ($settings_by_access as & $row) {
- if (empty($row['variable'])) {
- $row['variable'] = 0;
- }
- if (empty($row['subkey'])) {
- $row['subkey'] = 0;
- }
- if (empty($row['category'])) {
- $row['category'] = 0;
- }
- $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
- }
- }
- }
- $result = api_get_settings(null, 'list', 1);
- foreach ($result as & $row) {
- if ($access_url_id != 1) {
- if ($url_info['active'] == 1) {
- $var = empty($row['variable']) ? 0 : $row['variable'];
- $subkey = empty($row['subkey']) ? 0 : $row['subkey'];
- $category = empty($row['category']) ? 0 : $row['category'];
- }
- if ($row['access_url_changeable'] == 1 && $url_info['active'] == 1) {
- if (isset($settings_by_access_list[$var]) &&
- $settings_by_access_list[$var][$subkey][$category]['selected_value'] != '') {
- if ($row['subkey'] == null) {
- $_setting[$row['variable']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
- } else {
- $_setting[$row['variable']][$row['subkey']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
- }
- } else {
- if ($row['subkey'] == null) {
- $_setting[$row['variable']] = $row['selected_value'];
- } else {
- $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
- }
- }
- } else {
- if ($row['subkey'] == null) {
- $_setting[$row['variable']] = $row['selected_value'];
- } else {
- $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
- }
- }
- } else {
- if ($row['subkey'] == null) {
- $_setting[$row['variable']] = $row['selected_value'];
- } else {
- $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
- }
- }
- }
- $result = api_get_settings('Plugins', 'list', $access_url_id);
- $_plugins = array();
- foreach ($result as & $row) {
- $key = & $row['variable'];
- if (is_string($_setting[$key])) {
- $_setting[$key] = array();
- }
- $_setting[$key][] = $row['selected_value'];
- $_plugins[$key][] = $row['selected_value'];
- }
-
- $_SESSION['_setting'] = $_setting;
- $_SESSION['_plugins'] = $_plugins;
- }
- function api_set_setting_last_update() {
-
- api_set_setting('settings_latest_update', api_get_utc_datetime());
- }
- function api_set_memory_limit($mem){
-
- if (!function_exists('ini_set') || is_null($mem) || $mem == -1) {
- return false;
- }
- $memory_limit = ini_get('memory_limit');
- if (api_get_bytes_memory_limit($mem) > api_get_bytes_memory_limit($memory_limit)){
- ini_set('memory_limit', $mem);
- return true;
- }
- return false;
- }
- function api_get_bytes_memory_limit($mem){
- $size = strtolower(substr($mem,-1));
- switch ($size) {
- case 't':
- $mem = intval(substr($mem,-1))*1024*1024*1024*1024;
- break;
- case 'g':
- $mem = intval(substr($mem,0,-1))*1024*1024*1024;
- break;
- case 'm':
- $mem = intval(substr($mem,0,-1))*1024*1024;
- break;
- case 'k':
- $mem = intval(substr($mem,0,-1))*1024;
- break;
- default:
-
- $mem = intval($mem);
- break;
- }
- return $mem;
- }
- function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '', $extra_headers = '') {
- api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name, $sender_email, $extra_headers);
- }
- function api_mail_html($recipient_name, $recipient_email, $subject, $body, $sender_name = '', $sender_email = '', $extra_headers = null, $data_file = array(), $embedded_image = false) {
- global $app;
- $reply_to_mail = $sender_email;
- $reply_to_name = $sender_name;
- if (isset($extra_headers['reply_to'])) {
- $reply_to_mail = $extra_headers['reply_to']['mail'];
- $reply_to_name = $extra_headers['reply_to']['name'];
- }
- try {
- $message = \Swift_Message::newInstance()
- ->setSubject($subject)
- ->setFrom(array($sender_email => $sender_name))
- ->setTo(array($recipient_email => $recipient_name))
- ->setReplyTo(array($reply_to_mail => $reply_to_name))
- ->setBody($body);
- if (!empty($data_file)) {
-
- $message->attach(Swift_Attachment::fromPath($data_file['path']))->setFilename($data_file['filename']);
- }
- $type = $message->getHeaders()->get('Content-Type');
- $type->setValue('text/html');
- $type->setParameter('charset', 'utf-8');
- $app['monolog']->addDebug($message);
- $result = $app['mailer']->send($message);
- return $result;
- } catch (Exception $e) {
- $app['monolog']->addDebug('Email address not valid:' . $e->getMessage());
- }
- return false;
- $mail = new PHPMailer();
- $mail->Mailer = $platform_email['SMTP_MAILER'];
- $mail->Host = $platform_email['SMTP_HOST'];
- $mail->Port = $platform_email['SMTP_PORT'];
- $mail->CharSet = $platform_email['SMTP_CHARSET'];
- $mail->WordWrap = 200;
- if ($platform_email['SMTP_AUTH']) {
- $mail->SMTPAuth = 1;
- $mail->Username = $platform_email['SMTP_USER'];
- $mail->Password = $platform_email['SMTP_PASS'];
- }
- $mail->Priority = 3;
- $mail->AddCustomHeader('Errors-To: '.$platform_email['SMTP_FROM_EMAIL']);
- $mail->SMTPKeepAlive = true;
- if (($sender_email != '') && ($sender_name != '')) {
- $mail->AddReplyTo($sender_email, $sender_name);
- }
- if (isset($extra_headers['reply_to'])) {
- $mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']);
- }
-
-
-
- if ($sender_email != '') {
- $mail->From = $sender_email;
- $mail->Sender = $sender_email;
-
- } else {
- $mail->From = $platform_email['SMTP_FROM_EMAIL'];
- $mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
-
- }
- if ($sender_name != '') {
- $mail->FromName = $sender_name;
- } else {
- $mail->FromName = $platform_email['SMTP_FROM_NAME'];
- }
- $mail->Subject = $subject;
- $mail->AltBody = strip_tags(str_replace('<br />',"\n", api_html_entity_decode($message)));
-
- if ($embedded_image) {
-
- preg_match_all("/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']?[^>]*>/i", $message, $m);
-
- $new_images_html = array();
- $i = 1;
- if (!empty($m[1])) {
- foreach ($m[1] as $image_path) {
- $real_path = realpath($image_path);
- $filename = basename($image_path);
- $image_cid = $filename.'_'.$i;
- $encoding = 'base64';
- $image_type = mime_content_type($real_path);
- $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type);
- $new_images_html[] = '<img src="cid:'.$image_cid.'" />';
- $i++;
- }
- }
-
- $x = 0;
- if (!empty($m[0])) {
- foreach ($m[0] as $orig_img) {
- $message = str_replace($orig_img, $new_images_html[$x], $message);
- $x++;
- }
- }
- }
- $message = str_replace(array("\n\r", "\n", "\r"), '<br />', $message);
- $mail->Body = '<html><head></head><body>'.$message.'</body></html>';
-
- if (!empty($data_file)) {
- $mail->AddAttachment($data_file['path'], $data_file['filename']);
- }
-
- if (is_array($recipient_email)) {
- foreach ($recipient_email as $dest) {
- if (api_valid_email($dest)) {
- $mail->AddAddress($dest, $recipient_name);
-
- }
- }
- } else {
- if (api_valid_email($recipient_email)) {
- $mail->AddAddress($recipient_email, $recipient_name);
- } else {
- return 0;
- }
- }
- if (is_array($extra_headers) && count($extra_headers) > 0) {
- foreach ($extra_headers as $key => $value) {
- switch (strtolower($key)) {
- case 'reply-to':
-
- $sender_email = $value['email'];
- $sender_name = $value['complete_name'];
- $mail->AddReplyTo($sender_email, $sender_name);
- break;
- case 'encoding':
- case 'content-transfer-encoding':
- $mail->Encoding = $value;
- break;
- case 'charset':
- $mail->Charset = $value;
- break;
- case 'contenttype':
- case 'content-type':
- $mail->ContentType = $value;
- break;
- default:
- $mail->AddCustomHeader($key.':'.$value);
- break;
- }
- }
- } else {
- if (!empty($extra_headers)) {
- $mail->AddCustomHeader($extra_headers);
- }
- }
-
- $mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap);
-
- if (!$mail->Send()) {
-
- error_log('ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'<br />');
- return 0;
- }
-
- $mail->ClearAddresses();
- return 1;
- }
- function api_get_user_language() {
- $user_language = null;
- if (!empty($_SESSION['user_language_choice'])) {
- $user_language = $_SESSION['user_language_choice'];
- } elseif (!empty($_SESSION['_user']['language'])) {
- $user_language = $_SESSION['_user']['language'];
- } else {
- $user_language = api_get_setting('platformLanguage');
- }
- if (!empty($_GET['language'])) {
- $user_language = $_GET['language'];
- }
- if (!empty($_POST['language_list'])) {
- $user_language = str_replace('index.php?language=', '', $_POST['language_list']);
- }
- return $user_language;
- }
- function api_get_language_interface() {
- global $app;
- $valid_languages = array();
- if ($app['installed']) {
- $valid_languages = api_get_languages();
- }
- $user_language = api_get_user_language();
- $_course = api_get_course_info();
- $language_interface = 'english';
- if (!empty($valid_languages)) {
- if (!in_array($user_language, $valid_languages['folder'])) {
- $user_language = api_get_setting('platformLanguage');
- }
- $language_priority1 = api_get_setting('languagePriority1');
- $language_priority2 = api_get_setting('languagePriority2');
- $language_priority3 = api_get_setting('languagePriority3');
- $language_priority4 = api_get_setting('languagePriority4');
- if (in_array(
- $user_language,
- $valid_languages['folder']
- ) && (isset($_GET['language']) || isset($_POST['language_list']))
- ) {
- $user_selected_language = $user_language;
- $_SESSION['user_language_choice'] = $user_selected_language;
- $platformLanguage = $user_selected_language;
- }
- if (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false) {
- $language_interface = api_get_language_from_type($language_priority4);
- } else {
- $language_interface = api_get_setting('platformLanguage');
- }
- if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false) {
- $language_interface = api_get_language_from_type($language_priority3);
- } else {
- if (isset($_SESSION['user_language_choice'])) {
- $language_interface = $_SESSION['user_language_choice'];
- }
- }
- if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false) {
- $language_interface = api_get_language_from_type($language_priority2);
- } else {
- if (isset($_user['language'])) {
- $language_interface = $_user['language'];
- }
- }
- if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false) {
- $language_interface = api_get_language_from_type($language_priority1);
- } else {
- if (isset($_course['language']) && !empty($_course['language'])) {
- $language_interface = $_course['language'];
- }
- }
- }
- return $language_interface;
- }
- function getConfigurationArray($confPath) {
- }
- function api_get_default_course_document()
- {
- return api_get_path(SYS_PATH).'app/data/default_course_document/';
- }
- function api_get_web_default_course_document()
- {
- return api_get_path(WEB_PATH).'app/data/default_course_document/';
- }
- function load_translations($app) {
- }
|