dolibarr 22.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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
36// 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...
37// This file may have been already required by main.inc.php. But may not by scripts. So, here the require_once must be kept.
38require_once 'filefunc.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
48'
49@phan-var-force ?string $dolibarr_main_db_prefix
50@phan-var-force ?string $dolibarr_main_db_encryption
51@phan-var-force ?string $dolibarr_main_db_cryptkey
52@phan-var-force ?string $dolibarr_main_limit_users
53@phan-var-force ?string $dolibarr_main_url_root_alt
54';
55
56if (!function_exists('is_countable')) {
63 function is_countable($c)
64 {
65 return is_array($c) || $c instanceof Countable;
66 }
67}
68
69/*
70 * Create $conf object
71 */
72
73$conf = new Conf();
74
75// Set properties specific to database
76$conf->db->host = empty($dolibarr_main_db_host) ? '' : $dolibarr_main_db_host;
77$conf->db->port = empty($dolibarr_main_db_port) ? '' : $dolibarr_main_db_port;
78$conf->db->name = empty($dolibarr_main_db_name) ? '' : $dolibarr_main_db_name;
79$conf->db->user = empty($dolibarr_main_db_user) ? '' : $dolibarr_main_db_user;
80$conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass;
81$conf->db->type = $dolibarr_main_db_type;
82$conf->db->prefix = $dolibarr_main_db_prefix;
83$conf->db->character_set = $dolibarr_main_db_character_set;
84$conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
85$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
86$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
87if (defined('TEST_DB_FORCE_TYPE')) {
88 $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example)
89}
90
91// Set properties specific to conf file
92$conf->file->main_limit_users = $dolibarr_main_limit_users;
93$conf->file->mailing_limit_sendbyweb = empty($dolibarr_mailing_limit_sendbyweb) ? 0 : $dolibarr_mailing_limit_sendbyweb;
94$conf->file->mailing_limit_sendbycli = empty($dolibarr_mailing_limit_sendbycli) ? 0 : $dolibarr_mailing_limit_sendbycli;
95$conf->file->mailing_limit_sendbyday = empty($dolibarr_mailing_limit_sendbyday) ? 0 : $dolibarr_mailing_limit_sendbyday;
96$conf->file->main_authentication = empty($dolibarr_main_authentication) ? 'dolibarr' : $dolibarr_main_authentication; // Identification mode
97$conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https; // Force https
98$conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_mode; // Force php strict mode (for debug)
99$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
100$conf->file->dol_main_url_root = $dolibarr_main_url_root; // Define url inside the config file
101$conf->file->dol_document_root = array('main' => (string) DOL_DOCUMENT_ROOT); // Define an array of document root directories ('/home/htdocs')
102$conf->file->dol_url_root = array('main' => (string) DOL_URL_ROOT); // Define an array of url root path ('' or '/dolibarr')
103if (!empty($dolibarr_main_document_root_alt)) {
104 // dolibarr_main_document_root_alt can contains several directories
105 $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
106 $i = 0;
107 foreach ($values as $value) {
108 $conf->file->dol_document_root['alt'.($i++)] = (string) $value;
109 }
110 $values = preg_split('/[;,]/', (string) $dolibarr_main_url_root_alt);
111 $i = 0;
112 foreach ($values as $value) {
113 if (preg_match('/^http(s)?:/', $value)) {
114 // Show error message
115 $correct_value = str_replace($dolibarr_main_url_root, '', $value);
116 print '<b>Error:</b><br>'."\n";
117 print 'Wrong <b>$dolibarr_main_url_root_alt</b> value in <b>conf.php</b> file.<br>'."\n";
118 print 'We now use a relative path to $dolibarr_main_url_root to build alternate URLs.<br>'."\n";
119 print 'Value found: '.$value.'<br>'."\n";
120 print 'Should be replaced by: '.$correct_value.'<br>'."\n";
121 print "Or something like following examples:<br>\n";
122 print "\"/extensions\"<br>\n";
123 print "\"/extensions1,/extensions2,...\"<br>\n";
124 print "\"/../extensions\"<br>\n";
125 print "\"/custom\"<br>\n";
126 exit;
127 }
128 $conf->file->dol_url_root['alt'.($i++)] = (string) $value;
129 }
130}
131
132// Load the main includes of common libraries
133if (!defined('NOREQUIREUSER')) {
134 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Need 500ko memory
135}
136if (!defined('NOREQUIRETRAN')) {
137 require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
138}
139if (!defined('NOREQUIRESOC')) {
140 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
141}
142
143
144/*
145 * Create object $langs (must be before all other code)
146 */
147if (!defined('NOREQUIRETRAN')) {
148 $langs = new Translate('', $conf); // Must be after reading conf
149}
150
151/*
152 * Object $db
153 */
154$db = null;
155if (!defined('NOREQUIREDB')) {
156 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
157
158 if ($db->error) {
159 // If we were into a website context
160 if (!defined('USEDOLIBARREDITOR') && !defined('USEDOLIBARRSERVER') && !empty($_SERVER['SCRIPT_FILENAME']) && (strpos($_SERVER['SCRIPT_FILENAME'], DOL_DATA_ROOT.'/website') === 0)) {
161 $sapi_type = php_sapi_name();
162 if (substr($sapi_type, 0, 3) != 'cgi') {
163 http_response_code(503); // To tel search engine this is a temporary error
164 }
165 print '<div class="center" style="text-align: center; margin: 100px;">';
166 if (is_object($langs)) {
167 $langs->setDefaultLang('auto');
168 $langs->load("website");
169 print $langs->trans("SorryWebsiteIsCurrentlyOffLine");
170 } else {
171 print "SorryWebsiteIsCurrentlyOffLine";
172 }
173 print '</div>';
174 exit(1);
175 }
176 dol_print_error($db, "host=".$conf->db->host.", port=".$conf->db->port.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error);
177 exit(1);
178 }
179}
180
181// Now database connection is known, so we can forget password
182//unset($dolibarr_main_db_pass); // We comment this because this constant is used in some other pages
183unset($conf->db->pass); // This is to avoid password to be shown in memory/swap dump
184
185
186/*
187 * Object $user
188 */
189if (!defined('NOREQUIREUSER')) {
190 $user = new User($db);
191}
192
193/*
194 * Create the global $hookmanager object
195 */
196$hookmanager = new HookManager($db);
197
198
199/*
200 * Load object $conf
201 */
202
203// By default conf->entity is 1, but we change this if we ask another value.
204if (session_id() && !empty($_SESSION["dol_entity"])) {
205 // Entity inside an opened session
206 $conf->entity = $_SESSION["dol_entity"];
207} elseif (!empty($_ENV["dol_entity"])) {
208 // Entity inside a CLI script
209 $conf->entity = $_ENV["dol_entity"];
210} elseif (GETPOSTISSET("loginfunction") && (GETPOSTINT("entity") || GETPOSTINT("switchentity"))) {
211 // Just after a login page
212 $conf->entity = (GETPOSTISSET("entity") ? GETPOSTINT("entity") : GETPOSTINT("switchentity"));
213} elseif (defined('DOLENTITY') && is_numeric(constant('DOLENTITY'))) {
214 // For public page with MultiCompany module
215 $conf->entity = constant('DOLENTITY');
216}
217// Sanitize entity
218if (!is_numeric($conf->entity)) {
219 $conf->entity = 1;
220}
221// Here we read database (llx_const table) and define conf var $conf->global->XXX.
222//print "We work with data into entity instance number '".$conf->entity."'";
223if ($db !== null) {
224 $conf->setValues($db);
225}
226
227// Set default language (must be after the setValues setting global conf 'MAIN_LANG_DEFAULT'. Page main.inc.php will overwrite langs->defaultlang with user value later)
228if (!defined('NOREQUIRETRAN')) {
229 $langcode = (GETPOST('lang', 'aZ09') ? GETPOST('lang', 'aZ09', 1) : getDolGlobalString('MAIN_LANG_DEFAULT', 'auto'));
230 if (defined('MAIN_LANG_DEFAULT')) { // So a page can force the language whatever is setup and parameters in URL
231 $langcode = constant('MAIN_LANG_DEFAULT');
232 }
233 $langs->setDefaultLang($langcode);
234}
235
236// Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr.
237if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC') && $db != null) {
238 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
239
240 $mysoc = new Societe($db);
241 $mysoc->setMysoc($conf);
242
243 // We set some specific default values according to country
244
245 if ($mysoc->country_code == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
246 // For DE, we need to invert our address with customer address
247 $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1;
248 }
249 if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_CATEGORY_OF_OPERATION)) {
250 // For FR, default value of option to show category of operations is on by default. Decret n°2099-1299 2022-10-07
251 $conf->global->INVOICE_CATEGORY_OF_OPERATION = 1;
252 }
253 if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
254 // For FR, the replacement invoice type is not allowed.
255 // From an accounting point of view, this creates holes in the numbering of the invoice.
256 // This is very problematic during a fiscal control.
257 $conf->global->INVOICE_DISABLE_REPLACEMENT = 1;
258 }
259 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
260 // The replacement invoice type is not allowed in Greece.
261 $conf->global->INVOICE_DISABLE_REPLACEMENT = 1;
262 }
263 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_DISABLE_DEPOSIT)) {
264 // The deposit invoice type is not allowed in Greece.
265 $conf->global->INVOICE_DISABLE_DEPOSIT = 1;
266 }
267 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
268 // Standalone credit note is compulsory in Greece.
269 $conf->global->INVOICE_CREDIT_NOTE_STANDALONE = 1;
270 }
271 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_SUBTYPE_ENABLED)) {
272 // Invoice subtype is a requirement for Greece.
273 $conf->global->INVOICE_SUBTYPE_ENABLED = 1;
274 }
275
276 if (($mysoc->localtax1_assuj || $mysoc->localtax2_assuj) && !isset($conf->global->MAIN_NO_INPUT_PRICE_WITH_TAX)) {
277 // For countries using the 2nd or 3rd tax, we disable input/edit of lines using the price including tax (because 2nb and 3rd tax not yet taken into account).
278 // Work In Progress to support all taxes into unit price entry when MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES is set.
279 $conf->global->MAIN_NO_INPUT_PRICE_WITH_TAX = 1;
280 }
281}
global $dolibarr_main_url_root
$c
Definition line.php:331
Class to stock current configuration.
Class to manage hooks.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
$dolibarr_main_url_root_alt
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79