Fix: on exclus le contact de la liste déroulante lorsqu'il est sélectionné

This commit is contained in:
Regis Houssin 2007-10-29 20:22:55 +00:00
parent 55e8189b23
commit 125ce2dca6
2 changed files with 117 additions and 80 deletions

View File

@ -220,7 +220,17 @@ if ($id > 0)
print '</td>'; print '</td>';
print '<td colspan="1">'; print '<td colspan="1">';
$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 '</td>'; print '</td>';
print '<td>'; print '<td>';
$propal->selectTypeContact($propal, '', 'type','internal'); $propal->selectTypeContact($propal, '', 'type','internal');
@ -249,7 +259,17 @@ if ($id > 0)
print '</td>'; print '</td>';
print '<td colspan="1">'; print '<td colspan="1">';
$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 '</td>'; print '</td>';
print '<td>'; print '<td>';
$propal->selectTypeContact($propal, '', 'type','external'); $propal->selectTypeContact($propal, '', 'type','external');

View File

@ -787,105 +787,122 @@ class Form
/** /**
* \brief Retourne la liste déroulante des contacts d'une société donnée * \brief Retourne la liste déroulante des contacts d'une société donnée
* \param socid Id de la société * \param socid Id de la société
* \param selected Id contact pré-sélectionn * \param selected Id contact pré-sélectionn
* \param htmlname Nom champ formulaire ('none' pour champ non editable) * \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 * \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 // Permettre l'exclusion de contacts
$sql = "SELECT s.rowid, s.name, s.firstname FROM"; if (is_array($exclude))
$sql.= " ".MAIN_DB_PREFIX ."socpeople as s"; {
$sql.= " WHERE fk_soc=".$socid; $excludeContacts = implode("','",$exclude);
$sql.= " ORDER BY s.name ASC"; }
// 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); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{
$num=$this->db->num_rows();
if ($num==0) return 0;
if ($htmlname != 'none') print '<select class="flat" name="'.$htmlname.'">';
if ($showempty) print '<option value="1">&nbsp;</option>';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
while ($i < $num)
{ {
$num=$this->db->num_rows(); $obj = $this->db->fetch_object();
if ($num==0) return 0; if ($htmlname != 'none')
{
if ($htmlname != 'none') print '<select class="flat" name="'.$htmlname.'">'; if ($selected && $selected == $obj->rowid)
if ($showempty) print '<option value="1">&nbsp;</option>'; {
$num = $this->db->num_rows(); print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
$i = 0; }
if ($num) else
{ {
while ($i < $num) print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>';
{ }
$obj = $this->db->fetch_object(); }
if ($htmlname != 'none')
{
if ($selected && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
}
else
{
print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>';
}
}
else else
{ {
if ($selected == $obj->rowid) print $obj->name.' '.$obj->firstname; if ($selected == $obj->rowid) print $obj->name.' '.$obj->firstname;
} }
$i++; $i++;
} }
} }
if ($htmlname != 'none') print '</select>'; if ($htmlname != 'none') print '</select>';
return 1; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
/** /**
* \brief Retourne la liste déroulante des utilisateurs * \brief Retourne la liste déroulante des utilisateurs
* \param selected Id contact pré-sélectionn * \param selected Id contact pré-sélectionn
* \param htmlname Nom champ formulaire * \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 // Permettre l'exclusion d'utilisateurs
$sql = "SELECT u.rowid, u.name, u.firstname FROM "; if (is_array($exclude))
$sql .= MAIN_DB_PREFIX ."user as u"; {
$sql .= " ORDER BY u.name ASC"; $excludeUsers = implode("','",$exclude);
}
if ($this->db->query($sql))
// 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 '<select class="flat" name="'.$htmlname.'">';
if ($show_empty) print '<option value="-1"'.($id==-1?' selected="true"':'').'>&nbsp;</option>'."\n";
$num = $this->db->num_rows();
$i = 0;
if ($num)
{ {
print '<select class="flat" name="'.$htmlname.'">'; while ($i < $num)
if ($show_empty) print '<option value="-1"'.($id==-1?' selected="true"':'').'>&nbsp;</option>'."\n"; {
$num = $this->db->num_rows(); $obj = $this->db->fetch_object();
$i = 0;
if ($num) if ($selected && $selected == $obj->rowid)
{ {
while ($i < $num) print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
{
$obj = $this->db->fetch_object();
if ($selected && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
}
else
{
print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>';
}
$i++;
}
} }
print '</select>'; else
} {
else print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>';
{ }
dolibarr_print_error($this->db); $i++;
}
} }
print '</select>';
}
else
{
dolibarr_print_error($this->db);
}
} }