123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783 |
- <?php
- define('STUDENT', 5);
- define('COURSEMANAGER', 1);
- define('SESSIONADMIN', 3);
- define('DRH', 4);
- define('ANONYMOUS', 6);
- define('COURSEMANAGERLOWSECURITY',10);
- $_status_list[STUDENT] = 'user';
- $_status_list[COURSEMANAGER] = 'teacher';
- $_status_list[SESSIONADMIN] = 'session_admin';
- $_status_list[DRH] = 'drh';
- $_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('SUBSCRIBE_ALLOWED', 1);
- define('SUBSCRIBE_NOT_ALLOWED', 0);
- define('UNSUBSCRIBE_ALLOWED', 1);
- define('UNSUBSCRIBE_NOT_ALLOWED', 0);
- define('WEB_PATH', 'WEB_PATH');
- define('SYS_PATH', 'SYS_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_LANG_PATH', 'SYS_LANG_PATH');
- define('WEB_IMG_PATH', 'WEB_IMG_PATH');
- define('WEB_CSS_PATH', 'WEB_CSS_PATH');
- define('GARBAGE_PATH', 'GARBAGE_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('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_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('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('PLATFORM_AUTH_SOURCE', 'platform');
- define('DIR_HOTPOTATOES','/HotPotatoes_files');
- 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('LOG_COURSE_DELETE', 'course_deleted');
- define('LOG_COURSE_CREATE', 'course_created');
- define('LOG_USER_DELETE', 'user_deleted');
- define('LOG_USER_CREATE', 'user_created');
- define('LOG_SESSION_CREATE', 'session_created');
- define('LOG_SESSION_DELETE', 'session_deleted');
- define('LOG_SESSION_DELETE', 'session_deleted');
- define('LOG_CONFIGURATION_SETTINGS_CHANGE', 'settings_changed');
- define('LOG_SUBSCRIBE_USER_TO_COURSE', 'user_subscribed');
- define('LOG_UNSUBSCRIBE_USER_FROM_COURSE', 'user_unsubscribed');
- define('LOG_COURSE_CODE', 'course_code');
- define('LOG_USER_ID', 'user_id');
- define('LOG_SESSION_ID', 'session_id');
- define('LOG_CONFIGURATION_SETTINGS_CATEGORY', 'settings_category');
- define('LOG_CONFIGURATION_SETTINGS_VARIABLE', 'settings_variable');
- if (api_get_path(LIBRARY_PATH) == '/lib/') {
-
- require_once 'multibyte_string_functions.lib.php';
- } else {
-
- require_once api_get_path(LIBRARY_PATH).'multibyte_string_functions.lib.php';
- }
- function api_protect_course_script($print_headers=false) {
- global $is_allowed_in_course;
- if (!$is_allowed_in_course) {
- api_not_allowed($print_headers);
- return false;
- } else {
- return true;
- }
- }
- function api_protect_admin_script($allow_sessions_admins=false) {
- if (!api_is_platform_admin($allow_sessions_admins)) {
- include (api_get_path(INCLUDE_PATH)."header.inc.php");
- api_not_allowed();
- return false;
- }else{
- return true;
- }
- }
- function api_block_anonymous_users() {
- global $_user;
- if (!(isset ($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'],true)) {
- include (api_get_path(INCLUDE_PATH)."header.inc.php");
- api_not_allowed();
- return false;
- }else{
- return true;
- }
- }
- function api_get_navigator() {
- $navigator = 'Unknown';
- $version = 0;
- if (strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) {
- $navigator = 'Opera';
- list (, $version) = explode('Opera', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
- $navigator = 'Internet Explorer';
- list (, $version) = explode('MSIE', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko')) {
- $navigator = 'Mozilla';
- list (, $version) = explode('; rv:', $_SERVER['HTTP_USER_AGENT']);
- } elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'Netscape')) {
- $navigator = 'Netscape';
- list (, $version) = explode('Netscape', $_SERVER['HTTP_USER_AGENT']);
- }
- $version = doubleval($version);
- if (!strstr($version, '.')) {
- $version = number_format(doubleval($version), 1);
- }
- return array ('name' => $navigator, 'version' => $version);
- }
- function api_is_self_registration_allowed() {
- if(isset($GLOBALS['allowSelfReg'])) {
- return $GLOBALS["allowSelfReg"];
- } else {
- return false;
- }
- }
- function api_get_path($path_type) {
- global $_configuration;
- if (!isset($_configuration['access_url']) || $_configuration['access_url']==1 || $_configuration['access_url']=='') {
-
-
-
- $root_web = $_configuration['root_web'];
- } else {
-
-
- $url_info= api_get_access_url($_configuration['access_url']);
- if ($url_info['active']==1) {
- $root_web = $url_info['url'];
- } else {
- $root_web = $_configuration['root_web'];
- }
- }
- switch ($path_type) {
- case WEB_SERVER_ROOT_PATH:
-
- $result = preg_replace('@'.api_get_path(REL_PATH).'$@', '', api_get_path(WEB_PATH));
- if (substr($result, -1) == '/') {
- return $result;
- } else {
- return $result.'/';
- }
- break;
- case SYS_SERVER_ROOT_PATH:
- $result = preg_replace('@'.api_get_path(REL_PATH).'$@', '', api_get_path(SYS_PATH));
- if (substr($result, -1) == '/') {
- return $result;
- } else {
- return $result.'/';
- }
- break;
- case WEB_PATH :
-
-
- if (substr($root_web,-1) == '/') {
- return $root_web;
- } else {
- return $root_web.'/';
- }
- break;
- case SYS_PATH :
-
- if (substr($_configuration['root_sys'],-1) == '/') {
- return $_configuration['root_sys'];
- } else {
- return $_configuration['root_sys'].'/';
- }
- break;
- case REL_PATH :
-
- if (substr($_configuration['url_append'], -1) === '/') {
- return $_configuration['url_append'];
- } else {
- return $_configuration['url_append'].'/';
- }
- break;
- case WEB_COURSE_PATH :
-
- return $root_web.$_configuration['course_folder'];
- break;
- case SYS_COURSE_PATH :
-
- return $_configuration['root_sys'].$_configuration['course_folder'];
- break;
- case REL_COURSE_PATH :
-
- return api_get_path(REL_PATH).$_configuration['course_folder'];
- break;
- case REL_CODE_PATH :
-
- return api_get_path(REL_PATH).$_configuration['code_append'];
- break;
- case WEB_CODE_PATH :
-
-
- return $root_web.$_configuration['code_append'];
- break;
- case SYS_CODE_PATH :
-
- return $GLOBALS['clarolineRepositorySys'];
- break;
- case SYS_LANG_PATH :
-
- return api_get_path(SYS_CODE_PATH).'lang/';
- break;
- case WEB_IMG_PATH :
-
- return api_get_path(WEB_CODE_PATH).'img/';
- break;
- case GARBAGE_PATH :
-
- return $GLOBALS['garbageRepositorySys'];
- break;
- case SYS_PLUGIN_PATH :
-
- return api_get_path(SYS_PATH).'plugin/';
- break;
- case WEB_PLUGIN_PATH :
-
- return api_get_path(WEB_PATH).'plugin/';
- break;
- case SYS_ARCHIVE_PATH :
-
- return api_get_path(SYS_PATH).'archive/';
- break;
- case WEB_ARCHIVE_PATH :
-
- return api_get_path(WEB_PATH).'archive/';
- break;
- case INCLUDE_PATH :
-
-
- return str_replace('\\', '/', $GLOBALS['includePath']).'/';
- break;
- case LIBRARY_PATH :
-
- return api_get_path(INCLUDE_PATH).'lib/';
- break;
- case WEB_LIBRARY_PATH :
-
- return api_get_path(WEB_CODE_PATH).'inc/lib/';
- break;
- case CONFIGURATION_PATH :
-
- return api_get_path(INCLUDE_PATH).'conf/';
- break;
- default :
- return;
- break;
- }
- }
- function api_get_user_id() {
- if (empty($GLOBALS['_user']['user_id'])) {
- return 0;
- }
- return $GLOBALS['_user']['user_id'];
- }
- function api_get_user_courses($userid,$fetch_session=true) {
- if ($userid != strval(intval($userid))) { return array(); }
- $t_course = Database::get_main_table(TABLE_MAIN_COURSE);
- $t_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $t_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $t_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
- $t_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-
- $sql_select_courses = "SELECT cc.code code, cc.db_name db, cc.directory dir, cu.status status
- FROM $t_course cc,
- $t_course_user cu
- WHERE cc.code = cu.course_code
- AND cu.user_id = '".$userid."'";
- $result = api_sql_query($sql_select_courses);
- if ($result===false) { return array(); }
- while ($row = Database::fetch_array($result))
- {
-
- $courses[] = $row;
- }
- return $courses;
- }
- function api_get_user_info($user_id = '') {
- global $tbl_user;
- if ($user_id == '') {
- return $GLOBALS["_user"];
- } else {
- $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_USER)." WHERE user_id='".Database::escape_string($user_id)."'";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- if(Database::num_rows($result) > 0) {
- $result_array = Database::fetch_array($result);
-
-
-
-
- $user_info['firstName'] = $result_array['firstname'];
- $user_info['lastName'] = $result_array['lastname'];
- $user_info['mail'] = $result_array['email'];
- $user_info['picture_uri'] = $result_array['picture_uri'];
- $user_info['user_id'] = $result_array['user_id'];
- $user_info['official_code'] = $result_array['official_code'];
- $user_info['status'] = $result_array['status'];
- $user_info['auth_source'] = $result_array['auth_source'];
- $user_info['username'] = $result_array['username'];
- $user_info['theme'] = $result_array['theme'];
- return $user_info;
- }
- return false;
- }
- }
- function api_get_user_info_from_username($username = '') {
- if (empty($username)) { return false; }
- global $tbl_user;
- $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_USER)." WHERE username='".Database::escape_string($username)."'";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- if (Database::num_rows($result) > 0) {
- $result_array = Database::fetch_array($result);
-
-
-
-
- $user_info['firstName'] = $result_array['firstname'];
- $user_info['lastName'] = $result_array['lastname'];
- $user_info['mail'] = $result_array['email'];
- $user_info['picture_uri'] = $result_array['picture_uri'];
- $user_info['user_id'] = $result_array['user_id'];
- $user_info['official_code'] = $result_array['official_code'];
- $user_info['status'] = $result_array['status'];
- $user_info['auth_source'] = $result_array['auth_source'];
- $user_info['username'] = $result_array['username'];
- $user_info['theme'] = $result_array['theme'];
- return $user_info;
- }
- return false;
- }
- function api_get_course_id() {
- return $GLOBALS["_cid"];
- }
- function api_get_course_path($course_code=null) {
- if(!empty($course_code)) {
- $info = api_get_course_info($course_code);
- } else {
- $info = api_get_course_info();
- }
- return $info['path'];
- }
- function api_get_course_setting($setting_name, $course_code = null) {
- if (!empty($course_code)) {
- $c = api_get_course_info($course_code);
- $table = Database::get_course_table(TABLE_COURSE_SETTING,$c['dbName']);
- } else {
- $table = Database::get_course_table(TABLE_COURSE_SETTING);
- }
- $setting_name = Database::escape_string($setting_name);
- $sql = "SELECT * FROM $table WHERE variable = '$setting_name'";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- 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 = api_sql_query($sql,__FILE__,__LINE__);
- if (Database::num_rows($res)>0) {
- $row = Database::fetch_array($res);
-
- return $row['user_id'];
- } else {
- return 0;
- }
- }
- function api_get_cidreq() {
- if (!empty ($GLOBALS["_cid"])) {
- return 'cidReq='.htmlspecialchars($GLOBALS["_cid"]);
- }
- return '';
- }
- function api_get_course_info($course_code=null) {
- 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 = api_sql_query($sql,__FILE__,__LINE__);
- $_course = array();
- if (Database::num_rows($result)>0) {
- global $_configuration;
- $cData = Database::fetch_array($result);
- $_course['id' ] = $cData['code' ];
- $_course['name' ] = $cData['title' ];
- $_course['official_code'] = $cData['visual_code' ];
- $_course['sysCode' ] = $cData['code' ];
- $_course['path' ] = $cData['directory' ];
- $_course['dbName' ] = $cData['db_name' ];
- $_course['dbNameGlu' ] = $_configuration['table_prefix'] . $cData['db_name'] . $_configuration['db_glue'];
- $_course['titular' ] = $cData['tutor_name' ];
- $_course['language' ] = $cData['course_language' ];
- $_course['extLink' ]['url' ] = $cData['department_url' ];
- $_course['extLink' ]['name'] = $cData['department_name'];
- $_course['categoryCode'] = $cData['faCode' ];
- $_course['categoryName'] = $cData['faName' ];
- $_course['visibility' ] = $cData['visibility'];
- $_course['subscribe_allowed'] = $cData['subscribe'];
- $_course['unubscribe_allowed'] = $cData['unsubscribe'];
- }
- return $_course;
- } else {
- global $_course;
- return $_course;
- }
- }
- function api_sql_query($query, $file = '', $line = 0) {
- $result = @mysql_query($query);
- if ($line && !$result && api_get_setting('server_type')!='production') {
- $info = '<pre>';
- $info .= '<b>DATABASE ERROR :</b><br /> ';
- $info .= Security::remove_XSS(Database::error());
- $info .= '<br />';
- $info .= '<b>QUERY :</b><br /> ';
- $info .= Security::remove_XSS($query);
- $info .= '<br />';
- $info .= '<b>FILE :</b><br /> ';
- $info .= ($file == '' ? ' unknown ' : $file);
- $info .= '<br />';
- $info .= '<b>LINE :</b><br /> ';
- $info .= ($line == 0 ? ' unknown ' : $line);
- $info .= '</pre>';
-
-
- echo $info;
- }
- return $result;
- }
- function api_store_result($result) {
- $tab = array ();
- while ($row = Database::fetch_array($result)) {
- $tab[] = $row;
- }
- return $tab;
- }
- function api_session_start($already_installed = true) {
- global $storeSessionInDb;
- global $_configuration;
-
- if (is_null($storeSessionInDb)) {
- $storeSessionInDb = false;
- }
- if ($storeSessionInDb && function_exists('session_set_save_handler')) {
- include_once (api_get_path(LIBRARY_PATH).'session_handler.class.php');
- $session_handler = new session_handler();
- @ session_set_save_handler(array (& $session_handler, 'open'), array (& $session_handler, 'close'), array (& $session_handler, 'read'), array (& $session_handler, 'write'), array (& $session_handler, 'destroy'), array (& $session_handler, 'garbage'));
- }
- session_name('dk_sid');
- session_start();
- if ($already_installed) {
- if (empty ($_SESSION['checkDokeosURL'])) {
- $_SESSION['checkDokeosURL'] = api_get_path(WEB_PATH);
- } elseif ($_SESSION['checkDokeosURL'] != api_get_path(WEB_PATH)) {
- api_session_clear();
- }
- }
- }
- function api_session_register($variable) {
- global $$variable;
- session_register($variable);
- $_SESSION[$variable] = $$variable;
- }
- function api_session_unregister($variable) {
- $variable = strval($variable);
- if(isset($GLOBALS[$variable])) {
- unset ($GLOBALS[$variable]);
- }
- if(isset($_SESSION[$variable])) {
- $_SESSION[$variable] = null;
- session_unregister($variable);
- }
- }
- function api_session_clear() {
- session_regenerate_id();
- session_unset();
- $_SESSION = array ();
- }
- function api_session_destroy() {
- session_unset();
- $_SESSION = array ();
- session_destroy();
- }
- function api_add_url_param($url, $param, $filter_xss=true) {
- if (empty ($param)) {
- return $url;
- }
- if (strstr($url, '?')) {
- 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) {
- $lengthPass = strlen($password);
- if ($lengthPass < 5) {
- return false;
- }
- $passLower = strtolower($password);
- $cptLettres = $cptChiffres = 0;
- $consecutif = 0;
- $codeCharPrev = 0;
- for ($i = 0; $i < $lengthPass; $i ++) {
- $codeCharCur = ord($passLower[$i]);
- if ($i && abs($codeCharCur - $codeCharPrev) <= 1) {
- $consecutif ++;
- if ($consecutif == 3) {
- return false;
- }
- } else {
- $consecutif = 1;
- }
- if ($codeCharCur >= 97 && $codeCharCur <= 122) {
- $cptLettres ++;
- } elseif ($codeCharCur >= 48 && $codeCharCur <= 57) {
- $cptChiffres ++;
- } else {
- return false;
- }
- $codeCharPrev = $codeCharCur;
- }
- return ($cptLettres >= 3 && $cptChiffres >= 2) ? true : false;
- }
- function api_clear_anonymous($db_check=false) {
- global $_user;
- if (api_is_anonymous($_user['user_id'],$db_check)) {
- unset($_user['user_id']);
- api_session_unregister('_uid');
- return true;
- } else {
- return false;
- }
- }
- function api_trunc_str($text, $length = 30, $endStr = '...', $middle = false) {
- if (api_strlen($text) <= $length) {
- return $text;
- }
- if ($middle) {
- $text = rtrim(api_substr($text, 0, round($length / 2))).$endStr.ltrim(api_substr($text, -round($length / 2)));
- } else {
- $text = rtrim(api_substr($text, 0, $length)).$endStr;
- }
- return $text;
- }
- function shorten($input, $length = 15) {
- $length = intval($length);
- if (!$length) {
- $length = 15;
- }
- return api_trunc_str($input, $length);
- }
- function domesticate($input) {
- $input = stripslashes($input);
- $input = str_replace("'", "''", $input);
- $input = str_replace('"', "''", $input);
- return ($input);
- }
- function get_status_from_code($status_code)
- {
- switch ($status_code) {
- case STUDENT:
- return get_lang('Student');
- case TEACHER:
- return get_lang('Teacher');
- case COURSEMANAGER:
- return get_lang('Manager');
- case SESSIONADMIN:
- return get_lang('SessionsAdmin');
- case DRH:
- return get_lang('Drh');
- }
- }
- $api_failureList = array ();
- function api_set_failure($failureType) {
- global $api_failureList;
- $api_failureList[] = $failureType;
- return false;
- }
- function api_set_anonymous() {
- global $_user;
- if(!empty($_user['user_id'])) {
- return false;
- } else {
- $user_id = api_get_anonymous_id();
- if($user_id == 0) {
- return false;
- } else {
- api_session_unregister('_user');
- $_user['user_id'] = $user_id;
- $_user['is_anonymous'] = true;
- api_session_register('_user');
- $GLOBALS['_user'] = $_user;
- return true;
- }
- }
- }
- function api_get_last_failure() {
- global $api_failureList;
- return $api_failureList[count($api_failureList) - 1];
- }
- class api_failure
- {
-
- public $api_failureList = array ();
-
- function set_failure($failureType) {
- global $api_failureList;
- $api_failureList[] = $failureType;
- return false;
- }
-
- function get_last_failure() {
- global $api_failureList;
- if(count($api_failureList)==0){return '';}
- return $api_failureList[count($api_failureList) - 1];
- }
- }
- function get_setting($variable, $key = NULL) {
- global $_setting;
- return api_get_setting($variable, $key);
- }
- function api_get_session_id() {
- if (empty($_SESSION['id_session'])) {
- return 0;
- } else {
- return (int) $_SESSION['id_session'];
- }
- }
- 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 = api_sql_query($s,__FILE__,__LINE__);
- $c = Database::num_rows($r);
- if ($c > 0) {
-
- $rec = Database::fetch_array($r);
- return $rec['name'];
- }
- return null;
- }
- function api_get_setting($variable, $key = NULL) {
- global $_setting;
- return is_null($key) ? (!empty($_setting[$variable])?$_setting[$variable]:null) : $_setting[$variable][$key];
- }
- function api_get_self() {
- return htmlentities($_SERVER['PHP_SELF']);
- }
- function get_lang($variable, $notrans = 'DLTT', $language = null) {
-
-
-
-
- global $language_interface;
-
-
- global $language_interface_initial_value;
-
-
- static $cache = array();
-
- if (empty($language))
- {
- $language = $language_interface;
- }
-
-
- $dltt = $notrans == 'DLTT' ? true : false;
-
- if (!is_array($cache[$language]))
- {
- $cache[$language] = array(false => array(), true => array());
- }
-
- if (isset($cache[$language][$dltt][$variable])) {
-
- return $cache[$language][$dltt][$variable];
- }
-
-
-
- $seek_local_variables = false;
-
-
- if ($language != $language_interface_initial_value || api_get_setting('server_type') == 'test') {
- $seek_local_variables = true;
- global $language_files;
- $langpath = api_get_path(SYS_CODE_PATH).'lang/';
- if (isset ($language_files)) {
- if (!is_array($language_files)) {
- @include $langpath.$language.'/'.$language_files.'.inc.php';
- } else {
- foreach ($language_files as $index => $language_file) {
- @include $langpath.$language.'/'.$language_file.'.inc.php';
- }
- }
- }
- }
- $ot = '[=';
- $ct = '=]';
- if (api_get_setting('hide_dltt_markup') == 'true') {
- $ot = '';
- $ct = '';
- }
-
- if (api_get_setting('server_type') != 'test') {
- if (!$seek_local_variables) {
- $lvv = isset ($GLOBALS['lang'.$variable]) ? $GLOBALS['lang'.$variable] : (isset ($GLOBALS[$variable]) ? $GLOBALS[$variable] : $ot.$variable.$ct);
- } else {
- @eval('$lvv = $'.$variable.';');
- if (!isset($lvv)) {
- @eval('$lvv = $lang'.$variable.';');
- if (!isset($lvv)) {
- $lvv = $ot.$variable.$ct;
- }
- }
- }
- if (!is_string($lvv)) {
- $cache[$language][$dltt][$variable] = $lvv;
- return $lvv;
- }
- $lvv = str_replace("\\'", "'", $lvv);
- $lvv = get_lang_to_system_encoding($lvv, $language);
- $cache[$language][$dltt][$variable] = $lvv;
- return $lvv;
- }
-
- if (!is_string($variable)) {
- $cache[$language][$dltt][$variable] = $ot.'get_lang(?)'.$ct;
- return $cache[$language][$dltt][$variable];
- }
- @ eval ('$langvar = $'.$variable.';');
- if (isset ($langvar) && is_string($langvar) && strlen($langvar) > 0) {
- $langvar = str_replace("\\'", "'", $langvar);
- $langvar = get_lang_to_system_encoding($langvar, $language);
- $cache[$language][$dltt][$variable] = $langvar;
- return $langvar;
- }
- @ eval ('$langvar = $lang'.$variable.';');
- if (isset ($langvar) && is_string($langvar) && strlen($langvar) > 0) {
- $langvar = str_replace("\\'", "'", $langvar);
- $langvar = get_lang_to_system_encoding($langvar, $language);
- $cache[$language][$dltt][$variable] = $langvar;
- return $langvar;
- }
- if (!$dltt) {
- $cache[$language][$dltt][$variable] = $ot.$variable.$ct;
- return $cache[$language][$dltt][$variable];
- }
- if (!is_array($language_files)) {
- $language_file = $language_files;
- } else {
- $language_file = implode('.inc.php',$language_files);
- }
- $cache[$language][$dltt][$variable] =
- $ot.$variable.$ct."<a href=\"http://www.dokeos.com/DLTT/suggestion.php?file=".$language_file.".inc.php&variable=$".$variable."&language=".$language_interface."\" target=\"_blank\" style=\"color:#FF0000\"><strong>#</strong></a>";
- return $cache[$language][$dltt][$variable];
- }
- function & get_lang_to_system_encoding(& $string, $language) {
- $charset = api_get_system_encoding();
- if (api_is_utf8($charset)) {
- if (!api_is_valid_utf8($string)) {
- $string = api_utf8_encode($string, api_get_non_utf8_encoding($language));
- }
- } else {
- if (api_is_valid_utf8($string)) {
- $string = api_utf8_decode($string, $charset);
- }
- }
- $string = api_html_entity_decode($string, ENT_QUOTES, $charset);
- return $string;
- }
- function api_get_interface_language($purified = false) {
- global $language_interface;
- if ($purified) {
- return api_refine_language_id($language_interface);
- }
- return $language_interface;
- }
- function api_is_platform_admin($allow_sessions_admins = false) {
- if($_SESSION['is_platformAdmin']) {
- return true;
- } else {
- global $_user;
- if ($allow_sessions_admins && $_user['status']==SESSIONADMIN) {
- return true;
- }
- }
- return false;
- }
- function api_is_allowed_to_create_course() {
- return $_SESSION["is_allowedCreateCourse"];
- }
- function api_is_course_admin() {
- return $_SESSION["is_courseAdmin"];
- }
- function api_is_course_coach() {
- return $_SESSION['is_courseCoach'];
- }
- function api_is_course_tutor() {
- return $_SESSION['is_courseTutor'];
- }
- function api_is_coach() {
- global $_user;
- global $sessionIsCoach;
- $sql = "SELECT DISTINCT id, name, date_start, date_end
- FROM session
- INNER JOIN session_rel_course
- ON session_rel_course.id_coach = '".Database::escape_string($_user['user_id'])."'
- ORDER BY date_start, date_end, name";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- $sessionIsCoach = api_store_result($result);
- $sql = "SELECT DISTINCT id, name, date_start, date_end
- FROM session
- WHERE session.id_coach = '".Database::escape_string($_user['user_id'])."'
- ORDER BY date_start, date_end, name";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- $sessionIsCoach = array_merge($sessionIsCoach , api_store_result($result));
- if(count($sessionIsCoach) > 0) {
- return true;
- } else {
- return false;
- }
- }
- function api_is_session_admin() {
- global $_user;
- if ($_user['status']==SESSIONADMIN) {
- return true;
- } else{
- return false;
- }
- }
- function api_display_tool_title($titleElement) {
- if (is_string($titleElement)) {
- $tit = $titleElement;
- unset ($titleElement);
- $titleElement['mainTitle'] = $tit;
- }
- echo '<h3>';
- if (!empty($titleElement['supraTitle'])) {
- echo '<small>'.$titleElement['supraTitle'].'</small><br>';
- }
- if (!empty($titleElement['mainTitle'])) {
- echo $titleElement['mainTitle'];
- }
- if (!empty($titleElement['subTitle'])) {
- echo '<br><small>'.$titleElement['subTitle'].'</small>';
- }
- echo '</h3>';
- }
- function api_display_tool_view_option() {
- if (api_get_setting('student_view_enabled') != "true") {
- return '';
- }
- $output_string='';
- $sourceurl = '';
- $is_framed = false;
-
- if (strpos($_SERVER['REQUEST_URI'],'chat/chat_banner.php')!==false) {
- $is_framed = true;
- return '';
- }
-
- if (strpos($_SERVER['REQUEST_URI'],'document/headerpage.php')!==false) {
- $sourceurl = str_replace('document/headerpage.php','document/showinframes.php',$_SERVER['REQUEST_URI']);
-
-
- $is_framed = true;
- }
-
- 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 (!strstr($_SERVER['REQUEST_URI'], "?")) {
- $sourceurl = api_get_self()."?".api_get_cidreq();
- } else {
- $sourceurl = $_SERVER['REQUEST_URI'];
-
- }
- }
- if(!empty($_SESSION['studentview'])) {
- if ($_SESSION['studentview']=='studentview') {
-
- $sourceurl = str_replace('&isStudentView=true', '', $sourceurl);
- $sourceurl = str_replace('&isStudentView=false', '', $sourceurl);
- $output_string .= '<a 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 href="'.$sourceurl.'&isStudentView=true" target="_self">'.get_lang("StudentView").'</a>';
- }
- } else {
- $output_string .= '<a href="'.$sourceurl.'&isStudentView=true" target="_self">'.get_lang("StudentView").'</a>';
- }
- echo $output_string;
- }
- function api_display_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 is_allowed_to_edit() {
- return api_is_allowed_to_edit();
- }
- function api_is_allowed_to_edit($tutor=false,$coach=false) {
- $is_courseAdmin = api_is_course_admin() || api_is_platform_admin();
- if (!$is_courseAdmin && $tutor == true) {
- $is_courseAdmin = $is_courseAdmin || api_is_course_tutor();
- }
- if (!$is_courseAdmin && $coach == true) {
- $is_courseAdmin = $is_courseAdmin || api_is_course_coach();
- }
- if (api_get_setting('student_view_enabled') == 'true') {
- $is_allowed = $is_courseAdmin && $_SESSION['studentview'] != "studentview";
- return $is_allowed;
- } else {
- return $is_courseAdmin;
- }
- }
- function api_is_allowed($tool, $action, $task_id = 0) {
- global $_course;
- global $_user;
- if (api_is_course_admin()) {
- return true;
- }
-
- if (is_array($_course) and count($_course)>0) {
- require_once(api_get_path(SYS_CODE_PATH) . 'permissions/permissions_functions.inc.php');
- require_once(api_get_path(LIBRARY_PATH) . "/groupmanager.lib.php");
-
- if ($task_id == 0) {
- $user_permissions = get_permissions('user', $_user['user_id']);
- $_SESSION['total_permissions'][$_course['code']] = $user_permissions;
- }
-
- if ($task_id != 0) {
- $task_permissions = get_permissions('task', $task_id);
- $_SESSION['total_permissions'][$_course['code']] = $task_permissions;
- }
-
-
-
-
-
-
- $user_courserole_permissions = get_roles_permissions('user', $_user['user_id']);
-
-
-
-
-
-
-
-
- }
-
- if (api_get_setting('permissions') == 'limited') {
- if ($action == 'Visibility') {
- $action = 'Edit';
- }
- if($action == 'Move') {
- $action = 'Edit';
- }
- }
-
-
-
- if (is_array($_SESSION['total_permissions'][$_course['code']][$tool])) {
- if (in_array($action, $_SESSION['total_permissions'][$_course['code']][$tool])) {
- return true;
- } else {
- return false;
- }
- }
- }
- function api_is_anonymous($user_id=null,$db_check=false) {
- if(!isset($user_id)) {
- $user_id = api_get_user_id();
- }
- if($db_check) {
- $info = api_get_user_info($user_id);
- if($info['status'] == 6) {
- return true;
- }
- } else {
- global $_user;
- if (!isset($_user)) {
-
-
-
- global $use_anonymous;
- if (isset($use_anonymous) && $use_anonymous == true) {
- api_set_anonymous();
- }
- return true;
- }
- if (isset($_user['is_anonymous']) and $_user['is_anonymous'] === true) {
- return true;
- }
- }
- return false;
- }
- function api_not_allowed($print_headers = false) {
- $home_url = api_get_path(WEB_PATH);
- $user = api_get_user_id();
- $course = api_get_course_id();
- global $this_section;
-
- $origin = isset($_GET['origin'])?$_GET['origin']:'';
-
- if ($origin == 'learnpath') {
-
- echo '
- <style type="text/css" media="screen, projection">
- /*<![CDATA[*/
- @import "'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css";
- /*]]>*/
- </style>';
- }
-
- if ((isset($user) && !api_is_anonymous())
- && (!isset($course) || $course==-1)
- && empty($_GET['cidReq']))
- {
-
-
- if ((!headers_sent() or $print_headers) && $origin != 'learnpath'){Display::display_header('');}
- echo '<div align="center">';
- Display::display_error_message(get_lang('NotAllowedClickBack').'<br /><br /><a href="'.$_SERVER['HTTP_REFERER'].'">'.get_lang('BackToPreviousPage').'</a><br />',false);
- echo '</div>';
- if ($print_headers && $origin != 'learnpath'){Display::display_footer();}
- die();
- } elseif (!empty($_SERVER['REQUEST_URI']) && (!empty($_GET['cidReq']) || $this_section == SECTION_MYPROFILE)) {
-
- if (!empty($user) && !api_is_anonymous()) {
- if ((!headers_sent() or $print_headers) && $origin != 'learnpath') { Display::display_header('');}
- echo '<div align="center">';
- Display::display_error_message(get_lang('NotAllowedClickBack').'<br /><br /><a href="'.$_SERVER['HTTP_REFERER'].'">'.get_lang('BackToPreviousPage').'</a><br />',false);
- echo '</div>';
- if ($print_headers && $origin != 'learnpath') {Display::display_footer();}
- die();
- } else {
- include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
- $form = new FormValidator('formLogin','post',api_get_self().'?'.$_SERVER['QUERY_STRING']);
- $form->addElement('static',null,null,'Username');
- $form->addElement('text','login','',array('size'=>15));
- $form->addElement('static',null,null,'Password');
- $form->addElement('password','password','',array('size'=>15));
- $form->addElement('style_submit_button','submitAuth',get_lang('Enter'),'class="login"');
- $test ='<div id="expire_session"><br />'.$form->return_form();'</div>';
-
- if((!headers_sent() or $print_headers) && $origin != 'learnpath'){Display::display_header('');}
- Display::display_error_message('<left>'.get_lang('NotAllowed').'<br />'.get_lang('PleaseLoginAgainFromFormBelow').'<br />'.$test.'</left>',false);
- $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
- if ($print_headers && $origin != 'learnpath') {Display::display_footer();}
- die();
- }
- } else {
- if (!empty($user) && !api_is_anonymous()) {
- if ((!headers_sent() or $print_headers) && $origin != 'learnpath') {Display::display_header('');}
- echo '<div align="center">';
- Display::display_error_message(get_lang('NotAllowedClickBack').'<br /><br /><a href="'.$_SERVER['HTTP_REFERER'].'">'.get_lang('BackToPreviousPage').'</a><br />',false);
- echo '</div>';
- if ($print_headers && $origin != 'learnpath') {Display::display_footer();}
- die();
- } else {
-
- if ($print_headers && $origin != 'learnpath') {Display::display_header('');}
- echo '<div align="center">';
- Display::display_error_message(get_lang('NotAllowed').'<br /><br /><a href="'.$home_url.'">'.get_lang('PleaseLoginAgainFromHomepage').'</a><br />',false);
- echo '</div>';
- if ($print_headers && $origin != 'learnpath') {Display::display_footer();}
- die();
- }
- }
- }
- function convert_mysql_date($last_post_datetime) {
- list ($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
- list ($year, $month, $day) = explode("-", $last_post_date);
- list ($hour, $min, $sec) = explode(":", $last_post_time);
- $announceDate = mktime((int)$hour, (int)$min, (int)$sec, (int)$month, (int)$day, (int)$year);
- return $announceDate;
- }
- 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) {
- if (!is_array($_course) or count($_course)==0 or empty($tool) or empty($id)) return -1;
- $tool = Database::escape_string($tool);
- $id = Database::escape_string($id);
- $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']);
- $sql = "SELECT * FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $id";
- $res = api_sql_query($sql);
- if($res === false or 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 = NULL, $start_visible = 0, $end_visible = 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 = Database::escape_string($start_visible);
- $end_visible = Database::escape_string($end_visible);
- $to_filter = "";
- $time = time();
- $time = date("Y-m-d H:i:s", $time);
- $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']);
- if ($to_user_id <= 0) {
- $to_user_id = NULL;
- }
- $start_visible = ($start_visible == 0) ? "0000-00-00 00:00:00" : $start_visible;
- $end_visible = ($end_visible == 0) ? "0000-00-00 00:00:00" : $end_visible;
-
- $filter = "tool='$tool' AND ref='$item_id'";
- if ($item_id == "*") {
- $filter = "tool='$tool' AND visibility<>'2'";
- }
-
-
- 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'";
- } else {
- if (($to_group_id != 0) && $to_group_id == strval(intval($to_group_id))) {
- $to_filter = " AND to_group_id='$to_group_id'";
- }
- }
-
- $set_type = "";
- switch ($lastedit_type) {
- case "delete" :
- $visibility = '2';
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
- WHERE $filter";
- break;
- case "visible" :
- $visibility = '1';
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
- WHERE $filter";
- break;
- case "invisible" :
- $visibility = '0';
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
- WHERE $filter";
- break;
- default :
- $set_type = ", lastedit_type='$lastedit_type' ";
- $visibility = '1';
- $filter .= $to_filter;
- $sql = "UPDATE $TABLE_ITEMPROPERTY
- SET lastedit_date='$time', lastedit_user_id='$user_id' $set_type
- WHERE $filter";
- }
- $res = mysql_query($sql);
-
- if (mysql_affected_rows() == 0) {
- if (!is_null($to_user_id)) {
-
- $to_field = "to_user_id";
- $to_value = $to_user_id;
- } else {
-
- $to_field = "to_group_id";
- $to_value = $to_group_id;
- }
- $sql = "INSERT INTO $TABLE_ITEMPROPERTY
- (tool, ref, insert_date,insert_user_id,lastedit_date,lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible)
- VALUES ('$tool','$item_id','$time', '$user_id', '$time', '$lastedit_type','$user_id', '$to_value','$visibility','$start_visible','$end_visible')";
- $res = mysql_query($sql);
- if (!$res) {
- return FALSE;
- }
- }
- return TRUE;
- }
- function api_get_languages_combo($name="language") {
- $ret = "";
- $platformLanguage = api_get_setting('platformLanguage');
-
- $language_list = api_get_languages();
- if (count($language_list['name']) < 2) {
- return $ret;
- }
-
- if(isset($_SESSION['user_language_choice']))
- $default = $_SESSION['user_language_choice'];
- else
- $default = $platformLanguage;
- $languages = $language_list['name'];
- $folder = $language_list['folder'];
- $ret .= '<select name="'.$name.'">';
- foreach ($languages as $key => $value) {
- if ($folder[$key] == $default)
- $selected = ' selected="selected"';
- else
- $selected = '';
- $ret .= sprintf('<option value=%s" %s>%s</option>'."\n",
- $folder[$key], $selected, $value);
- }
- $ret .= '</select>';
- return $ret;
- }
- function api_display_language_form($hide_if_no_choice=false) {
- $platformLanguage = api_get_setting('platformLanguage');
- $dirname = api_get_path(SYS_PATH)."main/lang/";
-
- $language_list = api_get_languages();
- if (count($language_list['name'])<=1 && $hide_if_no_choice == true) {
- return;
- }
-
- if(isset($_SESSION['user_language_choice']))
- {
- $user_selected_language = $_SESSION['user_language_choice'];
- }
- if (!isset ($user_selected_language))
- $user_selected_language = $platformLanguage;
- $original_languages = $language_list['name'];
- $folder = $language_list['folder'];
- ?>
- <script language="JavaScript" type="text/JavaScript">
- <!--
- function jumpMenu(targ,selObj,restore){
- eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
- if (restore) selObj.selectedIndex=0;
- }
-
- </script>
- <?php
- echo "<form id=\"lang_form\" name=\"lang_form\" method=\"post\" action=\"".api_get_self()."\">", "<select name=\"language_list\" onchange=\"jumpMenu('parent',this,0)\">";
- foreach ($original_languages as $key => $value)
- {
- if ($folder[$key] == $user_selected_language)
- $option_end = " selected=\"selected\" >";
- else
- $option_end = ">";
- echo "<option value=\"".api_get_self()."?language=".$folder[$key]."\"$option_end";
-
- echo $value;
- echo "</option>\n";
- }
- echo "</select>";
- echo "<noscript><input type=\"submit\" name=\"user_select_language\" value=\"".get_lang("Ok")."\" /></noscript>";
- echo "</form>";
- }
- function api_get_languages() {
- $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
- $sql = "SELECT * FROM $tbl_language WHERE available='1' ORDER BY original_name ASC";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- while ($row = Database::fetch_array($result)) {
- $language_list['name'][] = $row['original_name'];
- $language_list['folder'][] = $row['dokeos_folder'];
- }
- return $language_list;
- }
- function api_get_language_id($language) {
- $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
- $language = Database::escape_string($language);
- $sql = "SELECT id FROM $tbl_language WHERE available='1' AND dokeos_folder = '$language' ORDER BY dokeos_folder ASC";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
- return $row['id'];
- }
- function api_get_language_isocode($language = null) {
- return Database::get_language_isocode($language);
- }
- 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();
- $return[]=$list_dir;
- $return[]=$list_name;
- return $return;
- }
- function api_disp_html_area($name, $content = '', $height = '', $width = '100%', $attributes = null, $editor_config = null) {
- global $_configuration, $_course, $fck_attribute;
- require_once(dirname(__FILE__).'/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(dirname(__FILE__).'/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_send_mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null) {
- return mail($to, $subject, $message, $additional_headers, $additional_parameters);
- }
- 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='".$user_id."' AND user_course_cat='".$user_course_category."'";
- $result_max = mysql_query($sql_max) or die(mysql_error());
- if (mysql_num_rows($result_max) == 1) {
- $row_max = mysql_fetch_array($result_max);
- $max_sort = $row_max['max_sort'];
- } else {
- $max_sort = 0;
- }
- return $max_sort;
- }
- function string_2_boolean($string) {
- if ($string == "true") {
- return true;
- }
- if ($string == "false") {
- return false;
- }
- }
- function api_number_of_plugins($location) {
- global $_plugins;
- if (isset($_plugins[$location]) && is_array($_plugins[$location])) {
- return count($_plugins[$location]);
- }
- return 0;
- }
- function api_plugin($location) {
- global $_plugins;
- if (isset($_plugins[$location]) && is_array($_plugins[$location])) {
- foreach ($_plugins[$location] as $this_plugin) {
- include (api_get_path(SYS_PLUGIN_PATH)."$this_plugin/index.php");
- }
- }
- }
- function api_is_plugin_installed($plugin_list, $plugin_name) {
- foreach ($plugin_list as $plugin_location) {
- if ( array_search($plugin_name, $plugin_location) !== false ) return true;
- }
- return false;
- }
- function api_parse_tex($textext) {
- if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
- $textext = str_replace(array ("[tex]", "[/tex]"), array ("<object classid=\"clsid:5AFAB315-AD87-11D3-98BB-002035EFB1A4\"><param name=\"autosize\" value=\"true\" /><param name=\"DataType\" value=\"0\" /><param name=\"Data\" value=\"", "\" /></object>"), $textext);
- } else {
- $textext = str_replace(array ("[tex]", "[/tex]"), array ("<embed type=\"application/x-techexplorer\" texdata=\"", "\" autosize=\"true\" pluginspage=\"http://www.integretechpub.com/techexplorer/\">"), $textext);
- }
- return $textext;
- }
- 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 copyr($source, $dest, $exclude=array(), $copied_files=array()) {
-
- if (is_file($source)) {
- $path_infos = pathinfo($source);
- if(!in_array($path_infos['filename'], $exclude))
- copy($source, $dest);
- return;
- }
-
- if (!is_dir($dest)) {
- mkdir($dest);
- }
-
- $dir = dir($source);
- while (false !== $entry = $dir->read()) {
-
- if ($entry == '.' || $entry == '..') {
- continue;
- }
-
- if ($dest !== "$source/$entry") {
- $zip_files = copyr("$source/$entry", "$dest/$entry", $exclude, $copied_files);
- }
- }
-
- $dir->close();
- return $zip_files;
- }
- function api_chmod_R($path, $filemode) {
- if (!is_dir($path))
- return chmod($path, $filemode);
- $dh = opendir($path);
- while ($file = readdir($dh)) {
- 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($dh);
- if(chmod($path, $filemode))
- return TRUE;
- else
- return FALSE;
- }
- function api_get_version() {
- global $_configuration;
- if(!empty($_configuration['dokeos_version'])) {
- return $_configuration['dokeos_version'];
- } else {
- return '';
- }
- }
- function api_status_exists($status_asked) {
- global $_status_list;
- if (in_array($status_asked, $_status_list)) {
- return true;
- } else {
- return isset($_status_list[$status_asked]);
- }
- }
- function api_status_key($status) {
- global $_status_list;
- if (isset($_status_list[$status])) {
- return $status;
- } else {
- return array_search($status,$_status_list);
- }
- }
- function api_get_status_langvars() {
- return array(
- COURSEMANAGER=>get_lang('Teacher'),
- SESSIONADMIN=>get_lang('SessionsAdmin'),
- DRH=>get_lang('Drh'),
- STUDENT=>get_lang('Student'),
- ANONYMOUS=>get_lang('Anonymous')
- );
- }
- function api_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 * 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 = api_sql_query($select,__FILE__,__LINE__);
- if(Database::num_rows($res)>0) {
-
- $row = Database::fetch_array($res);
- $update = "UPDATE $t_settings SET selected_value = '$value' WHERE id = ".$row['id'] ;
- $res = api_sql_query($update,__FILE__,__LINE__);
- } 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 = api_sql_query($select,__FILE__,__LINE__);
- 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 = api_sql_query($insert,__FILE__,__LINE__);
- } 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 = api_sql_query($select,__FILE__,__LINE__);
- if (Database::num_rows($res)>0) {
- $row = Database::fetch_array($res);
- if ($row['access_url_changeable']==1) {
- $insert = "INSERT INTO $t_settings " .
- "(variable,subkey," .
- "type,category," .
- "selected_value,title," .
- "comment,scope," .
- "subkeytext,access_url, access_url_changeable)" .
- " VALUES " .
- "('".$row['variable']."',".
- (!empty($row['subkey'])?"'".$row['subkey']."'":"NULL")."," .
- "'".$row['type']."','".$row['category']."'," .
- "'$value','".$row['title']."'," .
- "".(!empty($row['comment'])?"'".$row['comment']."'":"NULL").",".
- (!empty($row['scope'])?"'".$row['scope']."'":"NULL")."," .
- "".(!empty($row['subkeytext'])?"'".$row['subkeytext']."'":"NULL").",$access_url,".$row['access_url_changeable'].")";
- $res = api_sql_query($insert,__FILE__,__LINE__);
- }
- } 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) {
- 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";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- if($res === false){ return false; }
- return true;
- } else {
- $sql = "UPDATE $t_s SET selected_value = NULL WHERE category = '$category' AND access_url = $access_url";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- if($res === false){ return false; }
- return true;
- }
- }
- function api_get_access_urls($from=0,$to=1000000,$order='url',$direction='ASC') {
- $result = array();
- $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 = api_sql_query($sql,__FILE__,__LINE__);
- if ($res !==false) {
- $result = api_store_result($res);
- }
- return $result;
- }
- function api_get_access_url($id) {
- global $_configuration;
- $id = Database::escape_string(intval($id));
- $result = array();
-
-
- $table='access_url';
- $database = $_configuration['main_database'];
- $table_access_url = "`".$database."`.`".$table."`";
- $sql = "SELECT url, description, active, created_by, tms
- FROM $table_access_url WHERE id = '$id' ";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- $result = @Database::fetch_array($res);
- return $result;
- }
- function api_add_access_url($u,$d='',$a=1) {
- $t_au = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
- $u = Database::escape_string($u);
- $d = Database::escape_string($d);
- $a = (int) $a;
- $sql = "SELECT * FROM $t_au WHERE url LIKE '$u'";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- if ($res === false) {
-
- return false;
- } else {
- if (Database::num_rows($res)>0) {
- return Database::result($res,0,'id');
- } else {
- $ui = api_get_user_id();
-
- $sql = "INSERT INTO $t_au (url,description,active,created_by,tms)"
- ." VALUES ('$u','$d',$a,$ui,'')";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- if ($res === false){return false;}
- return Database::insert_id();
- }
- }
- }
- function api_get_settings($cat=null,$ordering='list',$access_url=1,$url_changeable=0) {
- $results = array();
- $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $access_url = (int) $access_url;
- $url_changeable_where='';
- if ($url_changeable==1) {
- $url_changeable_where= " AND access_url_changeable= '1' ";
- }
- if (empty($access_url)) {$access_url=1;}
- $sql = "SELECT id, variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable " .
- " FROM $t_cs WHERE access_url = $access_url $url_changeable_where ";
- 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";
- }
- $res = api_sql_query($sql,__FILE__,__LINE__);
- if ($res === false) {return $results;}
- $results = api_store_result($res);
- return $results;
- }
- function api_get_settings_categories($exceptions=array(),$access_url=1) {
- $result = array();
- $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";
- if ($list != "'',''" and $list != "''" and !empty($list)) {
- $sql .= " WHERE category NOT IN ($list)";
- }
- $r = api_sql_query($sql,__FILE__,__LINE__);
- if ($r === false) {
- return $result;
- }
- $result = api_store_result($r);
- 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 = api_sql_query($sql);
- return $r;
- } else {
- $sql = "DELETE FROM $t_cs WHERE variable = '$v' AND access_url = $a";
- $r = api_sql_query($sql);
- return $r;
- }
- }
- function api_delete_category_settings($c,$a=1) {
- if (empty($c)){return false;}
- $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- $c = Database::escape_string($c);
- $a = (int) $a;
- if(empty($a)){$a=1;}
- $sql = "DELETE FROM $t_cs WHERE category = '$c' AND access_url = $a";
- $r = api_sql_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) or !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 * 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 = api_sql_query($select,__FILE__,__LINE__);
- if(Database::num_rows($res)>0) {
- $row = Database::fetch_array($res);
- return $row['id'];
- } else {
-
- $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 = api_sql_query($insert,__FILE__,__LINE__);
- return $res;
- }
- }
- function api_is_course_visible_for_user( $userid = null, $cid = null ) {
- if ( $userid == null ) {
- $userid = $_SESSION['_user']['user_id'];
- }
- if( empty ($userid) or strval(intval($userid)) != $userid ) {
- if ( api_is_anonymous() ) {
- $userid = api_get_anonymous_id();
- } else {
- return false;
- }
- }
- $cid = Database::escape_string($cid);
- global $is_platformAdmin;
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
- $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
- $sql = "SELECT
- $course_table.category_code,
- $course_table.visibility,
- $course_table.code,
- $course_cat_table.code
- FROM $course_table
- LEFT JOIN $course_cat_table
- ON $course_table.category_code = $course_cat_table.code
- WHERE
- $course_table.code = '$cid'
- LIMIT 1";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- 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;
- }
- if (api_get_setting('use_session_mode') != 'true') {
- $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $sql = "SELECT tutor_id, status
- FROM $course_user_table
- WHERE user_id = '$userid'
- AND course_code = '$cid'
- LIMIT 1";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- if ( Database::num_rows($result) > 0 ) {
-
- $cuData = Database::fetch_array($result);
- $is_courseMember = true;
- $is_courseTutor = ($cuData['tutor_id' ] == 1);
- $is_courseAdmin = ($cuData['status'] == 1);
- } else {
-
- $is_courseMember = false;
- $is_courseAdmin = false;
- $is_courseTutor = false;
- }
- $is_courseAdmin = ($is_courseAdmin || $is_platformAdmin);
- } else {
- $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
- course_code = '$cid'
- LIMIT 1";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- if ( Database::num_rows($result) > 0 ) {
-
- $cuData = Database::fetch_array($result);
- $_courseUser['role'] = $cuData['role'];
- $is_courseMember = true;
- $is_courseTutor = ($cuData['tutor_id' ] == 1);
- $is_courseAdmin = ($cuData['status'] == 1);
- }
- if ( !$is_courseAdmin ) {
-
-
- $tbl_session =
- Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_course =
- Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
- $tbl_session_course_user =
- Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $sql = "SELECT
- session.id_coach, session_admin_id, session.id
- FROM
- $tbl_session as session
- INNER JOIN $tbl_session_course
- ON session_rel_course.id_session = session.id
- AND session_rel_course.course_code = '$cid'
- LIMIT 1";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = api_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;
- api_session_register('_courseUser');
- } elseif ( $row[0]['session_admin_id'] == $userid ) {
- $_courseUser['role'] = 'Professor';
- $is_courseMember = false;
- $is_courseTutor = false;
- $is_courseAdmin = false;
- $is_courseCoach = false;
- $is_sessionAdmin = true;
- } else {
-
- $sql = "SELECT 1
- FROM $tbl_session_course
- WHERE session_rel_course.course_code = '$cid'
- AND session_rel_course.id_coach = '$userid'
- LIMIT 1";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if ($row = Database::fetch_array($result)) {
- $_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 = api_sql_query($sql);
- if ( Database::result($result, 0, 0) == 1 ) {
- $is_courseAdmin = true;
- } else {
- $is_courseAdmin = false;
- }
- } else {
-
- $sql = "SELECT id
- FROM $tbl_session_course_user
- WHERE id_user = '$userid'
- AND course_code = '$cid'
- LIMIT 1";
- if ( Database::num_rows($result) > 0 ) {
-
- while ( $row = Database::fetch_array($result) ) {
- $is_courseMember = true;
- $is_courseTutor = false;
- $is_courseAdmin = false;
- $is_sessionAdmin = false;
- }
- }
- }
- }
- }
- }
- $is_allowed_in_course = false;
- switch ( $visibility ) {
- case COURSE_VISIBILITY_OPEN_WORLD:
- $is_allowed_in_course = true;
- break;
- case COURSE_VISIBILITY_OPEN_PLATFORM:
- if (isset($userid))
- $is_allowed_in_course = true;
- break;
- case COURSE_VISIBILITY_REGISTERED:
- case COURSE_VISIBILITY_CLOSED:
- if ($is_platformAdmin || $is_courseMember || $is_courseAdmin)
- $is_allowed_in_course = true;
- break;
- default:
- $is_allowed_in_course = false;
- break;
- }
- return $is_allowed_in_course;
- }
- 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;
- }
- $sql = 'SELECT session_id FROM '.$table_tool.' WHERE '.$key_field.'='.intval($element_id);
- $rs = api_sql_query($sql, __FILE__, __LINE__);
- if ($element_session_id = Database::result($rs, 0, 0)) {
- if ($element_session_id == intval($session_id)) {
- return true;
- }
- }
- return false;
- }
- function replace_dangerous_char($filename, $strict = 'loose')
- {
- static $search = array(' ', '/', '\\', '"', '\'', '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#');
- static $replace = array('_', '-', '-', '-', '_', '-', '-', '', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
- static $search_strict = array('-');
- static $replace_strict = array('_');
- $system_encoding = api_get_file_system_encoding();
-
- if (api_is_latin1($system_encoding)) {
- $filename = ereg_replace("\.+$", "", substr(strtr(ereg_replace(
- "[^!-~\x80-\xFF]", "_", trim($filename)), '\/:*?"<>|\'',
- '-----_---_'), 0, 250));
- if ($strict != 'strict') return $filename;
- return ereg_replace("[^!-~]", "x", $filename);
- }
-
- if (!api_is_valid_utf8($filename)) {
-
- $input_encoding = api_get_file_system_encoding();
- if (api_is_utf8($input_encoding)) {
- $input_encoding = $system_encoding;
- }
- if (api_is_utf8($input_encoding)) {
- $input_encoding = api_get_non_utf8_encoding(api_get_interface_language());
- }
- $filename = api_utf8_encode($filename, $input_encoding);
- }
-
- $filename = api_transliterate($filename, 'x', 'UTF-8');
- $filename = trim($filename);
-
- $filename = trim($filename, '.');
- $filename = trim($filename);
-
- $filename = str_replace($search, $replace, $filename);
- if ($strict == 'strict') {
- $filename = str_replace($search_strict, $replace_strict, $filename);
- $filename = preg_replace('/[^0-9A-Za-z_.-]/', '', $filename);
- }
-
- return substr($filename, 0, 250);
- }
- function api_request_uri()
- {
- if (!empty($_SERVER['REQUEST_URI']))
- {
- return $_SERVER['REQUEST_URI'];
- }
- else
- {
- $uri = $_SERVER['SCRIPT_NAME'];
- if (!empty($_SERVER['QUERY_STRING']))
- {
- $uri .= '?'.$_SERVER['QUERY_STRING'];
- }
- $_SERVER['REQUEST_URI'] = $uri;
- return $uri;
- }
- }
- function api_create_include_path_setting()
- {
- $include_path = ini_get('include_path');
- if (!empty($include_path))
- {
- $include_path_array = explode(PATH_SEPARATOR, $include_path);
- $dot_found = array_search('.', $include_path_array);
- if ($dot_found !== false)
- {
- $result = array();
- foreach ($include_path_array as $path)
- {
- $result[] = $path;
- if ($path == '.')
- {
-
- $result[] = api_get_path(LIBRARY_PATH).'pear';
- }
- }
- return implode(PATH_SEPARATOR, $result);
- }
-
- return api_get_path(LIBRARY_PATH).'pear'.PATH_SEPARATOR.$include_path;
- }
-
- return api_get_path(LIBRARY_PATH).'pear';
- }
- function api_get_current_access_url_id()
- {
- $access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
- $path = api_get_path(WEB_PATH);
- $sql = "SELECT id FROM $access_url_table WHERE url = '".$path."'";
- $result = api_sql_query($sql);
- if (Database::num_rows($result)>0) {
- $access_url_id = Database::result($result, 0, 0);
- return $access_url_id;
- } else {
- 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 = api_sql_query($sql, __FILE__, __LINE__);
- $url_list=array();
- while ($row = Database::fetch_array($result,'ASSOC')) {
- $url_list[] = $row['access_url_id'];
- }
- return $url_list;
- }
- function api_get_status_of_user_in_course ($user_id,$course_code) {
- $tbl_rel_course_user=Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $user_id = Database::escape_string(intval($user_id));
- $course_code = Database::escape_string($course_code);
- $sql='SELECT status FROM '.$tbl_rel_course_user.'
- WHERE user_id='.$user_id.' AND course_code="'.$course_code.'";';
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $row_status=Database::fetch_array($result,'ASSOC');
- return $row_status['status'];
- }
- function api_is_in_course($course_code = null) {
- if (isset($_SESSION['_course']['sysCode'])) {
- if (!empty($course_code)) {
- if ($course_code == $_SESSION['_course']['sysCode']) return true; else return false;
- } else {
- return true;
- }
- }
- return false;
- }
- function api_is_in_group($group_id = null, $course_code = null) {
- if (!empty($course_code)) {
- if (isset($_SESSION['_course']['sysCode'])) {
- if ($course_code != $_SESSION['_course']['sysCode']) return false;
- } else {
- return false;
- }
- }
- if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
- if (!empty($group_id)) {
- if ($group_id == $_SESSION['_gid']) return true; else return false;
- } else {
- return true;
- }
- }
- return false;
- }
- if ( !function_exists('sys_get_temp_dir') )
- {
-
-
- function sys_get_temp_dir()
- {
-
- if ( !empty($_ENV['TMP']) )
- {
- return realpath( $_ENV['TMP'] );
- }
- else if ( !empty($_ENV['TMPDIR']) )
- {
- return realpath( $_ENV['TMPDIR'] );
- }
- else if ( !empty($_ENV['TEMP']) )
- {
- return realpath( $_ENV['TEMP'] );
- }
-
- else
- {
-
-
- $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
- if ( $temp_file )
- {
- $temp_dir = realpath( dirname($temp_file) );
- unlink( $temp_file );
- return $temp_dir;
- }
- else
- {
- return FALSE;
- }
- }
- }
- }
- function api_is_xml_http_request() {
-
- return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false;
- }
- function api_get_encrypted_password($password,$salt = '')
- {
- global $userPasswordCrypted;
- switch ($userPasswordCrypted){
- case 'md5':
- if (!empty($salt)) {
- $passwordcrypted = md5($password.$salt);
- } else {
- $passwordcrypted = md5($password);
- }
- return $passwordcrypted;
- break;
- case 'sha1':
- if (!empty($salt)) {
- $passwordcrypted = sha1($password.$salt);
- } else {
- $passwordcrypted = sha1($password);
- }
- return $passwordcrypted;
- break;
- case 'none':
- return $password;
- break;
- default:
- if (!empty($salt)) {
- $passwordcrypted = md5($password.$salt);
- } else {
- $passwordcrypted = md5($password);
- }
- return $passwordcrypted;
- break;
- }
- }
- function api_is_valid_secret_key($original_key_secret,$security_key) {
- global $_configuration;
- if ( $original_key_secret == sha1($security_key)) {
- return true;
- } else {
- return false;
- }
- }
- function api_is_user_of_course ($course_id,$user_id) {
- $tbl_course_rel_user=Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $sql='SELECT user_id FROM '.$tbl_course_rel_user.' WHERE course_code="'.Database::escape_string($course_id).'" AND user_id="'.Database::escape_string($user_id).'"';
- $result=api_sql_query($sql,__FILE__,__LINE__);
- if (Database::num_rows($result)==1) {
- return true;
- } else {
- return false;
- }
- }
- 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 {
- $os = '';
- }
- return strtolower(substr($os, 0, 3 )) === 'win' ? true : false;
- }
- function api_url_to_local_path($url)
- {
-
- if (!preg_match('/https?:\/\/(.*?):{0,1}([0-9]*)(\/)(.*?)/i', $url))
- {
- return $url;
- }
- $original_url = $url;
- $url = urldecode($url);
-
-
-
-
-
-
-
-
- if (preg_match('/(.*)main\/document\/download.php\?doc_url=\/(.*)&cDir=\/(.*)?/', $url, $matches))
- {
- global $_cid, $_course;
- if (!empty($_cid) and $_cid != -1 and isset($_course))
- {
- $url = $matches[1].'courses/'.$_course['path'].'/document/'.str_replace('//', '/', $matches[3].'/'.$matches[2]);
- }
- else
- {
- return $original_url;
- }
- }
-
-
-
-
- $tmp = explode('?', $url);
- $array_url = explode ('/', $tmp[0]);
-
-
- $file_name = array_pop($array_url);
-
- $array_web_path = explode ('/', api_get_path(WEB_PATH));
-
-
-
-
-
- $array_local_path = array_values(array_diff($array_url, $array_web_path));
- $local_path = implode('/', $array_local_path);
-
-
-
- $local_path = preg_replace('@/{2,}@', '/', $local_path);
-
-
- return str_replace("\\", '/', api_get_path(SYS_PATH)).(empty($local_path) ? '' : $local_path.'/').$file_name;
- }
- function api_resize_image($image, $target_width, $target_height) {
- $image_properties = @getimagesize(api_url_to_local_path($image));
- $image_width = $image_properties[0];
- $image_height = $image_properties[1];
- return api_calculate_image_size($image_width, $image_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
- );
- if (is_null($my_tool)) {
- return $tools_list;
- } elseif (in_array($my_tool,$tools_list)) {
- return $my_tool;
- } else {
- return '';
- }
- }
- function api_check_term_condition($user_id) {
- $return = false;
- if (get_setting('allow_terms_conditions')=='true') {
- require_once api_get_path(LIBRARY_PATH).'legal.lib.php';
- $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;
- }
-
- $sqlv = "SELECT field_value FROM $t_ufv ufv inner join $t_uf uf on ufv.field_id= uf.id
- WHERE field_variable = 'legal_accept' AND user_id = ".intval($user_id);
- $resv = api_sql_query($sqlv,__FILE__,__LINE__);
- if (Database::num_rows($resv) > 0) {
- $rowv = Database::fetch_row($resv);
- $rowv = $rowv[0];
- $user_conditions = explode(':',$rowv);
- $version = $user_conditions[0];
- $lang_id= $user_conditions[1];
- $real_version = LegalManager::get_last_version($lang_id);
- if ($version < $real_version) {
- $return = false;
- } else {
- $return = true;
- }
- }
- }
- return $return;
- }
|