dolibarr  20.0.0-alpha
inc.php
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/>.
19  */
20 
27 // Define DOL_DOCUMENT_ROOT
28 if (!defined('DOL_DOCUMENT_ROOT')) {
29  define('DOL_DOCUMENT_ROOT', '..');
30 }
31 
32 require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37 
38 $conf = new Conf();
39 
40 // Force $_REQUEST["logtohtml"]
41 $_REQUEST["logtohtml"] = 1;
42 
43 // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
44 // et non path absolu.
45 if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
46  $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
47 }
48 
49 
50 $includeconferror = '';
51 
52 // Define vars
53 $conffiletoshowshort = "conf.php";
54 // Define localization of conf file
55 $conffile = "../conf/conf.php";
56 $conffiletoshow = "htdocs/conf/conf.php";
57 // For debian/redhat like systems
58 /*
59 if (!file_exists($conffile)) {
60  $conffile = "/etc/dolibarr/conf.php";
61  $conffiletoshow = "/etc/dolibarr/conf.php";
62 }
63 */
64 
65 // Load conf file if it is already defined
66 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
67  $result = include_once $conffile; // Load conf file
68  if ($result) {
69  if (empty($dolibarr_main_db_type)) {
70  $dolibarr_main_db_type = 'mysql'; // For backward compatibility
71  }
72 
73  //Mysql driver support has been removed in favor of mysqli
74  if ($dolibarr_main_db_type == 'mysql') {
75  $dolibarr_main_db_type = 'mysqli';
76  }
77 
78  if (!isset($dolibarr_main_db_port) && ($dolibarr_main_db_type == 'mysqli')) {
79  $dolibarr_main_db_port = '3306'; // For backward compatibility
80  }
81 
82  // Clean parameters
83  $dolibarr_main_data_root = isset($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : '';
84  $dolibarr_main_url_root = isset($dolibarr_main_url_root) ? trim($dolibarr_main_url_root) : '';
85  $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ? trim($dolibarr_main_url_root_alt) : '';
86  $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) : '';
87  $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ? trim($dolibarr_main_document_root_alt) : '';
88 
89  // Remove last / or \ on directories or url value
90  if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) {
91  $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
92  }
93  if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) {
94  $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
95  }
96  if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) {
97  $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
98  }
99  if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
100  $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt);
101  }
102  if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
103  $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt);
104  }
105 
106  // Create conf object
107  if (!empty($dolibarr_main_document_root)) {
108  $result = loadconf($dolibarr_main_document_root);
109  }
110  // Load database driver
111  if ($result) {
112  if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
113  $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php';
114  if (!$result) {
115  $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
116  }
117  }
118  } else {
119  $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
120  }
121  } else {
122  $includeconferror = 'ErrorBadFormatForConfFile';
123  }
124 }
125 $conf->global->MAIN_LOGTOHTML = 1;
126 
127 // Define prefix
128 if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
129  $dolibarr_main_db_prefix = 'llx_';
130 }
131 define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
132 
133 define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir
134 define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : ''));
135 define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root
136 $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
137 $suburi = strstr($uri, '/'); // $suburi contains url without domain
138 if ($suburi == '/') {
139  $suburi = ''; // If $suburi is /, it is now ''
140 }
141 define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
142 
143 if (empty($character_set_client)) {
144  $character_set_client = "UTF-8";
145 }
146 $conf->file->character_set_client = strtoupper($character_set_client);
147 if (empty($dolibarr_main_db_character_set)) {
148  $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : ''); // Old installation
149 }
150 $conf->db->character_set = $dolibarr_main_db_character_set;
151 if (empty($dolibarr_main_db_collation)) {
152  $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : ''); // Old installation
153 }
154 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
155 if (empty($dolibarr_main_db_encryption)) {
156  $dolibarr_main_db_encryption = 0;
157 }
158 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
159 if (empty($dolibarr_main_db_cryptkey)) {
160  $dolibarr_main_db_cryptkey = '';
161 }
162 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
163 
164 if (empty($conf->db->user)) {
165  $conf->db->user = '';
166 }
167 
168 
169 // Defini object langs
170 $langs = new Translate('..', $conf);
171 if (GETPOST('lang', 'aZ09')) {
172  $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
173 } else {
174  $langs->setDefaultLang('auto');
175 }
176 
177 
184 function loadconf($dolibarr_main_document_root)
185 {
186  global $conf;
187  global $dolibarr_main_db_type;
188  global $dolibarr_main_db_host;
189  global $dolibarr_main_db_port;
190  global $dolibarr_main_db_name;
191  global $dolibarr_main_db_user;
192  global $dolibarr_main_db_pass;
193  global $character_set_client;
194 
195  $return = 1;
196  if (!class_exists('Conf')) {
197  $return = include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
198  }
199  if (!$return) {
200  return -1;
201  }
202 
203  $conf = new Conf();
204  $conf->db->type = trim($dolibarr_main_db_type);
205  $conf->db->host = trim($dolibarr_main_db_host);
206  $conf->db->port = trim($dolibarr_main_db_port);
207  $conf->db->name = trim($dolibarr_main_db_name);
208  $conf->db->user = trim($dolibarr_main_db_user);
209  $conf->db->pass = trim($dolibarr_main_db_pass);
210 
211  if (empty($conf->db->dolibarr_main_db_collation)) {
212  $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
213  }
214 
215  return 1;
216 }
217 
218 
227 function pHeader($soutitre, $next, $action = 'none')
228 {
229  global $conf, $langs;
230 
231  $langs->loadLangs(array("main", "admin"));
232 
233  // On force contenu dans format sortie
234  header("Content-type: text/html; charset=".$conf->file->character_set_client);
235 
236  // Security options
237  header("X-Content-Type-Options: nosniff");
238  header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
239 
240  print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
241  print '<head>'."\n";
242  print '<meta http-equiv="content-type" content="text/html; charset='.$conf->file->character_set_client.'">'."\n";
243  print '<meta name="robots" content="index,follow">'."\n";
244  print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
245  print '<meta name="keywords" content="help, center, dolibarr, doliwamp">'."\n";
246  print '<meta name="description" content="Dolibarr help center">'."\n";
247  print '<link rel="stylesheet" type="text/css" href="../install/default.css">'."\n";
248  print '<title>'.$langs->trans("DolibarrHelpCenter").'</title>'."\n";
249  print '</head>'."\n";
250 
251  print '<body class="center">'."\n";
252 
253  print '<div class="noborder centpercent center valignmiddle inline-block">';
254  print '<img src="helpcenter.png" alt="logohelpcenter" class="inline-block"><br><br>';
255  print '<span class="titre inline-block">'.$soutitre.'</span>'."\n";
256  print '</div><br>';
257 }
258 
266 function pFooter($nonext = 0, $setuplang = '')
267 {
268  global $langs;
269  $langs->load("main");
270  $langs->load("admin");
271 
272  print '</body>'."\n";
273  print '</html>'."\n";
274 }
Class to stock current configuration.
Definition: conf.class.php:34
Class to manage translations.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition: inc.php:534
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition: inc.php:623
loadconf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:184