Passed
Branch develop (f6c1a1)
by
unknown
28:54
created

Conf::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 30
nc 1
nop 0
dl 0
loc 38
rs 9.44
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2003      Xavier Dutoit        <[email protected]>
4
 * Copyright (C) 2004-2020 Laurent Destailleur  <[email protected]>
5
 * Copyright (C) 2005-2017 Regis Houssin      	<[email protected]>
6
 * Copyright (C) 2006 	   Jean Heimburger    	<[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
/**
23
 *	\file       	htdocs/core/class/conf.class.php
24
 *	\ingroup		core
25
 *  \brief      	File of class to manage storage of current setup
26
 *  				Config is stored into file conf.php
27
 */
28
29
30
/**
31
 *  Class to stock current configuration
32
 */
33
class Conf
34
{
35
    /** \public */
36
    //! To store properties found in conf file
37
    public $file;
38
39
    /**
40
     * @var Object 	Associative array with some properties ->type, ->db, ...
41
     */
42
    public $db;
43
44
    //! To store properties found into database
45
    public $global;
46
    //! To store browser info
47
    public $browser;
48
49
    //! To store if javascript/ajax is enabked
50
    public $use_javascript_ajax;
51
    //! To store if javascript/ajax is enabked
52
    public $disable_compute;
53
	//! Used to store current currency (ISO code like 'USD', 'EUR', ...)
54
	public $currency;
55
	//! Used to store current css (from theme)
56
	public $theme; // Contains current theme ("eldy", "auguria", ...)
57
	public $css; // Contains full path of css page ("/theme/eldy/style.css.php", ...)
58
    //! Used to store current menu handler
59
	public $standard_menu;
60
    // List of activated modules
61
    public $modules = array();
62
    public $modules_parts = array(
63
        'css' => array(),
64
        'js' => array(),
65
        'tabs' => array(),
66
        'triggers' => array(),
67
        'login' => array(),
68
        'substitutions' => array(),
69
        'menus' => array(),
70
        'theme' => array(),
71
        'sms' => array(),
72
        'tpl' => array(),
73
        'barcode' => array(),
74
        'models' => array(),
75
        'societe' => array(),
76
        'hooks' => array(),
77
        'dir' => array(),
78
        'syslog' => array(),
79
    );
80
81
    public $logbuffer = array();
82
83
    /**
84
     * @var LogHandlerInterface[]
85
     */
86
    public $loghandlers = array();
87
88
    //! To store properties of multi-company
89
    public $multicompany;
90
	//! Used to store running instance for multi-company (default 1)
91
	public $entity = 1;
92
	//! Used to store list of entities to use for each element
93
	public $entities = array();
94
95
	public $dol_hide_topmenu; // Set if we force param dol_hide_topmenu into login url
96
	public $dol_hide_leftmenu; // Set if we force param dol_hide_leftmenu into login url
97
	public $dol_optimize_smallscreen; // Set if we force param dol_optimize_smallscreen into login url or if browser is smartphone
98
	public $dol_no_mouse_hover; // Set if we force param dol_no_mouse_hover into login url or if browser is smartphone
99
	public $dol_use_jmobile; // Set if we force param dol_use_jmobile into login url
100
101
102
	/**
103
	 * Constructor
104
	 */
105
	public function __construct()
106
	{
107
		// Properly declare multi-modules objects.
108
		$this->file = new stdClass();
109
		$this->db = new stdClass();
110
		$this->global = new stdClass();
111
		$this->mycompany = new stdClass();
112
		$this->admin			= new stdClass();
113
		$this->user				= new stdClass();
114
		$this->syslog			= new stdClass();
115
		$this->browser = new stdClass();
116
		$this->medias			= new stdClass();
117
		$this->multicompany = new stdClass();
118
119
		//! Charset for HTML output and for storing data in memory
120
		$this->file->character_set_client = 'UTF-8'; // UTF-8, ISO-8859-1
121
122
		// First level object
123
		// TODO Remove this part.
124
		$this->expedition_bon = new stdClass();
125
		$this->livraison_bon = new stdClass();
126
		$this->fournisseur = new stdClass();
127
		$this->product			= new stdClass();
128
		$this->service			= new stdClass();
129
		$this->contrat			= new stdClass();
130
		$this->actions			= new stdClass();
131
		$this->agenda			= new stdClass();
132
		$this->commande = new stdClass();
133
		$this->propal = new stdClass();
134
		$this->facture			= new stdClass();
135
		$this->contrat			= new stdClass();
136
		$this->usergroup		= new stdClass();
137
		$this->adherent			= new stdClass();
138
		$this->bank = new stdClass();
139
		$this->notification		= new stdClass();
140
		$this->mailing = new stdClass();
141
		$this->expensereport	= new stdClass();
142
		$this->productbatch		= new stdClass();
143
	}
144
145
146
	/**
147
	 *  Load setup values into conf object (read llx_const)
148
	 *  Note that this->db->xxx, this->file->xxx and this->multicompany have been already loaded when setValues is called.
149
	 *
150
	 *  @param      DoliDB      $db     Database handler
151
	 *  @return     int                 < 0 if KO, >= 0 if OK
152
	 */
153
	public function setValues($db)
154
	{
155
		dol_syslog(get_class($this)."::setValues");
156
157
		//Define all global constants into $this->global->key=value
158
		$sql = "SELECT ".$db->decrypt('name')." as name,";
159
		$sql .= " ".$db->decrypt('value')." as value, entity";
160
		$sql .= " FROM ".MAIN_DB_PREFIX."const";
161
		$sql .= " WHERE entity IN (0,".$this->entity.")";
162
		$sql .= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite.
163
164
		$resql = $db->query($sql);
165
		if ($resql)
166
		{
167
			$i = 0;
168
			$numr = $db->num_rows($resql);
169
			while ($i < $numr)
170
			{
171
				$objp = $db->fetch_object($resql);
172
				$key = $objp->name;
173
				$value = $objp->value;
174
				if ($key)
175
				{
176
					// Allow constants values to be overridden by environment variables
177
					if (isset($_SERVER['DOLIBARR_'.$key])) {
178
						$value = $_SERVER['DOLIBARR_'.$key];
179
					} elseif (isset($_ENV['DOLIBARR_'.$key])) {
180
						$value = $_ENV['DOLIBARR_'.$key];
181
					}
182
183
					//if (! defined("$key")) define("$key", $value);	// In some cases, the constant might be already forced (Example: SYSLOG_HANDLERS during install)
184
					$this->global->$key = $value;
185
186
					if ($value && strpos($key, 'MAIN_MODULE_') === 0)
187
					{
188
						$reg = array();
189
						// If this is constant for a new tab page activated by a module. It initializes modules_parts['tabs'].
190
						if (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)_TABS_/i', $key))
191
						{
192
							$partname = 'tabs';
193
							$params = explode(':', $value, 2);
194
							if (!is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); }
195
							$this->modules_parts[$partname][$params[0]][] = $value; // $value may be a string or an array
196
						}
197
						// If this is constant for all generic part activated by a module. It initializes
198
						// modules_parts['login'], modules_parts['menus'], modules_parts['substitutions'], modules_parts['triggers'], modules_parts['tpl'],
199
						// modules_parts['models'], modules_parts['theme']
200
						// modules_parts['sms'],
201
						// modules_parts['css'], ...
202
						elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)_([A-Z]+)$/i', $key, $reg))
203
						{
204
							$modulename = strtolower($reg[1]);
205
							$partname = strtolower($reg[2]);
206
							if (!is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); }
207
							$arrValue = json_decode($value, true);
208
							if (is_array($arrValue) && !empty($arrValue)) $value = $arrValue;
209
							elseif (in_array($partname, array('login', 'menus', 'substitutions', 'triggers', 'tpl'))) $value = '/'.$modulename.'/core/'.$partname.'/';
210
							elseif (in_array($partname, array('models', 'theme'))) $value = '/'.$modulename.'/';
211
							elseif (in_array($partname, array('sms'))) $value = '/'.$modulename.'/';
212
							elseif ($value == 1) $value = '/'.$modulename.'/core/modules/'.$partname.'/'; // ex: partname = societe
213
							$this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value)); // $value may be a string or an array
214
						}
215
                        // If this is a module constant (must be at end)
216
						elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)$/i', $key, $reg))
217
						{
218
							$modulename = strtolower($reg[1]);
219
							if ($modulename == 'propale') $modulename = 'propal';
220
							if ($modulename == 'supplierproposal') $modulename = 'supplier_proposal';
221
							if (!isset($this->$modulename) || !is_object($this->$modulename)) $this->$modulename = new stdClass();
222
							$this->$modulename->enabled = true;
223
							$this->modules[] = $modulename; // Add this module in list of enabled modules
224
						}
225
					}
