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 '';
+ 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)
{
- 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);
+ }
}
|