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