global.inc.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * It is recommended that ALL Chamilo scripts include this important file.
  5. * This script manages
  6. * - http get, post, post_files, session, server-vars extraction into global namespace;
  7. * (which doesn't occur anymore when servertype config setting is set to test,
  8. * and which will disappear completely in Dokeos 1.6.1)
  9. * - include of /conf/configuration.php;
  10. * - include of several libraries: main_api, database, display, text, security;
  11. * - selecting the main database;
  12. * - include of language files.
  13. *
  14. * @package chamilo.include
  15. * @todo isn't configuration.php renamed to configuration.inc.php yet?
  16. * @todo use the $_configuration array for all the needed variables
  17. * @todo remove the code that displays the button that links to the install page
  18. * but use a redirect immediately. By doing so the $already_installed variable can be removed.
  19. * @todo make it possible to enable / disable the tracking through the Chamilo config page.
  20. *
  21. */
  22. //@todo will be removed before a stable release
  23. //require '/var/www/chamilo11/tests/xhprof/header.php';
  24. $mtime = microtime();
  25. $mtime = explode(" ",$mtime);
  26. $mtime = $mtime[1] + $mtime[0];
  27. $starttime = $mtime;
  28. define('START', $starttime);
  29. // Showing/hiding error codes in global error messages.
  30. define('SHOW_ERROR_CODES', false);
  31. // Determine the directory path where this current file lies.
  32. // This path will be useful to include the other intialisation files.
  33. $includePath = dirname(__FILE__);
  34. // @todo Isn't this file renamed to configuration.inc.php yet?
  35. // Include the main Chamilo platform configuration file.
  36. $main_configuration_file_path = $includePath.'/conf/configuration.php';
  37. $already_installed = false;
  38. if (file_exists($main_configuration_file_path)) {
  39. require_once $main_configuration_file_path;
  40. $already_installed = true;
  41. } else {
  42. $_configuration = array();
  43. }
  44. //Redirects to the main/install/ page
  45. if (!$already_installed) {
  46. $global_error_code = 2;
  47. // The system has not been installed yet.
  48. require $includePath.'/global_error_message.inc.php';
  49. die();
  50. }
  51. // Ensure that _configuration is in the global scope before loading
  52. // main_api.lib.php. This is particularly helpful for unit tests
  53. if (!isset($GLOBALS['_configuration'])) {
  54. $GLOBALS['_configuration'] = $_configuration;
  55. }
  56. // Code for trnasitional purposes, it can be removed right before the 1.8.7 release.
  57. if (empty($_configuration['system_version'])) {
  58. $_configuration['system_version'] = (!empty($_configuration['dokeos_version'])?$_configuration['dokeos_version']:'');
  59. $_configuration['system_stable'] = (!empty($_configuration['dokeos_stable'])?$_configuration['dokeos_stable']:'');
  60. $_configuration['software_url'] = 'http://www.chamilo.org/';
  61. }
  62. // For backward compatibility.
  63. $_configuration['dokeos_version'] = $_configuration['system_version'];
  64. $_configuration['dokeos_stable'] = $_configuration['system_stable'];
  65. $userPasswordCrypted = (!empty($_configuration['password_encryption']) ? $_configuration['password_encryption'] : 'sha1');
  66. // Include the main Chamilo platform library file.
  67. require_once $includePath.'/lib/main_api.lib.php';
  68. // Specification for usernames:
  69. // 1. ASCII-letters, digits, "." (dot), "_" (underscore) are acceptable, 40 characters maximum length.
  70. // 2. Empty username is formally valid, but it is reserved for the anonymous user.
  71. // 3. Checking the login_is_email portal setting in order to accept 100 chars maximum
  72. $default_username_length = 40;
  73. if (api_get_setting('login_is_email') == 'true') {
  74. $default_username_length = 100;
  75. }
  76. define('USERNAME_MAX_LENGTH', $default_username_length);
  77. // Do not over-use this variable. It is only for this script's local use.
  78. $lib_path = api_get_path(LIBRARY_PATH);
  79. // Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI'].
  80. api_request_uri();
  81. // Add the path to the pear packages to the include path
  82. ini_set('include_path', api_create_include_path_setting());
  83. // This is for compatibility with MAC computers.
  84. ini_set('auto_detect_line_endings', '1');
  85. //Include the libraries that are necessary everywhere
  86. //require_once dirname(__FILE__).'/autoload.inc.php';
  87. //Fixes Htmlpurifier autoloader issue with composer
  88. define('HTMLPURIFIER_PREFIX', $lib_path.'htmlpurifier/library');
  89. //mpdf constants
  90. define("_MPDF_TEMP_PATH", api_get_path(SYS_ARCHIVE_PATH));
  91. define('_MPDF_PATH', api_get_path(LIBRARY_PATH).'mpdf/');
  92. //Composer autoloader
  93. require_once __DIR__.'../../../vendor/autoload.php';
  94. //Start Silex
  95. use Silex\Application;
  96. use Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
  97. $app = new Application();
  98. $app['configuration_file'] = $main_configuration_file_path;
  99. //require_once __DIR__.'/../../resources/config/prod.php';
  100. require_once __DIR__.'/../../resources/config/dev.php';
  101. //Setting HttpCacheService provider in order to use do: $app['http_cache']->run();
  102. /*
  103. $app->register(new Silex\Provider\HttpCacheServiceProvider(), array(
  104. 'http_cache.cache_dir' => $app['http_cache.cache_dir'].'/',
  105. ));
  106. */
  107. $app->register(new Silex\Provider\ValidatorServiceProvider());
  108. //URL generator provider
  109. $app->register(new Silex\Provider\UrlGeneratorServiceProvider());
  110. $app->register(new Silex\Provider\TranslationServiceProvider(),array(
  111. 'locale_fallback' => 'en'
  112. ));
  113. //Form provider
  114. $app->register(new Silex\Provider\FormServiceProvider());
  115. //Monolog
  116. $app->register(new Silex\Provider\MonologServiceProvider(), array(
  117. 'monolog.logfile' => api_get_path(SYS_ARCHIVE_PATH).'chamilo_development.log',
  118. 'monolog.name' => 'chamilo',
  119. ));
  120. /*
  121. //Monolog examples
  122. $app['monolog']->addDebug('Testing the Monolog logging.');
  123. $app['monolog']->addInfo('Testing the Monolog logging.');
  124. $app['monolog']->addError('Testing the Monolog logging.');
  125. */
  126. $app['translator.messages'] = array();
  127. //Setting the Twig service provider
  128. $app->register(new Silex\Provider\TwigServiceProvider(), array(
  129. 'twig.path' => array(
  130. api_get_path(SYS_CODE_PATH).'template', //template folder
  131. api_get_path(SYS_PLUGIN_PATH) //plugin folder
  132. ),
  133. 'twig.options' => array(
  134. 'twig.form.templates' => array('form_div_layout.html.twig'),
  135. 'debug' => $app['debug'],
  136. 'charset' => 'utf-8',
  137. 'strict_variables' => false,
  138. 'autoescape' => false,
  139. 'cache' => $app['debug'] ? false : $app['cache.path'].'twig',
  140. 'optimizations' => -1, // turn on optimizations with -1
  141. )
  142. ));
  143. //$app['twig']->addExtension(new Twig_Extension_Debug());
  144. //Setting Twig options
  145. $app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
  146. $twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
  147. $twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
  148. $twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
  149. $twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
  150. $twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
  151. $twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate'));
  152. $twig->addFilter('display_page_subheader', new Twig_Filter_Function('Display::page_subheader_and_translate'));
  153. $twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path'));
  154. $twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
  155. return $twig;
  156. }));
  157. //Setting Doctrine service provider
  158. //Gathering default info of the current installation from the $_configuration array
  159. $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
  160. 'db.options' => array(
  161. 'driver' => 'pdo_mysql',
  162. 'dbname' => $_configuration['main_database'],
  163. 'user' => $_configuration['db_user'],
  164. 'password' => $_configuration['db_password'],
  165. 'host' => $_configuration['db_host'],
  166. )
  167. ));
  168. $app->register(new DoctrineOrmServiceProvider, array(
  169. "orm.proxies_dir" => $app['db.orm.proxies_dir'],
  170. "orm.em.options" => array(
  171. "mappings" => array(
  172. array(
  173. "type" => "annotation",
  174. "namespace" => "Entity",
  175. "path" => api_get_path(INCLUDE_PATH).'Entity',
  176. )
  177. ),
  178. ),
  179. ));
  180. /*
  181. // Register Doctrine ORM
  182. $app->register(new Nutwerk\Provider\DoctrineORMServiceProvider(), array(
  183. 'db.orm.proxies_dir' => $app['db.orm.proxies_dir'],
  184. 'db.orm.proxies_namespace' => 'DoctrineProxy',
  185. 'db.orm.cache' =>
  186. !$app['debug'] && extension_loaded('apc') ? new ApcCache() : new ArrayCache(),
  187. 'db.orm.auto_generate_proxies' => true,
  188. 'db.orm.entities' => array(array(
  189. 'type' => 'annotation', // entity definition
  190. 'path' => api_get_path(INCLUDE_PATH).'Entity',
  191. 'namespace' => 'Entity', // your classes namespace
  192. )),
  193. ));*/
  194. //Creating Chamilo service provider
  195. use Silex\ServiceProviderInterface;
  196. class ChamiloServiceProvider implements ServiceProviderInterface {
  197. public function register(Application $app) {
  198. //Template
  199. $app['template'] = $app->share(function() use($app){
  200. return new Template(null, $app);
  201. });
  202. //Formvalidator
  203. $app['form_validator'] = $app->share(function() use($app){
  204. return new FormValidator();
  205. });
  206. }
  207. public function boot(Application $app) {
  208. }
  209. }
  210. //Registering Chamilo service provider
  211. $app->register(new ChamiloServiceProvider(), array());
  212. //Manage error messages
  213. /*
  214. $app->error(function (\Exception $e, $code) use ($app) {
  215. if ($app['debug']) {
  216. //return;
  217. }
  218. if (isset($code)) {
  219. switch ($code) {
  220. case 404:
  221. $message = 'The requested page could not be found.';
  222. break;
  223. default:
  224. //$message = 'We are sorry, but something went terribly wrong.';
  225. $message = $e->getMessage();
  226. }
  227. } else {
  228. $code = null;
  229. $message = null;
  230. }
  231. //$code = ($e instanceof HttpException) ? $e->getStatusCode() : 500;
  232. $app['template']->assign('error_code', $code);
  233. $app['template']->assign('error_message', $message);
  234. $response = $app['template']->render_layout('error.tpl');
  235. return new Response($response);
  236. });*/
  237. /*
  238. use Symfony\Component\HttpKernel\Debug\ErrorHandler;
  239. ErrorHandler::register();
  240. */
  241. //Filters
  242. $app->before(function() use ($app) {
  243. //Check the PHP version
  244. if (api_check_php_version() == false) {
  245. $app->abort(500, "Incorrect PHP version"); //error 1
  246. }
  247. if (!file_exists($app['configuration_file'])) {
  248. $app->abort(500, "Chamilo has not been installed"); //error 2
  249. }
  250. });
  251. $app->after(function() {
  252. });
  253. $app->finish(function() use ($app) {
  254. //@todo will be removed before a stable release
  255. $mtime = microtime();
  256. $mtime = explode(" ",$mtime);
  257. $mtime = $mtime[1] + $mtime[0];
  258. $message = "Page loaded in:".($mtime-START);
  259. $app['monolog']->addInfo($message);
  260. $message = "memory_get_usage: ".format_file_size(memory_get_usage(true));
  261. $app['monolog']->addInfo($message);
  262. $message = "memory_get_peak_usage: ".format_file_size(memory_get_peak_usage(true));
  263. $app['monolog']->addInfo($message);
  264. });
  265. $app['template.show_header'] = true;
  266. $app['template.show_footer'] = true;
  267. $app['template.show_learnpath'] = true;
  268. $app['template.hide_global_chat'] = true;
  269. $app['template.load_plugins'] = true;
  270. //Default template style
  271. $app['template_style'] = 'default';
  272. $app['default_layout'] = 'layout_1_col.tpl';
  273. //Database constants
  274. require_once $lib_path.'database.constants.inc.php';
  275. require_once $lib_path.'fileManage.lib.php';
  276. require_once $lib_path.'text.lib.php';
  277. require_once $lib_path.'array.lib.php';
  278. require_once $lib_path.'events.lib.inc.php';
  279. require_once $lib_path.'online.inc.php';
  280. /* DATABASE CONNECTION */
  281. // @todo: this shouldn't be done here. It should be stored correctly during installation.
  282. if (empty($_configuration['statistics_database']) && $already_installed) {
  283. $_configuration['statistics_database'] = $_configuration['main_database'];
  284. }
  285. global $database_connection;
  286. // Connect to the server database and select the main chamilo database.
  287. if (!($conn_return = @Database::connect(
  288. array(
  289. 'server' => $_configuration['db_host'],
  290. 'username' => $_configuration['db_user'],
  291. 'password' => $_configuration['db_password'],
  292. 'persistent' => $_configuration['db_persistent_connection'] // When $_configuration['db_persistent_connection'] is set, it is expected to be a boolean type.
  293. )))) {
  294. $app->abort(500, "Database is unavailable"); //error 3
  295. }
  296. if (!$_configuration['db_host']) {
  297. $app->abort(500, "Database is unavailable"); //error 3
  298. }
  299. /* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
  300. if (!empty($_configuration['multiple_access_urls'])) {
  301. $_configuration['access_url'] = 1;
  302. $access_urls = api_get_access_urls();
  303. $protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
  304. $request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
  305. $request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
  306. foreach ($access_urls as & $details) {
  307. if ($request_url1 == $details['url'] or $request_url2 == $details['url']) {
  308. $_configuration['access_url'] = $details['id'];
  309. }
  310. }
  311. } else {
  312. $_configuration['access_url'] = 1;
  313. }
  314. // The system has not been designed to use special SQL modes that were introduced since MySQL 5.
  315. Database::query("set session sql_mode='';");
  316. if (!Database::select_db($_configuration['main_database'], $database_connection)) {
  317. $app->abort(500, "Database is unavailable"); //error 3
  318. }
  319. /* Initialization of the default encodings */
  320. // The platform's character set must be retrieved at this early moment.
  321. $sql = "SELECT selected_value FROM settings_current WHERE variable = 'platform_charset';";
  322. $result = Database::query($sql);
  323. while ($row = @Database::fetch_array($result)) {
  324. $charset = $row[0];
  325. }
  326. if (empty($charset)) {
  327. $charset = 'UTF-8';
  328. }
  329. // Preserving the value of the global variable $charset.
  330. $charset_initial_value = $charset;
  331. // Initialization of the internationalization library.
  332. api_initialize_internationalization();
  333. // Initialization of the default encoding that will be used by the multibyte string routines in the internationalization library.
  334. api_set_internationalization_default_encoding($charset);
  335. // Initialization of the database encoding to be used.
  336. Database::query("SET SESSION character_set_server='utf8';");
  337. Database::query("SET SESSION collation_server='utf8_general_ci';");
  338. if (api_is_utf8($charset)) {
  339. // 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.
  340. Database::query("SET NAMES 'utf8';");
  341. } else {
  342. Database::query("SET CHARACTER SET '" . Database::to_db_encoding($charset) . "';");
  343. }
  344. Database::query("SET NAMES 'utf8';");
  345. // Start session after the internationalization library has been initialized.
  346. Chamilo::session()->start($already_installed);
  347. $settings_refresh_info = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
  348. $settings_latest_update = $settings_refresh_info ? $settings_refresh_info['selected_value'] : null;
  349. $_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
  350. $_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
  351. if (!isset($_setting)) {
  352. api_set_settings_and_plugins();
  353. } else {
  354. if (isset($_setting['settings_latest_update']) && $_setting['settings_latest_update'] != $settings_latest_update) {
  355. api_set_settings_and_plugins();
  356. $_setting = isset($_SESSION['_setting']) ? $_SESSION['_setting'] : null;
  357. $_plugins = isset($_SESSION['_plugins']) ? $_SESSION['_plugins'] : null;
  358. }
  359. }
  360. // Load allowed tag definitions for kses and/or HTMLPurifier.
  361. require_once $lib_path.'formvalidator/Rule/allowed_tags.inc.php';
  362. // Load HTMLPurifier.
  363. //require_once $lib_path.'htmlpurifier/library/HTMLPurifier.auto.php'; // It will be loaded later, in a lazy manner.
  364. // Before we call local.inc.php, let's define a global $this_section variable
  365. // which will then be usable from the banner and header scripts
  366. $this_section = SECTION_GLOBAL;
  367. // include the local (contextual) parameters of this course or section
  368. require $includePath.'/local.inc.php';
  369. //Include Chamilo Mail conf this is added here because the api_get_setting works
  370. //Fixes bug in Chamilo 1.8.7.1 array was not set
  371. $administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com';
  372. $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';
  373. $mail_conf = api_get_path(CONFIGURATION_PATH).'mail.conf.php';
  374. if (file_exists($mail_conf)) {
  375. require_once $mail_conf;
  376. }
  377. $app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
  378. 'swiftmailer.options' => array(
  379. 'host' => $platform_email['SMTP_HOST'],
  380. 'port' => $platform_email['SMTP_PORT'],
  381. 'username' => $platform_email['SMTP_USER'],
  382. 'password' => $platform_email['SMTP_PASS'],
  383. 'encryption' => null,
  384. 'auth_mode' => null
  385. ),
  386. ));
  387. // check and modify the date of user in the track.e.online table
  388. if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {
  389. LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : '');
  390. }
  391. //error_reporting(-1);
  392. if (api_get_setting('server_type') == 'test') {
  393. //error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
  394. } else {
  395. /*
  396. Server type is not test
  397. - normal error reporting level
  398. - full fake register globals block
  399. */
  400. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  401. // TODO: These obsolete variables $HTTP_* to be check whether they are actually used.
  402. if (!isset($HTTP_GET_VARS)) { $HTTP_GET_VARS = $_GET; }
  403. if (!isset($HTTP_POST_VARS)) { $HTTP_POST_VARS = $_POST; }
  404. if (!isset($HTTP_POST_FILES)) { $HTTP_POST_FILES = $_FILES; }
  405. if (!isset($HTTP_SESSION_VARS)) { $HTTP_SESSION_VARS = $_SESSION; }
  406. if (!isset($HTTP_SERVER_VARS)) { $HTTP_SERVER_VARS = $_SERVER; }
  407. // Register SESSION variables into $GLOBALS
  408. if (sizeof($HTTP_SESSION_VARS)) {
  409. if (!is_array($_SESSION)) {
  410. $_SESSION = array();
  411. }
  412. foreach ($HTTP_SESSION_VARS as $key => $val) {
  413. $_SESSION[$key] = $HTTP_SESSION_VARS[$key];
  414. $GLOBALS[$key] = $HTTP_SESSION_VARS[$key];
  415. }
  416. }
  417. // Register SERVER variables into $GLOBALS
  418. if (sizeof($HTTP_SERVER_VARS)) {
  419. $_SERVER = array();
  420. foreach ($HTTP_SERVER_VARS as $key => $val) {
  421. $_SERVER[$key] = $HTTP_SERVER_VARS[$key];
  422. if (!isset($_SESSION[$key]) && $key != 'includePath' && $key != 'rootSys' && $key!= 'lang_path' && $key!= 'extAuthSource' && $key!= 'thisAuthSource' && $key!= 'main_configuration_file_path' && $key!= 'phpDigIncCn' && $key!= 'drs') {
  423. $GLOBALS[$key]=$HTTP_SERVER_VARS[$key];
  424. }
  425. }
  426. }
  427. }
  428. /* LOAD LANGUAGE FILES SECTION */
  429. // if we use the javascript version (without go button) we receive a get
  430. // if we use the non-javascript version (with the go button) we receive a post
  431. $user_language = '';
  432. if (!empty($_GET['language'])) {
  433. $user_language = $_GET['language'];
  434. }
  435. if (!empty($_POST['language_list'])) {
  436. $user_language = str_replace('index.php?language=', '', $_POST['language_list']);
  437. }
  438. // Include all files (first english and then current interface language)
  439. $langpath = api_get_path(SYS_LANG_PATH);
  440. /* This will only work if we are in the page to edit a sub_language */
  441. if (isset($this_script) && $this_script == 'sub_language') {
  442. require_once '../admin/sub_language.class.php';
  443. // getting the arrays of files i.e notification, trad4all, etc
  444. $language_files_to_load = SubLanguageManager:: get_lang_folder_files_list(api_get_path(SYS_LANG_PATH).'english', true);
  445. //getting parent info
  446. $parent_language = SubLanguageManager::get_all_information_of_language($_REQUEST['id']);
  447. //getting sub language info
  448. $sub_language = SubLanguageManager::get_all_information_of_language($_REQUEST['sub_language_id']);
  449. $english_language_array = $parent_language_array = $sub_language_array = array();
  450. foreach ($language_files_to_load as $language_file_item) {
  451. $lang_list_pre = array_keys($GLOBALS);
  452. //loading english
  453. $path = $langpath.'english/'.$language_file_item.'.inc.php';
  454. if (file_exists($path)) {
  455. include $path;
  456. }
  457. $lang_list_post = array_keys($GLOBALS);
  458. $lang_list_result = array_diff($lang_list_post, $lang_list_pre);
  459. unset($lang_list_pre);
  460. // english language array
  461. $english_language_array[$language_file_item] = compact($lang_list_result);
  462. //cleaning the variables
  463. foreach ($lang_list_result as $item) {
  464. unset(${$item});
  465. }
  466. $parent_file = $langpath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  467. if (file_exists($parent_file) && is_file($parent_file)) {
  468. include_once $parent_file;
  469. }
  470. // parent language array
  471. $parent_language_array[$language_file_item] = compact($lang_list_result);
  472. //cleaning the variables
  473. foreach($lang_list_result as $item) {
  474. unset(${$item});
  475. }
  476. $sub_file = $langpath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  477. if (file_exists($sub_file) && is_file($sub_file)) {
  478. include $sub_file;
  479. }
  480. // sub language array
  481. $sub_language_array[$language_file_item] = compact($lang_list_result);
  482. //cleaning the variables
  483. foreach($lang_list_result as $item) {
  484. unset(${$item});
  485. }
  486. }
  487. }
  488. // Checking if we have a valid language. If not we set it to the platform language.
  489. $valid_languages = api_get_languages();
  490. if (!empty($valid_languages)) {
  491. if (!in_array($user_language, $valid_languages['folder'])) {
  492. $user_language = api_get_setting('platformLanguage');
  493. }
  494. $language_priority1 = api_get_setting('languagePriority1');
  495. $language_priority2 = api_get_setting('languagePriority2');
  496. $language_priority3 = api_get_setting('languagePriority3');
  497. $language_priority4 = api_get_setting('languagePriority4');
  498. if (in_array($user_language, $valid_languages['folder']) && (isset($_GET['language']) || isset($_POST['language_list']))) {
  499. $user_selected_language = $user_language; // $_GET['language'];
  500. $_SESSION['user_language_choice'] = $user_selected_language;
  501. $platformLanguage = $user_selected_language;
  502. }
  503. if (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false ) {
  504. $language_interface = api_get_language_from_type($language_priority4);
  505. } else {
  506. $language_interface = api_get_setting('platformLanguage');
  507. }
  508. if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false ) {
  509. $language_interface = api_get_language_from_type($language_priority3);
  510. } else {
  511. if (isset($_SESSION['user_language_choice'])) {
  512. $language_interface = $_SESSION['user_language_choice'];
  513. }
  514. }
  515. if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false ) {
  516. $language_interface = api_get_language_from_type($language_priority2);
  517. } else {
  518. if (isset($_user['language'])) {
  519. $language_interface = $_user['language'];
  520. }
  521. }
  522. if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false ) {
  523. $language_interface = api_get_language_from_type($language_priority1);
  524. } else {
  525. if ($_course['language']) {
  526. $language_interface = $_course['language'];
  527. }
  528. }
  529. }
  530. // Sometimes the variable $language_interface is changed
  531. // temporarily for achieving translation in different language.
  532. // We need to save the genuine value of this variable and
  533. // to use it within the function get_lang(...).
  534. $language_interface_initial_value = $language_interface;
  535. /**
  536. * Include all necessary language files
  537. * - trad4all
  538. * - notification
  539. * - custom tool language files
  540. */
  541. $language_files = array();
  542. $language_files[] = 'trad4all';
  543. $language_files[] = 'notification';
  544. $language_files[] = 'accessibility';
  545. if (isset($language_file)) {
  546. if (!is_array($language_file)) {
  547. $language_files[] = $language_file;
  548. } else {
  549. $language_files = array_merge($language_files, $language_file);
  550. }
  551. }
  552. // if a set of language files has been properly defined
  553. if (is_array($language_files)) {
  554. // if the sub-language feature is on
  555. if (api_get_setting('allow_use_sub_language') == 'true') {
  556. require_once api_get_path(SYS_CODE_PATH).'admin/sub_language.class.php';
  557. $parent_path = SubLanguageManager::get_parent_language_path($language_interface);
  558. foreach ($language_files as $index => $language_file) {
  559. // include English
  560. include $langpath.'english/'.$language_file.'.inc.php';
  561. // prepare string for current language and its parent
  562. $lang_file = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  563. $parent_lang_file = $langpath.$parent_path.'/'.$language_file.'.inc.php';
  564. // load the parent language file first
  565. if (file_exists($parent_lang_file)) {
  566. include $parent_lang_file;
  567. }
  568. // overwrite the parent language translations if there is a child
  569. if (file_exists($lang_file)) {
  570. include $lang_file;
  571. }
  572. }
  573. } else {
  574. // if the sub-languages feature is not on, then just load the
  575. // set language interface
  576. foreach ($language_files as $index => $language_file) {
  577. // include English
  578. include $langpath.'english/'.$language_file.'.inc.php';
  579. // prepare string for current language
  580. $langfile = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  581. if (file_exists($langfile)) {
  582. include $langfile;
  583. }
  584. }
  585. }
  586. }
  587. // The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation.
  588. // So, we have to reassign this variable again in order to keep its value right.
  589. $charset = $charset_initial_value;
  590. // The global variable $text_dir has been defined in the language file trad4all.inc.php.
  591. // For determing text direction correspondent to the current language we use now information from the internationalization library.
  592. $text_dir = api_get_text_direction();
  593. //Update of the logout_date field in the table track_e_login (needed for the calculation of the total connection time)
  594. if (!isset($_SESSION['login_as']) && isset($_user)) {
  595. // if $_SESSION['login_as'] is set, then the user is an admin logged as the user
  596. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  597. $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".$_user["user_id"]."' ORDER BY login_date DESC LIMIT 0,1";
  598. $q_last_connection = Database::query($sql_last_connection);
  599. if (Database::num_rows($q_last_connection) > 0) {
  600. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  601. // is the latest logout_date still relevant?
  602. $sql_logout_date = "SELECT logout_date FROM $tbl_track_login WHERE login_id=$i_id_last_connection";
  603. $q_logout_date = Database::query($sql_logout_date);
  604. $res_logout_date = convert_sql_date(Database::result($q_logout_date,0,'logout_date'));
  605. if ($res_logout_date < time() - $_configuration['session_lifetime']) {
  606. // it isn't, we should create a fresh entry
  607. event_login();
  608. // now that it's created, we can get its ID and carry on
  609. $q_last_connection = Database::query($sql_last_connection);
  610. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  611. }
  612. $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
  613. Database::query($s_sql_update_logout_date);
  614. }
  615. }
  616. // Add language_measure_frequency to your main/inc/conf/configuration.php in
  617. // order to generate language variables frequency measurements (you can then
  618. // see them through main/cron/lang/langstats.php)
  619. // The langstat object will then be used in the get_lang() function.
  620. // This block can be removed to speed things up a bit as it should only ever
  621. // be used in development versions.
  622. if (isset($_configuration['language_measure_frequency']) && $_configuration['language_measure_frequency'] == 1) {
  623. require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
  624. $langstats = new langstats();
  625. }
  626. //Default quota for the course documents folder
  627. $default_quota = api_get_setting('default_document_quotum');
  628. //Just in case the setting is not correctly set
  629. if (empty($default_quota)) {
  630. $default_quota = 100000000;
  631. }
  632. define('DEFAULT_DOCUMENT_QUOTA', $default_quota);