From 1a9e98cda9563b42f1f7e7d1faf215d165ff34bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 8 Aug 2014 19:30:21 +0200 Subject: [PATCH 1/2] Fix categories bug When using the string type, $typeid == 1 matched all strings making other conditions ineffective. --- htdocs/categories/class/categorie.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index b7e2ed030ab..1788f2e1ac6 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1123,11 +1123,11 @@ class Categorie $cats = array(); $table=''; $type=''; - if ($typeid == 0 || $typeid == 'product') { $typeid=0; $table='product'; $type='product'; } - else if ($typeid == 1 || $typeid == 'supplier') { $typeid=1; $table='societe'; $type='fournisseur'; } - else if ($typeid == 2 || $typeid == 'customer') { $typeid=2; $table='societe'; $type='societe'; } - else if ($typeid == 3 || $typeid == 'member') { $typeid=3; $table='member'; $type='member'; } - else if ($typeid == 4 || $typeid == 'contact') { $typeid=4; $table='socpeople'; $type='contact'; } + if ($typeid === 0 || $typeid == 'product') { $typeid=0; $table='product'; $type='product'; } + else if ($typeid === 1 || $typeid == 'supplier') { $typeid=1; $table='societe'; $type='fournisseur'; } + else if ($typeid === 2 || $typeid == 'customer') { $typeid=2; $table='societe'; $type='societe'; } + else if ($typeid === 3 || $typeid == 'member') { $typeid=3; $table='member'; $type='member'; } + else if ($typeid === 4 || $typeid == 'contact') { $typeid=4; $table='socpeople'; $type='contact'; } $sql = "SELECT ct.fk_categorie, c.label"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct, ".MAIN_DB_PREFIX."categorie as c"; From 739d309a0d3e38becd20c28bf07e41078fcf49c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 14 Aug 2014 08:46:51 +0200 Subject: [PATCH 2/2] Updated category fix Categories ID can be passed as strings PSR code formatting --- htdocs/categories/class/categorie.class.php | 29 ++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 1788f2e1ac6..60b738ea8ba 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1122,12 +1122,29 @@ class Categorie { $cats = array(); - $table=''; $type=''; - if ($typeid === 0 || $typeid == 'product') { $typeid=0; $table='product'; $type='product'; } - else if ($typeid === 1 || $typeid == 'supplier') { $typeid=1; $table='societe'; $type='fournisseur'; } - else if ($typeid === 2 || $typeid == 'customer') { $typeid=2; $table='societe'; $type='societe'; } - else if ($typeid === 3 || $typeid == 'member') { $typeid=3; $table='member'; $type='member'; } - else if ($typeid === 4 || $typeid == 'contact') { $typeid=4; $table='socpeople'; $type='contact'; } + $table = ''; + $type = ''; + if ($typeid === 0 || $typeid === '0' || $typeid == 'product') { + $typeid = 0; + $table = 'product'; + $type = 'product'; + } else if ($typeid === 1 || $typeid === '1' || $typeid == 'supplier') { + $typeid = 1; + $table = 'societe'; + $type = 'fournisseur'; + } else if ($typeid === 2 || $typeid === '2' || $typeid == 'customer') { + $typeid = 2; + $table = 'societe'; + $type = 'societe'; + } else if ($typeid === 3 || $typeid === '3' || $typeid == 'member') { + $typeid = 3; + $table = 'member'; + $type = 'member'; + } else if ($typeid === 4 || $typeid === '4' || $typeid == 'contact') { + $typeid = 4; + $table = 'socpeople'; + $type = 'contact'; + } $sql = "SELECT ct.fk_categorie, c.label"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct, ".MAIN_DB_PREFIX."categorie as c";