dolibarr  16.0.5
master.inc.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
4  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
9  * Copyright (C) 2006 Andre Cianfarani <andre.cianfarani@acdeveloppement.net>
10  * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
11  * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
12  * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  */
27 
35 // Include the conf.php and functions.lib.php and security.lib.php. This defined the constants like DOL_DOCUMENT_ROOT, DOL_DATA_ROOT, DOL_URL_ROOT...
36 // This file may have been already required by main.inc.php. But may not by scripts. So, here the require_once must be kept.
37 require_once 'filefunc.inc.php';
38 
39 
40 if (!function_exists('is_countable')) {
46  function is_countable($c)
47  {
48  return is_array($c) || $c instanceof Countable;
49  }
50 }
51 
52 /*
53  * Create $conf object
54  */
55 
56 require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
57 
58 $conf = new Conf();
59 
60 // Set properties specific to database
61 $conf->db->host = $dolibarr_main_db_host;
62 $conf->db->port = $dolibarr_main_db_port;
63 $conf->db->name = $dolibarr_main_db_name;
64 $conf->db->user = $dolibarr_main_db_user;
65 $conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass;
66 $conf->db->type = $dolibarr_main_db_type;
67 $conf->db->prefix = $dolibarr_main_db_prefix;
68 $conf->db->character_set = $dolibarr_main_db_character_set;
69 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
70 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
71 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
72 if (defined('TEST_DB_FORCE_TYPE')) {
73  $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example)
74 }
75 
76 // Set properties specific to conf file
77 $conf->file->main_limit_users = $dolibarr_main_limit_users;
78 $conf->file->mailing_limit_sendbyweb = empty($dolibarr_mailing_limit_sendbyweb) ? 0 : $dolibarr_mailing_limit_sendbyweb;
79 $conf->file->mailing_limit_sendbycli = empty($dolibarr_mailing_limit_sendbycli) ? 0 : $dolibarr_mailing_limit_sendbycli;
80 $conf->file->mailing_limit_sendbyday = empty($dolibarr_mailing_limit_sendbyday) ? 0 : $dolibarr_mailing_limit_sendbyday;
81 $conf->file->main_authentication = empty($dolibarr_main_authentication) ? '' : $dolibarr_main_authentication; // Identification mode
82 $conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https; // Force https
83 $conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_mode; // Force php strict mode (for debug)
84 $conf->file->instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ? '' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id; // Unique id of instance
85 $conf->file->dol_document_root = array('main' => (string) DOL_DOCUMENT_ROOT); // Define array of document root directories ('/home/htdocs')
86 $conf->file->dol_url_root = array('main' => (string) DOL_URL_ROOT); // Define array of url root path ('' or '/dolibarr')
87 if (!empty($dolibarr_main_document_root_alt)) {
88  // dolibarr_main_document_root_alt can contains several directories
89  $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
90  $i = 0;
91  foreach ($values as $value) {
92  $conf->file->dol_document_root['alt'.($i++)] = (string) $value;
93  }
94  $values = preg_split('/[;,]/', $dolibarr_main_url_root_alt);
95  $i = 0;
96  foreach ($values as $value) {
97  if (preg_match('/^http(s)?:/', $value)) {
98  // Show error message
99  $correct_value = str_replace($dolibarr_main_url_root, '', $value);
100  print '<b>Error:</b><br>'."\n";
101  print 'Wrong <b>$dolibarr_main_url_root_alt</b> value in <b>conf.php</b> file.<br>'."\n";
102  print 'We now use a relative path to $dolibarr_main_url_root to build alternate URLs.<br>'."\n";
103  print 'Value found: '.$value.'<br>'."\n";
104  print 'Should be replaced by: '.$correct_value.'<br>'."\n";
105  print "Or something like following examples:<br>\n";
106  print "\"/extensions\"<br>\n";
107  print "\"/extensions1,/extensions2,...\"<br>\n";
108  print "\"/../extensions\"<br>\n";
109  print "\"/custom\"<br>\n";
110  exit;
111  }
112  $conf->file->dol_url_root['alt'.($i++)] = (string) $value;
113  }
114 }
115 
116 // Chargement des includes principaux de librairies communes
117 if (!defined('NOREQUIREUSER')) {
118  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Need 500ko memory
119 }
120 if (!defined('NOREQUIRETRAN')) {
121  require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
122 }
123 if (!defined('NOREQUIRESOC')) {
124  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
125 }
126 
127 
128 /*
129  * Creation objet $langs (must be before all other code)
130  */
131 if (!defined('NOREQUIRETRAN')) {
132  $langs = new Translate('', $conf); // Must be after reading conf
133 }
134 
135 /*
136  * Object $db
137  */
138 $db = null;
139 if (!defined('NOREQUIREDB')) {
140  $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
141 
142  if ($db->error) {
143  // If we were into a website context
144  if (!defined('USEDOLIBARREDITOR') && !defined('USEDOLIBARRSERVER') && !empty($_SERVER['SCRIPT_FILENAME']) && (strpos($_SERVER['SCRIPT_FILENAME'], DOL_DATA_ROOT.'/website') === 0)) {
145  $sapi_type = php_sapi_name();
146  if (substr($sapi_type, 0, 3) != 'cgi') {
147  http_response_code(503); // To tel search engine this is a temporary error
148  }
149  print '<div class="center" style="text-align: center; margin: 100px;">';
150  if (is_object($langs)) {
151  $langs->setDefaultLang('auto');
152  $langs->load("website");
153  print $langs->trans("SorryWebsiteIsCurrentlyOffLine");
154  } else {
155  print "SorryWebsiteIsCurrentlyOffLine";
156  }
157  print '</div>';
158  exit;
159  }
160  dol_print_error($db, "host=".$conf->db->host.", port=".$conf->db->port.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error);
161  exit;
162  }
163 }
164 
165 // Now database connexion is known, so we can forget password
166 //unset($dolibarr_main_db_pass); // We comment this because this constant is used in some other pages
167 unset($conf->db->pass); // This is to avoid password to be shown in memory/swap dump
168 
169 
170 /*
171  * Object $user
172  */
173 if (!defined('NOREQUIREUSER')) {
174  $user = new User($db);
175 }
176 
177 
178 /*
179  * Load object $conf
180  */
181 
182 // By default conf->entity is 1, but we change this if we ask another value.
183 if (session_id() && !empty($_SESSION["dol_entity"])) {
184  // Entity inside an opened session
185  $conf->entity = $_SESSION["dol_entity"];
186 } elseif (!empty($_ENV["dol_entity"])) {
187  // Entity inside a CLI script
188  $conf->entity = $_ENV["dol_entity"];
189 } elseif (GETPOSTISSET("loginfunction") && GETPOST("entity", 'int')) {
190  // Just after a login page
191  $conf->entity = GETPOST("entity", 'int');
192 } elseif (defined('DOLENTITY') && is_numeric(constant('DOLENTITY'))) {
193  // For public page with MultiCompany module
194  $conf->entity = constant('DOLENTITY');
195 }
196 // Sanitize entity
197 if (!is_numeric($conf->entity)) {
198  $conf->entity = 1;
199 }
200 // Here we read database (llx_const table) and define $conf->global->XXX var.
201 //print "We work with data into entity instance number '".$conf->entity."'";
202 $conf->setValues($db);
203 
204 // Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr.
205 if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) {
206  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
207 
208  $mysoc = new Societe($db);
209  $mysoc->setMysoc($conf);
210 
211  // For some countries, we need to invert our address with customer address
212  if ($mysoc->country_code == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
213  $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1;
214  }
215 }
216 
217 
218 // Set default language (must be after the setValues setting global $conf->global->MAIN_LANG_DEFAULT. Page main.inc.php will overwrite langs->defaultlang with user value later)
219 if (!defined('NOREQUIRETRAN')) {
220  $langcode = (GETPOST('lang', 'aZ09') ? GETPOST('lang', 'aZ09', 1) : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
221  if (defined('MAIN_LANG_DEFAULT')) { // So a page can force the language whatever is setup and parameters in URL
222  $langcode = constant('MAIN_LANG_DEFAULT');
223  }
224  $langs->setDefaultLang($langcode);
225 }
226 
227 
228 // Create the global $hookmanager object
229 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
230 $hookmanager = new HookManager($db);
231 
232 
233 if (!defined('MAIN_LABEL_MENTION_NPR')) {
234  define('MAIN_LABEL_MENTION_NPR', 'NPR');
235 }
236 //if (! defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', $conf->user->dir_temp);
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
Translate
Class to manage translations.
Definition: translate.class.php:30
getDoliDBInstance
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
Definition: functions.lib.php:122
Conf
Class to stock current configuration.
Definition: conf.class.php:33
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30