From 51468b6c0af1943476d26b1ce516d628b41884bf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 Oct 2007 12:55:01 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Regression.=20Le=20contact=20doit=20touj?= =?UTF-8?q?ours=20apparaitre=20dans=20la=20liste=20des=20contacts=20car=20?= =?UTF-8?q?il=20doit=20pouvoir=20etre=20s=E9lectionner=20pour=20un=20autre?= =?UTF-8?q?=20type.=20Fix:=20bug=20#21119=20:=20Mettre=20un=20message=20d'?= =?UTF-8?q?erreur=20plus=20clair=20si=20doublon=20contact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/propal/contact.php | 18 +++++-- htdocs/commande/contact.php | 17 +++++-- htdocs/commonobject.class.php | 21 +++++--- htdocs/compta/facture/contact.php | 17 +++++-- htdocs/contrat/contact.php | 17 +++++-- htdocs/fichinter/contact.php | 14 ++++-- htdocs/html.form.class.php | 80 +++++++++++++++---------------- htdocs/langs/en_US/errors.lang | 1 + htdocs/langs/fr_FR/errors.lang | 3 +- htdocs/propal.class.php | 1 - 10 files changed, 120 insertions(+), 69 deletions(-) diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 51098f92e65..19035b5b504 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /** @@ -62,9 +61,18 @@ if ($_POST["action"] == 'addcontact' && $user->rights->propale->creer) { Header("Location: contact.php?propalid=".$propal->id); exit; - } else + } + else { - $mesg = '
'.$propal->error.'
'; + if ($propal->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } + else + { + $mesg = '
'.$propal->error.'
'; + } } } // modification d'un contact. On enregistre le type @@ -221,7 +229,7 @@ if ($id > 0) print ''; // On récupère les id des users déjà sélectionnés - $userAlreadySelected = $propal->getListContactId('internal'); + //$userAlreadySelected = $propal->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; print ''; @@ -252,7 +260,7 @@ if ($id > 0) print ''; // On récupère les id des contacts déjà sélectionnés - $contactAlreadySelected = $propal->getListContactId('external'); + //$contactAlreadySelected = $propal->getListContactId('external'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid',0,$contactAlreadySelected); print ''; print ''; diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php index 5305d52d0b4..ab69ba7918f 100644 --- a/htdocs/commande/contact.php +++ b/htdocs/commande/contact.php @@ -62,9 +62,18 @@ if ($_POST["action"] == 'addcontact' && $user->rights->commande->creer) { Header("Location: contact.php?id=".$commande->id); exit; - } else + } + else { - $mesg = '
'.$commande->error.'
'; + if ($commande->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } + else + { + $mesg = '
'.$commande->error.'
'; + } } } // modification d'un contact. On enregistre le type @@ -233,7 +242,7 @@ if ($id > 0) print ''; // On récupère les id des users déjà sélectionnés - $userAlreadySelected = $commande->getListContactId('internal'); + //$userAlreadySelected = $commande->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; print ''; @@ -264,7 +273,7 @@ if ($id > 0) print ''; // On récupère les id des contacts déjà sélectionnés - $contactAlreadySelected = $commande->getListContactId('external'); + // $contactAlreadySelected = $commande->getListContactId('external'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid',0,$contactAlreadySelected); print ''; print ''; diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index 58765b4a6f2..35d757d8034 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -16,7 +16,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /** @@ -101,9 +100,17 @@ class CommonObject } else { - $this->error=$this->db->error()." - $sql"; - dolibarr_syslog($this->error,LOG_ERR); - return -1; + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $this->error=$this->db->errno(); + return -2; + } + else + { + $this->error=$this->db->error()." - $sql"; + dolibarr_syslog($this->error,LOG_ERR); + return -1; + } } } @@ -170,8 +177,8 @@ class CommonObject if ($source == 'external') $sql.=" t.fk_soc as socid,"; $sql.=" t.name as nom,"; $sql.= "tc.source, tc.element, tc.code, tc.libelle"; - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact ec,"; - $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc)"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc,"; + $sql.= " ".MAIN_DB_PREFIX."element_contact ec"; if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; if ($source == 'external') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; $sql.= " WHERE ec.element_id =".$this->id; @@ -286,7 +293,7 @@ class CommonObject * Exemple: contact client de livraison ('external', 'SHIPPING') * Exemple: contact interne suivi paiement ('internal', 'SALESREPFOLL') * \param source 'external' or 'internal' - * \param source 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... + * \param code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... * \return array Liste des id contacts */ function getIdContact($source,$code) diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php index 898a38353e2..279a1f3e67c 100644 --- a/htdocs/compta/facture/contact.php +++ b/htdocs/compta/facture/contact.php @@ -60,9 +60,18 @@ if ($_POST["action"] == 'addcontact' && $user->rights->facture->creer) { Header("Location: contact.php?facid=".$facture->id); exit; - } else + } + else { - $mesg = '
'.$facture->error.'
'; + if ($facture->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } + else + { + $mesg = '
'.$facture->error.'
'; + } } } // modification d'un contact. On enregistre le type @@ -213,7 +222,7 @@ if ($id > 0) print ''; // On récupère les id des users déjà sélectionnés - $userAlreadySelected = $facture->getListContactId('internal'); + //$userAlreadySelected = $facture->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; print ''; @@ -244,7 +253,7 @@ if ($id > 0) print ''; // On récupère les id des contacts déjà sélectionnés - $contactAlreadySelected = $facture->getListContactId('external'); + //$contactAlreadySelected = $facture->getListContactId('external'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid',0,$contactAlreadySelected); print ''; print ''; diff --git a/htdocs/contrat/contact.php b/htdocs/contrat/contact.php index c434afa230f..27dd0ddfb06 100644 --- a/htdocs/contrat/contact.php +++ b/htdocs/contrat/contact.php @@ -60,9 +60,18 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer) { Header("Location: contact.php?id=".$contrat->id); exit; - } else + } + else { - $mesg = '
'.$contrat->error.'
'; + if ($contrat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } + else + { + $mesg = '
'.$contrat->error.'
'; + } } } // modification d'un contact. On enregistre le type @@ -234,7 +243,7 @@ if ($id > 0) print ''; // On récupère les id des users déjà sélectionnés - $userAlreadySelected = $contrat->getListContactId('internal'); + //$userAlreadySelected = $contrat->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; print ''; @@ -265,7 +274,7 @@ if ($id > 0) print ''; // On récupère les id des contacts déjà sélectionnés - $contactAlreadySelected = $contrat->getListContactId('external'); + //$contactAlreadySelected = $contrat->getListContactId('external'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid',0,$contactAlreadySelected); print ''; print ''; diff --git a/htdocs/fichinter/contact.php b/htdocs/fichinter/contact.php index aa4612436d1..97c7b940c4f 100644 --- a/htdocs/fichinter/contact.php +++ b/htdocs/fichinter/contact.php @@ -62,7 +62,15 @@ if ($_POST["action"] == 'addcontact' && $user->rights->ficheinter->creer) } else { - $mesg = '
'.$fichinter->error.'
'; + if ($fichinter->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } + else + { + $mesg = '
'.$fichinter->error.'
'; + } } } // modification d'un contact. On enregistre le type @@ -219,7 +227,7 @@ if ($id > 0) print ''; // On récupère les id des users déjà sélectionnés - $userAlreadySelected = $fichinter->getListContactId('internal'); + //$userAlreadySelected = $fichinter->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; print ''; @@ -250,7 +258,7 @@ if ($id > 0) print ''; // On récupère les id des contacts déjà sélectionnés - $contactAlreadySelected = $fichinter->getListContactId('external'); + //$contactAlreadySelected = $fichinter->getListContactId('external'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid',0,$contactAlreadySelected); print ''; print ''; diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 20bd9fdd512..72e2b9c72e6 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -862,47 +862,47 @@ class Form */ function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='') { - // Permettre l'exclusion d'utilisateurs - if (is_array($exclude)) - { - $excludeUsers = implode("','",$exclude); - } - - // On recherche les utilisateurs - $sql = "SELECT u.rowid, u.name, u.firstname FROM "; - $sql.= MAIN_DB_PREFIX ."user as u"; - if (is_array($exclude) && $excludeUsers) $sql.= " WHERE u.rowid NOT IN ('".$excludeUsers."')"; - $sql.= " ORDER BY u.name ASC"; + // Permettre l'exclusion d'utilisateurs + if (is_array($exclude)) + { + $excludeUsers = implode("','",$exclude); + } + + // On recherche les utilisateurs + $sql = "SELECT u.rowid, u.name, u.firstname FROM "; + $sql.= MAIN_DB_PREFIX ."user as u"; + if (is_array($exclude) && $excludeUsers) $sql.= " WHERE u.rowid NOT IN ('".$excludeUsers."')"; + $sql.= " ORDER BY u.name ASC"; - if ($this->db->query($sql)) - { - print ''; - } - else - { - dolibarr_print_error($this->db); - } + if ($this->db->query($sql)) + { + print ''; + } + else + { + dolibarr_print_error($this->db); + } } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index be6542ea115..5799e904a13 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -1,3 +1,4 @@ # Dolibarr language file - en_US - errors ErrorDuplicateTrigger=A trigger file named '%s' is already loaded. Remove duplicate trigger file in directory '%s'. ErrorFailToDeleteFile=Failed to remove file '%s'. +ErrorThisContactIsAlreadyDefinedAsThisType=this contact is already defined as contact for this type. \ No newline at end of file diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 19aa67e81c8..16b76319894 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -1,3 +1,4 @@ # Dolibarr language file - fr_FR - errors ErrorDuplicateTrigger=Un fichier trigger du nom de '%s' est deja chargé. Supprimer le doublon du répertoire '%s'. -ErrorFailToDeleteFile=Echec de l'effacement du fichier '%s'. \ No newline at end of file +ErrorFailToDeleteFile=Echec de l'effacement du fichier '%s'. +ErrorThisContactIsAlreadyDefinedAsThisType=Ce contact est déjà défini comme contact pour ce type. \ No newline at end of file diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 4c2cb97f83f..46278e94ef5 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -21,7 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /**