global.inc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <?php
  2. /**
  3. ==============================================================================
  4. * It is recommended that ALL dokeos 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 dokeos.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 Dokeos config page.
  20. *
  21. ==============================================================================
  22. */
  23. // PHP version check
  24. if ( !function_exists('version_compare') || version_compare( phpversion(), '5', '<' ) )
  25. {
  26. $error_message_php_version = <<<EOM
  27. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  28. <html>
  29. <head>
  30. <title>Wrong PHP version!</title>
  31. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  32. <style type="text/css" media="screen, projection">
  33. /*<![CDATA[*/
  34. @import "main/css/dokeos_blue/default.css";
  35. /*]]>*/
  36. </style>
  37. </head>
  38. <body>
  39. <div id="header">
  40. <div id="header1"><a href="http://www.dokeos.com" target="_blank">Dokeos Homepage</a></div>
  41. <div class="clear"></div>
  42. <div id="header2">&nbsp;</div>
  43. <div id="header3">&nbsp;</div>
  44. </div>
  45. <div style="text-align: center;"><br /><br />
  46. The version of scripting language on your server is wrong. Your server has to support PHP 5.x.x .<br />
  47. <a href="documentation/installation_guide.html" target="_blank">Read the installation guide.</a><br /><br />
  48. </div>
  49. <div id="footer">
  50. <div class="copyright">Platform <a href="http://www.dokeos.com" target="_blank"> Dokeos </a> &copy; 2009 </div>
  51. &nbsp;
  52. </div>
  53. </body>
  54. </html>
  55. EOM;
  56. header('Content-Type: text/html; charset=UTF-8');
  57. die($error_message_php_version);
  58. }
  59. // Determine the directory path where this current file lies
  60. // This path will be useful to include the other intialisation files
  61. $includePath = dirname(__FILE__);
  62. // @todo isn't this file renamed to configuration.inc.php yet?
  63. // include the main Dokeos platform configuration file
  64. $main_configuration_file_path = $includePath . "/conf/configuration.php";
  65. $already_installed = false;
  66. if(file_exists($main_configuration_file_path))
  67. {
  68. require_once($main_configuration_file_path);
  69. $already_installed = true;
  70. }
  71. else
  72. {
  73. $_configuration = array();
  74. }
  75. // include the main Dokeos platform library file
  76. require_once($includePath.'/lib/main_api.lib.php');
  77. //fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI']
  78. api_request_uri();
  79. // Start session
  80. api_session_start($already_installed);
  81. $error_message_not_installed = <<<EOM
  82. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  83. <html>
  84. <head>
  85. <title>Dokeos has been not installed!</title>
  86. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  87. <style type="text/css" media="screen, projection">
  88. /*<![CDATA[*/
  89. @import "main/css/dokeos_blue/default.css";
  90. /*]]>*/
  91. </style>
  92. </head>
  93. <body>
  94. <div id="header">
  95. <div id="header1"><a href="http://www.dokeos.com" target="_blank">Dokeos Homepage</a></div>
  96. <div class="clear"></div>
  97. <div id="header2">&nbsp;</div>
  98. <div id="header3">
  99. <ul id="logout">
  100. <li><a href="" target="_top"><span>&nbsp;</span></a></li>
  101. </ul>
  102. <ul>
  103. <li id="current"><a href="#"><span>Installation</span></a></li>
  104. </ul>
  105. <div style="clear: both;" class="clear"></div>
  106. </div>
  107. <div id="header4">&nbsp;</div>
  108. </div>
  109. <div style="text-align: center;"><br /><br />
  110. <form action="main/install/index.php" method="get"><button class="save" type="submit" value="&nbsp;&nbsp; Click to INSTALL DOKEOS &nbsp;&nbsp;" >Click to INSTALL DOKEOS</button></form><br />
  111. or <a href="documentation/installation_guide.html" target="_blank">read the installation guide</a><br /><br />
  112. </div>
  113. <div id="footer">
  114. <div class="copyright">Platform <a href="http://www.dokeos.com" target="_blank"> Dokeos </a> &copy; 2009 </div>
  115. &nbsp;
  116. </div>
  117. </body>
  118. </html>
  119. EOM;
  120. $error_message_db_problem = <<<EOM
  121. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  122. <html>
  123. <head>
  124. <title>Dokeos database unavailable!</title>
  125. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  126. <style type="text/css" media="screen, projection">
  127. /*<![CDATA[*/
  128. @import "main/css/public_admin/default.css";
  129. /*]]>*/
  130. </style>
  131. </head>
  132. <body>
  133. <div id="header">
  134. <div id="header1"><a href="http://www.dokeos.com" target="_blank">Dokeos Homepage</a></div>
  135. <div class="clear"></div>
  136. <div id="header2">&nbsp;</div>
  137. <div id="header3">&nbsp;</div>
  138. </div>
  139. EOM;
  140. $error_message_db_problem .= '
  141. <div style="text-align: center; font-size: large; margin-bottom: 2em;"><br /><br />
  142. This portal is currently experiencing database issues. Please report this to the portal administrator. Thank you for your help.</a>
  143. </div>
  144. <div id="footer">
  145. <div class="copyright">Platform <a href="http://www.dokeos.com" target="_blank"> Dokeos </a> &copy; 2009 </div>
  146. &nbsp;
  147. </div>
  148. </body>
  149. </html>';
  150. if (!$already_installed)
  151. {
  152. header('Content-Type: text/html; charset=UTF-8');
  153. //require('installedVersion.inc.php');
  154. die($error_message_not_installed);
  155. }
  156. //Assigning a variable to avoid several useless calls to the database setting.
  157. // Do not over-user. This is only for this script's local use.
  158. $lib_path = api_get_path(LIBRARY_PATH);
  159. // Add the path to the pear packages to the include path
  160. //ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.$lib_path.'pear');
  161. ini_set('include_path', api_create_include_path_setting());
  162. // This is for compatibility with MAC computers.
  163. ini_set('auto_detect_line_endings', '1');
  164. // Include the libraries that are necessary everywhere
  165. require_once($lib_path.'database.lib.php');
  166. require_once($lib_path.'display.lib.php');
  167. require_once($lib_path.'text.lib.php');
  168. require_once($lib_path.'security.lib.php');
  169. require_once($lib_path.'events.lib.inc.php');
  170. //require_once($lib_path.'media.lib.php'); // TODO: Deprecated, to be removed. Ivan Tcholakov, 23-SEP-2003.
  171. // @todo: this shouldn't be done here. It should be stored correctly during installation
  172. if(empty($_configuration['statistics_database']) && $already_installed)
  173. {
  174. $_configuration['statistics_database'] = $_configuration['main_database'];
  175. }
  176. // connect to the server database and select the main dokeos database
  177. $dokeos_database_connection = @mysql_connect($_configuration['db_host'], $_configuration['db_user'], $_configuration['db_password']) or die ($error_message_db_problem);
  178. if (! $_configuration['db_host'])
  179. {
  180. die($error_message_db_problem);
  181. }
  182. unset($error_message_db_problem);
  183. unset($error_message_not_installed);
  184. // The Dokeos system has not been designed to use special SQL modes that were introduced since MySQL 5
  185. api_sql_query("set session sql_mode='';", __FILE__, __LINE__);
  186. $selectResult = mysql_select_db($_configuration['main_database'],$dokeos_database_connection) or die ('<center>WARNING ! SYSTEM UNABLE TO SELECT THE MAIN DOKEOS DATABASE</center>');
  187. /*
  188. --------------------------------------------
  189. Initialization of the default encodings
  190. --------------------------------------------
  191. */
  192. // The platform's character set must be retrieved at this early moment.
  193. $sql = "SELECT selected_value FROM settings_current WHERE variable = 'platform_charset';";
  194. $result = api_sql_query($sql, __FILE__, __LINE__);
  195. while ($row = @mysql_fetch_array($result)) {
  196. $charset = $row[0];
  197. }
  198. if (empty($charset)) {
  199. $charset = "ISO-8859-15";
  200. }
  201. // Preserving the value of the global variable $charset.
  202. $charset_initial_value = $charset;
  203. // Initialization of the internationalization library.
  204. api_initialize_internationalization();
  205. // Initialization of the default encoding that will be used by the multibyte string routines in the internationalization library.
  206. api_set_internationalization_default_encoding($charset);
  207. /*
  208. --------------------------------------------
  209. RETRIEVING ALL THE DOKEOS CONFIG SETTINGS
  210. --------------------------------------------
  211. */
  212. if(!empty($_configuration['multiple_access_urls']))
  213. {
  214. $_configuration['access_url'] = 1;
  215. $access_urls = api_get_access_urls();
  216. $protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS'])!='OFF')?'https':'http').'://';
  217. $request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
  218. $request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
  219. foreach($access_urls as $details)
  220. {
  221. if($request_url1 == $details['url'] or $request_url2 == $details['url'])
  222. {
  223. $_configuration['access_url'] = $details['id'];
  224. }
  225. }
  226. }
  227. else
  228. {
  229. $_configuration['access_url'] = 1;
  230. }
  231. //$sql="SELECT * FROM settings_current";
  232. //$result=mysql_query($sql) or die(mysql_error());
  233. // access_url == 1 is the default dokeos location
  234. if ($_configuration['access_url']!=1)
  235. {
  236. $url_info = api_get_access_url($_configuration['access_url']);
  237. if ($url_info['active']==1)
  238. {
  239. $settings_by_access = api_get_settings(null,'list',$_configuration['access_url'],1);
  240. foreach($settings_by_access as $row)
  241. {
  242. if (empty($row['variable']))
  243. $row['variable']=0;
  244. if (empty($row['subkey']))
  245. $row['subkey']=0;
  246. if (empty($row['category']))
  247. $row['category']=0;
  248. $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
  249. }
  250. }
  251. }
  252. //echo '<pre>';print_r($result_other_site);
  253. $result = api_get_settings(null,'list',1);
  254. //while ($row=mysql_fetch_array($result))
  255. foreach($result as $row)
  256. {
  257. if ($_configuration['access_url']!=1)
  258. {
  259. if ($url_info['active']==1)
  260. {
  261. if (empty($row['variable']))
  262. $var=0;
  263. else
  264. $var=$row['variable'];
  265. if (empty($row['subkey']))
  266. $subkey=0;
  267. else
  268. $subkey=$row['subkey'];
  269. if (empty($row['category']))
  270. $category=0;
  271. else
  272. $category=$row['category'];
  273. }
  274. if ($row['access_url_changeable']==1 && $url_info['active']==1)
  275. {
  276. if ($settings_by_access_list[ $var ] [ $subkey ] [$category ]['selected_value'] !='')
  277. {
  278. if ($row['subkey']==NULL)
  279. {
  280. $_setting[$row['variable']]= $settings_by_access_list[ $var ] [ $subkey ] [$category ]['selected_value'];
  281. }
  282. else
  283. {
  284. $_setting[$row['variable']][$row['subkey']]=$settings_by_access_list[ $var ] [ $subkey ] [$category ]['selected_value'];
  285. }
  286. }
  287. else
  288. {
  289. if ($row['subkey']==NULL)
  290. {
  291. $_setting[$row['variable']]=$row['selected_value'];
  292. }
  293. else
  294. {
  295. $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
  296. }
  297. }
  298. }
  299. else
  300. {
  301. if ($row['subkey']==NULL)
  302. {
  303. $_setting[$row['variable']]=$row['selected_value'];
  304. }
  305. else
  306. {
  307. $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
  308. }
  309. }
  310. }
  311. else
  312. {
  313. if ($row['subkey']==NULL)
  314. {
  315. $_setting[$row['variable']]=$row['selected_value'];
  316. }
  317. else
  318. {
  319. $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
  320. }
  321. }
  322. }
  323. //echo '<pre>';print_r($_setting);echo '</pre>';
  324. // we have to store the settings for the plugins differently because it expects an array
  325. //$sql="SELECT * FROM settings_current WHERE category='plugins'";
  326. //$result=mysql_query($sql) or die(mysql_error());
  327. $result = api_get_settings('Plugins','list',$_configuration['access_url']);
  328. $_plugins=array();
  329. //while ($row=mysql_fetch_array($result))
  330. foreach($result as $row)
  331. {
  332. $key= $row['variable'];
  333. if (is_string($_setting[$key]))
  334. {
  335. $_setting[$key]=array();
  336. }
  337. $_setting[$key][]=$row['selected_value'];
  338. $_plugins[$key][]=$row['selected_value'];
  339. }
  340. //load array Kses for Htmlpurifier
  341. require_once $includePath."/lib/formvalidator/Rule/allowed_tags.inc.php";
  342. //load htmpurifier
  343. require_once $includePath."/lib/htmlpurifier/library/HTMLPurifier.auto.php";
  344. // include the local (contextual) parameters of this course or section
  345. require($includePath."/local.inc.php");
  346. // ===== "who is logged in?" module section =====
  347. require_once($includePath."/lib/online.inc.php");
  348. // check and modify the date of user in the track.e.online table
  349. if (!$x=strpos($_SERVER['PHP_SELF'],'whoisonline.php'))
  350. {
  351. LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : '',$_configuration['statistics_database']);
  352. }
  353. // ===== end "who is logged in?" module section =====
  354. if(api_get_setting('server_type') == 'test')
  355. {
  356. /*
  357. --------------------------------------------
  358. Server type is test
  359. - high error reporting level
  360. - only do addslashes on $_GET and $_POST
  361. --------------------------------------------
  362. */
  363. error_reporting(E_ALL & ~E_NOTICE);
  364. //error_reporting(E_ALL);
  365. //Addslashes to all $_GET variables
  366. foreach($_GET as $key=>$val)
  367. {
  368. if(!ini_get('magic_quotes_gpc'))
  369. {
  370. if(is_string($val))
  371. {
  372. $_GET[$key]=addslashes($val);
  373. }
  374. }
  375. }
  376. //Addslashes to all $_POST variables
  377. foreach($_POST as $key=>$val)
  378. {
  379. if(!ini_get('magic_quotes_gpc'))
  380. {
  381. if(is_string($val))
  382. {
  383. $_POST[$key]=addslashes($val);
  384. }
  385. }
  386. }
  387. }
  388. else
  389. {
  390. /*
  391. --------------------------------------------
  392. Server type is not test
  393. - normal error reporting level
  394. - full fake register globals block
  395. --------------------------------------------
  396. */
  397. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  398. if(!isset($HTTP_GET_VARS)) { $HTTP_GET_VARS=$_GET; }
  399. if(!isset($HTTP_POST_VARS)) { $HTTP_POST_VARS=$_POST; }
  400. if(!isset($HTTP_POST_FILES)) { $HTTP_POST_FILES=$_FILES; }
  401. if(!isset($HTTP_SESSION_VARS)) { $HTTP_SESSION_VARS=$_SESSION; }
  402. if(!isset($HTTP_SERVER_VARS)) { $HTTP_SERVER_VARS=$_SERVER; }
  403. // Register SESSION variables into $GLOBALS
  404. if(sizeof($HTTP_SESSION_VARS))
  405. {
  406. if(!is_array($_SESSION))
  407. {
  408. $_SESSION=array();
  409. }
  410. foreach($HTTP_SESSION_VARS as $key=>$val)
  411. {
  412. $_SESSION[$key]=$HTTP_SESSION_VARS[$key];
  413. $GLOBALS[$key]=$HTTP_SESSION_VARS[$key];
  414. }
  415. }
  416. // Register SERVER variables into $GLOBALS
  417. if(sizeof($HTTP_SERVER_VARS))
  418. {
  419. $_SERVER=array();
  420. foreach($HTTP_SERVER_VARS as $key=>$val)
  421. {
  422. $_SERVER[$key]=$HTTP_SERVER_VARS[$key];
  423. if(!isset($_SESSION[$key]) && $key != 'includePath' && $key != 'rootSys' && $key!= 'clarolineRepositorySys' && $key!= 'lang_path' && $key!= 'extAuthSource' && $key!= 'thisAuthSource' && $key!= 'main_configuration_file_path' && $key!= 'phpDigIncCn' && $key!= 'drs')
  424. {
  425. $GLOBALS[$key]=$HTTP_SERVER_VARS[$key];
  426. }
  427. }
  428. }
  429. }
  430. /*
  431. -----------------------------------------------------------
  432. LOAD LANGUAGE FILES SECTION
  433. -----------------------------------------------------------
  434. */
  435. // if we use the javascript version (without go button) we receive a get
  436. // if we use the non-javascript version (with the go button) we receive a post
  437. $user_language = '';
  438. if(!empty($_GET['language'])) {
  439. $user_language = $_GET["language"];
  440. }
  441. if (!empty($_POST["language_list"])) {
  442. $user_language = str_replace("index.php?language=","",$_POST["language_list"]);
  443. }
  444. // Include all files (first english and then current interface language)
  445. $langpath = api_get_path(SYS_CODE_PATH).'lang/';
  446. /* This will only work if we are in the page to edit a sub_language */
  447. if (api_get_self() == '/main/admin/sub_language.php' || api_get_self() == '/main/admin/sub_language_ajax.inc.php' ) {
  448. require_once '../admin/sub_language.class.php';
  449. // getting the arrays of files i.e notification, trad4all, etc
  450. $language_files_to_load = SubLanguageManager::get_all_data_of_dokeos_folder(api_get_path(SYS_LANG_PATH).'english',true);
  451. //getting parent info
  452. $parent_language = SubLanguageManager::get_all_information_of_language(intval($_REQUEST['id']));
  453. //getting sub language info
  454. $sub_language = SubLanguageManager::get_all_information_of_language(intval($_REQUEST['sub_language_id']));
  455. //echo '<pre>';
  456. $english_language_array = $parent_language_array= $sub_language_array=array();
  457. foreach ($language_files_to_load as $language_file_item) {
  458. $lang_list_pre = array_keys($GLOBALS);
  459. include $langpath.'english/'.$language_file_item.'.inc.php'; //loading english
  460. $lang_list_post = array_keys($GLOBALS);
  461. $lang_list_result = array_diff($lang_list_post, $lang_list_pre);
  462. unset($lang_list_pre);
  463. // ------ english language array
  464. $english_language_array[$language_file_item]= compact($lang_list_result);
  465. //cleaning the variables
  466. foreach($lang_list_result as $item) {
  467. unset(${$item});
  468. }
  469. $parent_file = $langpath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  470. if (is_file($parent_file))
  471. include $parent_file;
  472. // ------ parent language array
  473. $parent_language_array[$language_file_item]= compact($lang_list_result);
  474. //cleaning the variables
  475. foreach($lang_list_result as $item) {
  476. unset(${$item});
  477. }
  478. $sub_file = $langpath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
  479. if (is_file($sub_file))
  480. include $sub_file;
  481. // ------ sub language array
  482. $sub_language_array[$language_file_item]= compact($lang_list_result);
  483. //cleaning the variables
  484. foreach($lang_list_result as $item) {
  485. unset(${$item});
  486. }
  487. }
  488. /*
  489. print_r($english_language_array);
  490. print_r($parent_language_array);
  491. print_r($sub_language_array); exit
  492. */
  493. }
  494. // Checking if we have a valid language. If not we set it to the platform language.
  495. $valid_languages=api_get_languages();
  496. if (!in_array($user_language,$valid_languages['folder']))
  497. {
  498. $user_language=api_get_setting('platformLanguage');
  499. }
  500. if (in_array($user_language,$valid_languages['folder']) and (isset($_GET['language']) OR isset($_POST['language_list'])))
  501. {
  502. $user_selected_language = $user_language; // $_GET["language"];
  503. $_SESSION["user_language_choice"] = $user_selected_language;
  504. $platformLanguage = $user_selected_language;
  505. }else{
  506. $platformLanguage = api_get_setting('platformLanguage');
  507. }
  508. if (isset($_SESSION["user_language_choice"]))
  509. {
  510. $language_interface = $_SESSION["user_language_choice"];
  511. }
  512. else
  513. {
  514. $language_interface = api_get_setting('platformLanguage');
  515. }
  516. if (isset($_user['language']))
  517. {
  518. $language_interface = $_user['language'];
  519. }
  520. if ($_course['language'])
  521. {
  522. $language_interface = $_course['language'];
  523. }
  524. // Sometimes the variable $language_interface is changed
  525. // temporarily for achieving translation in different language.
  526. // We need to save the genuine value of this variable and
  527. // to use it within the function get_lang(...).
  528. $language_interface_initial_value = $language_interface;
  529. /*
  530. * Include all necessary language files
  531. * - trad4all
  532. * - notification
  533. * - custom tool language files
  534. */
  535. $language_files = array();
  536. $language_files[] = 'trad4all';
  537. $language_files[] = 'notification';
  538. $language_files[] = 'accessibility';
  539. if( isset($language_file) )
  540. {
  541. if( !is_array($language_file))
  542. {
  543. $language_files[] = $language_file;
  544. }
  545. else
  546. {
  547. $language_files = array_merge($language_files,$language_file);
  548. }
  549. }
  550. if (is_array($language_files)) {
  551. if (api_get_setting('allow_use_sub_language')=='true') {
  552. foreach ($language_files as $index => $language_file) {
  553. include $langpath.'english/'.$language_file.'.inc.php';
  554. $langfile = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  555. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  556. $sql_sub_language='SELECT dokeos_folder FROM '.$tbl_admin_languages.' WHERE parent_id=(SELECT id FROM '.$tbl_admin_languages.' WHERE dokeos_folder="'.Database::escape_string($language_interface).'" AND ISNULL(parent_id))';
  557. $rs_sub_language=Database::query($sql_sub_language,__FILE__,__LINE__);
  558. $num_row_sub_language=Database::num_rows($rs_sub_language);
  559. if (file_exists($langfile)) {
  560. include $langfile;
  561. for ($i=0;$i<$num_row_sub_language;$i++) {
  562. $row_sub_language=Database::result($rs_sub_language,$i,'dokeos_folder');
  563. $sub_langfile = $langpath.$row_sub_language.'/'.$language_file.'.inc.php';
  564. if (file_exists($sub_langfile)) {
  565. include $sub_langfile;
  566. }
  567. }
  568. }
  569. }
  570. } else {
  571. foreach ($language_files as $index => $language_file) {
  572. include $langpath.'english/'.$language_file.'.inc.php';
  573. $langfile = $langpath.$language_interface.'/'.$language_file.'.inc.php';
  574. if (file_exists($langfile)) {
  575. include $langfile;
  576. }
  577. }
  578. }
  579. }
  580. // The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation.
  581. // So, we have to reassign this variable again in order to keep its value right.
  582. $charset = $charset_initial_value;
  583. //Update of the logout_date field in the table track_e_login (needed for the calculation of the total connection time)
  584. if($_configuration['tracking_enabled'] && !isset($_SESSION['login_as']) && isset($_user))
  585. { // if $_SESSION['login_as'] is set, then the user is an admin logged as the user
  586. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  587. $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";
  588. $q_last_connection=api_sql_query($sql_last_connection);
  589. if(Database::num_rows($q_last_connection) > 0)
  590. {
  591. $i_id_last_connection=Database::result($q_last_connection,0,"login_id");
  592. $s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
  593. api_sql_query($s_sql_update_logout_date);
  594. }
  595. }
  596. ?>