global.inc.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. // Showing/hiding error codes in global error messages.
  23. define('SHOW_ERROR_CODES', false);
  24. // Determine the directory path where this current file lies.
  25. // This path will be useful to include the other initialisation files.
  26. $includePath = __DIR__;
  27. // @todo Isn't this file renamed to configuration.inc.php yet?
  28. // Include the main Chamilo platform configuration file.
  29. $main_configuration_file_path = $includePath.'/conf/configuration.php';
  30. $already_installed = false;
  31. if (file_exists($main_configuration_file_path)) {
  32. require_once $main_configuration_file_path;
  33. $already_installed = true;
  34. } else {
  35. $_configuration = array();
  36. }
  37. //Redirects to the main/install/ page
  38. if (!$already_installed) {
  39. $global_error_code = 2;
  40. // The system has not been installed yet.
  41. require $includePath.'/global_error_message.inc.php';
  42. die();
  43. }
  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. // Code for trnasitional purposes, it can be removed right before the 1.8.7 release.
  50. if (empty($_configuration['system_version'])) {
  51. $_configuration['system_version'] = $_configuration['dokeos_version'];
  52. $_configuration['system_stable'] = $_configuration['dokeos_stable'];
  53. $_configuration['software_url'] = 'http://www.chamilo.org/';
  54. }
  55. // For backward compatibility.
  56. $_configuration['dokeos_version'] = $_configuration['system_version'];
  57. $_configuration['dokeos_stable'] = $_configuration['system_stable'];
  58. $userPasswordCrypted = $_configuration['password_encryption'];
  59. // Include the main Chamilo platform library file.
  60. require_once $includePath.'/lib/api.lib.php';
  61. //Check the PHP version
  62. api_check_php_version($includePath.'/');
  63. // Specification for usernames:
  64. // 1. ASCII-letters, digits, "." (dot), "_" (underscore) are acceptable, 40 characters maximum length.
  65. // 2. Empty username is formally valid, but it is reserved for the anonymous user.
  66. // 3. Checking the login_is_email portal setting in order to accept 100 chars maximum
  67. $default_username_length = 40;
  68. if (api_get_setting('login_is_email') == 'true') {
  69. $default_username_length = 100;
  70. }
  71. define('USERNAME_MAX_LENGTH', $default_username_length);
  72. // Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI'].
  73. api_request_uri();
  74. // Add the path to the pear packages to the include path
  75. ini_set('include_path', api_create_include_path_setting());
  76. // This is for compatibility with MAC computers.
  77. ini_set('auto_detect_line_endings', '1');
  78. // Include the libraries that are necessary everywhere
  79. require_once __DIR__.'/../../vendor/autoload.php';
  80. // Do not over-use this variable. It is only for this script's local use.
  81. $libraryPath = api_get_path(LIBRARY_PATH);
  82. // @todo convert this libs in classes
  83. require_once $libraryPath.'database.constants.inc.php';
  84. require_once $libraryPath.'text.lib.php';
  85. require_once $libraryPath.'array.lib.php';
  86. require_once $libraryPath.'online.inc.php';
  87. require_once $libraryPath.'banner.lib.php';
  88. require_once $libraryPath.'fileManage.lib.php';
  89. require_once $libraryPath.'fileUpload.lib.php';
  90. require_once $libraryPath.'fileDisplay.lib.php';
  91. require_once $libraryPath.'course_category.lib.php';
  92. define('_MPDF_TEMP_PATH', api_get_path(SYS_ARCHIVE_PATH).'mpdf/');
  93. if (!is_dir(_MPDF_TEMP_PATH)) {
  94. mkdir(_MPDF_TEMP_PATH, api_get_permissions_for_new_directories(), true);
  95. }
  96. /* DATABASE CONNECTION */
  97. // @todo: this shouldn't be done here. It should be stored correctly during installation.
  98. if (empty($_configuration['statistics_database']) && $already_installed) {
  99. $_configuration['statistics_database'] = $_configuration['main_database'];
  100. }
  101. global $database_connection;
  102. // Connect to the server database and select the main chamilo database.
  103. // When $_configuration['db_persistent_connection'] is set, it is expected to be a boolean type.
  104. $dbPersistConnection = api_get_configuration_value('db_persistent_connection');
  105. // $_configuration['db_client_flags'] can be set in configuration.php to pass
  106. // flags to the DB connection
  107. $dbFlags = api_get_configuration_value('db_client_flags');
  108. $params = array(
  109. 'server' => $_configuration['db_host'],
  110. 'username' => $_configuration['db_user'],
  111. 'password' => $_configuration['db_password'],
  112. 'persistent' => $dbPersistConnection,
  113. 'client_flags' => $dbFlags,
  114. );
  115. if (!$_configuration['db_host']) {
  116. $global_error_code = 4;
  117. // A configuration option about database server is missing.
  118. require $includePath.'/global_error_message.inc.php';
  119. die();
  120. }
  121. if (!($conn_return = @Database::connect($params))) {
  122. $global_error_code = 3;
  123. // The database server is not available or credentials are invalid.
  124. require $includePath.'/global_error_message.inc.php';
  125. die();
  126. }
  127. // Doctrine ORM configuration
  128. use Doctrine\ORM\Tools\Setup;
  129. use Doctrine\ORM\EntityManager;
  130. // the connection configuration
  131. $dbParams = array(
  132. 'driver' => 'pdo_mysql',
  133. 'host' => $_configuration['db_host'],
  134. 'user' => $_configuration['db_user'],
  135. 'password' => $_configuration['db_password'],
  136. 'dbname' => $_configuration['main_database'],
  137. );
  138. $config = Database::getDoctrineConfig();
  139. $config->setEntityNamespaces(
  140. array(
  141. 'ChamiloUserBundle' => 'Chamilo\UserBundle\Entity',
  142. 'ChamiloCoreBundle' => 'Chamilo\CoreBundle\Entity',
  143. 'ChamiloCourseBundle' => 'Chamilo\CourseBundle\Entity'
  144. )
  145. );
  146. $entityManager = EntityManager::create($dbParams, $config);
  147. // Registering Constraints
  148. use Doctrine\Common\Annotations\AnnotationRegistry;
  149. AnnotationRegistry::registerAutoloadNamespace(
  150. 'Symfony\Component\Validator\Constraint',
  151. api_get_path(SYS_PATH)."vendor/symfony/validator"
  152. );
  153. AnnotationRegistry::registerFile(
  154. api_get_path(SYS_PATH)."vendor/symfony/doctrine-bridge/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php"
  155. );
  156. // Registering gedmo extensions
  157. AnnotationRegistry::registerAutoloadNamespace(
  158. 'Gedmo\Mapping\Annotation',
  159. api_get_path(SYS_PATH)."vendor/gedmo/doctrine-extensions/lib"
  160. );
  161. /*$repo = $entityManager->getRepository('ChamiloCoreBundle:Session');
  162. $repo = $entityManager->getRepository('ChamiloUserBundle:User');
  163. $repo = $entityManager->getRepository('ChamiloCoreBundle:Course');*/
  164. /*try {
  165. $connect = $entityManager->getConnection()->connect();
  166. } catch (Exception $e) {
  167. $global_error_code = 3;
  168. // The database server is not available or credentials are invalid.
  169. require $includePath.'/global_error_message.inc.php';
  170. die();
  171. }*/
  172. $database = new \Database();
  173. $database->setManager($entityManager);
  174. /* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
  175. if (!empty($_configuration['multiple_access_urls'])) {
  176. $_configuration['access_url'] = 1;
  177. $access_urls = api_get_access_urls();
  178. $root_rel = api_get_self();
  179. $root_rel = substr($root_rel, 1);
  180. $pos = strpos($root_rel, '/');
  181. $root_rel = substr($root_rel, 0, $pos);
  182. $protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
  183. //urls with subdomains (HTTP_HOST is preferred - see #6764)
  184. $request_url_root = '';
  185. if (empty($_SERVER['HTTP_HOST'])) {
  186. if (empty($_SERVER['SERVER_NAME'])) {
  187. $request_url_root = $protocol . 'localhost/';
  188. } else {
  189. $request_url_root = $protocol . $_SERVER['SERVER_NAME'] . '/';
  190. }
  191. } else {
  192. $request_url_root = $protocol.$_SERVER['HTTP_HOST'].'/';
  193. }
  194. //urls with subdirs
  195. $request_url_sub = $request_url_root.$root_rel.'/';
  196. // You can use subdirs as multi-urls, but in this case none of them can be
  197. // the root dir. The admin portal should be something like https://host/adm/
  198. // At this time, subdirs will still hold a share cookie, so not ideal yet
  199. // see #6510
  200. foreach ($access_urls as $details) {
  201. if ($request_url_sub == $details['url']) {
  202. $_configuration['access_url'] = $details['id'];
  203. break; //found one match with subdir, get out of foreach
  204. }
  205. // Didn't find any? Now try without subdirs
  206. if ($request_url_root == $details['url']) {
  207. $_configuration['access_url'] = $details['id'];
  208. break; //found one match, get out of foreach
  209. }
  210. }
  211. } else {
  212. $_configuration['access_url'] = 1;
  213. }
  214. // The system has not been designed to use special SQL modes that were introduced since MySQL 5.
  215. Database::query("set session sql_mode='';");
  216. /*if (!Database::select_db($_configuration['main_database'], $database_connection)) {
  217. $global_error_code = 5;
  218. // Connection to the main Chamilo database is impossible, it might be missing or restricted or its configuration option might be incorrect.
  219. require $includePath.'/global_error_message.inc.php';
  220. die();
  221. }*/
  222. /* Initialization of the default encodings */
  223. // The platform's character set must be retrieved at this early moment.
  224. $sql = "SELECT selected_value FROM settings_current WHERE variable = 'platform_charset';";
  225. $result = Database::query($sql);
  226. while ($row = Database::fetch_array($result)) {
  227. $charset = $row[0];
  228. }
  229. if (empty($charset)) {
  230. $charset = 'UTF-8';
  231. }
  232. // Preserving the value of the global variable $charset.
  233. $charset_initial_value = $charset;
  234. // Initialization of the internationalization library.
  235. api_initialize_internationalization();
  236. // Initialization of the default encoding that will be used by the multibyte string routines in the internationalization library.
  237. api_set_internationalization_default_encoding($charset);
  238. // Initialization of the database encoding to be used.
  239. Database::query("SET SESSION character_set_server='utf8';");
  240. Database::query("SET SESSION collation_server='utf8_general_ci';");
  241. if (api_is_utf8($charset)) {
  242. // 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.
  243. Database::query("SET NAMES 'utf8';");
  244. } else {
  245. Database::query("SET CHARACTER SET '" . Database::to_db_encoding($charset) . "';");
  246. }
  247. // Start session after the internationalization library has been initialized.
  248. Chamilo::session()->start($already_installed);
  249. // Remove quotes added by PHP - get_magic_quotes_gpc() is deprecated in PHP 5 see #2970
  250. if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
  251. array_walk_recursive_limited($_GET, 'stripslashes', true);
  252. array_walk_recursive_limited($_POST, 'stripslashes', true);
  253. array_walk_recursive_limited($_COOKIE, 'stripslashes', true);
  254. array_walk_recursive_limited($_REQUEST, 'stripslashes', true);
  255. }
  256. // access_url == 1 is the default chamilo location
  257. if ($_configuration['access_url'] != 1) {
  258. $url_info = api_get_access_url($_configuration['access_url']);
  259. if ($url_info['active'] == 1) {
  260. $settings_by_access = & api_get_settings(null, 'list', $_configuration['access_url'], 1);
  261. foreach ($settings_by_access as & $row) {
  262. if (empty($row['variable'])) {
  263. $row['variable'] = 0;
  264. }
  265. if (empty($row['subkey'])) {
  266. $row['subkey'] = 0;
  267. }
  268. if (empty($row['category'])) {
  269. $row['category'] = 0;
  270. }
  271. $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
  272. }
  273. }
  274. }
  275. $result = & api_get_settings(null, 'list', 1);
  276. foreach ($result as & $row) {
  277. if ($_configuration['access_url'] != 1) {
  278. if ($url_info['active'] == 1) {
  279. $var = empty($row['variable']) ? 0 : $row['variable'];
  280. $subkey = empty($row['subkey']) ? 0 : $row['subkey'];
  281. $category = empty($row['category']) ? 0 : $row['category'];
  282. }
  283. if ($row['access_url_changeable'] == 1 && $url_info['active'] == 1) {
  284. if (isset($settings_by_access_list[$var]) &&
  285. $settings_by_access_list[$var][$subkey][$category]['selected_value'] != '') {
  286. if ($row['subkey'] == null) {
  287. $_setting[$row['variable']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
  288. } else {
  289. $_setting[$row['variable']][$row['subkey']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
  290. }
  291. } else {
  292. if ($row['subkey'] == null) {
  293. $_setting[$row['variable']] = $row['selected_value'];
  294. } else {
  295. $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
  296. }
  297. }
  298. } else {
  299. if ($row['subkey'] == null) {
  300. $_setting[$row['variable']] = $row['selected_value'];
  301. } else {
  302. $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
  303. }
  304. }
  305. } else {
  306. if ($row['subkey'] == null) {
  307. $_setting[$row['variable']] = $row['selected_value'];
  308. } else {
  309. $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
  310. }
  311. }
  312. }
  313. $result = & api_get_settings('Plugins', 'list', $_configuration['access_url']);
  314. $_plugins = array();
  315. foreach ($result as & $row) {
  316. $key = & $row['variable'];
  317. if (is_string($_setting[$key])) {
  318. $_setting[$key] = array();
  319. }
  320. $_setting[$key][] = $row['selected_value'];
  321. $_plugins[$key][] = $row['selected_value'];
  322. }
  323. // Load allowed tag definitions for kses and/or HTMLPurifier.
  324. require_once $libraryPath.'formvalidator/Rule/allowed_tags.inc.php';
  325. // Before we call local.inc.php, let's define a global $this_section variable
  326. // which will then be usable from the banner and header scripts
  327. $this_section = SECTION_GLOBAL;
  328. // include the local (contextual) parameters of this course or section
  329. require $includePath.'/local.inc.php';
  330. //Include Chamilo Mail conf this is added here because the api_get_setting works
  331. //Fixes bug in Chamilo 1.8.7.1 array was not set
  332. $administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com';
  333. $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';
  334. // Including configuration files
  335. $configurationFiles = array(
  336. 'mail.conf.php',
  337. 'profile.conf.php',
  338. 'course_info.conf.php',
  339. 'add_course.conf.php',
  340. 'events.conf.php',
  341. 'auth.conf.php',
  342. 'portfolio.conf.php'
  343. );
  344. foreach ($configurationFiles as $file) {
  345. $file = api_get_path(CONFIGURATION_PATH).$file;
  346. if (file_exists($file)) {
  347. require_once $file;
  348. }
  349. }
  350. if (api_get_setting('server_type') == 'test') {
  351. ini_set('display_errors', '1');
  352. ini_set('log_errors', '1');
  353. error_reporting(-1);
  354. } else {
  355. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  356. }
  357. /* LOAD LANGUAGE FILES SECTION */
  358. // if we use the javascript version (without go button) we receive a get
  359. // if we use the non-javascript version (with the go button) we receive a post
  360. $user_language = '';
  361. $browser_language = '';
  362. if (!empty($_GET['language'])) {
  363. $user_language = $_GET['language'];
  364. }
  365. if (!empty($_POST['language_list'])) {
  366. $user_language = str_replace('index.php?language=', '', $_POST['language_list']);
  367. }
  368. if (empty($user_language) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !isset($_SESSION['_user'])) {
  369. $l = SubLanguageManager::getLanguageFromBrowserPreference($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  370. if (!empty($l)) {
  371. $user_language = $browser_language = $l;
  372. }
  373. }
  374. // Include all files (first english and then current interface language)
  375. $langpath = api_get_path(SYS_LANG_PATH);
  376. /* This will only work if we are in the page to edit a sub_language */
  377. if (isset($this_script) && $this_script == 'sub_language') {
  378. // getting the arrays of files i.e notification, trad4all, etc
  379. $language_files_to_load = SubLanguageManager:: get_lang_folder_files_list(api_get_path(SYS_LANG_PATH).'english', true);
  380. //getting parent info
  381. $parent_language = SubLanguageManager::get_all_information_of_language($_REQUEST['id']);
  382. //getting sub language info
  383. $sub_language = SubLanguageManager::get_all_information_of_language($_REQUEST['sub_language_id']);
  384. $english_language_array = $parent_language_array = $sub_language_array = array();
  385. foreach ($language_files_to_load as $language_file_item) {
  386. $lang_list_pre = array_keys($GLOBALS);
  387. //loading english
  388. $path = $langpath.'english/'.$language_file_item.'.inc.php';
  389. if (file_exists($path)) {
  390. include $path;
  391. }
  392. $lang_list_post = array_keys($GLOBALS);
  393. $lang_list_result = array_diff($lang_list_post, $lang_list_pre);
  394. unset($lang_list_pre);
  395. // english language array
  396. $english_language_array[$language_file_item] = compact($lang_list_result);
  397. //cleaning the variables
  398. foreach ($lang_list_result as $item) {
  399. unset(${$item});
  400. }
  401. $parent_file = $langpath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  402. if (file_exists($parent_file) && is_file($parent_file)) {
  403. include_once $parent_file;
  404. }
  405. // parent language array
  406. $parent_language_array[$language_file_item] = compact($lang_list_result);
  407. //cleaning the variables
  408. foreach ($lang_list_result as $item) {
  409. unset(${$item});
  410. }
  411. $sub_file = $langpath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  412. if (file_exists($sub_file) && is_file($sub_file)) {
  413. include $sub_file;
  414. }
  415. // sub language array
  416. $sub_language_array[$language_file_item] = compact($lang_list_result);
  417. //cleaning the variables
  418. foreach ($lang_list_result as $item) {
  419. unset(${$item});
  420. }
  421. }
  422. }
  423. // Checking if we have a valid language. If not we set it to the platform language.
  424. $valid_languages = api_get_languages();
  425. if (!empty($valid_languages)) {
  426. if (!in_array($user_language, $valid_languages['folder'])) {
  427. $user_language = api_get_setting('platformLanguage');
  428. }
  429. $language_priority1 = api_get_setting('languagePriority1');
  430. $language_priority2 = api_get_setting('languagePriority2');
  431. $language_priority3 = api_get_setting('languagePriority3');
  432. $language_priority4 = api_get_setting('languagePriority4');
  433. if (in_array($user_language, $valid_languages['folder']) &&
  434. (isset($_GET['language']) || isset($_POST['language_list']) || !empty($browser_language))
  435. ) {
  436. $user_selected_language = $user_language; // $_GET['language']; or HTTP_ACCEPT_LANGUAGE
  437. $_SESSION['user_language_choice'] = $user_selected_language;
  438. $platformLanguage = $user_selected_language;
  439. }
  440. if (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false) {
  441. $language_interface = api_get_language_from_type($language_priority4);
  442. } else {
  443. $language_interface = api_get_setting('platformLanguage');
  444. }
  445. if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false) {
  446. $language_interface = api_get_language_from_type($language_priority3);
  447. } else {
  448. if (isset($_SESSION['user_language_choice'])) {
  449. $language_interface = $_SESSION['user_language_choice'];
  450. }
  451. }
  452. if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false) {
  453. $language_interface = api_get_language_from_type($language_priority2);
  454. } else {
  455. if (isset($_user['language'])) {
  456. $language_interface = $_user['language'];
  457. }
  458. }
  459. if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false) {
  460. $language_interface = api_get_language_from_type($language_priority1);
  461. } else {
  462. if (isset($_course['language'])) {
  463. $language_interface = $_course['language'];
  464. }
  465. }
  466. }
  467. // Sometimes the variable $language_interface is changed
  468. // temporarily for achieving translation in different language.
  469. // We need to save the genuine value of this variable and
  470. // to use it within the function get_lang(...).
  471. $language_interface_initial_value = $language_interface;
  472. /**
  473. * Include all necessary language files
  474. * - trad4all
  475. * - notification
  476. * - custom tool language files
  477. */
  478. $language_files = array();
  479. $language_files[] = 'trad4all';
  480. if (isset($language_file)) {
  481. if (!is_array($language_file)) {
  482. $language_files[] = $language_file;
  483. } else {
  484. $language_files = array_merge($language_files, $language_file);
  485. }
  486. }
  487. // if a set of language files has been properly defined
  488. if (is_array($language_files)) {
  489. // if the sub-language feature is on
  490. if (api_get_setting('allow_use_sub_language') == 'true') {
  491. $parent_path = SubLanguageManager::get_parent_language_path($language_interface);
  492. foreach ($language_files as $index => $language_file) {
  493. // include English
  494. include $langpath.'english/'.$language_file.'.inc.php';
  495. // prepare string for current language and its parent
  496. $lang_file = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  497. $parent_lang_file = $langpath.$parent_path.'/'.$language_file.'.inc.php';
  498. // load the parent language file first
  499. if (file_exists($parent_lang_file)) {
  500. include $parent_lang_file;
  501. }
  502. // overwrite the parent language translations if there is a child
  503. if (file_exists($lang_file)) {
  504. include $lang_file;
  505. }
  506. }
  507. } else {
  508. // if the sub-languages feature is not on, then just load the
  509. // set language interface
  510. foreach ($language_files as $index => $language_file) {
  511. // include English
  512. include $langpath.'english/'.$language_file.'.inc.php';
  513. // prepare string for current language
  514. $langfile = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  515. if (file_exists($langfile)) {
  516. include $langfile;
  517. }
  518. }
  519. }
  520. }
  521. // The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation.
  522. // So, we have to reassign this variable again in order to keep its value right.
  523. $charset = $charset_initial_value;
  524. // The global variable $text_dir has been defined in the language file trad4all.inc.php.
  525. // For determing text direction correspondent to the current language we use now information from the internationalization library.
  526. $text_dir = api_get_text_direction();
  527. // ===== "who is logged in?" module section =====
  528. // check and modify the date of user in the track.e.online table
  529. if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {
  530. preventMultipleLogin($_user["user_id"]);
  531. LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : '');
  532. }
  533. // ===== end "who is logged in?" module section =====
  534. //Update of the logout_date field in the table track_e_login (needed for the calculation of the total connection time)
  535. if (!isset($_SESSION['login_as']) && isset($_user)) {
  536. // if $_SESSION['login_as'] is set, then the user is an admin logged as the user
  537. $tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  538. $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login
  539. WHERE login_user_id='".$_user["user_id"]."' ORDER BY login_date DESC LIMIT 0,1";
  540. $q_last_connection = Database::query($sql_last_connection);
  541. if (Database::num_rows($q_last_connection) > 0) {
  542. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  543. // is the latest logout_date still relevant?
  544. $sql_logout_date = "SELECT logout_date FROM $tbl_track_login WHERE login_id=$i_id_last_connection";
  545. $q_logout_date = Database::query($sql_logout_date);
  546. $res_logout_date = convert_sql_date(Database::result($q_logout_date, 0, 'logout_date'));
  547. if ($res_logout_date < time() - $_configuration['session_lifetime']) {
  548. // it isn't, we should create a fresh entry
  549. Event::event_login();
  550. // now that it's created, we can get its ID and carry on
  551. $q_last_connection = Database::query($sql_last_connection);
  552. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  553. }
  554. $now = api_get_utc_datetime(time());
  555. $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date='$now' WHERE login_id='$i_id_last_connection'";
  556. Database::query($s_sql_update_logout_date);
  557. // Saves the last login in the user table see BT#7297
  558. if (isset($_configuration['save_user_last_login']) &&
  559. $_configuration['save_user_last_login']
  560. ) {
  561. $tableUser = Database::get_main_table(TABLE_MAIN_USER);
  562. $sql = "UPDATE $tableUser SET last_login ='$now' WHERE user_id = ".$_user["user_id"];
  563. Database::query($sql);
  564. }
  565. }
  566. }
  567. // Add language_measure_frequency to your main/inc/conf/configuration.php in
  568. // order to generate language variables frequency measurements (you can then
  569. // see them through main/cron/lang/langstats.php)
  570. // The langstat object will then be used in the get_lang() function.
  571. // This block can be removed to speed things up a bit as it should only ever
  572. // be used in development versions.
  573. if (isset($_configuration['language_measure_frequency']) && $_configuration['language_measure_frequency'] == 1) {
  574. require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
  575. $langstats = new langstats();
  576. }
  577. //Default quota for the course documents folder
  578. $default_quota = api_get_setting('default_document_quotum');
  579. //Just in case the setting is not correctly set
  580. if (empty($default_quota)) {
  581. $default_quota = 100000000;
  582. }
  583. define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
  584. // Sets the ascii_math plugin see #7134
  585. $_SESSION['ascii_math_loaded'] = false;