From 73ab5386694145e2ac65fa0a5801b5bf03dec507 Mon Sep 17 00:00:00 2001 From: Regis Houssin <regis@dolibarr.fr> Date: Sat, 20 Feb 2010 10:29:53 +0000 Subject: [PATCH] Fix: uniformize code --- htdocs/product.class.php | 65 ++++++++-------------------------------- 1 file changed, 13 insertions(+), 52 deletions(-) diff --git a/htdocs/product.class.php b/htdocs/product.class.php index b22c7fffca9..3351251b485 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -451,62 +451,23 @@ class Product extends CommonObject function verif_prod_use($id) { $sqr = 0; + + $element = array('propaldet','commandedet','facturedet','contratdet'); - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."propaldet"; - $sql.= " WHERE fk_product = ".$id; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num != 0) - { - $sqr++; - } - } - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."facturedet"; - $sql.= " WHERE fk_product = ".$id; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num != 0) - { - $sqr++; - } - } - - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet"; - $sql.= " WHERE fk_product = ".$id; - - $result = $this->db->query($sql); - if ($result) + foreach($element as $table) { - $num = $this->db->num_rows($result); - if ($num != 0) - { - $sqr++; - } - } - - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet"; - $sql.= " WHERE fk_product = ".$id; + $sql = "SELECT rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE fk_product = ".$id; - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num != 0) + $result = $this->db->query($sql); + if ($result) { - $sqr++; + $num = $this->db->num_rows($result); + if ($num != 0) + { + $sqr++; + } } } -- GitLab