PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/glpi/config/config.php

#
PHP | 220 lines | 152 code | 26 blank | 42 comment | 40 complexity | c8a2bb7937a4f38d15b10d0ebb0e1692 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. * @version $Id: config.php 18771 2012-06-29 08:49:19Z moyo $
  4. -------------------------------------------------------------------------
  5. GLPI - Gestionnaire Libre de Parc Informatique
  6. Copyright (C) 2003-2012 by the INDEPNET Development Team.
  7. http://indepnet.net/ http://glpi-project.org
  8. -------------------------------------------------------------------------
  9. LICENSE
  10. This file is part of GLPI.
  11. GLPI is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. GLPI is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with GLPI. If not, see <http://www.gnu.org/licenses/>.
  21. --------------------------------------------------------------------------
  22. */
  23. // ----------------------------------------------------------------------
  24. // Original Author of file:
  25. // Purpose of file:
  26. // ----------------------------------------------------------------------
  27. if (!defined('GLPI_ROOT')) {
  28. die("Sorry. You can't access directly to this file");
  29. }
  30. include_once (GLPI_ROOT."/config/based_config.php");
  31. include_once (GLPI_ROOT."/config/define.php");
  32. include_once (GLPI_ROOT."/inc/dbconnection.class.php");
  33. Session::setPath();
  34. Session::start();
  35. Config::detectRootDoc();
  36. if (!file_exists(GLPI_CONFIG_DIR . "/config_db.php")) {
  37. Html::nullHeader("DB Error",$CFG_GLPI["root_doc"]);
  38. if (!isCommandLine()) {
  39. echo "<div class='center'>";
  40. echo "<p>Error : GLPI seems to not be installed properly.</p>";
  41. echo "<p> config_db.php file is missing.</p>";
  42. echo "<p>Please restart the install process.</p>";
  43. echo "<p><a class='red' href='".GLPI_ROOT."'>Click here to proceed</a></p>";
  44. echo "</div>";
  45. } else {
  46. echo "Error : GLPI seems to not be installed properly.\n";
  47. echo "config_db.php file is missing.\n";
  48. echo "Please restart the install process.\n";
  49. }
  50. Html::nullFooter();
  51. die();
  52. } else {
  53. require_once (GLPI_CONFIG_DIR . "/config_db.php");
  54. include_once (GLPI_CACHE_LITE_DIR."/Lite/Output.php");
  55. include_once (GLPI_CACHE_LITE_DIR."/Lite/File.php");
  56. //Database connection
  57. DBConnection::establishDBConnection((isset($USEDBREPLICATE) ? $USEDBREPLICATE : 0),
  58. (isset($DBCONNECTION_REQUIRED) ? $DBCONNECTION_REQUIRED : 0));
  59. // *************************** Statics config options **********************
  60. // ********************options d'installation statiques*********************
  61. // *************************************************************************
  62. //Options from DB, do not touch this part.
  63. // Default Use mode
  64. if (!isset($_SESSION['glpi_use_mode'])) {
  65. $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
  66. }
  67. $config_object = new Config();
  68. $config_ok = false;
  69. if (!isset($_GET['donotcheckversion']) // use normal config table on restore process
  70. && (isset($TRY_OLD_CONFIG_FIRST) // index case
  71. || (isset($_SESSION['TRY_OLD_CONFIG_FIRST']) && $_SESSION['TRY_OLD_CONFIG_FIRST']))) { // backup case
  72. if (isset($_SESSION['TRY_OLD_CONFIG_FIRST'])) {
  73. unset($_SESSION['TRY_OLD_CONFIG_FIRST']);
  74. }
  75. // First try old config table : for update proces management from < 0.80 to >= 0.80
  76. $config_object->forceTable('glpi_config');
  77. if ($config_object->getFromDB(1)) {
  78. $config_ok = true;
  79. } else {
  80. $config_object->forceTable('glpi_configs');
  81. if ($config_object->getFromDB(1)) {
  82. $config_ok = true;
  83. }
  84. }
  85. } else { // Normal load process : use normal config table. If problem try old one
  86. if ($config_object->getFromDB(1)) {
  87. $config_ok = true;
  88. } else {
  89. // Manage glpi_config table before 0.80
  90. $config_object->forceTable('glpi_config');
  91. if ($config_object->getFromDB(1)) {
  92. $config_ok = true;
  93. }
  94. }
  95. }
  96. if ($config_ok) {
  97. $CFG_GLPI = array_merge($CFG_GLPI,$config_object->fields);
  98. if (isset($config_object->fields['priority_matrix'])) {
  99. $CFG_GLPI['priority_matrix'] = importArrayFromDB($config_object->fields['priority_matrix'],
  100. true);
  101. }
  102. // Path for icon of document type
  103. $CFG_GLPI["typedoc_icon_dir"] = $CFG_GLPI["root_doc"]."/pics/icones";
  104. } else {
  105. echo "Error accessing config table";
  106. exit();
  107. }
  108. if (isCommandLine() && isset($_SERVER['argv'])) {
  109. $key = array_search('--debug', $_SERVER['argv']);
  110. if ($key) {
  111. $_SESSION['glpi_use_mode'] = Session::DEBUG_MODE;
  112. unset($_SERVER['argv'][$key]);
  113. $_SERVER['argv']= array_values($_SERVER['argv']);
  114. $_SERVER['argc']--;
  115. }
  116. }
  117. // If debug mode activated : display some informations
  118. if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
  119. // display_errors only need for for E_ERROR, E_PARSE, ... which cannot be catched
  120. ini_set('display_errors','On');
  121. // Recommended development settings
  122. error_reporting(E_ALL | E_STRICT);
  123. set_error_handler(array('Toolbox','userErrorHandlerDebug'));
  124. } else {
  125. // Recommended production settings
  126. ini_set('display_errors','Off');
  127. if (defined('E_DEPRECATED')) {
  128. error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
  129. } else {
  130. error_reporting(E_ALL & ~E_STRICT);
  131. }
  132. set_error_handler(array('Toolbox', 'userErrorHandlerNormal'));
  133. }
  134. if (isset($_SESSION["glpiroot"]) && $CFG_GLPI["root_doc"]!=$_SESSION["glpiroot"]) {
  135. Html::redirect($_SESSION["glpiroot"]);
  136. }
  137. // Override cfg_features by session value
  138. foreach ($CFG_GLPI['user_pref_field'] as $field) {
  139. if (!isset($_SESSION["glpi$field"]) && isset($CFG_GLPI[$field])) {
  140. $_SESSION["glpi$field"] = $CFG_GLPI[$field];
  141. }
  142. }
  143. if ((!isset($CFG_GLPI["version"]) || trim($CFG_GLPI["version"])!=GLPI_VERSION)
  144. && !isset($_GET["donotcheckversion"])) {
  145. Session::loadLanguage();
  146. if (isCommandLine()) {
  147. echo $LANG['update'][88] . "\n";
  148. } else {
  149. Html::nullHeader("UPDATE NEEDED",$CFG_GLPI["root_doc"]);
  150. echo "<div class='center'>";
  151. echo "<table class='tab_check'>";
  152. $error = Toolbox::commonCheckForUseGLPI();
  153. echo "</table><br>";
  154. if ($error) {
  155. echo "<form action='".$CFG_GLPI["root_doc"]."/index.php' method='post'>";
  156. echo "<input type='submit' name='submit' class='submit' value=\"".
  157. $LANG['install'][27]."\">";
  158. Html::closeForm();
  159. }
  160. if ($error < 2) {
  161. if (!isset($CFG_GLPI["version"]) || trim($CFG_GLPI["version"])<GLPI_VERSION) {
  162. echo "<form method='post' action='".$CFG_GLPI["root_doc"]."/install/update.php'>";
  163. echo "<p class='red'>".$LANG['update'][88]."</p>";
  164. echo "<input type='submit' name='from_update' value=\"".$LANG['install'][4].
  165. "\" class='submit'>";
  166. Html::closeForm();
  167. } else if (trim($CFG_GLPI["version"])>GLPI_VERSION) {
  168. echo "<p class='red'>".$LANG['update'][89]."</p>";
  169. }
  170. }
  171. echo "</div>";
  172. Html::nullFooter();
  173. }
  174. exit();
  175. }
  176. }
  177. ?>