diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 624fa795b39..fdddce669a9 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -885,7 +885,7 @@ class Categorie extends CommonObject $classnameforobj = $this->MAP_OBJ_CLASS[$type]; $obj = new $classnameforobj($this->db); - $sql = "SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]); + $sql = "SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." as fk_object"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type])." as c"; $sql .= ", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type])." as o"; $sql .= " WHERE o.entity IN (".getEntity($obj->element).")"; @@ -920,14 +920,15 @@ class Categorie extends CommonObject if ($resql) { while ($rec = $this->db->fetch_array($resql)) { if ($onlyids) { - $objs[] = $rec['fk_'.(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])]; + $objs[] = $rec['fk_object']; } else { $classnameforobj = $this->MAP_OBJ_CLASS[$type]; $obj = new $classnameforobj($this->db); - $obj->fetch($rec['fk_'.(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])]); - - $objs[] = $obj; + $obj->fetch($rec['fk_object']); + if ($obj->id > 0) { + $objs[] = $obj; + } } } return $objs; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 113a1cc1ad1..f1d2e08626c 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -678,6 +678,7 @@ if ($type == Categorie::TYPE_SUPPLIER) { $permission = $user->hasRight('societe', 'creer'); $socs = $object->getObjectsInCateg($type, 0, $limit, $offset); + if ($socs < 0) { dol_print_error($db, $object->error, $object->errors); } else { @@ -738,7 +739,7 @@ if ($type == Categorie::TYPE_SUPPLIER) { // Link to delete from category print ''; if ($permission) { - print "id."'>"; + print 'id.($limit?'&limit='.$limit:'').'">'; print $langs->trans("DeleteFromCat"); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print "";