inc.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  4. * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/support/inc.php
  22. * \ingroup core
  23. * \brief File that define environment for support pages
  24. */
  25. // Define DOL_DOCUMENT_ROOT
  26. if (! defined('DOL_DOCUMENT_ROOT')) define('DOL_DOCUMENT_ROOT', '..');
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. // Avoid warnings with strict mode E_STRICT
  32. $conf = new stdClass(); // instantiate $conf explicitely
  33. $conf->global = new stdClass();
  34. $conf->file = new stdClass();
  35. $conf->db = new stdClass();
  36. $conf->syslog = new stdClass();
  37. // Force $_REQUEST["logtohtml"]
  38. $_REQUEST["logtohtml"]=1;
  39. // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
  40. // et non path absolu.
  41. if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"])
  42. {
  43. $_SERVER["PHP_SELF"]=$_SERVER["DOCUMENT_URI"];
  44. }
  45. $includeconferror='';
  46. // Define vars
  47. $conffiletoshowshort = "conf.php";
  48. // Define localization of conf file
  49. $conffile = "../conf/conf.php";
  50. $conffiletoshow = "htdocs/conf/conf.php";
  51. // For debian/redhat like systems
  52. if (! file_exists($conffile))
  53. {
  54. $conffile = "/etc/dolibarr/conf.php";
  55. $conffiletoshow = "/etc/dolibarr/conf.php";
  56. }
  57. // Load conf file if it is already defined
  58. if (! defined('DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > 8) // Test on filesize is to ensure that conf file is more that an empty template with just <?php in first line
  59. {
  60. $result=include_once $conffile; // Load conf file
  61. if ($result)
  62. {
  63. if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysql'; // For backward compatibility
  64. //Mysql driver support has been removed in favor of mysqli
  65. if ($dolibarr_main_db_type == 'mysql') {
  66. $dolibarr_main_db_type = 'mysqli';
  67. }
  68. if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type=='mysqli')) $dolibarr_main_db_port='3306'; // For backward compatibility
  69. // Clean parameters
  70. $dolibarr_main_data_root =isset($dolibarr_main_data_root)?trim($dolibarr_main_data_root):'';
  71. $dolibarr_main_url_root =isset($dolibarr_main_url_root)?trim($dolibarr_main_url_root):'';
  72. $dolibarr_main_url_root_alt =isset($dolibarr_main_url_root_alt)?trim($dolibarr_main_url_root_alt):'';
  73. $dolibarr_main_document_root =isset($dolibarr_main_document_root)?trim($dolibarr_main_document_root):'';
  74. $dolibarr_main_document_root_alt=isset($dolibarr_main_document_root_alt)?trim($dolibarr_main_document_root_alt):'';
  75. // Remove last / or \ on directories or url value
  76. if (! empty($dolibarr_main_document_root) && ! preg_match('/^[\\/]+$/',$dolibarr_main_document_root)) $dolibarr_main_document_root=preg_replace('/[\\/]+$/','',$dolibarr_main_document_root);
  77. if (! empty($dolibarr_main_url_root) && ! preg_match('/^[\\/]+$/',$dolibarr_main_url_root)) $dolibarr_main_url_root=preg_replace('/[\\/]+$/','',$dolibarr_main_url_root);
  78. if (! empty($dolibarr_main_data_root) && ! preg_match('/^[\\/]+$/',$dolibarr_main_data_root)) $dolibarr_main_data_root=preg_replace('/[\\/]+$/','',$dolibarr_main_data_root);
  79. if (! empty($dolibarr_main_document_root_alt) && ! preg_match('/^[\\/]+$/',$dolibarr_main_document_root_alt)) $dolibarr_main_document_root_alt=preg_replace('/[\\/]+$/','',$dolibarr_main_document_root_alt);
  80. if (! empty($dolibarr_main_url_root_alt) && ! preg_match('/^[\\/]+$/',$dolibarr_main_url_root_alt)) $dolibarr_main_url_root_alt=preg_replace('/[\\/]+$/','',$dolibarr_main_url_root_alt);
  81. // Create conf object
  82. if (! empty($dolibarr_main_document_root))
  83. {
  84. $result=conf($dolibarr_main_document_root);
  85. }
  86. // Load database driver
  87. if ($result)
  88. {
  89. if (! empty($dolibarr_main_document_root) && ! empty($dolibarr_main_db_type))
  90. {
  91. $result=include_once $dolibarr_main_document_root . "/core/db/".$dolibarr_main_db_type.'.class.php';
  92. if (! $result)
  93. {
  94. $includeconferror='ErrorBadValueForDolibarrMainDBType';
  95. }
  96. }
  97. }
  98. else
  99. {
  100. $includeconferror='ErrorBadValueForDolibarrMainDocumentRoot';
  101. }
  102. }
  103. else
  104. {
  105. $includeconferror='ErrorBadFormatForConfFile';
  106. }
  107. }
  108. $conf->global->MAIN_LOGTOHTML = 1;
  109. // Define prefix
  110. if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_';
  111. define('MAIN_DB_PREFIX',(isset($dolibarr_main_db_prefix)?$dolibarr_main_db_prefix:''));
  112. define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
  113. define('DOL_DATA_ROOT',(isset($dolibarr_main_data_root)?$dolibarr_main_data_root:''));
  114. define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root)?$dolibarr_main_url_root:'')); // URL relative root
  115. $uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
  116. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  117. if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now ''
  118. define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
  119. if (empty($character_set_client)) $character_set_client="UTF-8";
  120. $conf->file->character_set_client=strtoupper($character_set_client);
  121. if (empty($dolibarr_main_db_character_set)) $dolibarr_main_db_character_set=($conf->db->type=='mysql'?'latin1':''); // Old installation
  122. $conf->db->character_set=$dolibarr_main_db_character_set;
  123. if (empty($dolibarr_main_db_collation)) $dolibarr_main_db_collation=($conf->db->type=='mysql'?'latin1_swedish_ci':''); // Old installation
  124. $conf->db->dolibarr_main_db_collation=$dolibarr_main_db_collation;
  125. if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0;
  126. $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
  127. if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey='';
  128. $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
  129. if (empty($conf->db->user)) $conf->db->user='';
  130. // Defini objet langs
  131. $langs = new Translate('..',$conf);
  132. if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
  133. else $langs->setDefaultLang('auto');
  134. $bc[false]=' class="bg1"';
  135. $bc[true]=' class="bg2"';
  136. /**
  137. * Load conf file (file must exists)
  138. *
  139. * @param string $dolibarr_main_document_root Root directory of Dolibarr bin files
  140. * @return int <0 if KO, >0 if OK
  141. */
  142. function conf($dolibarr_main_document_root)
  143. {
  144. global $conf;
  145. global $dolibarr_main_db_type;
  146. global $dolibarr_main_db_host;
  147. global $dolibarr_main_db_port;
  148. global $dolibarr_main_db_name;
  149. global $dolibarr_main_db_user;
  150. global $dolibarr_main_db_pass;
  151. global $character_set_client;
  152. $return=include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
  153. if (! $return) return -1;
  154. $conf=new Conf();
  155. $conf->db->type = trim($dolibarr_main_db_type);
  156. $conf->db->host = trim($dolibarr_main_db_host);
  157. $conf->db->port = trim($dolibarr_main_db_port);
  158. $conf->db->name = trim($dolibarr_main_db_name);
  159. $conf->db->user = trim($dolibarr_main_db_user);
  160. $conf->db->pass = trim($dolibarr_main_db_pass);
  161. if (empty($conf->db->dolibarr_main_db_collation)) $conf->db->dolibarr_main_db_collation='utf8_unicode_ci';
  162. return 1;
  163. }
  164. /**
  165. * Show HTML header
  166. *
  167. * @param string $soutitre Title
  168. * @param string $next Next
  169. * @param string $action Action code
  170. * @return void
  171. */
  172. function pHeader($soutitre,$next,$action='none')
  173. {
  174. global $conf;
  175. global $langs;
  176. $langs->load("main");
  177. $langs->load("admin");
  178. // On force contenu dans format sortie
  179. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  180. header("X-Content-Type-Options: nosniff");
  181. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
  182. print '<html manifest="'.DOL_URL_ROOT.'/cache.manifest">'."\n";
  183. print '<head>'."\n";
  184. print '<meta http-equiv="content-type" content="text/html; charset='.$conf->file->character_set_client.'">'."\n";
  185. print '<meta name="robots" content="index,follow">'."\n";
  186. print '<meta name="keywords" content="help, center, dolibarr, doliwamp">'."\n";
  187. print '<meta name="description" content="Dolibarr help center">'."\n";
  188. print '<link rel="stylesheet" type="text/css" href="default.css">'."\n";
  189. print '<title>'.$langs->trans("DolibarrHelpCenter").'</title>'."\n";
  190. print '</head>'."\n";
  191. print '<body>'."\n";
  192. print '<table class="noborder" summary="helpcentertitle"><tr valign="middle">';
  193. print '<td width="20">';
  194. print '<img src="helpcenter.png" alt="logohelpcenter">';
  195. print '</td>';
  196. print '<td>';
  197. print '<span class="titre">'.$soutitre.'</span>'."\n";
  198. print '</td></tr></table>';
  199. }
  200. /**
  201. * Print HTML footer
  202. *
  203. * @param integer $nonext No button "Next step"
  204. * @param string $setuplang Language code
  205. * @return void
  206. */
  207. function pFooter($nonext=0,$setuplang='')
  208. {
  209. global $langs;
  210. $langs->load("main");
  211. $langs->load("admin");
  212. print '</body>'."\n";
  213. print '</html>'."\n";
  214. }