From 227c3898064264946842f5e7f3617f90b3fd294f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 1 Jul 2008 19:30:39 +0000 Subject: [PATCH] Fix: List of supplier categories --- htdocs/categories/categorie.class.php | 23 ++++++++++++++++------- htdocs/categories/viewcat.php | 12 ++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index 23fab0b1810..897e41f48ec 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -382,21 +382,29 @@ class Categorie } /** - * Retourne les produits de la catégorie + * \brief Retourne les produits de la catégorie + * \param field Field name for select in table. Full field name will be fk_field. + * \param class PHP Class of object to store entity + * \param table Table name for select in table. Full table name will be PREFIX_categorie_table. */ - function get_type($type,$class) + function get_type($field,$class,$table='') { - $sql = "SELECT fk_".$type." FROM ".MAIN_DB_PREFIX."categorie_".$type." "; - $sql .= "WHERE fk_categorie = ".$this->id; + $objs = array(); + + // Clean parameters + if (empty($table)) $table=$field; + + + $sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table; + $sql .= " WHERE fk_categorie = ".$this->id; + dolibarr_syslog("Categorie::get_type sql=".$sql); $res = $this->db->query($sql); - if ($res) { - $obj = array(); while ($rec = $this->db->fetch_array ($res)) { - $obj = new $class ($this->db, $rec['fk_'.$type]); + $obj = new $class ($this->db, $rec['fk_'.$field]); $obj->fetch ($obj->id); $objs[] = $obj; } @@ -405,6 +413,7 @@ class Categorie else { $this->error=$this->db->error().' sql='.$sql; + dolibarr_syslog("Categorie::get_type ".$this->error, LOG_ERR); return -1; } } diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 506bf20ae26..1f8727c4c5f 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006-2007 Laurent Destailleur + * Copyright (C) 2006-2008 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2005-2007 Regis Houssin * @@ -69,10 +69,10 @@ if ($user->rights->categorie->supprimer && $_POST["action"] == 'confirm_delete' /* - * Affichage fiche categorie + * View */ + llxHeader ("","",$langs->trans("Categories")); -$html=new Form($db); if ($mesg) print $mesg.'
'; @@ -190,7 +190,7 @@ else } -if($c->type == 0) +if ($c->type == 0) { $prods = $c->get_type ("product","Product"); @@ -230,9 +230,9 @@ if($c->type == 0) } } -if($c->type == 1) +if ($c->type == 1) { - $socs = $c->get_type ("societe","Fournisseur"); + $socs = $c->get_type ("societe","Fournisseur","fournisseur"); if ($socs < 0) { dolibarr_print_error();