226
				}
227
				$i++;
228
			}
229
230
            $db->free($resql);
231
        }
232
233
        // Include other local consts.php files and fetch their values to the corresponding database constants.
234
        if (!empty($this->global->LOCAL_CONSTS_FILES)) {
235
            $filesList = explode(":", $this->global->LOCAL_CONSTS_FILES);
236
            foreach ($filesList as $file) {
237
                $file = dol_sanitizeFileName($file);
238
                include_once DOL_DOCUMENT_ROOT."/".$file."/".$file."_consts.php"; // This file can run code like setting $this->global->XXX vars.
239
            }
240
        }
241
242
        //var_dump($this->modules);
243
        //var_dump($this->modules_parts['theme']);
244
245
		// If you can't set timezone of your PHP, set this constant. Better is to set it to UTC.
246
		// In future, this constant will be forced to 'UTC' so PHP server timezone will not have effect anymore.
247
		//$this->global->MAIN_SERVER_TZ='Europe/Paris';
248
		if (!empty($this->global->MAIN_SERVER_TZ) && $this->global->MAIN_SERVER_TZ != 'auto')
249
		{
250
			try {
251
				date_default_timezone_set($this->global->MAIN_SERVER_TZ);
252
			} catch (Exception $e)
253
			{
254
				dol_syslog("Error: Bad value for parameter MAIN_SERVER_TZ=".$this->global->MAIN_SERVER_TZ, LOG_ERR);
255
			}
256
		}
257
258
		// Object $mc
