global.inc.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * It is recommended that ALL Chamilo scripts include this important file.
  5. * This script manages
  6. * - http get, post, post_files, session, server-vars extraction into global namespace;
  7. * (which doesn't occur anymore when servertype config setting is set to test,
  8. * and which will disappear completely in Dokeos 1.6.1)
  9. * - include of /conf/configuration.php;
  10. * - include of several libraries: main_api, database, display, text, security;
  11. * - selecting the main database;
  12. * - include of language files.
  13. *
  14. * @package chamilo.include
  15. * @todo isn't configuration.php renamed to configuration.inc.php yet?
  16. * @todo use the $_configuration array for all the needed variables
  17. * @todo remove the code that displays the button that links to the install page
  18. * but use a redirect immediately. By doing so the $already_installed variable can be removed.
  19. * @todo make it possible to enable / disable the tracking through the Chamilo config page.
  20. *
  21. */
  22. //@todo will be removed before a stable release
  23. $mtime = microtime();
  24. $mtime = explode(" ",$mtime);
  25. $mtime = $mtime[1] + $mtime[0];
  26. $starttime = $mtime;
  27. define('START', $starttime);
  28. // Showing/hiding error codes in global error messages.
  29. define('SHOW_ERROR_CODES', false);
  30. // Determine the directory path where this current file lies.
  31. // This path will be useful to include the other intialisation files.
  32. $includePath = dirname(__FILE__);
  33. // @todo Isn't this file renamed to configuration.inc.php yet?
  34. // Include the main Chamilo platform configuration file.
  35. $main_configuration_file_path = $includePath.'/conf/configuration.php';
  36. $already_installed = false;
  37. if (file_exists($main_configuration_file_path)) {
  38. require_once $main_configuration_file_path;
  39. $already_installed = true;
  40. } else {
  41. $_configuration = array();
  42. }
  43. //Redirects to the main/install/ page
  44. if (!$already_installed) {
  45. $global_error_code = 2;
  46. // The system has not been installed yet.
  47. require $includePath.'/global_error_message.inc.php';
  48. die();
  49. }
  50. // Ensure that _configuration is in the global scope before loading
  51. // main_api.lib.php. This is particularly helpful for unit tests
  52. if (!isset($GLOBALS['_configuration'])) {
  53. $GLOBALS['_configuration'] = $_configuration;
  54. }
  55. // Code for trnasitional purposes, it can be removed right before the 1.8.7 release.
  56. if (empty($_configuration['system_version'])) {
  57. $_configuration['system_version'] = $_configuration['dokeos_version'];
  58. $_configuration['system_stable'] = $_configuration['dokeos_stable'];
  59. $_configuration['software_url'] = 'http://www.chamilo.org/';
  60. }
  61. // For backward compatibility.
  62. $_configuration['dokeos_version'] = $_configuration['system_version'];
  63. $_configuration['dokeos_stable'] = $_configuration['system_stable'];
  64. // Include the main Chamilo platform library file.
  65. require_once $includePath.'/lib/main_api.lib.php';
  66. //Check the PHP version
  67. api_check_php_version($includePath.'/');
  68. // Specification for usernames:
  69. // 1. ASCII-letters, digits, "." (dot), "_" (underscore) are acceptable, 40 characters maximum length.
  70. // 2. Empty username is formally valid, but it is reserved for the anonymous user.
  71. // 3. Checking the login_is_email portal setting in order to accept 100 chars maximum
  72. $default_username_length = 40;
  73. if (api_get_setting('login_is_email') == 'true') {
  74. $default_username_length = 100;
  75. }
  76. define('USERNAME_MAX_LENGTH', $default_username_length);
  77. // Do not over-use this variable. It is only for this script's local use.
  78. $lib_path = api_get_path(LIBRARY_PATH);
  79. // Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI'].
  80. api_request_uri();
  81. // Add the path to the pear packages to the include path
  82. ini_set('include_path', api_create_include_path_setting());
  83. // This is for compatibility with MAC computers.
  84. ini_set('auto_detect_line_endings', '1');
  85. //Include the libraries that are necessary everywhere
  86. //require_once dirname(__FILE__).'/autoload.inc.php';
  87. //Fixes Htmlpurifier autoloader issue with composer
  88. define('HTMLPURIFIER_PREFIX', $lib_path.'htmlpurifier/library');
  89. //mpdf constants
  90. define("_MPDF_TEMP_PATH", api_get_path(SYS_ARCHIVE_PATH));
  91. define('_MPDF_PATH', api_get_path(LIBRARY_PATH).'mpdf/');
  92. //Composer autoloader
  93. require_once __DIR__.'../../../vendor/autoload.php';
  94. //Database constants
  95. require_once $lib_path.'database.constants.inc.php';
  96. //Removing support for this files:
  97. //require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
  98. //require_once api_get_path(CONFIGURATION_PATH).'course_info.conf.php';
  99. require_once $lib_path.'mail.lib.inc.php';
  100. require_once $lib_path.'fileManage.lib.php';
  101. require_once $lib_path.'text.lib.php';
  102. require_once $lib_path.'array.lib.php';
  103. require_once $lib_path.'events.lib.inc.php';
  104. require_once $lib_path.'online.inc.php';
  105. /* DATABASE CONNECTION */
  106. // @todo: this shouldn't be done here. It should be stored correctly during installation.
  107. if (empty($_configuration['statistics_database']) && $already_installed) {
  108. $_configuration['statistics_database'] = $_configuration['main_database'];
  109. }
  110. global $database_connection;
  111. // Connect to the server database and select the main chamilo database.
  112. if (!($conn_return = @Database::connect(
  113. array(
  114. 'server' => $_configuration['db_host'],
  115. 'username' => $_configuration['db_user'],
  116. 'password' => $_configuration['db_password'],
  117. 'persistent' => $_configuration['db_persistent_connection'] // When $_configuration['db_persistent_connection'] is set, it is expected to be a boolean type.
  118. )))) {
  119. $global_error_code = 3;
  120. // The database server is not available or credentials are invalid.
  121. require $includePath.'/global_error_message.inc.php';
  122. die();
  123. }
  124. if (!$_configuration['db_host']) {
  125. $global_error_code = 4;
  126. // A configuration option about database server is missing.
  127. require $includePath.'/global_error_message.inc.php';
  128. die();
  129. }
  130. /* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
  131. if (!empty($_configuration['multiple_access_urls'])) {
  132. $_configuration['access_url'] = 1;
  133. $access_urls = api_get_access_urls();
  134. $protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
  135. $request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
  136. $request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
  137. foreach ($access_urls as & $details) {
  138. if ($request_url1 == $details['url'] or $request_url2 == $details['url']) {
  139. $_configuration['access_url'] = $details['id'];
  140. }
  141. }
  142. } else {
  143. $_configuration['access_url'] = 1;
  144. }
  145. // The system has not been designed to use special SQL modes that were introduced since MySQL 5.
  146. Database::query("set session sql_mode='';");
  147. if (!Database::select_db($_configuration['main_database'], $database_connection)) {
  148. $global_error_code = 5;
  149. // Connection to the main Chamilo database is impossible, it might be missing or restricted or its configuration option might be incorrect.
  150. require $includePath.'/global_error_message.inc.php';
  151. die();
  152. }
  153. /* Initialization of the default encodings */
  154. // The platform's character set must be retrieved at this early moment.
  155. $sql = "SELECT selected_value FROM settings_current WHERE variable = 'platform_charset';";
  156. $result = Database::query($sql);
  157. while ($row = @Database::fetch_array($result)) {
  158. $charset = $row[0];
  159. }
  160. if (empty($charset)) {
  161. $charset = 'UTF-8';
  162. }
  163. // Preserving the value of the global variable $charset.
  164. $charset_initial_value = $charset;
  165. // Initialization of the internationalization library.
  166. api_initialize_internationalization();
  167. // Initialization of the default encoding that will be used by the multibyte string routines in the internationalization library.
  168. api_set_internationalization_default_encoding($charset);
  169. // Initialization of the database encoding to be used.
  170. Database::query("SET SESSION character_set_server='utf8';");
  171. Database::query("SET SESSION collation_server='utf8_general_ci';");
  172. if (api_is_utf8($charset)) {
  173. // See Bug #1802: For UTF-8 systems we prefer to use "SET NAMES 'utf8'" statement in order to avoid a bizarre problem with Chinese language.
  174. Database::query("SET NAMES 'utf8';");
  175. } else {
  176. Database::query("SET CHARACTER SET '" . Database::to_db_encoding($charset) . "';");
  177. }
  178. // Start session after the internationalization library has been initialized.
  179. Chamilo::session()->start($already_installed);
  180. // Remove quotes added by PHP - get_magic_quotes_gpc() is deprecated in PHP 5 see #2970
  181. if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
  182. array_walk_recursive_limited($_GET, 'stripslashes', true);
  183. array_walk_recursive_limited($_POST, 'stripslashes', true);
  184. array_walk_recursive_limited($_COOKIE, 'stripslashes', true);
  185. array_walk_recursive_limited($_REQUEST, 'stripslashes', true);
  186. }
  187. // access_url == 1 is the default chamilo location
  188. if ($_configuration['access_url'] != 1) {
  189. $url_info = api_get_access_url($_configuration['access_url']);
  190. if ($url_info['active'] == 1) {
  191. $settings_by_access = & api_get_settings(null, 'list', $_configuration['access_url'], 1);
  192. foreach ($settings_by_access as & $row) {
  193. if (empty($row['variable'])) {
  194. $row['variable'] = 0;
  195. }
  196. if (empty($row['subkey'])) {
  197. $row['subkey'] = 0;
  198. }
  199. if (empty($row['category'])) {
  200. $row['category'] = 0;
  201. }
  202. $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
  203. }
  204. }
  205. }
  206. $result = & api_get_settings(null, 'list', 1);
  207. foreach ($result as & $row) {
  208. if ($_configuration['access_url'] != 1) {
  209. if ($url_info['active'] == 1) {
  210. $var = empty($row['variable']) ? 0 : $row['variable'];
  211. $subkey = empty($row['subkey']) ? 0 : $row['subkey'];
  212. $category = empty($row['category']) ? 0 : $row['category'];
  213. }
  214. if ($row['access_url_changeable'] == 1 && $url_info['active'] == 1) {
  215. if (isset($settings_by_access_list[$var]) &&
  216. $settings_by_access_list[$var][$subkey][$category]['selected_value'] != '') {
  217. if ($row['subkey'] == null) {
  218. $_setting[$row['variable']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
  219. } else {
  220. $_setting[$row['variable']][$row['subkey']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
  221. }
  222. } else {
  223. if ($row['subkey'] == null) {
  224. $_setting[$row['variable']] = $row['selected_value'];
  225. } else {
  226. $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
  227. }
  228. }
  229. } else {
  230. if ($row['subkey'] == null) {
  231. $_setting[$row['variable']] = $row['selected_value'];
  232. } else {
  233. $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
  234. }
  235. }
  236. } else {
  237. if ($row['subkey'] == null) {
  238. $_setting[$row['variable']] = $row['selected_value'];
  239. } else {
  240. $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
  241. }
  242. }
  243. }
  244. $result = & api_get_settings('Plugins', 'list', $_configuration['access_url']);
  245. $_plugins = array();
  246. foreach ($result as & $row) {
  247. $key = & $row['variable'];
  248. if (is_string($_setting[$key])) {
  249. $_setting[$key] = array();
  250. }
  251. $_setting[$key][] = $row['selected_value'];
  252. $_plugins[$key][] = $row['selected_value'];
  253. }
  254. // Load allowed tag definitions for kses and/or HTMLPurifier.
  255. require_once $lib_path.'formvalidator/Rule/allowed_tags.inc.php';
  256. // Load HTMLPurifier.
  257. //require_once $lib_path.'htmlpurifier/library/HTMLPurifier.auto.php'; // It will be loaded later, in a lazy manner.
  258. // Before we call local.inc.php, let's define a global $this_section variable
  259. // which will then be usable from the banner and header scripts
  260. $this_section = SECTION_GLOBAL;
  261. // include the local (contextual) parameters of this course or section
  262. require $includePath.'/local.inc.php';
  263. //Include Chamilo Mail conf this is added here because the api_get_setting works
  264. //Fixes bug in Chamilo 1.8.7.1 array was not set
  265. $administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com';
  266. $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';
  267. $mail_conf = api_get_path(CONFIGURATION_PATH).'mail.conf.php';
  268. if (file_exists($mail_conf)) {
  269. require_once $mail_conf;
  270. }
  271. // ===== "who is logged in?" module section =====
  272. // check and modify the date of user in the track.e.online table
  273. if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {
  274. LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : '');
  275. }
  276. // ===== end "who is logged in?" module section =====
  277. if (api_get_setting('server_type') == 'test') {
  278. /*
  279. Server type is test
  280. - high error reporting level
  281. - only do addslashes on $_GET and $_POST
  282. */
  283. if (IS_PHP_53) {
  284. error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
  285. } else {
  286. error_reporting(E_ALL & ~E_NOTICE);
  287. }
  288. } else {
  289. /*
  290. Server type is not test
  291. - normal error reporting level
  292. - full fake register globals block
  293. */
  294. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  295. // TODO: These obsolete variables $HTTP_* to be check whether they are actually used.
  296. if (!isset($HTTP_GET_VARS)) { $HTTP_GET_VARS = $_GET; }
  297. if (!isset($HTTP_POST_VARS)) { $HTTP_POST_VARS = $_POST; }
  298. if (!isset($HTTP_POST_FILES)) { $HTTP_POST_FILES = $_FILES; }
  299. if (!isset($HTTP_SESSION_VARS)) { $HTTP_SESSION_VARS = $_SESSION; }
  300. if (!isset($HTTP_SERVER_VARS)) { $HTTP_SERVER_VARS = $_SERVER; }
  301. // Register SESSION variables into $GLOBALS
  302. if (sizeof($HTTP_SESSION_VARS)) {
  303. if (!is_array($_SESSION)) {
  304. $_SESSION = array();
  305. }
  306. foreach ($HTTP_SESSION_VARS as $key => $val) {
  307. $_SESSION[$key] = $HTTP_SESSION_VARS[$key];
  308. $GLOBALS[$key] = $HTTP_SESSION_VARS[$key];
  309. }
  310. }
  311. // Register SERVER variables into $GLOBALS
  312. if (sizeof($HTTP_SERVER_VARS)) {
  313. $_SERVER = array();
  314. foreach ($HTTP_SERVER_VARS as $key => $val) {
  315. $_SERVER[$key] = $HTTP_SERVER_VARS[$key];
  316. if (!isset($_SESSION[$key]) && $key != 'includePath' && $key != 'rootSys' && $key!= 'lang_path' && $key!= 'extAuthSource' && $key!= 'thisAuthSource' && $key!= 'main_configuration_file_path' && $key!= 'phpDigIncCn' && $key!= 'drs') {
  317. $GLOBALS[$key]=$HTTP_SERVER_VARS[$key];
  318. }
  319. }
  320. }
  321. }
  322. /* LOAD LANGUAGE FILES SECTION */
  323. // if we use the javascript version (without go button) we receive a get
  324. // if we use the non-javascript version (with the go button) we receive a post
  325. $user_language = '';
  326. if (!empty($_GET['language'])) {
  327. $user_language = $_GET['language'];
  328. }
  329. if (!empty($_POST['language_list'])) {
  330. $user_language = str_replace('index.php?language=', '', $_POST['language_list']);
  331. }
  332. // Include all files (first english and then current interface language)
  333. $langpath = api_get_path(SYS_LANG_PATH);
  334. /* This will only work if we are in the page to edit a sub_language */
  335. if (isset($this_script) && $this_script == 'sub_language') {
  336. require_once '../admin/sub_language.class.php';
  337. // getting the arrays of files i.e notification, trad4all, etc
  338. $language_files_to_load = SubLanguageManager:: get_lang_folder_files_list(api_get_path(SYS_LANG_PATH).'english', true);
  339. //getting parent info
  340. $parent_language = SubLanguageManager::get_all_information_of_language($_REQUEST['id']);
  341. //getting sub language info
  342. $sub_language = SubLanguageManager::get_all_information_of_language($_REQUEST['sub_language_id']);
  343. $english_language_array = $parent_language_array = $sub_language_array = array();
  344. foreach ($language_files_to_load as $language_file_item) {
  345. $lang_list_pre = array_keys($GLOBALS);
  346. //loading english
  347. $path = $langpath.'english/'.$language_file_item.'.inc.php';
  348. if (file_exists($path)) {
  349. include $path;
  350. }
  351. $lang_list_post = array_keys($GLOBALS);
  352. $lang_list_result = array_diff($lang_list_post, $lang_list_pre);
  353. unset($lang_list_pre);
  354. // english language array
  355. $english_language_array[$language_file_item] = compact($lang_list_result);
  356. //cleaning the variables
  357. foreach ($lang_list_result as $item) {
  358. unset(${$item});
  359. }
  360. $parent_file = $langpath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  361. if (file_exists($parent_file) && is_file($parent_file)) {
  362. include_once $parent_file;
  363. }
  364. // parent language array
  365. $parent_language_array[$language_file_item] = compact($lang_list_result);
  366. //cleaning the variables
  367. foreach($lang_list_result as $item) {
  368. unset(${$item});
  369. }
  370. $sub_file = $langpath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  371. if (file_exists($sub_file) && is_file($sub_file)) {
  372. include $sub_file;
  373. }
  374. // sub language array
  375. $sub_language_array[$language_file_item] = compact($lang_list_result);
  376. //cleaning the variables
  377. foreach($lang_list_result as $item) {
  378. unset(${$item});
  379. }
  380. }
  381. }
  382. // Checking if we have a valid language. If not we set it to the platform language.
  383. $valid_languages = api_get_languages();
  384. if (!empty($valid_languages)) {
  385. if (!in_array($user_language, $valid_languages['folder'])) {
  386. $user_language = api_get_setting('platformLanguage');
  387. }
  388. $language_priority1 = api_get_setting('languagePriority1');
  389. $language_priority2 = api_get_setting('languagePriority2');
  390. $language_priority3 = api_get_setting('languagePriority3');
  391. $language_priority4 = api_get_setting('languagePriority4');
  392. if (in_array($user_language, $valid_languages['folder']) && (isset($_GET['language']) || isset($_POST['language_list']))) {
  393. $user_selected_language = $user_language; // $_GET['language'];
  394. $_SESSION['user_language_choice'] = $user_selected_language;
  395. $platformLanguage = $user_selected_language;
  396. }
  397. if (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false ) {
  398. $language_interface = api_get_language_from_type($language_priority4);
  399. } else {
  400. $language_interface = api_get_setting('platformLanguage');
  401. }
  402. if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false ) {
  403. $language_interface = api_get_language_from_type($language_priority3);
  404. } else {
  405. if (isset($_SESSION['user_language_choice'])) {
  406. $language_interface = $_SESSION['user_language_choice'];
  407. }
  408. }
  409. if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false ) {
  410. $language_interface = api_get_language_from_type($language_priority2);
  411. } else {
  412. if (isset($_user['language'])) {
  413. $language_interface = $_user['language'];
  414. }
  415. }
  416. if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false ) {
  417. $language_interface = api_get_language_from_type($language_priority1);
  418. } else {
  419. if ($_course['language']) {
  420. $language_interface = $_course['language'];
  421. }
  422. }
  423. }
  424. // Sometimes the variable $language_interface is changed
  425. // temporarily for achieving translation in different language.
  426. // We need to save the genuine value of this variable and
  427. // to use it within the function get_lang(...).
  428. $language_interface_initial_value = $language_interface;
  429. /**
  430. * Include all necessary language files
  431. * - trad4all
  432. * - notification
  433. * - custom tool language files
  434. */
  435. $language_files = array();
  436. $language_files[] = 'trad4all';
  437. $language_files[] = 'notification';
  438. $language_files[] = 'accessibility';
  439. if (isset($language_file)) {
  440. if (!is_array($language_file)) {
  441. $language_files[] = $language_file;
  442. } else {
  443. $language_files = array_merge($language_files, $language_file);
  444. }
  445. }
  446. // if a set of language files has been properly defined
  447. if (is_array($language_files)) {
  448. // if the sub-language feature is on
  449. if (api_get_setting('allow_use_sub_language') == 'true') {
  450. require_once api_get_path(SYS_CODE_PATH).'admin/sub_language.class.php';
  451. $parent_path = SubLanguageManager::get_parent_language_path($language_interface);
  452. foreach ($language_files as $index => $language_file) {
  453. // include English
  454. include $langpath.'english/'.$language_file.'.inc.php';
  455. // prepare string for current language and its parent
  456. $lang_file = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  457. $parent_lang_file = $langpath.$parent_path.'/'.$language_file.'.inc.php';
  458. // load the parent language file first
  459. if (file_exists($parent_lang_file)) {
  460. include $parent_lang_file;
  461. }
  462. // overwrite the parent language translations if there is a child
  463. if (file_exists($lang_file)) {
  464. include $lang_file;
  465. }
  466. }
  467. } else {
  468. // if the sub-languages feature is not on, then just load the
  469. // set language interface
  470. foreach ($language_files as $index => $language_file) {
  471. // include English
  472. include $langpath.'english/'.$language_file.'.inc.php';
  473. // prepare string for current language
  474. $langfile = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  475. if (file_exists($langfile)) {
  476. include $langfile;
  477. }
  478. }
  479. }
  480. }
  481. // The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation.
  482. // So, we have to reassign this variable again in order to keep its value right.
  483. $charset = $charset_initial_value;
  484. // The global variable $text_dir has been defined in the language file trad4all.inc.php.
  485. // For determing text direction correspondent to the current language we use now information from the internationalization library.
  486. $text_dir = api_get_text_direction();
  487. //Update of the logout_date field in the table track_e_login (needed for the calculation of the total connection time)
  488. if (!isset($_SESSION['login_as']) && isset($_user)) {
  489. // if $_SESSION['login_as'] is set, then the user is an admin logged as the user
  490. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  491. $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".$_user["user_id"]."' ORDER BY login_date DESC LIMIT 0,1";
  492. $q_last_connection = Database::query($sql_last_connection);
  493. if (Database::num_rows($q_last_connection) > 0) {
  494. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  495. // is the latest logout_date still relevant?
  496. $sql_logout_date = "SELECT logout_date FROM $tbl_track_login WHERE login_id=$i_id_last_connection";
  497. $q_logout_date = Database::query($sql_logout_date);
  498. $res_logout_date = convert_sql_date(Database::result($q_logout_date,0,'logout_date'));
  499. if ($res_logout_date < time() - $_configuration['session_lifetime']) {
  500. // it isn't, we should create a fresh entry
  501. event_login();
  502. // now that it's created, we can get its ID and carry on
  503. $q_last_connection = Database::query($sql_last_connection);
  504. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  505. }
  506. $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
  507. Database::query($s_sql_update_logout_date);
  508. }
  509. }
  510. // Add language_measure_frequency to your main/inc/conf/configuration.php in
  511. // order to generate language variables frequency measurements (you can then
  512. // see them through main/cron/lang/langstats.php)
  513. // The langstat object will then be used in the get_lang() function.
  514. // This block can be removed to speed things up a bit as it should only ever
  515. // be used in development versions.
  516. if ($_configuration['language_measure_frequency'] == 1) {
  517. require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
  518. $langstats = new langstats();
  519. }
  520. //Default quota for the course documents folder
  521. $default_quota = api_get_setting('default_document_quotum');
  522. //Just in case the setting is not correctly set
  523. if (empty($default_quota)) {
  524. $default_quota = 100000000;
  525. }
  526. define('DEFAULT_DOCUMENT_QUOTA', $default_quota);