From 10bbf463e7c91df3deb44207e186475ef04f9401 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sat, 14 Mar 2015 14:55:41 +0100
Subject: [PATCH] Several bug fixes from scrutinizer

---
 htdocs/admin/system/dolibarr.php            |  2 +-
 htdocs/categories/class/categorie.class.php | 31 ++-------------------
 htdocs/commande/list.php                    |  6 ++--
 htdocs/core/class/commonobject.class.php    | 27 +++++++++++++++++-
 htdocs/core/lib/date.lib.php                |  1 +
 htdocs/core/lib/functions.lib.php           |  2 +-
 htdocs/product/class/product.class.php      | 27 ++----------------
 7 files changed, 36 insertions(+), 60 deletions(-)

diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php
index 96700ba1e16..4ec093dfafc 100644
--- a/htdocs/admin/system/dolibarr.php
+++ b/htdocs/admin/system/dolibarr.php
@@ -179,7 +179,7 @@ $c=getServerTimeZoneInt('summer');
 $daylight=(is_numeric($c) && is_numeric($b))?round($c-$b):'unknown';
 //print $a." ".$b." ".$c." ".$daylight;
 $val=($a>=0?'+':'').$a;
-$val.=' ('.($a==='unknown'?'unknown':($a>=0?'+':'').($a*3600)).')';
+$val.=' ('.($a=='unknown'?'unknown':($a>=0?'+':'').($a*3600)).')';
 $val.=' &nbsp; &nbsp; &nbsp; '.getServerTimeZoneString();
 $val.=' &nbsp; &nbsp; &nbsp; '.$langs->trans("DaylingSavingTime").': '.($daylight==='unknown'?'unknown':($a==$c?yn($daylight):yn(0).($daylight?'  &nbsp; &nbsp; ('.$langs->trans('YesInSummer').')':'')));
 print $form->textwithtooltip($val,$txt,2,1,img_info(''));
diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index e4ff0e4e0d1..5d64b7d9327 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -1295,11 +1295,9 @@ class Categorie extends CommonObject
 	 *
 	 *  @param      string	$sdir       Repertoire destination finale
 	 *  @param      string	$file		Nom du fichier uploade
-	 *  @param      int		$maxWidth   Largeur maximum que dois faire la miniature (160 par defaut)
-	 *  @param      int		$maxHeight  Hauteur maximum que dois faire la miniature (120 par defaut)
 	 *	@return		void
 	 */
-	function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120)
+	function add_photo($sdir, $file)
 	{
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
@@ -1321,36 +1319,11 @@ class Categorie extends CommonObject
 			if (file_exists($originImage))
 			{
 				// Cree fichier en taille vignette
-				$this->add_thumb($originImage,$maxWidth,$maxHeight);
+				$this->add_thumb($originImage);
 			}
 		}
 	}
 