259
		if (!defined('NOREQUIREMC') && !empty($this->multicompany->enabled)) {
260
			global $mc;
261
			$ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php');
262
			if ($ret) {
263
				$mc = new ActionsMulticompany($db);
0 ignored issues
show
Bug introduced by
The type ActionsMulticompany was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
264
				$this->mc = $mc;
265
			}
266
		}
267
268
		// Clean some variables
269
		if (empty($this->global->MAIN_MENU_STANDARD)) $this->global->MAIN_MENU_STANDARD = "eldy_menu.php";
270
		if (empty($this->global->MAIN_MENUFRONT_STANDARD)) $this->global->MAIN_MENUFRONT_STANDARD = "eldy_menu.php";
271
		if (empty($this->global->MAIN_MENU_SMARTPHONE)) $this->global->MAIN_MENU_SMARTPHONE = "eldy_menu.php"; // Use eldy by default because smartphone does not work on all phones
272
		if (empty($this->global->MAIN_MENUFRONT_SMARTPHONE)) $this->global->MAIN_MENUFRONT_SMARTPHONE = "eldy_menu.php"; // Use eldy by default because smartphone does not work on all phones
273
		if (!isset($this->global->FACTURE_TVAOPTION)) $this->global->FACTURE_TVAOPTION = 1;
274
275
		// Variable globales LDAP
276
		if (empty($this->global->LDAP_FIELD_FULLNAME)) $this->global->LDAP_FIELD_FULLNAME = '';
277
		if (!isset($this->global->LDAP_KEY_USERS)) $this->global->LDAP_KEY_USERS = $this->global->LDAP_FIELD_FULLNAME;
278
		if (!isset($this->global->LDAP_KEY_GROUPS)) $this->global->LDAP_KEY_GROUPS = $this->global->LDAP_FIELD_FULLNAME;
279
		if (!isset($this->global->LDAP_KEY_CONTACTS)) $this->global->LDAP_KEY_CONTACTS = $this->global->LDAP_FIELD_FULLNAME;
280
		if (!isset($this->global->LDAP_KEY_MEMBERS)) $this->global->LDAP_KEY_MEMBERS = $this->global->LDAP_FIELD_FULLNAME;
281
		if (!isset($this->global->LDAP_KEY_MEMBERS_TYPES)) $this->global->LDAP_KEY_MEMBERS_TYPES = $this->global->LDAP_FIELD_FULLNAME;
282
283
		// Load translation object with current language
284
		if (empty($this->global->MAIN_LANG_DEFAULT)) $this->global->MAIN_LANG_DEFAULT = "en_US";
285
286
		$rootfordata = DOL_DATA_ROOT;
287
		$rootforuser = DOL_DATA_ROOT;
288
		// If multicompany module is enabled, we redefine the root of data
289
		if (!empty($this->multicompany->enabled) && !empty($this->entity) && $this->entity > 1)
290
		{
291
			$rootfordata .= '/'.$this->entity;
292
		}
293
		// Set standard temporary folder name or global override
294
		$rootfortemp = empty($this->global->MAIN_TEMP_DIR) ? $rootfordata : $this->global->MAIN_TEMP_DIR;
295
296
		// Define default dir_output and dir_temp for directories of modules
297
		foreach ($this->modules as $module)
298
		{
299
		    //var_dump($module);
300
			// For multicompany sharings
301
			$this->$module->multidir_output = array($this->entity => $rootfordata."/".$module);
302
			$this->$module->multidir_temp = array($this->entity => $rootfortemp."/".$module."/temp");
303
			// For backward compatibility
304
			$this->$module->dir_output = $rootfordata."/".$module;
305
			$this->$module->dir_temp = $rootfortemp."/".$module."/temp";
306
		}
307
308
		// External modules storage
309
		if (!empty($this->modules_parts['dir']))
310
		{
311
			foreach ($this->modules_parts['dir'] as $module => $dirs)
312
			{
313
				if (!empty($this->$module->enabled))
314
				{
315
					foreach ($dirs as $type => $name)  // $type is 'output' or 'temp'
316
					{
317
						$multidirname = 'multidir_'.$type;
318
						$dirname = 'dir_'.$type;
319
320
						if ($type != 'temp')
321
						{
322
							// For multicompany sharings
323
							$this->$module->$multidirname = array($this->entity => $rootfordata."/".$name);
324
325
							// For backward compatibility
326
							$this->$module->$dirname = $rootfordata."/".$name;
327
						} else {
328
							// For multicompany sharings
329
							$this->$module->$multidirname = array($this->entity => $rootfortemp."/".$name."/temp");
330
331
							// For backward compatibility
332
							$this->$module->$dirname = $rootfortemp."/".$name."/temp";
333
						}
334
					}
335
				}
336
			}
337
		}
338
339
		// For mycompany storage
340
		$this->mycompany->dir_output = $rootfordata."/mycompany";
341
		$this->mycompany->dir_temp = $rootfortemp."/mycompany/temp";
342
343
		// For admin storage
344
		$this->admin->dir_output = $rootfordata.'/admin';
345
		$this->admin->dir_temp = $rootfortemp.'/admin/temp';
346
347
		// For user storage
348
		$this->user->multidir_output = array($this->entity => $rootfordata."/users");
349
		$this->user->multidir_temp = array($this->entity => $rootfortemp."/users/temp");
350
		// For backward compatibility
