conf.class.php 30 KB

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