-	/**
-	 *  Build thumb
-	 *
-	 *  @param      string	$file           Chemin du fichier d'origine
-	 *	@return		void
-	 */
-	function add_thumb($file)
-	{
-		global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality;
-
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php';		// This define also $maxwidthsmall, $quality, ...
-
-		if (file_exists($file))
-		{
-			// Create small thumbs for company (Ratio is near 16/9)
-	        // Used on logon for example
-	        $imgThumbSmall = vignette($file, $maxwidthsmall, $maxheightsmall, '_small', $quality);
-
-	        // Create mini thumbs for company (Ratio is near 16/9)
-	        // Used on menu or for setup page for example
-	        $imgThumbMini = vignette($file, $maxwidthmini, $maxheightmini, '_mini', $quality);
-		}
-	}
-
-
 	/**
 	 *    Return tableau de toutes les photos de la categorie
 	 *
diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php
index c38b1a8e34f..e51ded5e297 100644
--- a/htdocs/commande/list.php
+++ b/htdocs/commande/list.php
@@ -259,7 +259,7 @@ if ($resql)
 	if ($search_user > 0) 		$param.='&search_user='.$search_user;
 	if ($search_sale > 0) 		$param.='&search_sale='.$search_sale;
 	if ($search_total_ht != '') $param.='&search_total_ht='.$search_total_ht;
-	
+
 	$num = $db->num_rows($resql);
 	print_barre_liste($title, $page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
 	$i = 0;
@@ -337,7 +337,7 @@ if ($resql)
 
     $generic_commande = new Commande($db);
     $generic_product = new Product($db);
-    while ($i < min($num,$limit)) 
+    while ($i < min($num,$limit))
     {
         $objp = $db->fetch_object($resql);
         $var=!$var;
@@ -368,7 +368,7 @@ if ($resql)
                     $nbprod++; // order contains real products
                     $generic_product->id = $generic_commande->lines[$lig]->fk_product;
                     if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
-                        $generic_product->load_stock(true);
+                        $generic_product->load_stock();
                         $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
                     } else {
                         $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'];
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index a316c3cd511..fe9cfd24013 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -3458,6 +3458,31 @@ abstract class CommonObject
 		}
 	}
 
+	/**
+	 *  Build thumb
+	 *
+	 *  @param      string	$file           Path file in UTF8 to original file to create thumbs from.
+	 *	@return		void
+	 */
+	function add_thumb($file)
+	{
+		global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality;
+
+		require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php';		// This define also $maxwidthsmall, $quality, ...
+
+		$file_osencoded=dol_osencode($file);
+		if (file_exists($file_osencoded))
+		{
+			// Create small thumbs for company (Ratio is near 16/9)
+	        // Used on logon for example
+	        $imgThumbSmall = vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality);
+
+	        // Create mini thumbs for company (Ratio is near 16/9)
+	        // Used on menu or for setup page for example
+	        $imgThumbMini = vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality);
+		}
+	}
+
 
 	/* Functions common to commonobject and commonobjectline */
 
@@ -3624,7 +3649,7 @@ abstract class CommonObject
                	$attributeType  = $extrafields->attribute_type[$attributeKey];
                	$attributeSize  = $extrafields->attribute_size[$attributeKey];
                	$attributeLabel = $extrafields->attribute_label[$attributeKey];
-               	$attributeParam = $extrafields->attribute_param[$attributeKey];  
+               	$attributeParam = $extrafields->attribute_param[$attributeKey];
                	switch ($attributeType)
                	{
                		case 'int':
diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php
index 777b3633cb5..e5b60f4094c 100644
--- a/htdocs/core/lib/date.lib.php
+++ b/htdocs/core/lib/date.lib.php
@@ -95,6 +95,7 @@ function getServerTimeZoneInt($refgmtdate='now')
     }
     else
     {
+    	$tmp=0;
     	dol_print_error('','PHP version must be 5.3+');
     	/*
         // Method 2 (does not include daylight, not supported by adodb)
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 63c0f6ce433..c1845482eaf 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -4542,7 +4542,7 @@ function utf8_check($str)
 
 
 /**
- *      Return an UTF-8 string encoded into OS filesystem encoding. This function is used to define
+ *      Return a string encoded into OS filesystem encoding. This function is used to define
  * 	    value to pass to filesystem PHP functions.
  *
  *      @param	string	$str        String to encode (UTF-8)
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 02686a94f03..4c341e58906 100755
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -138,6 +138,8 @@ class Product extends CommonObject
 	var $stats_commande=array();
 	var $stats_contrat=array();
 	var $stats_facture=array();
+    var $stats_commande_fournisseur=array();
+
 	var $multilangs=array();
 
 	//! Taille de l'image
@@ -3311,31 +3313,6 @@ class Product extends CommonObject
 		else return -1;
 	}
 
-	/**
-	 *  Build thumb
-	 *
-	 *  @param  string	$file           Chemin du fichier d'origine
-	 *  @return	void
-	 */
-	function add_thumb($file)
-	{
-		global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality;
-
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php';		// This define also $maxwidthsmall, $quality, ...
-
-		$file_osencoded=dol_osencode($file);
-		if (file_exists($file_osencoded))
-		{
-			// Create small thumbs for company (Ratio is near 16/9)
-	        // Used on logon for example
-	        $imgThumbSmall = vignette($file, $maxwidthsmall, $maxheightsmall, '_small', $quality);
-
-	        // Create mini thumbs for company (Ratio is near 16/9)
-	        // Used on menu or for setup page for example
-	        $imgThumbMini = vignette($file, $maxwidthmini, $maxheightmini, '_mini', $quality);
-		}
-	}
-
 	/**
 	 *  Affiche la premiere photo du produit
 	 *
-- 
GitLab