123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050 |
- <?php
- use \ChamiloSession as Session;
- define('REQUIRED_PHP_VERSION', '5.3.3');
- define('REQUIRED_MIN_MEMORY_LIMIT', '32');
- define('REQUIRED_MIN_UPLOAD_MAX_FILESIZE', '10');
- define('REQUIRED_MIN_POST_MAX_SIZE', '10');
- define('COURSEMANAGER', 1);
- define('TEACHER', 1);
- define('SESSIONADMIN', 3);
- define('DRH', 4);
- define('STUDENT', 5);
- define('ANONYMOUS', 6);
- define('COURSEMANAGERLOWSECURITY', 10);
- 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);
- define('QUESTION_MANAGER', 17);
- $_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('COURSE_VISIBILITY_HIDDEN', 4);
- 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('TOOL_CURRICULUM', 'curriculum');
- 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('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('WEB_PUBLIC_PATH', 'WEB_PUBLIC_PATH');
- define('SYS_WEB_PATH', 'SYS_WEB_PATH');
- define('SYS_PATH', 'SYS_PATH');
- define('SYS_DATA_PATH', 'SYS_DATA_PATH');
- define('SYS_LOG_PATH', 'SYS_LOG_PATH');
- define('WEB_DATA_COURSE_PATH', 'WEB_DATA_COURSE_PATH');
- define('WEB_DATA_PATH', 'WEB_DATA_PATH');
- define('REL_DATA_PATH', 'REL_DATA_PATH');
- define('SYS_DEFAULT_COURSE_DOCUMENT_PATH', 'SYS_DEFAULT_COURSE_DOCUMENT_PATH');
- define('WEB_DEFAULT_COURSE_DOCUMENT_PATH', 'WEB_DEFAULT_COURSE_DOCUMENT_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('UNIQUE_ANSWER', 1);
- define('MULTIPLE_ANSWER', 2);
- define('FILL_IN_BLANKS', 3);
- define('MATCHING', 4);
- define('FREE_ANSWER', 5);
- define('HOT_SPOT', 6);
- define('HOT_SPOT_ORDER', 7);
- define('HOT_SPOT_DELINEATION', 8);
- define('MULTIPLE_ANSWER_COMBINATION', 9);
- define('UNIQUE_ANSWER_NO_OPTION', 10);
- define('MULTIPLE_ANSWER_TRUE_FALSE', 11);
- define('MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE', 12);
- define('ORAL_EXPRESSION', 13);
- define('GLOBAL_MULTIPLE_ANSWER', 14);
- define('MEDIA_QUESTION', 15);
- define('UNIQUE_ANSWER_IMAGE', 16);
- define('DRAGGABLE', 17);
- define('MCUA', 1);
- define('TF', 1);
- define('MCMA', 2);
- define('FIB', 3);
- 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);
- define ('SKILL_TYPE_REQUIREMENT', 'required');
- define ('SKILL_TYPE_ACQUIRED', 'acquired');
- define ('SKILL_TYPE_BOTH', 'both');
- function api_get_path($path_type, $path = null) {
- global $app;
- static $paths = array(
- SYS_DATA_PATH => 'data/',
- SYS_WEB_PATH => 'web/',
- SYS_CONFIG_PATH => 'config/',
- SYS_LOG_PATH => 'logs/',
- WEB_DATA_COURSE_PATH => 'courses/',
- WEB_DATA_PATH => '/',
- SYS_COURSE_PATH => 'data/',
- SYS_CSS_PATH => 'css/',
- SYS_LANG_PATH => 'lang/',
- WEB_IMG_PATH => 'img/',
- WEB_CSS_PATH => 'css/',
- SYS_PLUGIN_PATH => 'plugin/',
- WEB_PLUGIN_PATH => 'plugin/',
- 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 = $_configuration['root_web'];
-
- $root_sys = isset($_configuration['root_sys']) ? $_configuration['root_sys'] : $app['root_sys'];
- $load_new_config = false;
-
- if ($path_type == WEB_PATH) {
- if (isset($_configuration['access_url']) && $_configuration['access_url'] != 1) {
-
- $url_info = api_get_current_access_url_info();
- $root_web = $url_info['active'] == 1 ? $url_info['url'] : $_configuration['root_web'];
- $load_new_config = true;
- }
- }
- if (!$is_this_function_initialized) {
- $root_rel = $_configuration['url_append'];
- $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_DATA_PATH] = $app['sys_data_path'];
- $paths[SYS_LOG_PATH] = $app['sys_log_path'];
- $paths[SYS_CONFIG_PATH] = $app['sys_config_path'];
- $paths[SYS_COURSE_PATH] = $app['sys_course_path'];
- $paths[SYS_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[SYS_DATA_PATH].'default_course_document/';
- $paths[SYS_WEB_PATH] = $root_sys.'web/';
- $paths[REL_PATH] = $root_rel;
- $paths[WEB_SERVER_ROOT_PATH] = $server_base_web.'/';
- $paths[SYS_SERVER_ROOT_PATH] = $server_base_sys.'/';
- $paths[WEB_DATA_PATH] = $paths[WEB_PUBLIC_PATH].'data/';
- $paths[WEB_COURSE_PATH] = $root_web.$course_folder;
- $paths[WEB_DATA_COURSE_PATH] = $paths[WEB_DATA_PATH].$course_folder;
- $paths[WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[WEB_DATA_PATH].'default_course_document/';
- $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[REL_DATA_PATH] = $root_rel.'data/';
- $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] = $app['sys_temp_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_PUBLIC_PATH].'main/'.$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/',
- WEB_PUBLIC_PATH => 'web/',
- );
- $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];
- $paths[WEB_PUBLIC_PATH] = $paths[WEB_PATH].$web_paths[WEB_PUBLIC_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) {
- $is_allowed_in_course = Session::read('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)
- {
- $_user = Session::read('_user');
- if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'])) {
- api_not_allowed($print_headers);
- return false;
- }
- return true;
- }
- function api_get_navigator() {
- $navigator = 'Unknown';
- $version = 0;
- if (isset($_SERVER['HTTP_USER_AGENT'])) {
- 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() {
- $userInfo = Session::read('_user');
- if ($userInfo && isset($userInfo['user_id'])) {
- return $userInfo['user_id'];
- }
- return 0;
-
- }
- 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);
- $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.id = cu.c_id
- 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_from_obj($user)
- {
- $user = (array) $user;
-
-
- }
- function api_format_user($user, $add_password = false) {
- $result = array();
-
- if (isset($user['is_anonymous']) && $user['is_anonymous']) {
- return $user;
- }
- $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'].' ('.$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'];
- $result['expiration_date'] = $user['expiration_date'];
- $result['registration_date'] = $user['registration_date'];
- $result['creator_id'] = $user['creator_id'];
- if (isset($user['username'])) {
- $result['username'] = $user['username'];
- }
- $result['theme'] = $user['theme'];
- $result['language'] = $user['language'];
- if (!empty($result['user_id'])) {
- 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'];
- }
- }
- } else {
- $last_login = api_get_utc_datetime();
- }
- $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'];
- }
- $result['extra_fields'] = isset($user['extra_fields']) ? $user['extra_fields'] : array();
- 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)) {
- $_user = Session::read('_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($_SESSION['_cid']) ? $_SESSION['_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);
- if (isset($course_info['settings']) && isset($course_info['settings'][$setting_name])) {
- return $course_info['settings'][$setting_name]['value'];
- } else {
- $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) {
- $courseCode = api_get_course_id();
- $courseId = api_get_course_int_id();
- $url = empty($courseCode) || $courseCode == -1 ? '' : 'cidReq='.htmlspecialchars($courseCode).'&courseId='.$courseId;
- 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, $addCourseSettings = 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);
- }
- if ($addCourseSettings) {
- $course_data['settings'] = CourseManager::getCourseSettings($course_data['id']);
- }
- $course_data['teacher_list'] = CourseManager::get_teacher_list_from_course_code($course_data['id']);
- $course_data['teacher_list_formatted'] = CourseManager::formatUserListToString($course_data['teacher_list'], null, true);
- $_course = api_format_course_array($course_data);
- }
- return $_course;
- }
- $_course = Session::read('_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;
- }
- $_course = Session::read('_course');
- if ($_course == '-1') $_course = array();
- return $_course;
- }
- function api_format_course_array($course_data) {
- 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['course_web_public_url'] = api_get_path(WEB_PUBLIC_PATH).'courses/'.$course_data['directory'].'/';
- $_course['course_sys_data'] = api_get_path(SYS_DATA_PATH).'courses/'.$course_data['directory'].'/';
- $_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;
- $_course['extra_fields'] = isset($course_data['extra_fields']) ? $course_data['extra_fields'] : array();
- $_course['settings'] = isset($course_data['settings']) ? $course_data['settings'] : array();
- $_course['teacher_list'] = isset($course_data['teacher_list']) ? $course_data['teacher_list'] : array();
- $_course['teacher_list_formatted'] = isset($course_data['teacher_list_formatted']) ? $course_data['teacher_list_formatted'] : array();
- 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) {
- $_user = Session::read('_user');
- if (api_is_anonymous($_user['user_id'], $db_check)) {
- unset($_user['user_id']);
- Session::erase('_uid');
- Session::erase('_user');
- return true;
- }
- return false;
- }
- function api_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() {
- $_user = Session::read('_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);
- 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 (
- (empty($session_info['access_start_date']) && empty($session_info['access_end_date'])) ||
- ($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 {
- $accessStart = true;
-
- 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;
- $accessStart = false;
- }
- }
- if ($accessStart == true) {
-
- 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_setting($variable, $key = null) {
- $_setting = Session::read('_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() {
- if (isset($_SERVER['REQUEST_URI'])) {
- $urlInfo = parse_url($_SERVER['REQUEST_URI']);
- return $urlInfo['path'];
- }
- return null;
-
-
- }
- function api_is_platform_admin($allow_sessions_admins = false)
- {
- global $app;
- $token = $app['security']->getToken();
- if (!empty($token)) {
- if ($app['security']->isGranted('ROLE_ADMIN')) {
- return true;
- }
- if ($allow_sessions_admins) {
- if ($app['security']->isGranted('ROLE_SESSION_MANAGER')) {
- return true;
- }
- }
- }
- return false;
- }
- function api_is_question_manager()
- {
- global $app;
- $token = $app['security']->getToken();
- if (!empty($token)) {
- if ($app['security']->isGranted('ROLE_QUESTION_MANAGER')) {
- return true;
- }
- }
- return false;
- }
- function api_is_session_admin()
- {
- global $app;
- $token = $app['security']->getToken();
- if (!empty($token)) {
- if ($app['security']->isGranted('ROLE_SESSION_MANAGER')) {
- return true;
- }
- }
- return false;
- }
- function api_is_drh() {
- global $app;
- $token = $app['security']->getToken();
- if (!empty($token)) {
- if ($app['security']->isGranted('ROLE_RRHH')) {
- return true;
- }
- }
- return false;
- }
- function api_is_student() {
- global $app;
- $token = $app['security']->getToken();
- if (!empty($token)) {
- if ($app['security']->isGranted('ROLE_STUDENT')) {
- return true;
- }
- }
- return false;
- }
- function api_is_teacher() {
- global $app;
- if ($app['security']->isGranted('ROLE_TEACHER')) {
- return true;
- }
- return false;
- }
- 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 isset($_SESSION['is_courseCoach']) ? $_SESSION['is_courseCoach'] : null;
- }
- function api_is_course_tutor() {
- return isset($_SESSION['is_courseTutor']) ? $_SESSION['is_courseTutor'] : null;
- }
- 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_id, $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_id);
- if ($tutor_course_status) {
- $course_status['status'] = 'tutor';
- }
- break;
- }
- }
- }
- $status['course'] = $course_status;
- }
- return $status;
- }
- function api_is_course_session_coach($user_id, $courseId, $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);
- $courseId = Database::escape_string($courseId);
- $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.c_id = '$courseId' 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, $courseId = null) {
- if (!empty($session_id)) {
- $session_id = intval($session_id);
- } else {
- $session_id = api_get_session_id();
- }
-
- if (isset($_SESSION['studentview']) && $_SESSION['studentview'] == "studentview") {
- return false;
- }
- if (!empty($courseId)) {
- $courseId = Database::escape_string($courseId);
- } else {
- $courseId = api_get_course_int_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.c_id = '$courseId' 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);
- }
- }
- $result = count($sessionIsCoach) > 0;
- return $result;
- }
- 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') {
- $studentViewSession = Session::read('studentview');
- 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 && $studentViewSession != 'studentview';
- }
- } else {
- if ($check_student_view) {
- $is_allowed = $is_courseAdmin && $studentViewSession != '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) {
- $_course = api_get_course_info();
- $_user = api_get_user_info();
- 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 || $user_id == 0 || empty($info)) {
- return true;
- }
- }
- $_user = Session::read('_user');
- if (!isset($_user) || $_user['user_id'] == 0) {
-
-
-
- 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 = $app['template'];
- $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 api_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";
- }
- $result = Database::query($sql);
-
- if (Database::affected_rows($result) == 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_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_main_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()."'";
- $result = Database::query($sql);
- $affected_rows = Database::affected_rows($result);
- return $affected_rows;
- }
- return false;
- }
- function api_get_track_item_property_history($tool, $ref) {
- $tbl_stats_item_property = Database::get_main_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 = '';
-
- $language_list = api_get_languages();
- if (count($language_list['name']) < 2) {
- return $ret;
- }
- $default = api_get_user_language();
- $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;
- }
- $user_selected_language = api_get_language_selected_in_login();
- $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_path(WEB_PUBLIC_PATH).'index?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() {
- $language_list = Session::read('_setting.api_get_languages');
- if (isset($language_list) && !empty($language_list)) {
- return $language_list;
- }
- $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'];
- }
- Session::write('_setting.api_get_languages', $language_list);
- 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)
- {
- $language = false;
- switch ($lang_type) {
- case 'platform_lang':
- $platformLanguage = api_get_setting('platformLanguage');
- if (!empty($platformLanguage)) {
- $language = $platformLanguage;
- }
- break;
- case 'user_profil_lang':
-
- $_user = Session::read('_user');
- if (isset($_user['language']) && !empty($_user['language']) ) {
- $language = $_user['language'];
- }
- break;
- case 'user_selected_lang':
- $language = api_get_language_selected_in_login();
- break;
- case 'course_lang':
- $_course = api_get_course_info();
- if (isset($_course['language']) && !empty($_course['language'])) {
- $language = $_course['language'];
- }
- break;
- default :
- $language = false;
- break;
- }
- return $language;
- }
- 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 api_string_2_boolean($string) {
- if ($string == 'true') {
- return true;
- }
- if ($string == 'false') {
- return false;
- }
- return false;
- }
- function api_number_of_plugins($location)
- {
- $_plugins = Session::read('_plugins');
- return isset($_plugins[$location]) && is_array($_plugins[$location]) ? count($_plugins[$location]) : 0;
- }
- function api_plugin($location)
- {
- $_plugins = Session::read('_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;
- }
- function api_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;
- }
-
- api_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 api_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 = api_copyr("$source/$entry", "$dest/$entry", $exclude, $copied_files);
- }
- }
-
- $dir->close();
- return true;
- }
- function api_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('api_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 api_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() {
- 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', ''),
- QUESTION_MANAGER => get_lang('SessionManager')
- );
- }
- 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'] ;
- 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'].")";
- 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)
- {
- $id = intval($id);
- $table_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
- $sql = "SELECT id, 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_get_current_access_url_info()
- {
- $userInfo = Session::read('url_info');
- return $userInfo;
- }
- 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);
- $courseInfo = api_get_course_info($cid);
- $courseId = $courseInfo['real_id'];
- $is_platformAdmin = api_is_platform_admin();
- $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 = ".$courseId."
- 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.c_id = '$courseId'
- 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.c_id = '$courseId'
- 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 c_id = '$courseId'
- LIMIT 1";
- $result = Database::query($sql);
- 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 api_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()
- {
- $urlId = Session::read('url_id');
- if (empty($urlId)) {
- return 1;
- } else {
- return $urlId;
- }
- }
- function api_get_access_url_id_from_web_path()
- {
- $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, $courseId)
- {
- if (!empty($user_id) && !empty($courseId)) {
- $tbl_rel_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $user_id = intval($user_id);
- $courseId = Database::escape_string($courseId);
- $sql = 'SELECT status FROM '.$tbl_rel_course_user.' WHERE user_id='.$user_id.' AND c_id="'.$courseId.'"';
- $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) {
- $courseCodeInSession = api_get_course_id();
- if (isset($courseCodeInSession)) {
- if (!empty($course_code)) {
- return $course_code == $courseCodeInSession;
- }
- return true;
- }
- return false;
- }
- function api_is_in_group($group_id = null, $course_code = null)
- {
- $courseCodeInSession = api_get_course_id();
- $groupIdInSession = api_get_group_id();
- if (!empty($course_code)) {
- if (isset($courseCodeInSession)) {
- if ($course_code != $courseCodeInSession) return false;
- } else {
- return false;
- }
- }
- if (isset($groupIdInSession) && $groupIdInSession != '') {
- if (!empty($group_id)) {
- return $group_id == $groupIdInSession;
- } 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 c_id ="'.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';
- }
- 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_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 api_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, api_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) {
- 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/';
- $access_url_id = api_get_current_access_url_id();
- if (api_get_multiple_access_url() && $access_url_id != -1) {
- $url_info = api_get_current_access_url_info();
- $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
- $clean_url = api_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 (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;
- if (PHP_SAPI === 'cli' && !isset($_SERVER['REMOTE_ADDR'])) {
- $_SERVER['REMOTE_ADDR'] = 'localhost';
- }
- $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($courseInfo, $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($courseInfo, $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($courseInfo['real_id']);
- $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, $courseId, $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, $courseId)) {
- $user_roles[] = COURSEMANAGER;
- }
- if (CourseManager::get_tutor_in_course_status($user_id, $courseId)) {
- $user_roles[] = COURSE_TUTOR;
- }
- if (CourseManager::is_user_subscribed_in_course($user_id, $courseId)) {
- $user_roles[] = COURSE_STUDENT;
- }
- } else {
- $user_status_in_session = SessionManager::get_user_status_in_course_session($user_id, $courseId, $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[] = api_get_status_from_code($role);
- }
- }
- if (!empty($role_names)) {
- return implode(', ', $role_names);
- }
- return null;
- }
- function api_coach_can_edit_view_results($courseId = null, $session_id = null) {
- $user_id = api_get_user_id();
- if (empty($courseId)) {
- $courseId = api_get_course_int_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, $courseId, $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_current_access_url_info();
- 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);
- 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::write('_setting', $_setting);
- Session::write('_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,
- $text_body = null
- ) {
- 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'];
- }
-
- if (strpos($body, '<html>') === false) {
- $htmlBody = str_replace(array("\n\r", "\n", "\r"), '<br />', $body);
- $htmlBody = '<html><head></head><body>'.$htmlBody.'</body></html>';
- } else {
- $htmlBody = $body;
- }
- if (!empty($text_body)) {
- $textBody = $text_body;
- } else {
- $textBody = $body;
- }
- 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($htmlBody, 'text/html')
- ->addPart($textBody, 'text/plain')
- ->setEncoder(Swift_Encoding::get8BitEncoding());
- 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) {
-
- }
- return false;
-
- }
- function api_set_login_language($lang) {
- global $app;
- $valid_languages = array();
- if ($app['installed']) {
- $valid_languages = api_get_languages();
- }
- if (isset($lang) && isset($valid_languages)) {
- if (in_array($lang, $valid_languages['folder'])) {
- $_SESSION['user_language_choice'] = $lang;
- }
- }
- }
- function api_get_language_selected_in_login()
- {
- $language = api_get_setting('platformLanguage');
- if (isset($_SESSION['user_language_choice']) && !empty($_SESSION['user_language_choice'])) {
- $language = $_SESSION['user_language_choice'];
- }
- return $language;
- }
- function api_get_user_language()
- {
- $user_language = null;
- if (!api_is_anonymous()) {
- $userInfo = api_get_user_info();
- if (isset($userInfo['language'])) {
- $user_language = $userInfo['language'];
- }
- }
-
-
- if (isset($_REQUEST['language']) && !empty($_REQUEST['language'])) {
- api_set_login_language($_REQUEST['language']);
- }
-
- if (empty($user_language)) {
- $user_language = api_get_setting('platformLanguage');
- }
- return $user_language;
- }
- function api_get_language_interface()
- {
- $valid_languages = api_get_languages();
- $user_language = api_get_user_language();
- $courseInfo = api_get_course_info();
- $language_interface = 'english';
- $languageFromLogin = api_get_language_selected_in_login();
- if (!empty($languageFromLogin)) {
- $language_interface = $languageFromLogin;
- }
- if (!empty($valid_languages)) {
-
-
-
- $language_interface = $user_language;
-
-
- if (!empty($courseInfo) && isset($courseInfo['language'])) {
- $language_interface = $courseInfo['language'];
- }
-
-
- $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 (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false) {
- $language_interface = api_get_language_from_type($language_priority4);
- }
- if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false) {
- $language_interface = api_get_language_from_type($language_priority3);
- }
- if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false) {
- $language_interface = api_get_language_from_type($language_priority2);
- }
- if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false) {
- $language_interface = api_get_language_from_type($language_priority1);
- }
-
- if (empty($language_interface) || !in_array($language_interface, $valid_languages['folder'])) {
- $language_interface = api_get_setting('platformLanguage');
- }
- }
- return $language_interface;
- }
- function api_get_user_roles()
- {
- global $app;
- $em = $app['orm.ems']['db_read'];
- $roles = $em->getRepository('Entity\Role')->findBy(array(), array('name'=>'asc'));
- $userRoles = array();
- foreach ($roles as $role) {
- $userRoles[$role->getId()] = $role->getName();
- }
- return $userRoles;
-
- $status = array();
- $status[COURSEMANAGER] = get_lang('Teacher');
- $status[STUDENT] = get_lang('Learner');
- $status[DRH] = get_lang('Drh');
- $status[SESSIONADMIN] = get_lang('SessionsAdmin');
- $status[QUESTION_MANAGER] = get_lang('QuestionManager');
- return $status;
- }
- function api_get_user_info_from_official_code($official_code = '') {
- if (empty($official_code)) { return false; }
- $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_USER)." WHERE official_code ='".Database::escape_string($official_code)."'";
- $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_password_checker_js($inputId)
- {
- global $_configuration;
- $useStrengthPassChecker = isset($_configuration['allow_strength_pass_checker']) ? $_configuration['allow_strength_pass_checker'] : false;
- if ($useStrengthPassChecker == false) {
- return null;
- }
- $verdicts = array(get_lang('Weak'), get_lang('Normal'), get_lang('Medium'), get_lang('Strong'), get_lang('VeryStrong'));
- $js = api_get_js('strength/strength.js');
- $js .= "<script>
- var verdicts = ['".implode("','", $verdicts)."'];
- var errorMessages = {
- password_to_short : '".get_lang('PasswordIsTooShort')."'
- };
- $(document).ready(function() {
- var options = {
- verdicts: verdicts,
- onLoad : function () {
- //$('#messages').text('Start typing password');
- },
- onKeyUp: function (evt) {
- $(evt.target).pwstrength('outputErrorList');
- },
- errorMessages : errorMessages,
- viewports: {
- progress: '#password_progress',
- //verdict: undefined,
- //errors: undefined
- }
- };
- $('".$inputId."').pwstrength(options);
- });
- </script>";
- return $js;
- }
- function api_get_easy_password_list()
- {
- $passwordList = array('123', '1234', '123456', 'admin', 'user', 'student', 'teacher');
- $file = api_get_path(CONFIGURATION_PATH).'easy_password_list.php';
- if (file_exists($file)) {
- $passwordList = require_once $file;
- }
- return $passwordList;
- }
- function api_is_profile_editable()
- {
- global $profileIsEditable;
- return isset($profileIsEditable) ? $profileIsEditable : false;
- }
- function api_is_profile_readable()
- {
- global $profileIsReadable;
- return isset($profileIsReadable) ? $profileIsReadable : true;
- }
- function api_http_request($ip, $port = 80, $uri = '/', $getdata = array(), $timeout = 1, $req_hdr = false, $res_hdr = false) {
- $verb = 'GET';
- $ret = '';
- $getdata_str = count($getdata) ? '?' : '';
- foreach ($getdata as $k => $v) {
- $getdata_str .= urlencode($k) .'='. urlencode($v) . '&';
- }
- $crlf = "\r\n";
- $req = $verb .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf;
- $req .= 'Host: '. $ip . $crlf;
- $req .= 'User-Agent: Mozilla/5.0 Firefox/3.6.12' . $crlf;
- $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf;
- $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf;
- $req .= 'Accept-Encoding: deflate' . $crlf;
- $req .= 'Accept-Charset: utf-8;q=0.7,*;q=0.7' . $crlf;
- $req .= $crlf;
- if ($req_hdr) {
- $ret .= $req;
- }
- if (($fp = @fsockopen($ip, $port, $errno, $errstr, $timeout)) == false) {
- return "Error $errno: $errstr\n";
- }
- stream_set_timeout($fp, $timeout);
- $r = @fwrite($fp, $req);
- $line = @fread($fp, 512);
- $ret .= $line;
- fclose($fp);
- if (!$res_hdr) {
- $ret = substr($ret, strpos($ret, "\r\n\r\n") + 4);
- }
- return trim($ret);
- }
|