global.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. return;
  4. /**
  5. * It is recommended that ALL Chamilo scripts include this important file.
  6. * This script manages
  7. * - include of /app/config/configuration.php;
  8. * - include of several libraries: api, database, display, text, security;
  9. * - selecting the main database;
  10. * - include of language files.
  11. *
  12. * @package chamilo.include
  13. * @todo remove the code that displays the button that links to the install page
  14. * but use a redirect immediately. By doing so the $alreadyInstalled variable can be removed.
  15. *
  16. */
  17. // Showing/hiding error codes in global error messages.
  18. define('SHOW_ERROR_CODES', false);
  19. // Include the libraries that are necessary everywhere
  20. require_once __DIR__.'/../../vendor/autoload.php';
  21. require_once __DIR__.'/../../app/AppKernel.php';
  22. $kernel = new AppKernel('', '');
  23. // Determine the directory path where this current file lies.
  24. // This path will be useful to include the other initialisation files.
  25. $includePath = __DIR__;
  26. // Include the main Chamilo platform configuration file.
  27. $alreadyInstalled = false;
  28. if (file_exists($kernel->getConfigurationFile())) {
  29. require_once $kernel->getConfigurationFile();
  30. $alreadyInstalled = true;
  31. // Recalculate a system absolute path symlinks insensible.
  32. $includePath = $_configuration['root_sys'].'main/inc/';
  33. } else {
  34. $_configuration = array();
  35. //Redirects to the main/install/ page
  36. if (!$alreadyInstalled) {
  37. $global_error_code = 2;
  38. // The system has not been installed yet.
  39. require_once __DIR__.'/../inc/global_error_message.inc.php';
  40. die();
  41. }
  42. }
  43. $kernel->setApi($_configuration);
  44. // Ensure that _configuration is in the global scope before loading
  45. // main_api.lib.php. This is particularly helpful for unit tests
  46. if (!isset($GLOBALS['_configuration'])) {
  47. $GLOBALS['_configuration'] = $_configuration;
  48. }
  49. // Include the main Chamilo platform library file.
  50. require_once $_configuration['root_sys'].'main/inc/lib/api.lib.php';
  51. $passwordEncryption = api_get_configuration_value('password_encryption');
  52. if ($passwordEncryption === 'bcrypt') {
  53. require_once __DIR__.'/../../vendor/ircmaxell/password-compat/lib/password.php';
  54. }
  55. // Check the PHP version
  56. api_check_php_version($includePath.'/');
  57. // Specification for usernames:
  58. // 1. ASCII-letters, digits, "." (dot), "_" (underscore) are acceptable, 40 characters maximum length.
  59. // 2. Empty username is formally valid, but it is reserved for the anonymous user.
  60. // 3. Checking the login_is_email portal setting in order to accept 100 chars maximum
  61. $defaultUserNameLength = 50;
  62. if (api_get_setting('login_is_email') == 'true') {
  63. $defaultUserNameLength = 100;
  64. }
  65. define('USERNAME_MAX_LENGTH', $defaultUserNameLength);
  66. // Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI'].
  67. api_request_uri();
  68. define('_MPDF_TEMP_PATH', __DIR__.'/../../app/cache/mpdf/');
  69. define('_MPDF_TTFONTDATAPATH', __DIR__.'/../../app/cache/mpdf/');
  70. // Include the libraries that are necessary everywhere
  71. require_once __DIR__.'/../../vendor/autoload.php';
  72. // Do not over-use this variable. It is only for this script's local use.
  73. $libraryPath = __DIR__.'/lib/';
  74. // @todo convert this libs in classes
  75. require_once $libraryPath.'database.constants.inc.php';
  76. require_once $libraryPath.'text.lib.php';
  77. require_once $libraryPath.'array.lib.php';
  78. require_once $libraryPath.'online.inc.php';
  79. require_once $libraryPath.'banner.lib.php';
  80. require_once $libraryPath.'fileManage.lib.php';
  81. require_once $libraryPath.'fileUpload.lib.php';
  82. require_once $libraryPath.'fileDisplay.lib.php';
  83. require_once $libraryPath.'course_category.lib.php';
  84. if (!is_dir(_MPDF_TEMP_PATH)) {
  85. mkdir(_MPDF_TEMP_PATH, api_get_permissions_for_new_directories(), true);
  86. }
  87. // Connect to the server database and select the main chamilo database.
  88. // When $_configuration['db_persistent_connection'] is set, it is expected to be a boolean type.
  89. /*$dbPersistConnection = api_get_configuration_value('db_persistent_connection');
  90. // $_configuration['db_client_flags'] can be set in configuration.php to pass
  91. // flags to the DB connection
  92. $dbFlags = api_get_configuration_value('db_client_flags');
  93. $params = array(
  94. 'server' => $_configuration['db_host'],
  95. 'username' => $_configuration['db_user'],
  96. 'password' => $_configuration['db_password'],
  97. 'persistent' => $dbPersistConnection,
  98. 'client_flags' => $dbFlags,
  99. );*/
  100. // Doctrine ORM configuration
  101. $dbParams = array(
  102. 'driver' => 'pdo_mysql',
  103. 'host' => $_configuration['db_host'],
  104. 'user' => $_configuration['db_user'],
  105. 'password' => $_configuration['db_password'],
  106. 'dbname' => $_configuration['main_database'],
  107. // Only relevant for pdo_sqlite, specifies the path to the SQLite database.
  108. 'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
  109. // Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
  110. 'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : ''
  111. );
  112. try {
  113. $database = new \Database();
  114. $database->connect($dbParams);
  115. } catch (Exception $e) {
  116. $global_error_code = 3;
  117. // The database server is not available or credentials are invalid.
  118. require $includePath.'/global_error_message.inc.php';
  119. die();
  120. }
  121. /* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
  122. if (!empty($_configuration['multiple_access_urls'])) {
  123. $_configuration['access_url'] = 1;
  124. $access_urls = api_get_access_urls();
  125. $root_rel = api_get_self();
  126. $root_rel = substr($root_rel, 1);
  127. $pos = strpos($root_rel, '/');
  128. $root_rel = substr($root_rel, 0, $pos);
  129. $protocol = 'http://';
  130. if (!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') {
  131. $protocol = 'https://';
  132. } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
  133. $protocol = 'https://';
  134. }
  135. //urls with subdomains (HTTP_HOST is preferred - see #6764)
  136. $request_url_root = '';
  137. if (empty($_SERVER['HTTP_HOST'])) {
  138. if (empty($_SERVER['SERVER_NAME'])) {
  139. $request_url_root = $protocol.'localhost/';
  140. } else {
  141. $request_url_root = $protocol.$_SERVER['SERVER_NAME'].'/';
  142. }
  143. } else {
  144. $request_url_root = $protocol.$_SERVER['HTTP_HOST'].'/';
  145. }
  146. //urls with subdirs
  147. $request_url_sub = $request_url_root.$root_rel.'/';
  148. // You can use subdirs as multi-urls, but in this case none of them can be
  149. // the root dir. The admin portal should be something like https://host/adm/
  150. // At this time, subdirs will still hold a share cookie, so not ideal yet
  151. // see #6510
  152. foreach ($access_urls as $details) {
  153. if ($request_url_sub == $details['url']) {
  154. $_configuration['access_url'] = $details['id'];
  155. break; //found one match with subdir, get out of foreach
  156. }
  157. // Didn't find any? Now try without subdirs
  158. if ($request_url_root == $details['url']) {
  159. $_configuration['access_url'] = $details['id'];
  160. break; //found one match, get out of foreach
  161. }
  162. }
  163. } else {
  164. $_configuration['access_url'] = 1;
  165. }
  166. // Check if APCu is available. If so, store the value in $_configuration
  167. if (extension_loaded('apcu')) {
  168. $apcEnabled = ini_get('apc.enabled');
  169. if (!empty($apcEnabled) && $apcEnabled != 'Off' && $apcEnabled != 'off') {
  170. $_configuration['apc'] = true;
  171. $_configuration['apc_prefix'] = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
  172. }
  173. }
  174. $charset = 'UTF-8';
  175. // Enables the portability layer and configures PHP for UTF-8
  176. \Patchwork\Utf8\Bootup::initAll();
  177. // Start session after the internationalization library has been initialized.
  178. ChamiloSession::start($alreadyInstalled);
  179. // access_url == 1 is the default chamilo location
  180. if ($_configuration['access_url'] != 1) {
  181. $url_info = api_get_access_url($_configuration['access_url']);
  182. if ($url_info['active'] == 1) {
  183. $settings_by_access = & api_get_settings(null, 'list', $_configuration['access_url'], 1);
  184. foreach ($settings_by_access as & $row) {
  185. if (empty($row['variable'])) {
  186. $row['variable'] = 0;
  187. }
  188. if (empty($row['subkey'])) {
  189. $row['subkey'] = 0;
  190. }
  191. if (empty($row['category'])) {
  192. $row['category'] = 0;
  193. }
  194. $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
  195. }
  196. }
  197. }
  198. $result = & api_get_settings(null, 'list', 1);
  199. foreach ($result as & $row) {
  200. if ($_configuration['access_url'] != 1) {
  201. if ($url_info['active'] == 1) {
  202. $var = empty($row['variable']) ? 0 : $row['variable'];
  203. $subkey = empty($row['subkey']) ? 0 : $row['subkey'];
  204. $category = empty($row['category']) ? 0 : $row['category'];
  205. }
  206. if ($row['access_url_changeable'] == 1 && $url_info['active'] == 1) {
  207. if (isset($settings_by_access_list[$var]) &&
  208. isset($settings_by_access_list[$var][$subkey]) &&
  209. $settings_by_access_list[$var][$subkey][$category]['selected_value'] != '') {
  210. if ($row['subkey'] == null) {
  211. $_setting[$row['variable']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
  212. } else {
  213. $_setting[$row['variable']][$row['subkey']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
  214. }
  215. } else {
  216. if ($row['subkey'] == null) {
  217. $_setting[$row['variable']] = $row['selected_value'];
  218. } else {
  219. $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
  220. }
  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. }
  237. $result = & api_get_settings('Plugins', 'list', $_configuration['access_url']);
  238. $_plugins = array();
  239. foreach ($result as & $row) {
  240. $key = & $row['variable'];
  241. if (isset($_setting[$key]) && is_string($_setting[$key])) {
  242. $_setting[$key] = array();
  243. }
  244. $_setting[$key][] = $row['selected_value'];
  245. $_plugins[$key][] = $row['selected_value'];
  246. }
  247. // Error reporting settings.
  248. if (api_get_setting('server_type') == 'test') {
  249. ini_set('display_errors', '1');
  250. ini_set('log_errors', '1');
  251. ini_set('html_errors', '1');
  252. error_reporting(-1);
  253. if (function_exists('opcache_reset')) {
  254. opcache_reset();
  255. }
  256. } else {
  257. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  258. }
  259. // Load allowed tag definitions for kses and/or HTMLPurifier.
  260. require_once $libraryPath.'formvalidator/Rule/allowed_tags.inc.php';
  261. // Before we call local.inc.php, let's define a global $this_section variable
  262. // which will then be usable from the banner and header scripts
  263. $this_section = SECTION_GLOBAL;
  264. // Include Chamilo Mail conf this is added here because the api_get_setting works
  265. // Fixes bug in Chamilo 1.8.7.1 array was not set
  266. $administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com';
  267. $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';
  268. // Including configuration files
  269. $configurationFiles = array(
  270. 'mail.conf.php',
  271. 'profile.conf.php',
  272. 'course_info.conf.php',
  273. 'add_course.conf.php',
  274. 'events.conf.php',
  275. 'auth.conf.php',
  276. 'portfolio.conf.php'
  277. );
  278. foreach ($configurationFiles as $file) {
  279. $file = api_get_path(CONFIGURATION_PATH).$file;
  280. if (file_exists($file)) {
  281. require_once $file;
  282. }
  283. }
  284. /* LOAD LANGUAGE FILES SECTION */
  285. // if we use the javascript version (without go button) we receive a get
  286. // if we use the non-javascript version (with the go button) we receive a post
  287. $user_language = '';
  288. $browser_language = '';
  289. // see #8149
  290. if (!empty($_SESSION['user_language_choice'])) {
  291. $user_language = $_SESSION['user_language_choice'];
  292. }
  293. if (!empty($_GET['language'])) {
  294. $user_language = $_GET['language'];
  295. }
  296. if (!empty($_POST['language_list'])) {
  297. $user_language = str_replace('index.php?language=', '', $_POST['language_list']);
  298. }
  299. if (empty($user_language) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !isset($_SESSION['_user'])) {
  300. $l = SubLanguageManager::getLanguageFromBrowserPreference($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  301. if (!empty($l)) {
  302. $user_language = $browser_language = $l;
  303. }
  304. }
  305. // Include all files (first english and then current interface language)
  306. $langpath = api_get_path(SYS_LANG_PATH);
  307. /* This will only work if we are in the page to edit a sub_language */
  308. if (isset($this_script) && $this_script == 'sub_language') {
  309. // getting the arrays of files i.e notification, trad4all, etc
  310. $language_files_to_load = SubLanguageManager:: get_lang_folder_files_list(
  311. api_get_path(SYS_LANG_PATH).'english',
  312. true
  313. );
  314. //getting parent info
  315. $parent_language = SubLanguageManager::get_all_information_of_language($_REQUEST['id']);
  316. //getting sub language info
  317. $sub_language = SubLanguageManager::get_all_information_of_language($_REQUEST['sub_language_id']);
  318. $english_language_array = $parent_language_array = $sub_language_array = array();
  319. foreach ($language_files_to_load as $language_file_item) {
  320. $lang_list_pre = array_keys($GLOBALS);
  321. //loading english
  322. $path = $langpath.'english/'.$language_file_item.'.inc.php';
  323. if (file_exists($path)) {
  324. include $path;
  325. }
  326. $lang_list_post = array_keys($GLOBALS);
  327. $lang_list_result = array_diff($lang_list_post, $lang_list_pre);
  328. unset($lang_list_pre);
  329. // english language array
  330. $english_language_array[$language_file_item] = compact($lang_list_result);
  331. //cleaning the variables
  332. foreach ($lang_list_result as $item) {
  333. unset(${$item});
  334. }
  335. $parent_file = $langpath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  336. if (file_exists($parent_file) && is_file($parent_file)) {
  337. include_once $parent_file;
  338. }
  339. // parent language array
  340. $parent_language_array[$language_file_item] = compact($lang_list_result);
  341. //cleaning the variables
  342. foreach ($lang_list_result as $item) {
  343. unset(${$item});
  344. }
  345. $sub_file = $langpath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  346. if (file_exists($sub_file) && is_file($sub_file)) {
  347. include $sub_file;
  348. }
  349. // sub language array
  350. $sub_language_array[$language_file_item] = compact($lang_list_result);
  351. //cleaning the variables
  352. foreach ($lang_list_result as $item) {
  353. unset(${$item});
  354. }
  355. }
  356. }
  357. // Checking if we have a valid language. If not we set it to the platform language.
  358. $valid_languages = api_get_languages();
  359. if (!empty($valid_languages)) {
  360. if (!in_array($user_language, $valid_languages['folder'])) {
  361. $user_language = api_get_setting('platformLanguage');
  362. }
  363. $language_priority1 = api_get_setting('languagePriority1');
  364. $language_priority2 = api_get_setting('languagePriority2');
  365. $language_priority3 = api_get_setting('languagePriority3');
  366. $language_priority4 = api_get_setting('languagePriority4');
  367. if (isset($_GET['language']) ||
  368. (isset($_POST['language_list']) && !empty($_POST['language_list'])) ||
  369. !empty($browser_language)
  370. ) {
  371. $user_selected_language = $user_language; // $_GET['language']; or HTTP_ACCEPT_LANGUAGE
  372. $_SESSION['user_language_choice'] = $user_selected_language;
  373. $platformLanguage = $user_selected_language;
  374. }
  375. if (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false) {
  376. $language_interface = api_get_language_from_type($language_priority4);
  377. } else {
  378. $language_interface = api_get_setting('platformLanguage');
  379. }
  380. if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false) {
  381. $language_interface = api_get_language_from_type($language_priority3);
  382. } else {
  383. if (isset($_SESSION['user_language_choice'])) {
  384. $language_interface = $_SESSION['user_language_choice'];
  385. }
  386. }
  387. if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false) {
  388. $language_interface = api_get_language_from_type($language_priority2);
  389. } else {
  390. if (isset($_user['language'])) {
  391. $language_interface = $_user['language'];
  392. }
  393. }
  394. if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false) {
  395. $language_interface = api_get_language_from_type($language_priority1);
  396. } else {
  397. if (isset($_course['language'])) {
  398. $language_interface = $_course['language'];
  399. }
  400. }
  401. // If language is set via browser ignore the priority
  402. if (isset($_GET['language'])) {
  403. $language_interface = $user_language;
  404. }
  405. $allow = api_get_configuration_value('show_language_selector_in_menu');
  406. // Overwrite all lang configs and use the menu language
  407. if ($allow) {
  408. if (isset($_SESSION['user_language_choice'])) {
  409. $userEntity = api_get_user_entity(api_get_user_id());
  410. if ($userEntity) {
  411. if (isset($_GET['language'])) {
  412. $language_interface = $_SESSION['user_language_choice'];
  413. $userEntity->setLanguage($language_interface);
  414. Database::getManager()->merge($userEntity);
  415. Database::getManager()->flush();
  416. // Update cache
  417. api_get_user_info(
  418. api_get_user_id(),
  419. true,
  420. false,
  421. true,
  422. false,
  423. true,
  424. true
  425. );
  426. if (isset($_SESSION['_user'])) {
  427. $_SESSION['_user']['language'] = $language_interface;
  428. }
  429. }
  430. $language_interface = $_SESSION['user_language_choice'] = $userEntity->getLanguage();
  431. }
  432. } else {
  433. $userInfo = api_get_user_info();
  434. if (!empty($userInfo['language'])) {
  435. $_SESSION['user_language_choice'] = $userInfo['language'];
  436. $language_interface = $userInfo['language'];
  437. }
  438. }
  439. }
  440. }
  441. // Sometimes the variable $language_interface is changed
  442. // temporarily for achieving translation in different language.
  443. // We need to save the genuine value of this variable and
  444. // to use it within the function get_lang(...).
  445. $language_interface_initial_value = $language_interface;
  446. /**
  447. * Include the trad4all language file
  448. */
  449. // if the sub-language feature is on
  450. $parent_path = SubLanguageManager::get_parent_language_path($language_interface);
  451. if (!empty($parent_path)) {
  452. // include English
  453. include $langpath.'english/trad4all.inc.php';
  454. // prepare string for current language and its parent
  455. $lang_file = $langpath.$language_interface.'/trad4all.inc.php';
  456. $parent_lang_file = $langpath.$parent_path.'/trad4all.inc.php';
  457. // load the parent language file first
  458. if (file_exists($parent_lang_file)) {
  459. include $parent_lang_file;
  460. }
  461. // overwrite the parent language translations if there is a child
  462. if (file_exists($lang_file)) {
  463. include $lang_file;
  464. }
  465. } else {
  466. // if the sub-languages feature is not on, then just load the
  467. // set language interface
  468. // include English
  469. include $langpath.'english/trad4all.inc.php';
  470. // prepare string for current language
  471. $langfile = $langpath.$language_interface.'/trad4all.inc.php';
  472. if (file_exists($langfile)) {
  473. include $langfile;
  474. }
  475. }
  476. // include the local (contextual) parameters of this course or section
  477. require $includePath.'/local.inc.php';
  478. // The global variable $text_dir has been defined in the language file trad4all.inc.php.
  479. // For determining text direction correspondent to the current language
  480. // we use now information from the internationalization library.
  481. $text_dir = api_get_text_direction();
  482. // ===== "who is logged in?" module section =====
  483. // check and modify the date of user in the track.e.online table
  484. if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {
  485. preventMultipleLogin($_user["user_id"]);
  486. LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : '');
  487. }
  488. // ===== end "who is logged in?" module section =====
  489. //Update of the logout_date field in the table track_e_login
  490. // (needed for the calculation of the total connection time)
  491. if (!isset($_SESSION['login_as']) && isset($_user)) {
  492. // if $_SESSION['login_as'] is set, then the user is an admin logged as the user
  493. $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  494. $sql = "SELECT login_id, login_date
  495. FROM $tbl_track_login
  496. WHERE
  497. login_user_id='".$_user["user_id"]."'
  498. ORDER BY login_date DESC
  499. LIMIT 0,1";
  500. $q_last_connection = Database::query($sql);
  501. if (Database::num_rows($q_last_connection) > 0) {
  502. $now = api_get_utc_datetime();
  503. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  504. // is the latest logout_date still relevant?
  505. $sql = "SELECT logout_date FROM $tbl_track_login
  506. WHERE login_id = $i_id_last_connection";
  507. $q_logout_date = Database::query($sql);
  508. $res_logout_date = convert_sql_date(Database::result($q_logout_date, 0, 'logout_date'));
  509. $lifeTime = api_get_configuration_value('session_lifetime');
  510. if ($res_logout_date < time() - $lifeTime) {
  511. // it isn't, we should create a fresh entry
  512. Event::eventLogin($_user['user_id']);
  513. // now that it's created, we can get its ID and carry on
  514. } else {
  515. $sql = "UPDATE $tbl_track_login SET logout_date = '$now'
  516. WHERE login_id = '$i_id_last_connection'";
  517. Database::query($sql);
  518. }
  519. $tableUser = Database::get_main_table(TABLE_MAIN_USER);
  520. $sql = "UPDATE $tableUser SET last_login = '$now'
  521. WHERE user_id = ".$_user["user_id"];
  522. Database::query($sql);
  523. }
  524. }
  525. // Add language_measure_frequency to your main/inc/conf/configuration.php in
  526. // order to generate language variables frequency measurements (you can then
  527. // see them through main/cron/lang/langstats.php)
  528. // The langstat object will then be used in the get_lang() function.
  529. // This block can be removed to speed things up a bit as it should only ever
  530. // be used in development versions.
  531. if (isset($_configuration['language_measure_frequency']) &&
  532. $_configuration['language_measure_frequency'] == 1
  533. ) {
  534. require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
  535. $langstats = new langstats();
  536. }
  537. //Default quota for the course documents folder
  538. $default_quota = api_get_setting('default_document_quotum');
  539. //Just in case the setting is not correctly set
  540. if (empty($default_quota)) {
  541. $default_quota = 100000000;
  542. }
  543. define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
  544. // Forcing PclZip library to use a custom temporary folder.
  545. define('PCLZIP_TEMPORARY_DIR', api_get_path(SYS_ARCHIVE_PATH));