global.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 and /lib/main_api.lib.php;
  10. * - selecting the main database;
  11. * - include of language files.
  12. *
  13. * @package dokeos.include
  14. * @todo isn't configuration.php renamed to configuration.inc.php yet?
  15. * @todo use the $_configuration array for all the needed variables
  16. * @todo remove the code that displays the button that links to the install page
  17. * but use a redirect immediately. By doing so the $already_installed variable can be removed.
  18. * @todo make it possible to enable / disable the tracking through the Dokeos config page.
  19. *
  20. ==============================================================================
  21. */
  22. // Determine the directory path where this current file lies
  23. // This path will be useful to include the other intialisation files
  24. $includePath = dirname(__FILE__);
  25. // @todo isn't this file renamed to configuration.inc.php yet?
  26. // include the main Dokeos platform configuration file
  27. $main_configuration_file_path = $includePath . "/conf/configuration.php";
  28. $already_installed = false;
  29. if(file_exists($main_configuration_file_path))
  30. {
  31. require_once($main_configuration_file_path);
  32. $already_installed = true;
  33. }
  34. // include the main Dokeos platform library file
  35. require_once($includePath.'/lib/main_api.lib.php');
  36. // Start session
  37. api_session_start($already_installed);
  38. if (!$already_installed)
  39. {
  40. require('installedVersion.inc.php');
  41. $error_message = <<<EOM
  42. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  43. <html>
  44. <head>
  45. <title>Dokeos not installed!</title>
  46. <style type="text/css" media="screen, projection">
  47. /*<![CDATA[*/
  48. @import "main/css/default/default.css";
  49. /*]]>*/
  50. </style>
  51. </head>
  52. <body>
  53. <div id="header">
  54. <div id="header1"><a href="http://www.dokeos.com">Dokeos Homepage</a></div>
  55. <div class="clear"></div>
  56. <div id="header2">&nbsp;</div>
  57. <div id="header3">&nbsp;</div>
  58. </div>
  59. <div style="text-align: center;"><br /><br />
  60. <form action="main/install/index.php" method="get"><input type="submit" value="&nbsp;&nbsp; Click to INSTALL DOKEOS &nbsp;&nbsp;" /></form><br />
  61. or <a href="documentation/installation_guide.html" target="_blank">read the installation guide</a><br /><br />
  62. </div>
  63. <div id="footer">
  64. <div class="copyright">Platform <a href="http://www.dokeos.com"> Dokeos $dokeos_version</a> &copy; 2006 </div>
  65. &nbsp;
  66. </div>
  67. </body>
  68. </html>
  69. EOM;
  70. die($error_message);
  71. }
  72. // Add the path to the pear packages to the include path
  73. ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.api_get_path(LIBRARY_PATH).'pear');
  74. // Include the libraries that are necessary everywhere
  75. require_once(api_get_path(LIBRARY_PATH).'database.lib.php');
  76. require_once(api_get_path(LIBRARY_PATH).'display.lib.php');
  77. require_once(api_get_path(LIBRARY_PATH).'text.lib.php');
  78. // @todo: this shouldn't be done here. It should be stored correctly during installation
  79. if(empty($_configuration['statistics_database']) && $already_installed)
  80. {
  81. $_configuration['statistics_database'] = $_configuration['main_database'];
  82. }
  83. // connect to the server database and select the main dokeos database
  84. $dokeos_database_connection = @mysql_connect($_configuration['db_host'], $_configuration['db_user'], $_configuration['db_password']) or die ($error_message);
  85. if (! $_configuration['db_host'])
  86. {
  87. die($error_message);
  88. }
  89. unset($error_message);
  90. $selectResult = mysql_select_db($_configuration['main_database'],$dokeos_database_connection) or die ('<center>WARNING ! SYSTEM UNABLE TO SELECT THE MAIN DOKEOS DATABASE</center>');
  91. /*
  92. --------------------------------------------
  93. RETRIEVING ALL THE DOKEOS CONFIG SETTINGS
  94. --------------------------------------------
  95. */
  96. $sql="SELECT * FROM settings_current";
  97. $result=mysql_query($sql) or die(mysql_error());
  98. while ($row=mysql_fetch_array($result))
  99. {
  100. if ($row['subkey']==NULL)
  101. {
  102. $_setting[$row['variable']]=$row['selected_value'];
  103. }
  104. else
  105. {
  106. $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
  107. }
  108. }
  109. // we have to store the settings for the plugins differently because it expects an array
  110. $sql="SELECT * FROM settings_current WHERE category='plugins'";
  111. $result=mysql_query($sql) or die(mysql_error());
  112. $_plugins=array();
  113. while ($row=mysql_fetch_array($result))
  114. {
  115. $key= $row['variable'];
  116. if (is_string($_setting[$key]))
  117. {
  118. $_setting[$key]=array();
  119. }
  120. $_setting[$key][]=$row['selected_value'];
  121. $_plugins[$key][]=$row['selected_value'];
  122. }
  123. // include the local (contextual) parameters of this course or section
  124. require($includePath."/local.inc.php");
  125. // ===== "who is logged in?" module section =====
  126. include_once($includePath."/lib/online.inc.php");
  127. // check and modify the date of user in the track.e.online table
  128. if (!$x=strpos($_SERVER['PHP_SELF'],'whoisonline.php'))
  129. {
  130. LoginCheck(isset($_user['user_id']) ? $_user['user_id'] : '',$_configuration['statistics_database']);
  131. }
  132. // ===== end "who is logged in?" module section =====
  133. if(get_setting('server_type') == 'test')
  134. {
  135. /*
  136. --------------------------------------------
  137. Server type is test
  138. - high error reporting level
  139. - only do addslashes on $_GET and $_POST
  140. --------------------------------------------
  141. */
  142. error_reporting(E_ALL & ~E_NOTICE);
  143. //error_reporting(E_ALL);
  144. //Addslashes to all $_GET variables
  145. foreach($_GET as $key=>$val)
  146. {
  147. if(!ini_get('magic_quotes_gpc'))
  148. {
  149. if(is_string($val))
  150. {
  151. $_GET[$key]=addslashes($val);
  152. }
  153. }
  154. }
  155. //Addslashes to all $_POST variables
  156. foreach($_POST as $key=>$val)
  157. {
  158. if(!ini_get('magic_quotes_gpc'))
  159. {
  160. if(is_string($val))
  161. {
  162. $_POST[$key]=addslashes($val);
  163. }
  164. }
  165. }
  166. }
  167. else
  168. {
  169. /*
  170. --------------------------------------------
  171. Server type is not test
  172. - normal error reporting level
  173. - full fake register globals block
  174. --------------------------------------------
  175. */
  176. error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
  177. if(!isset($HTTP_GET_VARS)) { $HTTP_GET_VARS=$_GET; }
  178. if(!isset($HTTP_POST_VARS)) { $HTTP_POST_VARS=$_POST; }
  179. if(!isset($HTTP_POST_FILES)) { $HTTP_POST_FILES=$_FILES; }
  180. if(!isset($HTTP_SESSION_VARS)) { $HTTP_SESSION_VARS=$_SESSION; }
  181. if(!isset($HTTP_SERVER_VARS)) { $HTTP_SERVER_VARS=$_SERVER; }
  182. /*
  183. // Register GET variables into $GLOBALS
  184. if(sizeof($HTTP_GET_VARS))
  185. {
  186. $_GET=array();
  187. foreach($HTTP_GET_VARS as $key=>$val)
  188. {
  189. if(!ini_get('magic_quotes_gpc'))
  190. {
  191. if(is_string($val))
  192. {
  193. $HTTP_GET_VARS[$key]=addslashes($val);
  194. }
  195. }
  196. $_GET[$key]=$HTTP_GET_VARS[$key];
  197. 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')
  198. {
  199. $GLOBALS[$key]=$HTTP_GET_VARS[$key];
  200. }
  201. }
  202. }
  203. // Register POST variables into $GLOBALS
  204. if(sizeof($HTTP_POST_VARS))
  205. {
  206. $_POST=array();
  207. foreach($HTTP_POST_VARS as $key=>$val)
  208. {
  209. if(!ini_get('magic_quotes_gpc'))
  210. {
  211. if(is_string($val))
  212. {
  213. $HTTP_POST_VARS[$key]=addslashes($val);
  214. }
  215. }
  216. $_POST[$key]=$HTTP_POST_VARS[$key];
  217. 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')
  218. {
  219. $GLOBALS[$key]=$HTTP_POST_VARS[$key];
  220. }
  221. }
  222. }
  223. if(sizeof($HTTP_POST_FILES))
  224. {
  225. $_FILES=array();
  226. foreach($HTTP_POST_FILES as $key=>$val)
  227. {
  228. $_FILES[$key]=$HTTP_POST_FILES[$key];
  229. 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')
  230. {
  231. $GLOBALS[$key]=$HTTP_POST_FILES[$key];
  232. }
  233. }
  234. }
  235. */
  236. // Register SESSION variables into $GLOBALS
  237. if(sizeof($HTTP_SESSION_VARS))
  238. {
  239. if(!is_array($_SESSION))
  240. {
  241. $_SESSION=array();
  242. }
  243. foreach($HTTP_SESSION_VARS as $key=>$val)
  244. {
  245. $_SESSION[$key]=$HTTP_SESSION_VARS[$key];
  246. $GLOBALS[$key]=$HTTP_SESSION_VARS[$key];
  247. }
  248. }
  249. // Register SERVER variables into $GLOBALS
  250. if(sizeof($HTTP_SERVER_VARS))
  251. {
  252. $_SERVER=array();
  253. foreach($HTTP_SERVER_VARS as $key=>$val)
  254. {
  255. $_SERVER[$key]=$HTTP_SERVER_VARS[$key];
  256. 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')
  257. {
  258. $GLOBALS[$key]=$HTTP_SERVER_VARS[$key];
  259. }
  260. }
  261. }
  262. }
  263. /*
  264. -----------------------------------------------------------
  265. LOAD LANGUAGE FILES SECTION
  266. -----------------------------------------------------------
  267. */
  268. // if we use the javascript version (without go button) we receive a get
  269. // if we use the non-javascript version (with the go button) we receive a post
  270. $user_language = $_GET["language"];
  271. if ($_POST["language_list"])
  272. {
  273. $user_language = str_replace("index.php?language=","",$_POST["language_list"]);
  274. }
  275. // Checking if we have a valid language. If not we set it to the platform language.
  276. $valid_languages=api_get_languages();
  277. if (!in_array($user_language,$valid_languages['folder']))
  278. {
  279. $user_language=get_setting('platformLanguage');
  280. }
  281. if (in_array($user_language,$valid_languages['folder']) and (isset($_GET['language']) OR isset($_POST['language_list'])))
  282. {
  283. $user_selected_language = $user_language; // $_GET["language"];
  284. $_SESSION["user_language_choice"] = $user_selected_language;
  285. $platformLanguage = $user_selected_language;
  286. }
  287. if (isset($_SESSION["user_language_choice"]))
  288. {
  289. $language_interface = $_SESSION["user_language_choice"];
  290. }
  291. else
  292. {
  293. $language_interface = get_setting('platformLanguage');
  294. }
  295. if (isset($_user['language']))
  296. {
  297. $language_interface = $_user['language'];
  298. }
  299. if ($_course['language'])
  300. {
  301. $language_interface = $_course['language'];
  302. }
  303. /*
  304. * Include all necessary language files
  305. * - trad4all
  306. * - notification
  307. * - custom tool language files
  308. */
  309. $language_files = array();
  310. $language_files[] = 'trad4all';
  311. $language_files[] = 'notification';
  312. if( isset($language_file) )
  313. {
  314. if( !is_array($language_file))
  315. {
  316. $language_files[] = $language_file;
  317. }
  318. else
  319. {
  320. $language_files = array_merge($language_files,$language_file);
  321. }
  322. }
  323. // Include all files (first english and then current interface language)
  324. foreach($language_files as $index => $language_file)
  325. {
  326. include(api_get_path(SYS_CODE_PATH).'lang/english/'.$language_file.'.inc.php');
  327. include(api_get_path(SYS_CODE_PATH).'lang/'.$language_interface.'/'.$language_file.'.inc.php');
  328. }
  329. //Update of the logout_date field in the table track_e_login (needed for the calculation of the total connection time)
  330. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  331. $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";
  332. $q_last_connection=mysql_query($sql_last_connection);
  333. if(mysql_num_rows($q_last_connection) > 0)
  334. {
  335. $i_id_last_connection=mysql_result($q_last_connection,0,"login_id");
  336. $s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
  337. api_sql_query($s_sql_update_logout_date);
  338. }
  339. ?>