diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index e67cec11e31..070ab826a25 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -325,10 +325,10 @@ class Categorie } /** - * Ajout d'un objet à la catégorie - * retour : 1 : OK - * -1 : erreur SQL - * -2 : id non renseign + * \brief Link an object to the category + * \param obj Object to link to category + * \param type Type of category + * \return int 1 : OK, -1 : erreur SQL, -2 : id non renseign, -3 : Already linked */ function add_type($obj,$type) { @@ -346,7 +346,15 @@ class Categorie } else { - $this->error=$this->db->error().' sql='.$sql; + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $this->error=$this->db->lasterrno(); + return -3; + } + else + { + $this->error=$this->db->error().' sql='.$sql; + } return -1; } } diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index f0b719be985..fec1d836914 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -49,7 +49,7 @@ else accessforbidden(); } -// S�curit� d'acc�s client et commerciaux +// Securite d'acces client et commerciaux $objectid = restrictedArea($user, $type, $objectid); @@ -58,7 +58,7 @@ $objectid = restrictedArea($user, $type, $objectid); * Actions */ -//Suppression d'un objet d'une cat�gorie +//Suppression d'un objet d'une categorie if ($_REQUEST["removecat"]) { if ($_REQUEST["socid"] && $user->rights->societe->creer) @@ -77,7 +77,7 @@ if ($_REQUEST["removecat"]) $result=$cat->del_type($object,$type); } -//Ajoute d'un objet dans une cat�gorie +//Ajoute d'un objet dans une categorie if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0) { if ($_REQUEST["socid"] && $user->rights->societe->creer) @@ -101,7 +101,8 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0) } else { - $mesg='
'.$langs->trans("Error").' '.$cat->error.'
'; + if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') $mesg='
'.$langs->trans("ObjectAlreadyLinkedToCategory").'
'; + else $mesg='
'.$langs->trans("Error").' '.$cat->error.'
'; } }