global.inc.php 10 KB

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