dolibarr  13.0.2
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 require_once 'filefunc.inc.php'; // May have been already require by main.inc.php. But may not by scripts.
36 
37 
38 
39 /*
40  * Create $conf object
41  */
42 
43 require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
44 
45 $conf = new Conf();
46 
47 // Set properties specific to database
48 $conf->db->host = $dolibarr_main_db_host;
49 $conf->db->port = $dolibarr_main_db_port;
50 $conf->db->name = $dolibarr_main_db_name;
51 $conf->db->user = $dolibarr_main_db_user;
52 $conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass;
53 $conf->db->type = $dolibarr_main_db_type;
54 $conf->db->prefix = $dolibarr_main_db_prefix;
55 $conf->db->character_set = $dolibarr_main_db_character_set;
56 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
57 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
58 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
59 if (defined('TEST_DB_FORCE_TYPE')) $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example)
60 
61 // Set properties specific to conf file
62 $conf->file->main_limit_users = $dolibarr_main_limit_users;
63 $conf->file->mailing_limit_sendbyweb = $dolibarr_mailing_limit_sendbyweb;
64 $conf->file->mailing_limit_sendbycli = $dolibarr_mailing_limit_sendbycli;
65 $conf->file->main_authentication = empty($dolibarr_main_authentication) ? '' : $dolibarr_main_authentication; // Identification mode
66 $conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https; // Force https
67 $conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_mode; // Force php strict mode (for debug)
68 $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
69 $conf->file->dol_document_root = array('main' => (string) DOL_DOCUMENT_ROOT); // Define array of document root directories ('/home/htdocs')
70 $conf->file->dol_url_root = array('main' => (string) DOL_URL_ROOT); // Define array of url root path ('' or '/dolibarr')
71 if (!empty($dolibarr_main_document_root_alt))
72 {
73  // dolibarr_main_document_root_alt can contains several directories
74  $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
75  $i = 0;
76  foreach ($values as $value) $conf->file->dol_document_root['alt'.($i++)] = (string) $value;
77  $values = preg_split('/[;,]/', $dolibarr_main_url_root_alt);
78  $i = 0;
79  foreach ($values as $value)
80  {
81  if (preg_match('/^http(s)?:/', $value))
82  {
83  // Show error message
84  $correct_value = str_replace($dolibarr_main_url_root, '', $value);
85  print '<b>Error:</b><br>'."\n";
86  print 'Wrong <b>$dolibarr_main_url_root_alt</b> value in <b>conf.php</b> file.<br>'."\n";
87  print 'We now use a relative path to $dolibarr_main_url_root to build alternate URLs.<br>'."\n";
88  print 'Value found: '.$value.'<br>'."\n";
89  print 'Should be replaced by: '.$correct_value.'<br>'."\n";
90  print "Or something like following examples:<br>\n";
91  print "\"/extensions\"<br>\n";
92  print "\"/extensions1,/extensions2,...\"<br>\n";
93  print "\"/../extensions\"<br>\n";
94  print "\"/custom\"<br>\n";
95  exit;
96  }
97  $conf->file->dol_url_root['alt'.($i++)] = (string) $value;
98  }
99 }
100 
101 // Chargement des includes principaux de librairies communes
102 if (!defined('NOREQUIREUSER')) require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; // Need 500ko memory
103 if (!defined('NOREQUIRETRAN')) require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
104 if (!defined('NOREQUIRESOC')) require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
105 
106 
107 /*
108  * Creation objet $langs (must be before all other code)
109  */
110 if (!defined('NOREQUIRETRAN'))
111 {
112  $langs = new Translate('', $conf); // Must be after reading conf
113 }
114 
115 /*
116  * Object $db
117  */
118 if (!defined('NOREQUIREDB'))
119 {
120  $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
121 
122  if ($db->error)
123  {
124  // If we were into a website context
125  if (!defined('USEDOLIBARREDITOR') && !defined('USEDOLIBARRSERVER') && !empty($_SERVER['SCRIPT_FILENAME']) && (strpos($_SERVER['SCRIPT_FILENAME'], DOL_DATA_ROOT.'/website') === 0))
126  {
127  $sapi_type = php_sapi_name();
128  if (substr($sapi_type, 0, 3) != 'cgi') http_response_code(503); // To tel search engine this is a temporary error
129  print '<div class="center" style="text-align: center; margin: 100px;">';
130  if (is_object($langs))
131  {
132  $langs->setDefaultLang('auto');
133  $langs->load("website");
134  print $langs->trans("SorryWebsiteIsCurrentlyOffLine");
135  } else {
136  print "SorryWebsiteIsCurrentlyOffLine";
137  }
138  print '</div>';
139  exit;
140  }
141  dol_print_error($db, "host=".$conf->db->host.", port=".$conf->db->port.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error);
142  exit;
143  }
144 }
145 
146 // Now database connexion is known, so we can forget password
147 //unset($dolibarr_main_db_pass); // We comment this because this constant is used in a lot of pages
148 unset($conf->db->pass); // This is to avoid password to be shown in memory/swap dump
149 
150 /*
151  * Object $user
152  */
153 if (!defined('NOREQUIREUSER')) {
154  $user = new User($db);
155 }
156 
157 /*
158  * Load object $conf
159  * After this, all parameters conf->global->CONSTANTS are loaded
160  */
161 
162 // By default conf->entity is 1, but we change this if we ask another value.
163 if (session_id() && !empty($_SESSION["dol_entity"])) {
164  // Entity inside an opened session
165  $conf->entity = $_SESSION["dol_entity"];
166 } elseif (!empty($_ENV["dol_entity"])) {
167  // Entity inside a CLI script
168  $conf->entity = $_ENV["dol_entity"];
169 } elseif (GETPOSTISSET("loginfunction") && GETPOST("entity", 'int')) {
170  // Just after a login page
171  $conf->entity = GETPOST("entity", 'int');
172 } elseif (defined('DOLENTITY') && is_numeric(constant('DOLENTITY'))) {
173  // For public page with MultiCompany module
174  $conf->entity = constant('DOLENTITY');
175 }
176 
177 // Sanitize entity
178 if (!is_numeric($conf->entity)) $conf->entity = 1;
179 
180 if (!defined('NOREQUIREDB'))
181 {
182  //print "Will work with data into entity instance number '".$conf->entity."'";
183 
184  // Here we read database (llx_const table) and define $conf->global->XXX var.
185  $conf->setValues($db);
186 }
187 
188 // Overwrite database value
189 if (!empty($conf->file->mailing_limit_sendbyweb)) {
190  $conf->global->MAILING_LIMIT_SENDBYWEB = $conf->file->mailing_limit_sendbyweb;
191 }
192 if (empty($conf->global->MAILING_LIMIT_SENDBYWEB)) {
193  $conf->global->MAILING_LIMIT_SENDBYWEB = 25;
194 }
195 if (!empty($conf->file->mailing_limit_sendbycli)) {
196  $conf->global->MAILING_LIMIT_SENDBYCLI = $conf->file->mailing_limit_sendbycli;
197 }
198 
199 // Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr.
200 if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC'))
201 {
202  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
203 
204  $mysoc = new Societe($db);
205  $mysoc->setMysoc($conf);
206 
207  // For some countries, we need to invert our address with customer address
208  if ($mysoc->country_code == 'DE' && !isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1;
209 }
210 
211 
212 // 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)
213 if (!defined('NOREQUIRETRAN'))
214 {
215  $langcode = (GETPOST('lang', 'aZ09') ? GETPOST('lang', 'aZ09', 1) : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
216  if (defined('MAIN_LANG_DEFAULT')) $langcode = constant('MAIN_LANG_DEFAULT');
217  $langs->setDefaultLang($langcode);
218 }
219 
220 
221 // Create the global $hookmanager object
222 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
223 $hookmanager = new HookManager($db);
224 
225 
226 if (!defined('MAIN_LABEL_MENTION_NPR')) define('MAIN_LABEL_MENTION_NPR', 'NPR');
227 //if (! defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', $conf->user->dir_temp);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to stock current configuration.
Definition: conf.class.php:33
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage hooks.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.