351
		$this->user->dir_output = $rootforuser."/users";
352
		$this->user->dir_temp = $rootfortemp."/users/temp";
353
354
		// For usergroup storage
355
		$this->usergroup->dir_output = $rootforuser."/usergroups";
356
		$this->usergroup->dir_temp = $rootfortemp."/usergroups/temp";
357
358
		// For proposal storage
359
		$this->propal->multidir_output = array($this->entity => $rootfordata."/propale");
360
		$this->propal->multidir_temp = array($this->entity => $rootfortemp."/propale/temp");
361
		// For backward compatibility
362
		$this->propal->dir_output = $rootfordata."/propale";
363
		$this->propal->dir_temp = $rootfortemp."/propale/temp";
364
365
		// For medias storage
366
		$this->medias->multidir_output = array($this->entity => $rootfordata."/medias");
367
		$this->medias->multidir_temp = array($this->entity => $rootfortemp."/medias/temp");
368
369
		// Exception: Some dir are not the name of module. So we keep exception here for backward compatibility.
370
371
		// Sous module bons d'expedition
372
		$this->expedition_bon->enabled = (!empty($this->global->MAIN_SUBMODULE_EXPEDITION) ? $this->global->MAIN_SUBMODULE_EXPEDITION : 0);
373
		// Sous module bons de livraison
374
		$this->livraison_bon->enabled = (!empty($this->global->MAIN_SUBMODULE_LIVRAISON) ? $this->global->MAIN_SUBMODULE_LIVRAISON : 0);
375
376
		// Module fournisseur
377
		if (!empty($this->fournisseur))
378
		{
379
			$this->fournisseur->commande = new stdClass();
380
			$this->fournisseur->commande->multidir_output = array($this->entity => $rootfordata."/fournisseur/commande");
381
			$this->fournisseur->commande->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/commande/temp");
382
			$this->fournisseur->commande->dir_output = $rootfordata."/fournisseur/commande"; // For backward compatibility
383
			$this->fournisseur->commande->dir_temp = $rootfortemp."/fournisseur/commande/temp"; // For backward compatibility
384
385
			$this->fournisseur->facture = new stdClass();
386
			$this->fournisseur->facture->multidir_output = array($this->entity => $rootfordata."/fournisseur/facture");
387
			$this->fournisseur->facture->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/facture/temp");
388
			$this->fournisseur->facture->dir_output = $rootfordata."/fournisseur/facture"; // For backward compatibility
389
			$this->fournisseur->facture->dir_temp = $rootfortemp."/fournisseur/facture/temp"; // For backward compatibility
390
391
			$this->supplierproposal = new stdClass();
392
			$this->supplierproposal->multidir_output = array($this->entity => $rootfordata."/supplier_proposal");
393
			$this->supplierproposal->multidir_temp = array($this->entity => $rootfortemp."/supplier_proposal/temp");
394
			$this->supplierproposal->dir_output = $rootfordata."/supplier_proposal"; // For backward compatibility
395
			$this->supplierproposal->dir_temp = $rootfortemp."/supplier_proposal/temp"; // For backward compatibility
396
397
			$this->fournisseur->payment = new stdClass();
398
			$this->fournisseur->payment->multidir_output = array($this->entity => $rootfordata."/fournisseur/payment");
399
			$this->fournisseur->payment->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/payment/temp");
400
			$this->fournisseur->payment->dir_output = $rootfordata."/fournisseur/payment"; // For backward compatibility
401
			$this->fournisseur->payment->dir_temp = $rootfortemp."/fournisseur/payment/temp"; // For backward compatibility
402
403
			// To prepare split of module fournisseur into module 'fournisseur' + supplier_order + supplier_invoice
404
			if (!empty($this->fournisseur->enabled) && empty($this->global->MAIN_USE_NEW_SUPPLIERMOD))  // By default, if module supplier is on, and we don't use yet the new modules, we set artificialy the module properties
405
			{
406
				$this->supplier_order = new stdClass();
407
				$this->supplier_order->enabled = 1;
408
				$this->supplier_order->multidir_output = array($this->entity => $rootfordata."/fournisseur/commande");
409
				$this->supplier_order->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/commande/temp");
410
				$this->supplier_order->dir_output = $rootfordata."/fournisseur/commande"; // For backward compatibility
411
				$this->supplier_order->dir_temp = $rootfortemp."/fournisseur/commande/temp"; // For backward compatibility
412
413
				$this->supplier_invoice = new stdClass();
414
				$this->supplier_invoice->enabled = 1;
415
				$this->supplier_invoice->multidir_output = array($this->entity => $rootfordata."/fournisseur/facture");
416
				$this->supplier_invoice->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/facture/temp");
417
				$this->supplier_invoice->dir_output = $rootfordata."/fournisseur/facture"; // For backward compatibility
418
				$this->supplier_invoice->dir_temp = $rootfortemp."/fournisseur/facture/temp"; // For backward compatibility
419
			}
420
		}
421
422
		// Module product/service
423
		$this->product->multidir_output 		= array($this->entity => $rootfordata."/produit");
424
		$this->product->multidir_temp			= array($this->entity => $rootfortemp."/produit/temp");
425
		$this->service->multidir_output			= array($this->entity => $rootfordata."/produit");
