conf.class.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
  4. * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2006 Jean Heimburger <jean@tiaris.info>
  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. * \file htdocs/core/class/conf.class.php
  23. * \ingroup core
  24. * \brief File of class to manage storage of current setup
  25. * Config is stored into file conf.php
  26. */
  27. /**
  28. * Class to stock current configuration
  29. */
  30. class Conf
  31. {
  32. /** \public */
  33. //! To store properties found in conf file
  34. public $file;
  35. /**
  36. * @var Object Associative array with some properties ->type, ->db, ...
  37. */
  38. public $db;
  39. //! To store properties found into database
  40. public $global;
  41. //! To store browser info
  42. public $browser;
  43. //! To store if javascript/ajax is enabked
  44. public $use_javascript_ajax;
  45. //! To store if javascript/ajax is enabked
  46. public $disable_compute;
  47. //! Used to store current currency (ISO code like 'USD', 'EUR', ...)
  48. public $currency;
  49. //! Used to store current css (from theme)
  50. public $theme; // Contains current theme ("eldy", "auguria", ...)
  51. public $css; // Contains full path of css page ("/theme/eldy/style.css.php", ...)
  52. //! Used to store current menu handler
  53. public $standard_menu;
  54. // List of activated modules
  55. public $modules = array();
  56. public $modules_parts = array(
  57. 'css' => array(),
  58. 'js' => array(),
  59. 'tabs' => array(),
  60. 'triggers' => array(),
  61. 'login' => array(),
  62. 'substitutions' => array(),
  63. 'menus' => array(),
  64. 'theme' => array(),
  65. 'sms' => array(),
  66. 'tpl' => array(),
  67. 'barcode' => array(),
  68. 'models' => array(),
  69. 'societe' => array(),
  70. 'hooks' => array(),
  71. 'dir' => array(),
  72. 'syslog' => array(),
  73. );
  74. public $logbuffer = array();
  75. /**
  76. * @var LogHandlerInterface[]
  77. */
  78. public $loghandlers = array();
  79. //! To store properties of multi-company
  80. public $multicompany;
  81. //! Used to store running instance for multi-company (default 1)
  82. public $entity = 1;
  83. //! Used to store list of entities to use for each element
  84. public $entities = array();
  85. public $dol_hide_topmenu; // Set if we force param dol_hide_topmenu into login url
  86. public $dol_hide_leftmenu; // Set if we force param dol_hide_leftmenu into login url
  87. public $dol_optimize_smallscreen; // Set if we force param dol_optimize_smallscreen into login url or if browser is smartphone
  88. public $dol_no_mouse_hover; // Set if we force param dol_no_mouse_hover into login url or if browser is smartphone
  89. public $dol_use_jmobile; // Set if we force param dol_use_jmobile into login url
  90. /**
  91. * Constructor
  92. */
  93. public function __construct()
  94. {
  95. // Properly declare multi-modules objects.
  96. $this->file = new stdClass();
  97. $this->db = new stdClass();
  98. $this->global = new stdClass();
  99. $this->mycompany = new stdClass();
  100. $this->admin = new stdClass();
  101. $this->user = new stdClass();
  102. $this->syslog = new stdClass();
  103. $this->browser = new stdClass();
  104. $this->medias = new stdClass();
  105. $this->multicompany = new stdClass();
  106. //! Charset for HTML output and for storing data in memory
  107. $this->file->character_set_client = 'UTF-8'; // UTF-8, ISO-8859-1
  108. // First level object
  109. // TODO Remove this part.
  110. $this->expedition_bon = new stdClass();
  111. $this->delivery_note = new stdClass();
  112. $this->fournisseur = new stdClass();
  113. $this->product = new stdClass();
  114. $this->service = new stdClass();
  115. $this->contrat = new stdClass();
  116. $this->actions = new stdClass();
  117. $this->agenda = new stdClass();
  118. $this->commande = new stdClass();
  119. $this->propal = new stdClass();
  120. $this->facture = new stdClass();
  121. $this->contrat = new stdClass();
  122. $this->usergroup = new stdClass();
  123. $this->adherent = new stdClass();
  124. $this->bank = new stdClass();
  125. $this->notification = new stdClass();
  126. $this->mailing = new stdClass();
  127. $this->expensereport = new stdClass();
  128. $this->productbatch = new stdClass();
  129. }
  130. /**
  131. * Load setup values into conf object (read llx_const)
  132. * Note that this->db->xxx, this->file->xxx and this->multicompany have been already loaded when setValues is called.
  133. *
  134. * @param DoliDB $db Database handler
  135. * @return int < 0 if KO, >= 0 if OK
  136. */
  137. public function setValues($db)
  138. {
  139. dol_syslog(get_class($this)."::setValues");
  140. //Define all global constants into $this->global->key=value
  141. $sql = "SELECT ".$db->decrypt('name')." as name,";
  142. $sql .= " ".$db->decrypt('value')." as value, entity";
  143. $sql .= " FROM ".MAIN_DB_PREFIX."const";
  144. $sql .= " WHERE entity IN (0,".$this->entity.")";
  145. $sql .= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite.
  146. $resql = $db->query($sql);
  147. if ($resql)
  148. {
  149. $i = 0;
  150. $numr = $db->num_rows($resql);
  151. while ($i < $numr)
  152. {
  153. $objp = $db->fetch_object($resql);
  154. $key = $objp->name;
  155. $value = $objp->value;
  156. if ($key)
  157. {
  158. // Allow constants values to be overridden by environment variables
  159. if (isset($_SERVER['DOLIBARR_'.$key])) {
  160. $value = $_SERVER['DOLIBARR_'.$key];
  161. } elseif (isset($_ENV['DOLIBARR_'.$key])) {
  162. $value = $_ENV['DOLIBARR_'.$key];
  163. }
  164. //if (! defined("$key")) define("$key", $value); // In some cases, the constant might be already forced (Example: SYSLOG_HANDLERS during install)
  165. $this->global->$key = $value;
  166. if ($value && strpos($key, 'MAIN_MODULE_') === 0)
  167. {
  168. $reg = array();
  169. // If this is constant for a new tab page activated by a module. It initializes modules_parts['tabs'].
  170. if (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)_TABS_/i', $key))
  171. {
  172. $partname = 'tabs';
  173. $params = explode(':', $value, 2);
  174. if (!is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); }
  175. $this->modules_parts[$partname][$params[0]][] = $value; // $value may be a string or an array
  176. }
  177. // If this is constant for all generic part activated by a module. It initializes
  178. // modules_parts['login'], modules_parts['menus'], modules_parts['substitutions'], modules_parts['triggers'], modules_parts['tpl'],
  179. // modules_parts['models'], modules_parts['theme']
  180. // modules_parts['sms'],
  181. // modules_parts['css'], ...
  182. elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)_([A-Z]+)$/i', $key, $reg))
  183. {
  184. $modulename = strtolower($reg[1]);
  185. $partname = strtolower($reg[2]);
  186. if (!is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); }
  187. $arrValue = json_decode($value, true);
  188. if (is_array($arrValue) && !empty($arrValue)) $value = $arrValue;
  189. elseif (in_array($partname, array('login', 'menus', 'substitutions', 'triggers', 'tpl'))) $value = '/'.$modulename.'/core/'.$partname.'/';
  190. elseif (in_array($partname, array('models', 'theme'))) $value = '/'.$modulename.'/';
  191. elseif (in_array($partname, array('sms'))) $value = '/'.$modulename.'/';
  192. elseif ($value == 1) $value = '/'.$modulename.'/core/modules/'.$partname.'/'; // ex: partname = societe
  193. $this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value)); // $value may be a string or an array
  194. }
  195. // If this is a module constant (must be at end)
  196. elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)$/i', $key, $reg))
  197. {
  198. $modulename = strtolower($reg[1]);
  199. if ($modulename == 'propale') $modulename = 'propal';
  200. if ($modulename == 'supplierproposal') $modulename = 'supplier_proposal';
  201. if (!isset($this->$modulename) || !is_object($this->$modulename)) $this->$modulename = new stdClass();
  202. $this->$modulename->enabled = true;
  203. $this->modules[] = $modulename; // Add this module in list of enabled modules
  204. }
  205. }
  206. }
  207. $i++;
  208. }
  209. $db->free($resql);
  210. }
  211. // Include other local consts.php files and fetch their values to the corresponding database constants.
  212. if (!empty($this->global->LOCAL_CONSTS_FILES)) {
  213. $filesList = explode(":", $this->global->LOCAL_CONSTS_FILES);
  214. foreach ($filesList as $file) {
  215. $file = dol_sanitizeFileName($file);
  216. include_once DOL_DOCUMENT_ROOT."/".$file."/".$file."_consts.php"; // This file can run code like setting $this->global->XXX vars.
  217. }
  218. }
  219. //var_dump($this->modules);
  220. //var_dump($this->modules_parts['theme']);
  221. // If you can't set timezone of your PHP, set this constant. Better is to set it to UTC.
  222. // In future, this constant will be forced to 'UTC' so PHP server timezone will not have effect anymore.
  223. //$this->global->MAIN_SERVER_TZ='Europe/Paris';
  224. if (!empty($this->global->MAIN_SERVER_TZ) && $this->global->MAIN_SERVER_TZ != 'auto')
  225. {
  226. try {
  227. date_default_timezone_set($this->global->MAIN_SERVER_TZ);
  228. } catch (Exception $e)
  229. {
  230. dol_syslog("Error: Bad value for parameter MAIN_SERVER_TZ=".$this->global->MAIN_SERVER_TZ, LOG_ERR);
  231. }
  232. }
  233. // Object $mc
  234. if (!defined('NOREQUIREMC') && !empty($this->multicompany->enabled)) {
  235. global $mc;
  236. $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php');
  237. if ($ret) {
  238. $mc = new ActionsMulticompany($db);
  239. $this->mc = $mc;
  240. }
  241. }
  242. // Clean some variables
  243. if (empty($this->global->MAIN_MENU_STANDARD)) $this->global->MAIN_MENU_STANDARD = "eldy_menu.php";
  244. if (empty($this->global->MAIN_MENUFRONT_STANDARD)) $this->global->MAIN_MENUFRONT_STANDARD = "eldy_menu.php";
  245. 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
  246. 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
  247. if (!isset($this->global->FACTURE_TVAOPTION)) $this->global->FACTURE_TVAOPTION = 1;
  248. // Variable globales LDAP
  249. if (empty($this->global->LDAP_FIELD_FULLNAME)) $this->global->LDAP_FIELD_FULLNAME = '';
  250. if (!isset($this->global->LDAP_KEY_USERS)) $this->global->LDAP_KEY_USERS = $this->global->LDAP_FIELD_FULLNAME;
  251. if (!isset($this->global->LDAP_KEY_GROUPS)) $this->global->LDAP_KEY_GROUPS = $this->global->LDAP_FIELD_FULLNAME;
  252. if (!isset($this->global->LDAP_KEY_CONTACTS)) $this->global->LDAP_KEY_CONTACTS = $this->global->LDAP_FIELD_FULLNAME;
  253. if (!isset($this->global->LDAP_KEY_MEMBERS)) $this->global->LDAP_KEY_MEMBERS = $this->global->LDAP_FIELD_FULLNAME;
  254. if (!isset($this->global->LDAP_KEY_MEMBERS_TYPES)) $this->global->LDAP_KEY_MEMBERS_TYPES = $this->global->LDAP_FIELD_FULLNAME;
  255. // Load translation object with current language
  256. if (empty($this->global->MAIN_LANG_DEFAULT)) $this->global->MAIN_LANG_DEFAULT = "en_US";
  257. $rootfordata = DOL_DATA_ROOT;
  258. $rootforuser = DOL_DATA_ROOT;
  259. // If multicompany module is enabled, we redefine the root of data
  260. if (!empty($this->multicompany->enabled) && !empty($this->entity) && $this->entity > 1)
  261. {
  262. $rootfordata .= '/'.$this->entity;
  263. }
  264. // Set standard temporary folder name or global override
  265. $rootfortemp = empty($this->global->MAIN_TEMP_DIR) ? $rootfordata : $this->global->MAIN_TEMP_DIR;
  266. // Define default dir_output and dir_temp for directories of modules
  267. foreach ($this->modules as $module)
  268. {
  269. //var_dump($module);
  270. // For multicompany sharings
  271. $this->$module->multidir_output = array($this->entity => $rootfordata."/".$module);
  272. $this->$module->multidir_temp = array($this->entity => $rootfortemp."/".$module."/temp");
  273. // For backward compatibility
  274. $this->$module->dir_output = $rootfordata."/".$module;
  275. $this->$module->dir_temp = $rootfortemp."/".$module."/temp";
  276. }
  277. // External modules storage
  278. if (!empty($this->modules_parts['dir']))
  279. {
  280. foreach ($this->modules_parts['dir'] as $module => $dirs)
  281. {
  282. if (!empty($this->$module->enabled))
  283. {
  284. foreach ($dirs as $type => $name) // $type is 'output' or 'temp'
  285. {
  286. $multidirname = 'multidir_'.$type;
  287. $dirname = 'dir_'.$type;
  288. if ($type != 'temp')
  289. {
  290. // For multicompany sharings
  291. $this->$module->$multidirname = array($this->entity => $rootfordata."/".$name);
  292. // For backward compatibility
  293. $this->$module->$dirname = $rootfordata."/".$name;
  294. } else {
  295. // For multicompany sharings
  296. $this->$module->$multidirname = array($this->entity => $rootfortemp."/".$name."/temp");
  297. // For backward compatibility
  298. $this->$module->$dirname = $rootfortemp."/".$name."/temp";
  299. }
  300. }
  301. }
  302. }
  303. }
  304. // For mycompany storage
  305. $this->mycompany->dir_output = $rootfordata."/mycompany";
  306. $this->mycompany->dir_temp = $rootfortemp."/mycompany/temp";
  307. // For admin storage
  308. $this->admin->dir_output = $rootfordata.'/admin';
  309. $this->admin->dir_temp = $rootfortemp.'/admin/temp';
  310. // For user storage
  311. $this->user->multidir_output = array($this->entity => $rootfordata."/users");
  312. $this->user->multidir_temp = array($this->entity => $rootfortemp."/users/temp");
  313. // For backward compatibility
  314. $this->user->dir_output = $rootforuser."/users";
  315. $this->user->dir_temp = $rootfortemp."/users/temp";
  316. // For usergroup storage
  317. $this->usergroup->dir_output = $rootforuser."/usergroups";
  318. $this->usergroup->dir_temp = $rootfortemp."/usergroups/temp";
  319. // For proposal storage
  320. $this->propal->multidir_output = array($this->entity => $rootfordata."/propale");
  321. $this->propal->multidir_temp = array($this->entity => $rootfortemp."/propale/temp");
  322. // For backward compatibility
  323. $this->propal->dir_output = $rootfordata."/propale";
  324. $this->propal->dir_temp = $rootfortemp."/propale/temp";
  325. // For medias storage
  326. $this->medias->multidir_output = array($this->entity => $rootfordata."/medias");
  327. $this->medias->multidir_temp = array($this->entity => $rootfortemp."/medias/temp");
  328. // Exception: Some dir are not the name of module. So we keep exception here for backward compatibility.
  329. // Sous module bons d'expedition
  330. $this->expedition_bon->enabled = (!empty($this->global->MAIN_SUBMODULE_EXPEDITION) ? $this->global->MAIN_SUBMODULE_EXPEDITION : 0);
  331. // Sub module delivery note Sous module bons de livraison
  332. $this->delivery_note->enabled = (!empty($this->global->MAIN_SUBMODULE_LIVRAISON) ? $this->global->MAIN_SUBMODULE_LIVRAISON : 0);
  333. // Module fournisseur
  334. if (!empty($this->fournisseur))
  335. {
  336. $this->fournisseur->commande = new stdClass();
  337. $this->fournisseur->commande->multidir_output = array($this->entity => $rootfordata."/fournisseur/commande");
  338. $this->fournisseur->commande->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/commande/temp");
  339. $this->fournisseur->commande->dir_output = $rootfordata."/fournisseur/commande"; // For backward compatibility
  340. $this->fournisseur->commande->dir_temp = $rootfortemp."/fournisseur/commande/temp"; // For backward compatibility
  341. $this->fournisseur->facture = new stdClass();
  342. $this->fournisseur->facture->multidir_output = array($this->entity => $rootfordata."/fournisseur/facture");
  343. $this->fournisseur->facture->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/facture/temp");
  344. $this->fournisseur->facture->dir_output = $rootfordata."/fournisseur/facture"; // For backward compatibility
  345. $this->fournisseur->facture->dir_temp = $rootfortemp."/fournisseur/facture/temp"; // For backward compatibility
  346. $this->supplierproposal = new stdClass();
  347. $this->supplierproposal->multidir_output = array($this->entity => $rootfordata."/supplier_proposal");
  348. $this->supplierproposal->multidir_temp = array($this->entity => $rootfortemp."/supplier_proposal/temp");
  349. $this->supplierproposal->dir_output = $rootfordata."/supplier_proposal"; // For backward compatibility
  350. $this->supplierproposal->dir_temp = $rootfortemp."/supplier_proposal/temp"; // For backward compatibility
  351. $this->fournisseur->payment = new stdClass();
  352. $this->fournisseur->payment->multidir_output = array($this->entity => $rootfordata."/fournisseur/payment");
  353. $this->fournisseur->payment->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/payment/temp");
  354. $this->fournisseur->payment->dir_output = $rootfordata."/fournisseur/payment"; // For backward compatibility
  355. $this->fournisseur->payment->dir_temp = $rootfortemp."/fournisseur/payment/temp"; // For backward compatibility
  356. // To prepare split of module fournisseur into module 'fournisseur' + supplier_order + supplier_invoice
  357. 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
  358. {
  359. $this->supplier_order = new stdClass();
  360. $this->supplier_order->enabled = 1;
  361. $this->supplier_order->multidir_output = array($this->entity => $rootfordata."/fournisseur/commande");
  362. $this->supplier_order->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/commande/temp");
  363. $this->supplier_order->dir_output = $rootfordata."/fournisseur/commande"; // For backward compatibility
  364. $this->supplier_order->dir_temp = $rootfortemp."/fournisseur/commande/temp"; // For backward compatibility
  365. $this->supplier_invoice = new stdClass();
  366. $this->supplier_invoice->enabled = 1;
  367. $this->supplier_invoice->multidir_output = array($this->entity => $rootfordata."/fournisseur/facture");
  368. $this->supplier_invoice->multidir_temp = array($this->entity => $rootfortemp."/fournisseur/facture/temp");
  369. $this->supplier_invoice->dir_output = $rootfordata."/fournisseur/facture"; // For backward compatibility
  370. $this->supplier_invoice->dir_temp = $rootfortemp."/fournisseur/facture/temp"; // For backward compatibility
  371. }
  372. }
  373. // Module product/service
  374. $this->product->multidir_output = array($this->entity => $rootfordata."/produit");
  375. $this->product->multidir_temp = array($this->entity => $rootfortemp."/produit/temp");
  376. $this->service->multidir_output = array($this->entity => $rootfordata."/produit");
  377. $this->service->multidir_temp = array($this->entity => $rootfortemp."/produit/temp");
  378. // For backward compatibility
  379. $this->product->dir_output = $rootfordata."/produit";
  380. $this->product->dir_temp = $rootfortemp."/produit/temp";
  381. $this->service->dir_output = $rootfordata."/produit";
  382. $this->service->dir_temp = $rootfortemp."/produit/temp";
  383. // Module productbatch
  384. $this->productbatch->multidir_output = array($this->entity => $rootfordata."/produitlot");
  385. $this->productbatch->multidir_temp = array($this->entity => $rootfortemp."/produitlot/temp");
  386. // Module contrat
  387. $this->contrat->multidir_output = array($this->entity => $rootfordata."/contract");
  388. $this->contrat->multidir_temp = array($this->entity => $rootfortemp."/contract/temp");
  389. // For backward compatibility
  390. $this->contrat->dir_output = $rootfordata."/contract";
  391. $this->contrat->dir_temp = $rootfortemp."/contract/temp";
  392. // Module bank
  393. $this->bank->multidir_output = array($this->entity => $rootfordata."/bank");
  394. $this->bank->multidir_temp = array($this->entity => $rootfortemp."/bank/temp");
  395. // For backward compatibility
  396. $this->bank->dir_output = $rootfordata."/bank";
  397. $this->bank->dir_temp = $rootfortemp."/bank/temp";
  398. // Set some default values
  399. //$this->global->MAIN_LIST_FILTER_ON_DAY=1; // On filter that show date, we must show input field for day before or after month
  400. $this->global->MAIN_MAIL_USE_MULTI_PART = 1;
  401. // societe
  402. if (empty($this->global->SOCIETE_CODECLIENT_ADDON)) $this->global->SOCIETE_CODECLIENT_ADDON = "mod_codeclient_leopard";
  403. if (empty($this->global->SOCIETE_CODECOMPTA_ADDON)) $this->global->SOCIETE_CODECOMPTA_ADDON = "mod_codecompta_panicum";
  404. if (empty($this->global->CHEQUERECEIPTS_ADDON)) $this->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
  405. if (empty($this->global->TICKET_ADDON)) $this->global->TICKET_ADDON = 'mod_ticket_simple';
  406. // Security
  407. if (empty($this->global->USER_PASSWORD_GENERATED)) $this->global->USER_PASSWORD_GENERATED = 'standard'; // Default password generator
  408. if (empty($this->global->MAIN_UMASK)) $this->global->MAIN_UMASK = '0664'; // Default mask
  409. // conf->use_javascript_ajax
  410. $this->use_javascript_ajax = 1;
  411. if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) $this->use_javascript_ajax = !$this->global->MAIN_DISABLE_JAVASCRIPT;
  412. // If no javascript_ajax, Ajax features are disabled.
  413. if (empty($this->use_javascript_ajax))
  414. {
  415. unset($this->global->PRODUIT_USE_SEARCH_TO_SELECT);
  416. unset($this->global->COMPANY_USE_SEARCH_TO_SELECT);
  417. unset($this->global->CONTACT_USE_SEARCH_TO_SELECT);
  418. unset($this->global->PROJECT_USE_SEARCH_TO_SELECT);
  419. }
  420. if (!empty($this->productbatch->enabled))
  421. {
  422. $this->global->STOCK_CALCULATE_ON_BILL = 0;
  423. $this->global->STOCK_CALCULATE_ON_VALIDATE_ORDER = 0;
  424. $this->global->STOCK_CALCULATE_ON_SHIPMENT = 1;
  425. $this->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE = 0;
  426. $this->global->STOCK_CALCULATE_ON_SUPPLIER_BILL = 0;
  427. $this->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER = 0;
  428. if (empty($this->reception->enabled)) {
  429. $this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER = 1;
  430. }
  431. else {
  432. $this->global->STOCK_CALCULATE_ON_RECEPTION = 1;
  433. $this->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE = 0;
  434. }
  435. }
  436. // conf->currency
  437. if (empty($this->global->MAIN_MONNAIE)) $this->global->MAIN_MONNAIE = 'EUR';
  438. $this->currency = $this->global->MAIN_MONNAIE;
  439. if (empty($this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)) $this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY = 30; // Less than 1 minutes to be sure
  440. // conf->global->ACCOUNTING_MODE = Option des modules Comptabilites (simple ou expert). Defini le mode de calcul des etats comptables (CA,...)
  441. if (empty($this->global->ACCOUNTING_MODE)) $this->global->ACCOUNTING_MODE = 'RECETTES-DEPENSES'; // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES'
  442. // By default, suppliers objects can be linked to all projects
  443. if (!isset($this->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)) $this->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS = 1;
  444. // By default we enable feature to bill time spent
  445. if (!isset($this->global->PROJECT_BILL_TIME_SPENT)) $this->global->PROJECT_BILL_TIME_SPENT = 1;
  446. // MAIN_HTML_TITLE
  447. if (!isset($this->global->MAIN_HTML_TITLE)) $this->global->MAIN_HTML_TITLE = 'noapp,thirdpartynameonly,contactnameonly,projectnameonly';
  448. // conf->liste_limit = constante de taille maximale des listes
  449. if (empty($this->global->MAIN_SIZE_LISTE_LIMIT)) $this->global->MAIN_SIZE_LISTE_LIMIT = 25;
  450. $this->liste_limit = $this->global->MAIN_SIZE_LISTE_LIMIT;
  451. // conf->product->limit_size = constante de taille maximale des select de produit
  452. if (!isset($this->global->PRODUIT_LIMIT_SIZE)) $this->global->PRODUIT_LIMIT_SIZE = 1000;
  453. $this->product->limit_size = $this->global->PRODUIT_LIMIT_SIZE;
  454. // conf->theme et $this->css
  455. if (empty($this->global->MAIN_THEME)) $this->global->MAIN_THEME = "eldy";
  456. if (!empty($this->global->MAIN_FORCETHEME)) $this->global->MAIN_THEME = $this->global->MAIN_FORCETHEME;
  457. $this->theme = $this->global->MAIN_THEME;
  458. $this->css = "/theme/".$this->theme."/style.css.php";
  459. // conf->email_from = email pour envoi par dolibarr des mails automatiques
  460. $this->email_from = "robot@example.com";
  461. if (!empty($this->global->MAIN_MAIL_EMAIL_FROM)) $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM;
  462. // conf->notification->email_from = email pour envoi par Dolibarr des notifications
  463. $this->notification->email_from = $this->email_from;
  464. if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) $this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM;
  465. // conf->mailing->email_from = email pour envoi par Dolibarr des mailings
  466. $this->mailing->email_from = $this->email_from;
  467. if (!empty($this->global->MAILING_EMAIL_FROM)) $this->mailing->email_from = $this->global->MAILING_EMAIL_FROM;
  468. if (!isset($this->global->MAIN_EMAIL_ADD_TRACK_ID)) $this->global->MAIN_EMAIL_ADD_TRACK_ID = 1;
  469. // Format for date (used by default when not found or not searched in lang)
  470. $this->format_date_short = "%d/%m/%Y"; // Format of day with PHP/C tags (strftime functions)
  471. $this->format_date_short_java = "dd/MM/yyyy"; // Format of day with Java tags
  472. $this->format_hour_short = "%H:%M";
  473. $this->format_hour_short_duration = "%H:%M";
  474. $this->format_date_text_short = "%d %b %Y";
  475. $this->format_date_text = "%d %B %Y";
  476. $this->format_date_hour_short = "%d/%m/%Y %H:%M";
  477. $this->format_date_hour_sec_short = "%d/%m/%Y %H:%M:%S";
  478. $this->format_date_hour_text_short = "%d %b %Y %H:%M";
  479. $this->format_date_hour_text = "%d %B %Y %H:%M";
  480. // Duration of workday
  481. if (!isset($this->global->MAIN_DURATION_OF_WORKDAY)) $this->global->MAIN_DURATION_OF_WORKDAY = 86400;
  482. // Limites decimales si non definie (peuvent etre egale a 0)
  483. if (!isset($this->global->MAIN_MAX_DECIMALS_UNIT)) $this->global->MAIN_MAX_DECIMALS_UNIT = 5;
  484. if (!isset($this->global->MAIN_MAX_DECIMALS_TOT)) $this->global->MAIN_MAX_DECIMALS_TOT = 2;
  485. if (!isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) $this->global->MAIN_MAX_DECIMALS_SHOWN = 8;
  486. // Default pdf option
  487. if (!isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) $this->global->MAIN_PDF_DASH_BETWEEN_LINES = 1; // use dash between lines
  488. 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
  489. // Default max file size for upload
  490. $this->maxfilesize = (empty($this->global->MAIN_UPLOAD_DOC) ? 0 : (int) $this->global->MAIN_UPLOAD_DOC * 1024);
  491. // By default, we propagate contacts
  492. 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)
  493. // By default, we do not use the zip town table but the table of third parties
  494. if (!isset($this->global->MAIN_USE_ZIPTOWN_DICTIONNARY)) $this->global->MAIN_USE_ZIPTOWN_DICTIONNARY = 0;
  495. // By default, we open card if one found
  496. if (!isset($this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE)) $this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE = 1;
  497. // By default, we show state code in combo list
  498. if (!isset($this->global->MAIN_SHOW_STATE_CODE)) $this->global->MAIN_SHOW_STATE_CODE = 1;
  499. // Use a SCA ready workflow with Stripe module (STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION by default if nothing defined)
  500. 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;
  501. // Define list of limited modules (value must be key found for "name" property of module, so for example 'supplierproposal' for Module "Supplier Proposal"
  502. 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.
  503. if (!empty($this->modules_parts['moduleforexternal'])) // Module part to include an external module into the MAIN_MODULES_FOR_EXTERNAL list
  504. {
  505. foreach ($this->modules_parts['moduleforexternal'] as $key=>$value) $this->global->MAIN_MODULES_FOR_EXTERNAL .= ",".$key;
  506. }
  507. // Enable select2
  508. if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT) || $this->global->MAIN_USE_JQUERY_MULTISELECT == '1') $this->global->MAIN_USE_JQUERY_MULTISELECT = 'select2';
  509. // Timeouts
  510. if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) $this->global->MAIN_USE_CONNECT_TIMEOUT = 10;
  511. if (empty($this->global->MAIN_USE_RESPONSE_TIMEOUT)) $this->global->MAIN_USE_RESPONSE_TIMEOUT = 30;
  512. // Set default variable to calculate VAT as if option tax_mode was 0 (standard)
  513. if (empty($this->global->TAX_MODE_SELL_PRODUCT)) $this->global->TAX_MODE_SELL_PRODUCT = 'invoice';
  514. if (empty($this->global->TAX_MODE_BUY_PRODUCT)) $this->global->TAX_MODE_BUY_PRODUCT = 'invoice';
  515. if (empty($this->global->TAX_MODE_SELL_SERVICE)) $this->global->TAX_MODE_SELL_SERVICE = 'payment';
  516. if (empty($this->global->TAX_MODE_BUY_SERVICE)) $this->global->TAX_MODE_BUY_SERVICE = 'payment';
  517. // Delay before warnings
  518. // Avoid strict errors. TODO: Replace xxx->warning_delay with a property ->warning_delay_xxx
  519. if (isset($this->agenda)) {
  520. $this->adherent->subscription = new stdClass();
  521. $this->adherent->subscription->warning_delay = (isset($this->global->MAIN_DELAY_MEMBERS) ? $this->global->MAIN_DELAY_MEMBERS : 0) * 86400;
  522. }
  523. if (isset($this->agenda)) {
  524. $this->agenda->warning_delay = (isset($this->global->MAIN_DELAY_ACTIONS_TODO) ? $this->global->MAIN_DELAY_ACTIONS_TODO : 7) * 86400;
  525. }
  526. if (isset($this->projet))
  527. {
  528. $this->projet->warning_delay = (isset($this->global->MAIN_DELAY_PROJECT_TO_CLOSE) ? $this->global->MAIN_DELAY_PROJECT_TO_CLOSE : 7) * 86400;
  529. $this->projet->task = new StdClass();
  530. $this->projet->task->warning_delay = (isset($this->global->MAIN_DELAY_TASKS_TODO) ? $this->global->MAIN_DELAY_TASKS_TODO : 7) * 86400;
  531. }
  532. if (isset($this->commande)) {
  533. $this->commande->client = new stdClass();
  534. $this->commande->fournisseur = new stdClass();
  535. $this->commande->client->warning_delay = (isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_ORDERS_TO_PROCESS : 2) * 86400;
  536. $this->commande->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS : 7) * 86400;
  537. }
  538. if (isset($this->propal)) {
  539. $this->propal->cloture = new stdClass();
  540. $this->propal->facturation = new stdClass();
  541. $this->propal->cloture->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE) ? $this->global->MAIN_DELAY_PROPALS_TO_CLOSE : 0) * 86400;
  542. $this->propal->facturation->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_BILL) ? $this->global->MAIN_DELAY_PROPALS_TO_BILL : 0) * 86400;
  543. }
  544. if (isset($this->facture)) {
  545. $this->facture->client = new stdClass();
  546. $this->facture->fournisseur = new stdClass();
  547. $this->facture->client->warning_delay = (isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED) ? $this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED : 0) * 86400;
  548. $this->facture->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY) ? $this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY : 0) * 86400;
  549. }
  550. if (isset($this->contrat)) {
  551. $this->contrat->services = new stdClass();
  552. $this->contrat->services->inactifs = new stdClass();
  553. $this->contrat->services->expires = new stdClass();
  554. $this->contrat->services->inactifs->warning_delay = (isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES) ? $this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES : 0) * 86400;
  555. $this->contrat->services->expires->warning_delay = (isset($this->global->MAIN_DELAY_RUNNING_SERVICES) ? $this->global->MAIN_DELAY_RUNNING_SERVICES : 0) * 86400;
  556. }
  557. if (isset($this->commande)) {
  558. $this->bank->rappro = new stdClass();
  559. $this->bank->cheque = new stdClass();
  560. $this->bank->rappro->warning_delay = (isset($this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE) ? $this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE : 0) * 86400;
  561. $this->bank->cheque->warning_delay = (isset($this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT) ? $this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT : 0) * 86400;
  562. }
  563. if (isset($this->expensereport)) {
  564. $this->expensereport->approve = new stdClass();
  565. $this->expensereport->approve->warning_delay = (isset($this->global->MAIN_DELAY_EXPENSEREPORTS) ? $this->global->MAIN_DELAY_EXPENSEREPORTS : 0) * 86400;
  566. $this->expensereport->payment = new stdClass();
  567. $this->expensereport->payment->warning_delay = (isset($this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY) ? $this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY : 0) * 86400;
  568. }
  569. if (isset($this->holiday)) {
  570. $this->holiday->approve = new stdClass();
  571. $this->holiday->approve->warning_delay = (isset($this->global->MAIN_DELAY_HOLIDAYS) ? $this->global->MAIN_DELAY_HOLIDAYS : 0) * 86400;
  572. }
  573. if (!empty($this->global->PRODUIT_MULTIPRICES) && empty($this->global->PRODUIT_MULTIPRICES_LIMIT))
  574. {
  575. $this->global->PRODUIT_MULTIPRICES_LIMIT = 5;
  576. }
  577. // For modules that want to disable top or left menu
  578. if (!empty($this->global->MAIN_HIDE_TOP_MENU)) $this->dol_hide_topmenu = $this->global->MAIN_HIDE_TOP_MENU;
  579. if (!empty($this->global->MAIN_HIDE_LEFT_MENU)) $this->dol_hide_leftmenu = $this->global->MAIN_HIDE_LEFT_MENU;
  580. if (empty($this->global->MAIN_SIZE_SHORTLIST_LIMIT)) $this->global->MAIN_SIZE_SHORTLIST_LIMIT = 3;
  581. if (!isset($this->global->THEME_HIDE_BORDER_ON_INPUT)) $this->global->THEME_HIDE_BORDER_ON_INPUT = 0;
  582. // Save inconsistent option
  583. if (empty($this->global->AGENDA_USE_EVENT_TYPE) && (!isset($this->global->AGENDA_DEFAULT_FILTER_TYPE) || $this->global->AGENDA_DEFAULT_FILTER_TYPE == 'AC_NON_AUTO'))
  584. {
  585. $this->global->AGENDA_DEFAULT_FILTER_TYPE = '0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on.
  586. }
  587. if (!isset($this->global->MAIN_JS_GRAPH)) $this->global->MAIN_JS_GRAPH = 'chart'; // Use chart.js library
  588. if (empty($this->global->MAIN_MODULE_DOLISTORE_API_SRV)) $this->global->MAIN_MODULE_DOLISTORE_API_SRV = 'https://www.dolistore.com';
  589. if (empty($this->global->MAIN_MODULE_DOLISTORE_API_KEY)) $this->global->MAIN_MODULE_DOLISTORE_API_KEY = 'dolistorecatalogpublickey1234567';
  590. // If we are in develop mode, we activate the option MAIN_SECURITY_CSRF_WITH_TOKEN to 1 if not already defined.
  591. if (!isset($this->global->MAIN_SECURITY_CSRF_WITH_TOKEN) && $this->global->MAIN_FEATURES_LEVEL >= 2) $this->global->MAIN_SECURITY_CSRF_WITH_TOKEN = 1;
  592. if (defined('MAIN_ANTIVIRUS_COMMAND')) $this->global->MAIN_ANTIVIRUS_COMMAND = constant('MAIN_ANTIVIRUS_COMMAND');
  593. if (defined('MAIN_ANTIVIRUS_PARAM')) $this->global->MAIN_ANTIVIRUS_PARAM = constant('MAIN_ANTIVIRUS_PARAM');
  594. // For backward compatibility
  595. if (isset($this->product)) $this->produit = $this->product;
  596. if (isset($this->facture)) $this->invoice = $this->facture;
  597. if (isset($this->commande)) $this->order = $this->commande;
  598. if (isset($this->contrat)) $this->contract = $this->contrat;
  599. if (isset($this->categorie)) $this->category = $this->categorie;
  600. if (isset($this->project)) $this->project = $this->projet;
  601. // Object $mc
  602. if (!defined('NOREQUIREMC') && !empty($this->multicompany->enabled))
  603. {
  604. if (is_object($mc)) $mc->setValues($this);
  605. }
  606. if (!empty($this->syslog->enabled)) {
  607. // We init log handlers
  608. if (!empty($this->global->SYSLOG_HANDLERS)) {
  609. $handlers = json_decode($this->global->SYSLOG_HANDLERS);
  610. } else {
  611. $handlers = array();
  612. }
  613. foreach ($handlers as $handler) {
  614. $handler_file_found = '';
  615. $dirsyslogs = array_merge(array('/core/modules/syslog/'), $this->modules_parts['syslog']);
  616. foreach ($dirsyslogs as $reldir) {
  617. $dir = dol_buildpath($reldir, 0);
  618. $newdir = dol_osencode($dir);
  619. if (is_dir($newdir)) {
  620. $file = $newdir.$handler.'.php';
  621. if (file_exists($file)) {
  622. $handler_file_found = $file;
  623. break;
  624. }
  625. }
  626. }
  627. if (empty($handler_file_found)) {
  628. throw new Exception('Missing log handler file '.$handler.'.php');
  629. }
  630. require_once $handler_file_found;
  631. $loghandlerinstance = new $handler();
  632. if (!$loghandlerinstance instanceof LogHandlerInterface) {
  633. throw new Exception('Log handler does not extend LogHandlerInterface');
  634. }
  635. if (empty($this->loghandlers[$handler])) {
  636. $this->loghandlers[$handler] = $loghandlerinstance;
  637. }
  638. }
  639. }
  640. }
  641. }