global.inc.php 24 KB

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