426
		$this->service->multidir_temp			= array($this->entity => $rootfortemp."/produit/temp");
427
		// For backward compatibility
428
		$this->product->dir_output				= $rootfordata."/produit";
429
		$this->product->dir_temp				= $rootfortemp."/produit/temp";
430
		$this->service->dir_output				= $rootfordata."/produit";
431
		$this->service->dir_temp				= $rootfortemp."/produit/temp";
432
433
		// Module productbatch
434
		$this->productbatch->multidir_output = array($this->entity => $rootfordata."/produitlot");
435
		$this->productbatch->multidir_temp = array($this->entity => $rootfortemp."/produitlot/temp");
436
437
		// Module contrat
438
		$this->contrat->multidir_output = array($this->entity => $rootfordata."/contract");
439
		$this->contrat->multidir_temp = array($this->entity => $rootfortemp."/contract/temp");
440
		// For backward compatibility
441
		$this->contrat->dir_output = $rootfordata."/contract";
442
		$this->contrat->dir_temp = $rootfortemp."/contract/temp";
443
444
		// Module bank
445
		$this->bank->multidir_output = array($this->entity => $rootfordata."/bank");
446
		$this->bank->multidir_temp = array($this->entity => $rootfortemp."/bank/temp");
447
		// For backward compatibility
448
		$this->bank->dir_output = $rootfordata."/bank";
449
		$this->bank->dir_temp = $rootfortemp."/bank/temp";
450
451
		// Set some default values
452
		//$this->global->MAIN_LIST_FILTER_ON_DAY=1;		// On filter that show date, we must show input field for day before or after month
453
        $this->global->MAIN_MAIL_USE_MULTI_PART = 1;
454
455
		// societe
456
		if (empty($this->global->SOCIETE_CODECLIENT_ADDON))		$this->global->SOCIETE_CODECLIENT_ADDON = "mod_codeclient_leopard";
457
		if (empty($this->global->SOCIETE_CODECOMPTA_ADDON))		$this->global->SOCIETE_CODECOMPTA_ADDON = "mod_codecompta_panicum";
458
459
		if (empty($this->global->CHEQUERECEIPTS_ADDON))			$this->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
460
		if (empty($this->global->TICKET_ADDON))				    $this->global->TICKET_ADDON = 'mod_ticket_simple';
461
462
        // Security
463
		if (empty($this->global->USER_PASSWORD_GENERATED)) $this->global->USER_PASSWORD_GENERATED = 'standard'; // Default password generator
464
        if (empty($this->global->MAIN_UMASK)) $this->global->MAIN_UMASK = '0664'; // Default mask
465
466
		// conf->use_javascript_ajax
467
		$this->use_javascript_ajax = 1;
468
		if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) $this->use_javascript_ajax = !$this->global->MAIN_DISABLE_JAVASCRIPT;
469
		// If no javascript_ajax, Ajax features are disabled.
470
		if (empty($this->use_javascript_ajax))
471
		{
472
			unset($this->global->PRODUIT_USE_SEARCH_TO_SELECT);
473
			unset($this->global->COMPANY_USE_SEARCH_TO_SELECT);
474
			unset($this->global->CONTACT_USE_SEARCH_TO_SELECT);
475
			unset($this->global->PROJECT_USE_SEARCH_TO_SELECT);
476
		}
477
478
		if (!empty($this->productbatch->enabled))
479
		{
480
			$this->global->STOCK_CALCULATE_ON_BILL = 0;
481
			$this->global->STOCK_CALCULATE_ON_VALIDATE_ORDER = 0;
482
			$this->global->STOCK_CALCULATE_ON_SHIPMENT = 1;
483
			$this->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE = 0;
484
			$this->global->STOCK_CALCULATE_ON_SUPPLIER_BILL = 0;
485
			$this->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER = 0;
486
			if (empty($this->reception->enabled)) {
0 ignored issues
show
Bug Best Practice introduced by
The property reception does not exist on Conf. Did you maybe forget to declare it?
Loading history...
487
				$this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER = 1;
488
			}
489
			else {
490
				$this->global->STOCK_CALCULATE_ON_RECEPTION = 1;
491
				$this->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE = 0;
492
			}
493
		}
494
495
		// conf->currency
496
		if (empty($this->global->MAIN_MONNAIE)) $this->global->MAIN_MONNAIE = 'EUR';
497
		$this->currency = $this->global->MAIN_MONNAIE;
498
499
		if (empty($this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)) $this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY = 30; // Less than 1 minutes to be sure
500
501
		// conf->global->ACCOUNTING_MODE = Option des modules Comptabilites (simple ou expert). Defini le mode de calcul des etats comptables (CA,...)
502
        if (empty($this->global->ACCOUNTING_MODE)) $this->global->ACCOUNTING_MODE = 'RECETTES-DEPENSES'; // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES'
503
504
        // By default, suppliers objects can be linked to all projects
505
        if (!isset($this->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)) $this->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS = 1;
506
507
        // By default we enable feature to bill time spent
508
        if (!isset($this->global->PROJECT_BILL_TIME_SPENT)) $this->global->PROJECT_BILL_TIME_SPENT = 1;
509
510
        // MAIN_HTML_TITLE
511
        if (!isset($this->global->MAIN_HTML_TITLE)) $this->global->MAIN_HTML_TITLE = 'noapp,thirdpartynameonly,contactnameonly,projectnameonly';
512
513
		// conf->liste_limit = constante de taille maximale des listes
514
		if (empty($this->global->MAIN_SIZE_LISTE_LIMIT)) $this->global->MAIN_SIZE_LISTE_LIMIT = 25;
515
		$this->liste_limit = $this->global->MAIN_SIZE_LISTE_LIMIT;
516
517
		// conf->product->limit_size = constante de taille maximale des select de produit
518
		if (!isset($this->global->PRODUIT_LIMIT_SIZE)) $this->global->PRODUIT_LIMIT_SIZE = 1000;
519
		$this->product->limit_size = $this->global->PRODUIT_LIMIT_SIZE;
520
521
		// conf->theme et $this->css
522
		if (empty($this->global->MAIN_THEME)) $this->global->MAIN_THEME = "eldy";
523
        if (!empty($this->global->MAIN_FORCETHEME)) $this->global->MAIN_THEME = $this->global->MAIN_FORCETHEME;
524
		$this->theme = $this->global->MAIN_THEME;
525
		$this->css = "/theme/".$this->theme."/style.css.php";
526
527
		// conf->email_from = email pour envoi par dolibarr des mails automatiques
528
		$this->email_from = "[email protected]";
529
		if (!empty($this->global->MAIN_MAIL_EMAIL_FROM)) $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM;
530
531
		// conf->notification->email_from = email pour envoi par Dolibarr des notifications
532
		$this->notification->email_from = $this->email_from;
533
		if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) $this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM;
534
535
		// conf->mailing->email_from = email pour envoi par Dolibarr des mailings
536
		$this->mailing->email_from = $this->email_from;
537
		if (!empty($this->global->MAILING_EMAIL_FROM))	$this->mailing->email_from = $this->global->MAILING_EMAIL_FROM;
538
		if (!isset($this->global->MAIN_EMAIL_ADD_TRACK_ID)) $this->global->MAIN_EMAIL_ADD_TRACK_ID = 1;
539
540
        // Format for date (used by default when not found or not searched in lang)
541
        $this->format_date_short = "%d/%m/%Y"; // Format of day with PHP/C tags (strftime functions)
542
        $this->format_date_short_java = "dd/MM/yyyy"; // Format of day with Java tags
543
        $this->format_hour_short = "%H:%M";
544
        $this->format_hour_short_duration = "%H:%M";
545
        $this->format_date_text_short = "%d %b %Y";
546
        $this->format_date_text = "%d %B %Y";
547
        $this->format_date_hour_short = "%d/%m/%Y %H:%M";
548
        $this->format_date_hour_sec_short = "%d/%m/%Y %H:%M:%S";
549
        $this->format_date_hour_text_short = "%d %b %Y %H:%M";
550
        $this->format_date_hour_text = "%d %B %Y %H:%M";
551
552
        // Duration of workday
553
        if (!isset($this->global->MAIN_DURATION_OF_WORKDAY)) $this->global->MAIN_DURATION_OF_WORKDAY = 86400;
554
555
		// Limites decimales si non definie (peuvent etre egale a 0)
556
		if (!isset($this->global->MAIN_MAX_DECIMALS_UNIT))  $this->global->MAIN_MAX_DECIMALS_UNIT = 5;
557
		if (!isset($this->global->MAIN_MAX_DECIMALS_TOT))   $this->global->MAIN_MAX_DECIMALS_TOT = 2;
558
		if (!isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) $this->global->MAIN_MAX_DECIMALS_SHOWN = 8;
559
560
		// Default pdf option
561
		if (!isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) $this->global->MAIN_PDF_DASH_BETWEEN_LINES = 1; // use dash between lines
562
		if (!isset($this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) $this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT = 1; // allow html content into free footer text
563
564
		// Default max file size for upload
565
		$this->maxfilesize = (empty($this->global->MAIN_UPLOAD_DOC) ? 0 : (int) $this->global->MAIN_UPLOAD_DOC * 1024);
566
567
		// By default, we propagate contacts
568
		if (!isset($this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) $this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN = '*'; // Can be also '*' or '^(BILLING|SHIPPING|CUSTOMER|.*)$' (regex not yet implemented)
569
570
		// By default, we do not use the zip town table but the table of third parties
571
		if (!isset($this->global->MAIN_USE_ZIPTOWN_DICTIONNARY)) $this->global->MAIN_USE_ZIPTOWN_DICTIONNARY = 0;
572
573
		// By default, we open card if one found
574
		if (!isset($this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE)) $this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE = 1;
575
576
		// By default, we show state code in combo list
577
		if (!isset($this->global->MAIN_SHOW_STATE_CODE)) $this->global->MAIN_SHOW_STATE_CODE = 1;
578
579
		// Use a SCA ready workflow with Stripe module (STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION by default if nothing defined)
580
		if (!isset($this->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION) && empty($this->global->STRIPE_USE_NEW_CHECKOUT)) $this->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 1;
581
582
		// Define list of limited modules (value must be key found for "name" property of module, so for example 'supplierproposal' for Module "Supplier Proposal"
583
		if (!isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) $this->global->MAIN_MODULES_FOR_EXTERNAL = 'user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,agenda,resource,adherent,blockedlog'; // '' means 'all'. Note that contact is added here as it should be a module later.
584
		if (!empty($this->modules_parts['moduleforexternal']))		// Module part to include an external module into the MAIN_MODULES_FOR_EXTERNAL list
585
		{
586
			foreach ($this->modules_parts['moduleforexternal'] as $key=>$value) $this->global->MAIN_MODULES_FOR_EXTERNAL .= ",".$key;
587
		}
588
589
		// Enable select2
590
		if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT) || $this->global->MAIN_USE_JQUERY_MULTISELECT == '1') $this->global->MAIN_USE_JQUERY_MULTISELECT = 'select2';
