dolibarr  13.0.2
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')) define('DOL_DOCUMENT_ROOT', '..');
29 
30 require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34 
35 // Avoid warnings with strict mode E_STRICT
36 $conf = new stdClass(); // instantiate $conf explicitely
37 $conf->global = new stdClass();
38 $conf->file = new stdClass();
39 $conf->db = new stdClass();
40 $conf->syslog = new stdClass();
41 
42 // Force $_REQUEST["logtohtml"]
43 $_REQUEST["logtohtml"] = 1;
44 
45 // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
46 // et non path absolu.
47 if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"])
48 {
49  $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
50 }
51 
52 
53 $includeconferror = '';
54 
55 // Define vars
56 $conffiletoshowshort = "conf.php";
57 // Define localization of conf file
58 $conffile = "../conf/conf.php";
59 $conffiletoshow = "htdocs/conf/conf.php";
60 // For debian/redhat like systems
61 if (!file_exists($conffile))
62 {
63  $conffile = "/etc/dolibarr/conf.php";
64  $conffiletoshow = "/etc/dolibarr/conf.php";
65 }
66 
67 
68 // Load conf file if it is already defined
69 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
70 {
71  $result = include_once $conffile; // Load conf file
72  if ($result)
73  {
74  if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type = 'mysql'; // For backward compatibility
75 
76  //Mysql driver support has been removed in favor of mysqli
77  if ($dolibarr_main_db_type == 'mysql') {
78  $dolibarr_main_db_type = 'mysqli';
79  }
80 
81  if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type == 'mysqli')) $dolibarr_main_db_port = '3306'; // For backward compatibility
82 
83  // Clean parameters
84  $dolibarr_main_data_root = isset($dolibarr_main_data_root) ?trim($dolibarr_main_data_root) : '';
85  $dolibarr_main_url_root = isset($dolibarr_main_url_root) ?trim($dolibarr_main_url_root) : '';
86  $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ?trim($dolibarr_main_url_root_alt) : '';
87  $dolibarr_main_document_root = isset($dolibarr_main_document_root) ?trim($dolibarr_main_document_root) : '';
88  $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ?trim($dolibarr_main_document_root_alt) : '';
89 
90  // Remove last / or \ on directories or url value
91  if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
92  if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
93  if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
94  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);
95  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);
96 
97  // Create conf object
98  if (!empty($dolibarr_main_document_root))
99  {
100  $result = conf($dolibarr_main_document_root);
101  }
102  // Load database driver
103  if ($result)
104  {
105  if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type))
106  {
107  $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php';
108  if (!$result)
109  {
110  $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
111  }
112  }
113  } else {
114  $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
115  }
116  } else {
117  $includeconferror = 'ErrorBadFormatForConfFile';
118  }
119 }
120 $conf->global->MAIN_LOGTOHTML = 1;
121 
122 // Define prefix
123 if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) $dolibarr_main_db_prefix = 'llx_';
124 define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
125 
126 define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
127 define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : ''));
128 define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root
129 $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
130 $suburi = strstr($uri, '/'); // $suburi contains url without domain
131 if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now ''
132 define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
133 
134 if (empty($character_set_client)) $character_set_client = "UTF-8";
135 $conf->file->character_set_client = strtoupper($character_set_client);
136 if (empty($dolibarr_main_db_character_set)) $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : ''); // Old installation
137 $conf->db->character_set = $dolibarr_main_db_character_set;
138 if (empty($dolibarr_main_db_collation)) $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : ''); // Old installation
139 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
140 if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption = 0;
141 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
142 if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey = '';
143 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
144 
145 if (empty($conf->db->user)) $conf->db->user = '';
146 
147 
148 // Defini objet langs
149 $langs = new Translate('..', $conf);
150 if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
151 else $langs->setDefaultLang('auto');
152 
153 $bc[false] = ' class="bg1"';
154 $bc[true] = ' class="bg2"';
155 
156 
163 function conf($dolibarr_main_document_root)
164 {
165  global $conf;
166  global $dolibarr_main_db_type;
167  global $dolibarr_main_db_host;
168  global $dolibarr_main_db_port;
169  global $dolibarr_main_db_name;
170  global $dolibarr_main_db_user;
171  global $dolibarr_main_db_pass;
172  global $character_set_client;
173 
174  $return = include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
175  if (!$return) return -1;
176 
177  $conf = new Conf();
178  $conf->db->type = trim($dolibarr_main_db_type);
179  $conf->db->host = trim($dolibarr_main_db_host);
180  $conf->db->port = trim($dolibarr_main_db_port);
181  $conf->db->name = trim($dolibarr_main_db_name);
182  $conf->db->user = trim($dolibarr_main_db_user);
183  $conf->db->pass = trim($dolibarr_main_db_pass);
184 
185  if (empty($conf->db->dolibarr_main_db_collation)) $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
186 
187  return 1;
188 }
189 
190 
199 function pHeader($soutitre, $next, $action = 'none')
200 {
201  global $conf;
202  global $langs;
203  $langs->load("main");
204  $langs->load("admin");
205 
206  // On force contenu dans format sortie
207  header("Content-type: text/html; charset=".$conf->file->character_set_client);
208  header("X-Content-Type-Options: nosniff");
209 
210  print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
211  print '<html manifest="'.DOL_URL_ROOT.'/cache.manifest">'."\n";
212  print '<head>'."\n";
213  print '<meta http-equiv="content-type" content="text/html; charset='.$conf->file->character_set_client.'">'."\n";
214  print '<meta name="robots" content="index,follow">'."\n";
215  print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
216  print '<meta name="keywords" content="help, center, dolibarr, doliwamp">'."\n";
217  print '<meta name="description" content="Dolibarr help center">'."\n";
218  print '<link rel="stylesheet" type="text/css" href="default.css">'."\n";
219  print '<title>'.$langs->trans("DolibarrHelpCenter").'</title>'."\n";
220  print '</head>'."\n";
221 
222  print '<body class="center">'."\n";
223 
224  print '<div class="noborder centpercent center valignmiddle inline-block">';
225  print '<img src="helpcenter.png" alt="logohelpcenter" class="inline-block"><br><br>';
226  print '<span class="titre inline-block">'.$soutitre.'</span>'."\n";
227  print '</div><br>';
228 }
229 
237 function pFooter($nonext = 0, $setuplang = '')
238 {
239  global $langs;
240  $langs->load("main");
241  $langs->load("admin");
242 
243  print '</body>'."\n";
244  print '</html>'."\n";
245 }
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:347
Class to stock current configuration.
Definition: conf.class.php:33
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:262
Class to manage translations.
print $_SERVER["PHP_SELF"]
Edit parameters.
pFooter($nonext=0, $setuplang= '', $jscheckfunction= '', $withpleasewait=0)
Print HTML footer of install pages.
Definition: inc.php:424
print
Draft customers invoices.
Definition: index.php:89