dolibarr 21.0.0-beta
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 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';
48if (!function_exists('is_countable')) {
55 function is_countable($c)
56 {
57 return is_array($c) || $c instanceof Countable;
58 }
59}
60
61/*
62 * Create $conf object
63 */
64
65$conf = new Conf();
66
67// Set properties specific to database
68$conf->db->host = empty($dolibarr_main_db_host) ? '' : $dolibarr_main_db_host;
69$conf->db->port = empty($dolibarr_main_db_port) ? '' : $dolibarr_main_db_port;
70$conf->db->name = empty($dolibarr_main_db_name) ? '' : $dolibarr_main_db_name;
71$conf->db->user = empty($dolibarr_main_db_user) ? '' : $dolibarr_main_db_user;
72$conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass;
73$conf->db->type = $dolibarr_main_db_type;
74$conf->db->prefix = $dolibarr_main_db_prefix;
75$conf->db->character_set = $dolibarr_main_db_character_set;
76$conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
77$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
78$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
79if (defined('TEST_DB_FORCE_TYPE')) {
80 $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example)
81}
82
83// Set properties specific to conf file
84$conf->file->main_limit_users = $dolibarr_main_limit_users;
85$conf->file->mailing_limit_sendbyweb = empty($dolibarr_mailing_limit_sendbyweb) ? 0 : $dolibarr_mailing_limit_sendbyweb;
86$conf->file->mailing_limit_sendbycli = empty($dolibarr_mailing_limit_sendbycli) ? 0 : $dolibarr_mailing_limit_sendbycli;
87$conf->file->mailing_limit_sendbyday = empty($dolibarr_mailing_limit_sendbyday) ? 0 : $dolibarr_mailing_limit_sendbyday;
88$conf->file->main_authentication = empty($dolibarr_main_authentication) ? 'dolibarr' : $dolibarr_main_authentication; // Identification mode
89$conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https; // Force https
90$conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_mode; // Force php strict mode (for debug)
91$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
92$conf->file->dol_main_url_root = $dolibarr_main_url_root; // Define url inside the config file
93$conf->file->dol_document_root = array('main' => (string) DOL_DOCUMENT_ROOT); // Define an array of document root directories ('/home/htdocs')
94$conf->file->dol_url_root = array('main' => (string) DOL_URL_ROOT); // Define an array of url root path ('' or '/dolibarr')
95if (!empty($dolibarr_main_document_root_alt)) {
96 // dolibarr_main_document_root_alt can contains several directories
97 $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
98 $i = 0;
99 foreach ($values as $value) {
100 $conf->file->dol_document_root['alt'.($i++)] = (string) $value;
101 }
102 $values = preg_split('/[;,]/', $dolibarr_main_url_root_alt);
103 $i = 0;
104 foreach ($values as $value) {
105 if (preg_match('/^http(s)?:/', $value)) {
106 // Show error message
107 $correct_value = str_replace($dolibarr_main_url_root, '', $value);
108 print '<b>Error:</b><br>'."\n";
109 print 'Wrong <b>$dolibarr_main_url_root_alt</b> value in <b>conf.php</b> file.<br>'."\n";
110 print 'We now use a relative path to $dolibarr_main_url_root to build alternate URLs.<br>'."\n";
111 print 'Value found: '.$value.'<br>'."\n";
112 print 'Should be replaced by: '.$correct_value.'<br>'."\n";
113 print "Or something like following examples:<br>\n";
114 print "\"/extensions\"<br>\n";
115 print "\"/extensions1,/extensions2,...\"<br>\n";
116 print "\"/../extensions\"<br>\n";
117 print "\"/custom\"<br>\n";
118 exit;
119 }
120 $conf->file->dol_url_root['alt'.($i++)] = (string) $value;
121 }
122}
123
124// Load the main includes of common libraries
125if (!defined('NOREQUIREUSER')) {
126 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Need 500ko memory
127}
128if (!defined('NOREQUIRETRAN')) {
129 require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
130}
131if (!defined('NOREQUIRESOC')) {
132 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
133}
134
135
136/*
137 * Create object $langs (must be before all other code)
138 */
139if (!defined('NOREQUIRETRAN')) {
140 $langs = new Translate('', $conf); // Must be after reading conf
141}
142
143/*
144 * Object $db
145 */
146$db = null;
147if (!defined('NOREQUIREDB')) {
148 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
149
150 if ($db->error) {
151 // If we were into a website context
152 if (!defined('USEDOLIBARREDITOR') && !defined('USEDOLIBARRSERVER') && !empty($_SERVER['SCRIPT_FILENAME']) && (strpos($_SERVER['SCRIPT_FILENAME'], DOL_DATA_ROOT.'/website') === 0)) {
153 $sapi_type = php_sapi_name();
154 if (substr($sapi_type, 0, 3) != 'cgi') {
155 http_response_code(503); // To tel search engine this is a temporary error
156 }
157 print '<div class="center" style="text-align: center; margin: 100px;">';
158 if (is_object($langs)) {
159 $langs->setDefaultLang('auto');
160 $langs->load("website");
161 print $langs->trans("SorryWebsiteIsCurrentlyOffLine");
162 } else {
163 print "SorryWebsiteIsCurrentlyOffLine";
164 }
165 print '</div>';
166 exit(1);
167 }
168 dol_print_error($db, "host=".$conf->db->host.", port=".$conf->db->port.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error);
169 exit(1);
170 }
171}
172
173// Now database connection is known, so we can forget password
174//unset($dolibarr_main_db_pass); // We comment this because this constant is used in some other pages
175unset($conf->db->pass); // This is to avoid password to be shown in memory/swap dump
176
177
178/*
179 * Object $user
180 */
181if (!defined('NOREQUIREUSER')) {
182 $user = new User($db);
183}
184
185/*
186 * Create the global $hookmanager object
187 */
188$hookmanager = new HookManager($db);
189
190
191/*
192 * Load object $conf
193 */
194
195// By default conf->entity is 1, but we change this if we ask another value.
196if (session_id() && !empty($_SESSION["dol_entity"])) {
197 // Entity inside an opened session
198 $conf->entity = $_SESSION["dol_entity"];
199} elseif (!empty($_ENV["dol_entity"])) {
200 // Entity inside a CLI script
201 $conf->entity = $_ENV["dol_entity"];
202} elseif (GETPOSTISSET("loginfunction") && (GETPOSTINT("entity") || GETPOSTINT("switchentity"))) {
203 // Just after a login page
204 $conf->entity = (GETPOSTISSET("entity") ? GETPOSTINT("entity") : GETPOSTINT("switchentity"));
205} elseif (defined('DOLENTITY') && is_numeric(constant('DOLENTITY'))) {
206 // For public page with MultiCompany module
207 $conf->entity = constant('DOLENTITY');
208}
209// Sanitize entity
210if (!is_numeric($conf->entity)) {
211 $conf->entity = 1;
212}
213// Here we read database (llx_const table) and define conf var $conf->global->XXX.
214//print "We work with data into entity instance number '".$conf->entity."'";
215$conf->setValues($db);
216
217// Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr.
218if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) {
219 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
220
221 $mysoc = new Societe($db);
222 $mysoc->setMysoc($conf);
223
224 // We set some specific default values according to country
225
226 if ($mysoc->country_code == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
227 // For DE, we need to invert our address with customer address
228 $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1;
229 }
230 if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_CATEGORY_OF_OPERATION)) {
231 // For FR, default value of option to show category of operations is on by default. Decret n°2099-1299 2022-10-07
232 $conf->global->INVOICE_CATEGORY_OF_OPERATION = 1;
233 }
234 if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
235 // For FR, the replacement invoice type is not allowed.
236 // From an accounting point of view, this creates holes in the numbering of the invoice.
237 // This is very problematic during a fiscal control.
238 $conf->global->INVOICE_DISABLE_REPLACEMENT = 1;
239 }
240 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_DISABLE_REPLACEMENT)) {
241 // The replacement invoice type is not allowed in Greece.
242 $conf->global->INVOICE_DISABLE_REPLACEMENT = 1;
243 }
244 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_DISABLE_DEPOSIT)) {
245 // The deposit invoice type is not allowed in Greece.
246 $conf->global->INVOICE_DISABLE_DEPOSIT = 1;
247 }
248 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
249 // Standalone credit note is compulsory in Greece.
250 $conf->global->INVOICE_CREDIT_NOTE_STANDALONE = 1;
251 }
252 if ($mysoc->country_code == 'GR' && !isset($conf->global->INVOICE_SUBTYPE_ENABLED)) {
253 // Invoice subtype is a requirement for Greece.
254 $conf->global->INVOICE_SUBTYPE_ENABLED = 1;
255 }
256
257 if (($mysoc->localtax1_assuj || $mysoc->localtax2_assuj) && !isset($conf->global->MAIN_NO_INPUT_PRICE_WITH_TAX)) {
258 // 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).
259 // Work In Progress to support all taxes into unit price entry when MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES is set.
260 $conf->global->MAIN_NO_INPUT_PRICE_WITH_TAX = 1;
261 }
262}
263
264
265// 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)
266if (!defined('NOREQUIRETRAN')) {
267 $langcode = (GETPOST('lang', 'aZ09') ? GETPOST('lang', 'aZ09', 1) : getDolGlobalString('MAIN_LANG_DEFAULT', 'auto'));
268 if (defined('MAIN_LANG_DEFAULT')) { // So a page can force the language whatever is setup and parameters in URL
269 $langcode = constant('MAIN_LANG_DEFAULT');
270 }
271 $langs->setDefaultLang($langcode);
272}
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