591
592
		// Timeouts
593
        if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) $this->global->MAIN_USE_CONNECT_TIMEOUT = 10;
594
        if (empty($this->global->MAIN_USE_RESPONSE_TIMEOUT)) $this->global->MAIN_USE_RESPONSE_TIMEOUT = 30;
595
596
		// Set default variable to calculate VAT as if option tax_mode was 0 (standard)
597
        if (empty($this->global->TAX_MODE_SELL_PRODUCT)) $this->global->TAX_MODE_SELL_PRODUCT = 'invoice';
598
        if (empty($this->global->TAX_MODE_BUY_PRODUCT))  $this->global->TAX_MODE_BUY_PRODUCT = 'invoice';
599
        if (empty($this->global->TAX_MODE_SELL_SERVICE)) $this->global->TAX_MODE_SELL_SERVICE = 'payment';
600
        if (empty($this->global->TAX_MODE_BUY_SERVICE))  $this->global->TAX_MODE_BUY_SERVICE = 'payment';
601
602
		// Delay before warnings
603
		// Avoid strict errors. TODO: Replace xxx->warning_delay with a property ->warning_delay_xxx
604
		if (isset($this->agenda)) {
605
		    $this->adherent->subscription = new stdClass();
606
            $this->adherent->subscription->warning_delay = (isset($this->global->MAIN_DELAY_MEMBERS) ? $this->global->MAIN_DELAY_MEMBERS : 0) * 86400;
607
		}
608
		if (isset($this->agenda)) {
609
			$this->agenda->warning_delay = (isset($this->global->MAIN_DELAY_ACTIONS_TODO) ? $this->global->MAIN_DELAY_ACTIONS_TODO : 7) * 86400;
610
        }
611
		if (isset($this->projet))
0 ignored issues
show
Bug introduced by
The property projet does not exist on Conf. Did you mean project?
Loading history...
612
		{
613
			$this->projet->warning_delay = (isset($this->global->MAIN_DELAY_PROJECT_TO_CLOSE) ? $this->global->MAIN_DELAY_PROJECT_TO_CLOSE : 7) * 86400;
614
		    $this->projet->task = new StdClass();
615
		    $this->projet->task->warning_delay = (isset($this->global->MAIN_DELAY_TASKS_TODO) ? $this->global->MAIN_DELAY_TASKS_TODO : 7) * 86400;
616
		}
617
618
        if (isset($this->commande)) {
619
            $this->commande->client = new stdClass();
620
    		$this->commande->fournisseur = new stdClass();
621
    		$this->commande->client->warning_delay = (isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_ORDERS_TO_PROCESS : 2) * 86400;
622
    		$this->commande->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS : 7) * 86400;
623
		}
624
		if (isset($this->propal)) {
625
		    $this->propal->cloture = new stdClass();
626
    		$this->propal->facturation = new stdClass();
627
    		$this->propal->cloture->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE) ? $this->global->MAIN_DELAY_PROPALS_TO_CLOSE : 0) * 86400;
628
    		$this->propal->facturation->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_BILL) ? $this->global->MAIN_DELAY_PROPALS_TO_BILL : 0) * 86400;
629
		}
630
		if (isset($this->facture)) {
631
		    $this->facture->client = new stdClass();
632
    		$this->facture->fournisseur = new stdClass();
633
    		$this->facture->client->warning_delay = (isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED) ? $this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED : 0) * 86400;
634
    		$this->facture->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY) ? $this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY : 0) * 86400;
635
		}
636
		if (isset($this->contrat)) {
637
		    $this->contrat->services = new stdClass();
638
    		$this->contrat->services->inactifs = new stdClass();
639
	   	    $this->contrat->services->expires = new stdClass();
640
	   	    $this->contrat->services->inactifs->warning_delay = (isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES) ? $this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES : 0) * 86400;
641
	   	    $this->contrat->services->expires->warning_delay = (isset($this->global->MAIN_DELAY_RUNNING_SERVICES) ? $this->global->MAIN_DELAY_RUNNING_SERVICES : 0) * 86400;
642
		}
643
		if (isset($this->commande)) {
644
		    $this->bank->rappro					= new stdClass();
645
    		$this->bank->cheque					= new stdClass();
646
    		$this->bank->rappro->warning_delay = (isset($this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE) ? $this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE : 0) * 86400;
647
    		$this->bank->cheque->warning_delay = (isset($this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT) ? $this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT : 0) * 86400;
648
		}
649
		if (isset($this->expensereport)) {
650
		    $this->expensereport->approve = new stdClass();
651
		    $this->expensereport->approve->warning_delay = (isset($this->global->MAIN_DELAY_EXPENSEREPORTS) ? $this->global->MAIN_DELAY_EXPENSEREPORTS : 0) * 86400;
652
		    $this->expensereport->payment = new stdClass();
653
		    $this->expensereport->payment->warning_delay = (isset($this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY) ? $this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY : 0) * 86400;
654
		}
655
        if (isset($this->holiday)) {
656
            $this->holiday->approve = new stdClass();
657
            $this->holiday->approve->warning_delay = (isset($this->global->MAIN_DELAY_HOLIDAYS) ? $this->global->MAIN_DELAY_HOLIDAYS : 0) * 86400;
658
        }
659
660
		if (!empty($this->global->PRODUIT_MULTIPRICES) && empty($this->global->PRODUIT_MULTIPRICES_LIMIT))
661
		{
662
		    $this->global->PRODUIT_MULTIPRICES_LIMIT = 5;
663
		}
664
665
		// For modules that want to disable top or left menu
666
		if (!empty($this->global->MAIN_HIDE_TOP_MENU)) $this->dol_hide_topmenu = $this->global->MAIN_HIDE_TOP_MENU;
667
		if (!empty($this->global->MAIN_HIDE_LEFT_MENU)) $this->dol_hide_leftmenu = $this->global->MAIN_HIDE_LEFT_MENU;
668
669
		if (empty($this->global->MAIN_SIZE_SHORTLIST_LIMIT)) $this->global->MAIN_SIZE_SHORTLIST_LIMIT = 3;
670
671
		if (!isset($this->global->THEME_HIDE_BORDER_ON_INPUT)) $this->global->THEME_HIDE_BORDER_ON_INPUT = 0;
672
673
		// Save inconsistent option
674
		if (empty($this->global->AGENDA_USE_EVENT_TYPE) && (!isset($this->global->AGENDA_DEFAULT_FILTER_TYPE) || $this->global->AGENDA_DEFAULT_FILTER_TYPE == 'AC_NON_AUTO'))
675
		{
676
			$this->global->AGENDA_DEFAULT_FILTER_TYPE = '0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on.
677
		}
678
679
		if (!isset($this->global->MAIN_JS_GRAPH)) $this->global->MAIN_JS_GRAPH = 'chart'; // Use chart.js library
680
681
		if (empty($this->global->MAIN_MODULE_DOLISTORE_API_SRV)) $this->global->MAIN_MODULE_DOLISTORE_API_SRV = 'https://www.dolistore.com';
682
		if (empty($this->global->MAIN_MODULE_DOLISTORE_API_KEY)) $this->global->MAIN_MODULE_DOLISTORE_API_KEY = 'dolistorecatalogpublickey1234567';
683
684
		// If we are in develop mode, we activate the option MAIN_SECURITY_CSRF_WITH_TOKEN to 1 if not already defined.
685
		if (!isset($this->global->MAIN_SECURITY_CSRF_WITH_TOKEN) && $this->global->MAIN_FEATURES_LEVEL >= 2) $this->global->MAIN_SECURITY_CSRF_WITH_TOKEN = 1;
686
687
		// For backward compatibility
688
		if (isset($this->product))   $this->produit = $this->product;
689
		if (isset($this->facture))   $this->invoice = $this->facture;
690
		if (isset($this->commande))  $this->order = $this->commande;
691
		if (isset($this->contrat))   $this->contract = $this->contrat;
692
		if (isset($this->categorie)) $this->category = $this->categorie;
693
		if (isset($this->project))   $this->project = $this->projet;
694
695
        // Object $mc
696
        if (!defined('NOREQUIREMC') && !empty($this->multicompany->enabled))
697
        {
698
        	if (is_object($mc)) $mc->setValues($this);
699
        }
700
701
        if (!empty($this->syslog->enabled)) {
702
			// We init log handlers
703
			if (!empty($this->global->SYSLOG_HANDLERS)) {
704
				$handlers = json_decode($this->global->SYSLOG_HANDLERS);
705
			} else {
706
				$handlers = array();
707
			}
708
			foreach ($handlers as $handler) {
709
				$handler_file_found = '';
710
				$dirsyslogs = array_merge(array('/core/modules/syslog/'), $this->modules_parts['syslog']);
711
				foreach ($dirsyslogs as $reldir) {
712
					$dir = dol_buildpath($reldir, 0);
713
					$newdir = dol_osencode($dir);
714
					if (is_dir($newdir)) {
715
						$file = $newdir.$handler.'.php';
716
						if (file_exists($file)) {
717
							$handler_file_found = $file;
718
							break;
719
						}
720
					}
721
				}
722
723
				if (empty($handler_file_found)) {
724
					throw new Exception('Missing log handler file '.$handler.'.php');
725
				}
726
727
				require_once $handler_file_found;
728
				$loghandlerinstance = new $handler();
729
				if (!$loghandlerinstance instanceof LogHandlerInterface) {
730
					throw new Exception('Log handler does not extend LogHandlerInterface');
731
				}
732
733
				if (empty($this->loghandlers[$handler])) {
734
					$this->loghandlers[$handler] = $loghandlerinstance;
735
				}
736
			}
737
        }
738
	}
739
}
740