From 125ce2dca65231edc150c94a015e27dd5e99927e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 29 Oct 2007 20:22:55 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20on=20exclus=20le=20contact=20de=20la=20l?= =?UTF-8?q?iste=20d=E9roulante=20lorsqu'il=20est=20s=E9lectionn=E9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/propal/contact.php | 24 ++++- htdocs/html.form.class.php | 173 ++++++++++++++++++--------------- 2 files changed, 117 insertions(+), 80 deletions(-) diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 8a871f0dd93..d5bc7d2b30f 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -220,7 +220,17 @@ if ($id > 0) print ''; print ''; - $html->select_users($user->id,'contactid'); + // On récupère les id des users déjà sélectionnés + $userAlreadySelected = array(); + $tab = $propal->liste_contact(-1,'internal'); + $num=sizeof($tab); + $i = 0; + while ($i < $num) + { + $userAlreadySelected[$i] = $tab[$i]['id']; + $i++; + } + $html->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; print ''; $propal->selectTypeContact($propal, '', 'type','internal'); @@ -249,7 +259,17 @@ if ($id > 0) print ''; print ''; - $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid'); + // On récupère les id des contacts déjà sélectionnés + $contactAlreadySelected = array(); + $tab = $propal->liste_contact(-1,'external'); + $num=sizeof($tab); + $i = 0; + while ($i < $num) + { + $contactAlreadySelected[$i] = $tab[$i]['id']; + $i++; + } + $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid',0,$contactAlreadySelected); print ''; print ''; $propal->selectTypeContact($propal, '', 'type','external'); diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 40be82d80fb..20bd9fdd512 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -787,105 +787,122 @@ class Form /** * \brief Retourne la liste déroulante des contacts d'une société donnée - * \param socid Id de la société - * \param selected Id contact pré-sélectionn - * \param htmlname Nom champ formulaire ('none' pour champ non editable) + * \param socid Id de la société + * \param selected Id contact pré-sélectionn + * \param htmlname Nom champ formulaire ('none' pour champ non editable) + * \param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue + * \param exclude Liste des id contacts à exclure * \return int <0 si ko, >=0 si ok */ - function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0) + function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='') { - // On recherche les societes - $sql = "SELECT s.rowid, s.name, s.firstname FROM"; - $sql.= " ".MAIN_DB_PREFIX ."socpeople as s"; - $sql.= " WHERE fk_soc=".$socid; - $sql.= " ORDER BY s.name ASC"; + // Permettre l'exclusion de contacts + if (is_array($exclude)) + { + $excludeContacts = implode("','",$exclude); + } + + // On recherche les societes + $sql = "SELECT s.rowid, s.name, s.firstname FROM"; + $sql.= " ".MAIN_DB_PREFIX ."socpeople as s"; + $sql.= " WHERE fk_soc=".$socid; + if (is_array($exclude) && $excludeContacts) $sql.= " AND s.rowid NOT IN ('".$excludeContacts."')"; + $sql.= " ORDER BY s.name ASC"; - $resql=$this->db->query($sql); - if ($resql) + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows(); + if ($num==0) return 0; + + if ($htmlname != 'none') print ''; - if ($showempty) print ''; - $num = $this->db->num_rows(); - $i = 0; - if ($num) - { - while ($i < $num) - { - $obj = $this->db->fetch_object(); - - if ($htmlname != 'none') - { - if ($selected && $selected == $obj->rowid) - { - print ''; - } - else - { - print ''; - } - } + $obj = $this->db->fetch_object(); + if ($htmlname != 'none') + { + if ($selected && $selected == $obj->rowid) + { + print ''; + } + else + { + print ''; + } + } else { if ($selected == $obj->rowid) print $obj->name.' '.$obj->firstname; } - $i++; - } - } - if ($htmlname != 'none') print ''; - return 1; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } + $i++; + } + } + if ($htmlname != 'none') print ''; + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } /** * \brief Retourne la liste déroulante des utilisateurs * \param selected Id contact pré-sélectionn * \param htmlname Nom champ formulaire + * \param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue + * \param exclude Liste des id utilisateurs à exclure */ - function select_users($selected='',$htmlname='userid',$show_empty=0) + function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='') { - // On recherche les utilisateurs - $sql = "SELECT u.rowid, u.name, u.firstname FROM "; - $sql .= MAIN_DB_PREFIX ."user as u"; - $sql .= " ORDER BY u.name ASC"; - - if ($this->db->query($sql)) + // 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 ''; - if ($show_empty) print ''."\n"; - $num = $this->db->num_rows(); - $i = 0; - if ($num) + while ($i < $num) + { + $obj = $this->db->fetch_object(); + + if ($selected && $selected == $obj->rowid) { - while ($i < $num) - { - $obj = $this->db->fetch_object(); - - if ($selected && $selected == $obj->rowid) - { - print ''; - } - else - { - print ''; - } - $i++; - } + print ''; } - print ''; - } - else - { - dolibarr_print_error($this->db); + else + { + print ''; + } + $i++; + } } + print ''; + } + else + { + dolibarr_print_error($this->db); + } }