From 7bb2af86cd8f56c1c9e2cf0df8a8d7bbac2ff89a Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sat, 3 Dec 2011 20:21:45 +0100
Subject: [PATCH] Qual: Clean code to reduce nb of properties into classes

---
 htdocs/boxes.php                    | 10 ++--
 htdocs/core/class/conf.class.php    | 72 ++++++++++++-----------------
 htdocs/core/lib/fichinter.lib.php   |  2 +-
 htdocs/core/lib/functions.lib.php   |  4 +-
 htdocs/core/lib/invoice.lib.php     |  2 +-
 htdocs/core/lib/order.lib.php       |  2 +-
 htdocs/core/lib/prelevement.lib.php |  2 +-
 htdocs/core/lib/propal.lib.php      |  8 +---
 8 files changed, 43 insertions(+), 59 deletions(-)

diff --git a/htdocs/boxes.php b/htdocs/boxes.php
index ad661583a8f..84e899f8290 100644
--- a/htdocs/boxes.php
+++ b/htdocs/boxes.php
@@ -46,13 +46,15 @@ function printBoxesArea($user,$areacode)
 		print '<table width="100%" class="notopnoleftnoright">';
 		print '<tr><td class="notopnoleftnoright">'."\n";
 
-
         print '<div class="fichehalfleft">';
 
-
 		print "\n<!-- Box left container -->\n";
 		print '<div id="left" class="connectedSortable">'."\n";
 
+		// Define $box_max_lines
+		$box_max_lines=5;
+		if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
+		
 		$ii=0;
 		foreach ($boxarray as $key => $box)
 		{
@@ -62,7 +64,7 @@ function printBoxesArea($user,$areacode)
 				//print 'box_id '.$boxarray[$ii]->box_id.' ';
 				//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
 				// Affichage boite key
-				$box->loadBox($conf->box_max_lines);
+				$box->loadBox($box_max_lines);
 				$box->showBox();
 			}
 		}
@@ -90,7 +92,7 @@ function printBoxesArea($user,$areacode)
 				//print 'box_id '.$boxarray[$ii]->box_id.' ';
 				//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
 				// Affichage boite key
-				$box->loadBox($conf->box_max_lines);
+				$box->loadBox($box_max_lines);
 				$box->showBox();
 			}
 		}
diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php
index 242d140dbaf..ecb6820f267 100644
--- a/htdocs/core/class/conf.class.php
+++ b/htdocs/core/class/conf.class.php
@@ -34,41 +34,40 @@
 class Conf
 {
 	/** \public */
-	//! Object with database handler
-	var $db;
 	//! To store properties found in conf file
 	var $file;
+	//! Object with database handler
+	var $db;
 	//! To store properties found into database
 	var $global;
 
 	//! To store if javascript/ajax is enabked
-	var $use_javascript_ajax;
+	public $use_javascript_ajax;
 
 	//! Used to store current currency
-	var $monnaie;
+	public $currency;
 	//! Used to store current css (from theme)
-	var $theme;        // Contains current theme ("eldy", "auguria", ...)
-	var $css;          // Contains full path of css page ("/theme/eldy/style.css.php", ...)
+	public $theme;        // Contains current theme ("eldy", "auguria", ...)
+	public $css;          // Contains full path of css page ("/theme/eldy/style.css.php", ...)
     //! Used to store current menu handlers
-	var $top_menu;
-	var $smart_menu;
+	public $top_menu;
+	public $smart_menu;
 
 	//! To store properties of multi-company
-	var $multicompany;
-	//! Used to store instance for multi-company (default 1)
-	var $entity=1;
-
-	var $css_modules			= array();
-	var $tabs_modules			= array();
-	var $triggers_modules		= array();
-	var $hooks_modules			= array();
-	public $login_method_modules	= array();
-	var $modules				= array();
-	var $entities				= array();
-
-	var $logbuffer				= array();
-
-	var $filesystem_forbidden_chars = array('<','>',':','/','\\','?','*','|','"');
+	public $multicompany;
+	//! Used to store running instance for multi-company (default 1)
+	public $entity=1;
+	//! Used to store list of entities to use for each element
+	public $entities		 	 = array();
+	
+	public $modules				 = array();	// List of modules	
+	public $css_modules			 = array();
+	public $tabs_modules		 = array();
+	public $triggers_modules	 = array('/core/triggers');
+	public $hooks_modules		 = array();
+	public $login_method_modules = array();
+	
+	var $logbuffer = array();
 
 
 	/**
@@ -98,10 +97,7 @@ class Conf
 	 */
 	function setValues($db)
 	{
-		dol_syslog("Conf::setValues");
-
-		// Directory of core triggers
-		$this->triggers_modules[] = "/core/triggers";	// Default relative path to triggers file
+		dol_syslog(get_class($this)."::setValues");
 
 		// Avoid warning if not defined
 		if (empty($this->db->dolibarr_main_db_encryption)) $this->db->dolibarr_main_db_encryption=0;
@@ -128,10 +124,10 @@ class Conf
 		$result = $db->query($sql);
 		if ($result)
 		{
-			$numr = $db->num_rows($result);
 			$multicompany_sharing=array();
+			
 			$i = 0;
-
+			$numr = $db->num_rows($result);
 			while ($i < $numr)
 			{
 				$objp = $db->fetch_object($result);
@@ -207,7 +203,7 @@ class Conf
 			}
 
 			// Sharings between entities
-			if (isset($this->multicompany->enabled) && $this->multicompany->enabled && ! empty($multicompany_sharing))
+			if (! empty($this->multicompany->enabled) && ! empty($multicompany_sharing))
 			{
 				$ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php');
 				if ($ret)
@@ -291,7 +287,7 @@ class Conf
 		$this->service->dir_temp  =$rootfordata."/produit/temp";
 		// Module contrat
 		$this->contrat->dir_output=$rootfordata."/contracts";
-		$this->contrat->dir_temp=$rootfordata."/contracts/temp";
+		$this->contrat->dir_temp  =$rootfordata."/contracts/temp";
 
 
 		/*
@@ -299,9 +295,9 @@ class Conf
 		 */
 
 		// societe
-		if (empty($this->global->SOCIETE_CODECLIENT_ADDON))      $this->global->SOCIETE_CODECLIENT_ADDON="mod_codeclient_leopard";
-		if (empty($this->global->SOCIETE_CODEFOURNISSEUR_ADDON)) $this->global->SOCIETE_CODEFOURNISSEUR_ADDON=$this->global->SOCIETE_CODECLIENT_ADDON;
-		if (empty($this->global->SOCIETE_CODECOMPTA_ADDON))      $this->global->SOCIETE_CODECOMPTA_ADDON="mod_codecompta_panicum";
+		if (empty($this->global->SOCIETE_CODECLIENT_ADDON))       $this->global->SOCIETE_CODECLIENT_ADDON="mod_codeclient_leopard";
+		if (empty($this->global->SOCIETE_CODEFOURNISSEUR_ADDON))  $this->global->SOCIETE_CODEFOURNISSEUR_ADDON=$this->global->SOCIETE_CODECLIENT_ADDON;
+		if (empty($this->global->SOCIETE_CODECOMPTA_ADDON))       $this->global->SOCIETE_CODECOMPTA_ADDON="mod_codecompta_panicum";
         if (empty($this->global->COMPANY_AQUARIUM_MASK_SUPPLIER)) $this->global->COMPANY_AQUARIUM_MASK_SUPPLIER='401';
 		if (empty($this->global->COMPANY_AQUARIUM_MASK_CUSTOMER)) $this->global->COMPANY_AQUARIUM_MASK_CUSTOMER='411';
 
@@ -309,14 +305,6 @@ class Conf
 		if (empty($this->global->USER_PASSWORD_GENERATED)) $this->global->USER_PASSWORD_GENERATED='standard'; // Default password generator
         if (empty($this->global->MAIN_UMASK)) $this->global->MAIN_UMASK='0664';         // Default mask
 
-		// conf->box_max_lines
-		$this->box_max_lines=5;
-		if (isset($this->global->MAIN_BOXES_MAXLINES)) $this->box_max_lines=$this->global->MAIN_BOXES_MAXLINES;
-
-		// conf->use_preview_tabs
-		$this->use_preview_tabs=0;
-		if (isset($this->global->MAIN_USE_PREVIEW_TABS)) $this->use_preview_tabs=$this->global->MAIN_USE_PREVIEW_TABS;
-
 		// conf->use_javascript_ajax
 		$this->use_javascript_ajax=1;
 		if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) $this->use_javascript_ajax=! $this->global->MAIN_DISABLE_JAVASCRIPT;
diff --git a/htdocs/core/lib/fichinter.lib.php b/htdocs/core/lib/fichinter.lib.php
index 53ac8662738..dc89615c874 100644
--- a/htdocs/core/lib/fichinter.lib.php
+++ b/htdocs/core/lib/fichinter.lib.php
@@ -41,7 +41,7 @@ function fichinter_prepare_head($object)
 	$head[$h][2] = 'contact';
 	$h++;
 
-	if ($conf->use_preview_tabs)
+	if (! empty($conf->global->MAIN_USE_PREVIEW_TABS))
 	{
 		$head[$h][0] = DOL_URL_ROOT.'/fichinter/apercu.php?id='.$object->id;
 		$head[$h][1] = $langs->trans('Preview');
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 756165f77a8..d34308792ee 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -373,8 +373,8 @@ function dol_now($mode='gmt')
  */
 function dol_sanitizeFileName($str,$newstr='_')
 {
-    global $conf;
-    return dol_string_nospecial(dol_string_unaccent($str),$newstr,$conf->filesystem_forbidden_chars);
+	$filesystem_forbidden_chars = array('<','>',':','/','\\','?','*','|','"');
+    return dol_string_nospecial(dol_string_unaccent($str), $newstr, $filesystem_forbidden_chars);
 }
 
 /**
diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php
index f718b345eec..7dbd628e82d 100644
--- a/htdocs/core/lib/invoice.lib.php
+++ b/htdocs/core/lib/invoice.lib.php
@@ -44,7 +44,7 @@ function facture_prepare_head($object)
 	$head[$h][2] = 'contact';
 	$h++;
 
-	if ($conf->use_preview_tabs)
+	if (! empty($conf->global->MAIN_USE_PREVIEW_TABS))
 	{
 		$head[$h][0] = DOL_URL_ROOT.'/compta/facture/apercu.php?facid='.$object->id;
 		$head[$h][1] = $langs->trans('Preview');
diff --git a/htdocs/core/lib/order.lib.php b/htdocs/core/lib/order.lib.php
index fb1000b0dd2..8c34d06cb19 100644
--- a/htdocs/core/lib/order.lib.php
+++ b/htdocs/core/lib/order.lib.php
@@ -54,7 +54,7 @@ function commande_prepare_head($object)
 		$h++;
 	}
 
-	if ($conf->use_preview_tabs)
+	if (! empty($conf->global->MAIN_USE_PREVIEW_TABS))
 	{
 		$head[$h][0] = DOL_URL_ROOT.'/commande/apercu.php?id='.$object->id;
 		$head[$h][1] = $langs->trans("Preview");
diff --git a/htdocs/core/lib/prelevement.lib.php b/htdocs/core/lib/prelevement.lib.php
index 2e1f13cc220..c1fa99af7a1 100644
--- a/htdocs/core/lib/prelevement.lib.php
+++ b/htdocs/core/lib/prelevement.lib.php
@@ -43,7 +43,7 @@ function prelevement_prepare_head($object)
 	$head[$h][2] = 'prelevement';
 	$h++;
 
-	if ($conf->use_preview_tabs)
+	if (! empty($conf->global->MAIN_USE_PREVIEW_TABS))
 	{
 		$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/bon.php?id='.$object->id;
 		$head[$h][1] = $langs->trans("Preview");
diff --git a/htdocs/core/lib/propal.lib.php b/htdocs/core/lib/propal.lib.php
index 29451e58cd0..e30cde362f8 100644
--- a/htdocs/core/lib/propal.lib.php
+++ b/htdocs/core/lib/propal.lib.php
@@ -49,13 +49,7 @@ function propal_prepare_head($object)
 		$head[$h][2] = 'shipping';
 		$h++;
 	}
-/*
-	$head[$h][0] = DOL_URL_ROOT.'/compta/propal.php?id='.$propal->id;
-	$head[$h][1] = $langs->trans('AccountancyCard');
-	$head[$h][2] = 'compta';
-	$h++;
-*/
-	if ($conf->use_preview_tabs)
+	if (! empty($conf->global->MAIN_USE_PREVIEW_TABS))
 	{
 		$head[$h][0] = DOL_URL_ROOT.'/comm/propal/apercu.php?id='.$object->id;
 		$head[$h][1] = $langs->trans("Preview");
-- 
GitLab