dolibarr 25.0.0-alpha
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 * Copyright (C) 2025-2026 Frédéric France <frederic.france@free.fr>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
37// 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...
38// This file may have been already required by main.inc.php. But may not by scripts. So, here the require_once must be kept.
39require_once 'filefunc.inc.php';
69'
70@phan-var-force ?string $dolibarr_main_db_prefix
71@phan-var-force ?string $dolibarr_main_db_collation
72@phan-var-force ?string $dolibarr_main_db_encryption
73@phan-var-force ?string $dolibarr_main_db_cryptkey
74@phan-var-force ?string $dolibarr_main_limit_users
75@phan-var-force ?string $dolibarr_main_limit_sessions_per_user
76@phan-var-force ?string $dolibarr_main_url_root_alt
77';
78require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
79require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
80
81
82if (!function_exists('is_countable')) {
89 function is_countable($c)
90 {
91 return is_array($c) || $c instanceof Countable;
92 }
93}
94
95
96/*
97 * Define some constants
98 */
99
100if (!defined('EURO')) {
101 define('EURO', chr(128));
102}
103
104// Define syslog constants
105if (!defined('LOG_DEBUG')) {
106 if (!function_exists("syslog")) {
107 // For PHP versions without syslog (like running on Windows OS)
108 define('LOG_EMERG', 0);
109 define('LOG_ALERT', 1);
110 define('LOG_CRIT', 2);
111 define('LOG_ERR', 3);
112 define('LOG_WARNING', 4);
113 define('LOG_NOTICE', 5);
114 define('LOG_INFO', 6);
115 define('LOG_DEBUG', 7);
116 }
117}
118
119if (!defined('SUBTOTALS_SPECIAL_CODE')) {
120 define('SUBTOTALS_SPECIAL_CODE', 81);
121}
122
123
124/*
125 * Disable some not used PHP stream
126 */
127$listofwrappers = stream_get_wrappers();
128// We need '.phar' for geoip2. TODO Replace phar in geoip with exploded files so we can disable phar by default.
129// phar stream does not auto unserialize content (possible code execution) since PHP 8.1
130// zip stream is necessary by excel import module
131$arrayofstreamtodisable = array('compress.zlib', 'compress.bzip2', 'ftp', 'ftps', 'glob', 'data', 'expect', 'ogg', 'rar', 'zlib');
132if (!empty($dolibarr_main_stream_to_disable) && is_array($dolibarr_main_stream_to_disable)) {
133 $arrayofstreamtodisable = $dolibarr_main_stream_to_disable;
134}
135foreach ($arrayofstreamtodisable as $streamtodisable) {
136 if (!empty($listofwrappers) && in_array($streamtodisable, $listofwrappers)) {
137 /*if (!empty($dolibarr_main_stream_do_not_disable) && is_array($dolibarr_main_stream_do_not_disable) && in_array($streamtodisable, $dolibarr_main_stream_do_not_disable)) {
138 continue; // We do not disable this stream
139 }*/
140 stream_wrapper_unregister($streamtodisable);
141 }
142}
143
144
145/*
146 * Create $conf object
147 */
148
149$conf = new Conf();
150
151// Set properties specific to database
152$conf->db->host = empty($dolibarr_main_db_host) ? '' : $dolibarr_main_db_host;
153$conf->db->port = empty($dolibarr_main_db_port) ? '' : $dolibarr_main_db_port;
154$conf->db->name = empty($dolibarr_main_db_name) ? '' : $dolibarr_main_db_name;
155$conf->db->user = empty($dolibarr_main_db_user) ? '' : $dolibarr_main_db_user;
156$conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass;
157$conf->db->type = empty($dolibarr_main_db_type) ? '' : $dolibarr_main_db_type;
158$conf->db->prefix = $dolibarr_main_db_prefix;
159$conf->db->character_set = $dolibarr_main_db_character_set;
160$conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
161$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
162$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
163if (defined('TEST_DB_FORCE_TYPE')) {
164 $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example)
165}
166
167// Set properties specific to conf file
168$conf->file->main_limit_users = $dolibarr_main_limit_users;
169$conf->file->main_limit_sessions_per_user = empty($dolibarr_main_limit_sessions_per_user) ? 0 : $dolibarr_main_limit_sessions_per_user;
170$conf->file->mailing_limit_sendbyweb = empty($dolibarr_mailing_limit_sendbyweb) ? 0 : $dolibarr_mailing_limit_sendbyweb;
171$conf->file->mailing_limit_sendbycli = empty($dolibarr_mailing_limit_sendbycli) ? 0 : $dolibarr_mailing_limit_sendbycli;
172$conf->file->mailing_limit_sendbyday = empty($dolibarr_mailing_limit_sendbyday) ? 0 : $dolibarr_mailing_limit_sendbyday;
173$conf->file->main_authentication = empty($dolibarr_main_authentication) ? 'dolibarr' : $dolibarr_main_authentication; // Identification mode
174$conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https; // Force https
175$conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_mode; // Force php strict mode (for debug)
176$conf->file->restrict_password_generation_none = empty($dolibarr_main_restrict_password_generation_none) ? 0 : $dolibarr_main_restrict_password_generation_none; // Forbid the 'none' password generation model (can only be changed by editing conf.php on the server)
177$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
178$conf->file->dol_main_url_root = $dolibarr_main_url_root; // Define url inside the config file
179$conf->file->dol_document_root = array('main' => (string) DOL_DOCUMENT_ROOT); // Define an array of document root directories ('/home/htdocs')
180$conf->file->dol_url_root = array('main' => (string) DOL_URL_ROOT); // Define an array of url root path ('' or '/dolibarr')
181if (!empty($dolibarr_main_document_root_alt)) {
182 // dolibarr_main_document_root_alt can contains several directories
183 $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
184 $i = 0;
185 foreach ($values as $value) {
186 $conf->file->dol_document_root['alt'.($i++)] = (string) $value;
187 }
188 $values = preg_split('/[;,]/', (string) $dolibarr_main_url_root_alt);
189 $i = 0;
190 foreach ($values as $value) {
191 if (preg_match('/^http(s)?:/', $value)) {
192 // Show error message
193 $correct_value = str_replace($dolibarr_main_url_root, '', $value);
194 print '<b>Error:</b><br>'."\n";
195 print 'Wrong <b>$dolibarr_main_url_root_alt</b> value in <b>conf.php</b> file.<br>'."\n";
196 print 'We now use a relative path to $dolibarr_main_url_root to build alternate URLs.<br>'."\n";
197 print 'Value found: '.$value.'<br>'."\n";
198 print 'Should be replaced by: '.$correct_value.'<br>'."\n";
199 print "Or something like following examples:<br>\n";
200 print "\"/extensions\"<br>\n";
201 print "\"/extensions1,/extensions2,...\"<br>\n";
202 print "\"/../extensions\"<br>\n";
203 print "\"/custom\"<br>\n";
204 exit;
205 }
206 $conf->file->dol_url_root['alt'.($i++)] = (string) $value;
207 }
208}
209
210// Load the main includes of common libraries
211if (!defined('NOREQUIREUSER')) {
212 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Need 500ko memory
213}
214if (!defined('NOREQUIRETRAN')) {
215 require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
216}
217if (!defined('NOREQUIRESOC')) {
218 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
219}
220
221
222/*
223 * Create object $langs (must be before all other code)
224 */
225$langs = null;
226if (!defined('NOREQUIRETRAN')) {
227 $langs = new Translate('', $conf); // Must be after reading conf
228}
229
230
231/*
232 * Create object $db
233 */
234$db = null;
235if (!defined('NOREQUIREDB')) {
236 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
241 if ($db->error) {
242 if (is_object($langs)) {
243 $langs->setDefaultLang('auto');
244 }
245 // If we were into a website context
246 if (!defined('USEDOLIBARREDITOR') && !defined('USEDOLIBARRSERVER') && !empty($_SERVER['SCRIPT_FILENAME']) && (strpos($_SERVER['SCRIPT_FILENAME'], DOL_DATA_ROOT.'/website') === 0)) {
247 $sapi_type = php_sapi_name();
248 if (substr($sapi_type, 0, 3) != 'cgi') {
249 http_response_code(503); // To tel search engine this is a temporary error
250 }
251 print '<div class="center" style="text-align: center; margin: 100px;">';
252 if (is_object($langs)) {
253 $langs->load("website");
254 print $langs->trans("SorryWebsiteIsCurrentlyOffLine");
255 } else {
256 print "SorryWebsiteIsCurrentlyOffLine";
257 }
258 print '</div>';
259 exit(1);
260 }
261 dol_print_error($db, "host=".$conf->db->host.", port=".$conf->db->port.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error);
262 exit(1);
263 }
264}
265
266// Now database connection is known, so we can forget password
267//unset($dolibarr_main_db_pass); // We comment this because this constant is used in some other pages
268unset($conf->db->pass); // This is to avoid password to be shown in memory/swap dump
269
270
271/*
272 * Create object $user
273 */
274if (!defined('NOREQUIREUSER')) {
275 $user = new User($db);
276}
277
278/*
279 * Create the global $hookmanager object
280 */
281if (!defined('NOHOOKMANAGER')) {
282 $hookmanager = new HookManager($db);
283}
284/*
285 * Create $extrafields object
286 */
287if ($db !== null) {
288 require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
289 $extrafields = new ExtraFields($db);
290}
291
292
293/*
294 * Load object $conf
295 */
296
297// By default conf->entity is 1, but we change this if we ask another value.
298if (session_id() && !empty($_SESSION["dol_entity"])) {
299 // Entity inside an opened session
300 $conf->entity = $_SESSION["dol_entity"];
301} elseif (!empty($_ENV["dol_entity"])) {
302 // Entity inside a CLI script
303 $conf->entity = $_ENV["dol_entity"];
304} elseif (GETPOSTISSET("loginfunction") && (GETPOSTINT("entity") || GETPOSTINT("switchentity"))) {
305 // Just after a login page
306 $conf->entity = (GETPOSTISSET("entity") ? GETPOSTINT("entity") : GETPOSTINT("switchentity"));
307} elseif (defined('DOLENTITY') && is_numeric(constant('DOLENTITY'))) {
308 // For public page with MultiCompany module
309 $conf->entity = constant('DOLENTITY');
310}
311// Sanitize entity
312if (!is_numeric($conf->entity)) {
313 $conf->entity = 1;
314}
315// Here we read database (llx_const table) and define conf var $conf->global->XXX.
316//print "We work with data into entity instance number '".$conf->entity."'";
317if ($db !== null) {
318 $conf->setValues($db);
319}
320
321
322// 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)
323if (!defined('NOREQUIRETRAN')) {
324 // On a public page, the visitor has no user setup: the language of his browser wins over the default language of the backoffice
325 $langcode = (GETPOST('lang', 'aZ09') ? GETPOST('lang', 'aZ09', 1) : ((defined('NOLOGIN') && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) ? 'auto' : getDolGlobalString('MAIN_LANG_DEFAULT', 'auto')));
326 if (defined('MAIN_LANG_DEFAULT')) { // So a page can force the language whatever is setup and parameters in URL
327 $langcode = constant('MAIN_LANG_DEFAULT');
328 }
329 $langs->setDefaultLang($langcode);
330}
331
332
333// Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr.
334if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC') && $db != null) {
335 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
336
337 $mysoc = new Societe($db);
338 $mysoc->setMysoc($conf);
339
340 // We set some specific default values according to country
341
342 if ($mysoc->country_code == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
343 // For DE, we need to invert our address with customer address
344 $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1;
345 }
346 if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_CATEGORY_OF_OPERATION)) {
347 // For FR, default value of option to show category of operations is on by default. Decret n°2099-1299 2022-10-07
348 $conf->global->INVOICE_CATEGORY_OF_OPERATION = 1;
349 }
350 if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
351 // For FR, the replacement invoice type is not allowed.
352 // From an accounting point of view, this creates holes in the numbering of the invoice.
353 // This is very problematic during a fiscal control.
354 $conf->global->INVOICE_DISABLE_REPLACEMENT = 1;
355 }
356 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
357 // The replacement invoice type is not allowed in Greece.
358 $conf->global->INVOICE_DISABLE_REPLACEMENT = 1;
359 }
360 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_DISABLE_DEPOSIT)) {
361 // The deposit invoice type is not allowed in Greece.
362 $conf->global->INVOICE_DISABLE_DEPOSIT = 1;
363 }
364 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
365 // Standalone credit note is compulsory in Greece.
366 $conf->global->INVOICE_CREDIT_NOTE_STANDALONE = 1;
367 }
368 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_SUBTYPE_ENABLED)) {
369 // Invoice subtype is a requirement for Greece.
370 $conf->global->INVOICE_SUBTYPE_ENABLED = 1;
371 }
372
373 if (($mysoc->localtax1_assuj || $mysoc->localtax2_assuj) && !isset($conf->global->MAIN_NO_INPUT_PRICE_WITH_TAX)) {
374 // 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).
375 // Work In Progress to support all taxes into unit price entry when MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES is set.
376 $conf->global->MAIN_NO_INPUT_PRICE_WITH_TAX = 1;
377 }
378}
global $dolibarr_main_url_root
$c
Definition line.php:346
Class to stock current configuration.
Class to manage standard extra fields.
Class to manage hooks.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDoliDBInstance($type, $host, $user, $pass, $name, $port, $forcenew=false)
Return a DoliDB instance (database handler).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.