Fix: Contacts in task list must be limited to contact linked to project

This commit is contained in:
Laurent Destailleur 2010-04-24 13:39:16 +00:00
parent 6848d72010
commit e86d33e008
8 changed files with 122 additions and 63 deletions

View File

@ -162,10 +162,10 @@ class CommonObject
} }
/** /**
* \brief Recupere les lignes de contact de l'objet * \brief Get array of all contacts for an object
* \param statut Statut des lignes detail a recuperer * \param statut Status of lines to get (-1=all)
* \param source Source du contact external (llx_socpeople) ou internal (llx_user) * \param source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user)
* \return array Tableau des rowid des contacts * \return array Array of id of contacts
*/ */
function liste_contact($statut=-1,$source='external') function liste_contact($statut=-1,$source='external')
{ {
@ -175,18 +175,18 @@ class CommonObject
$sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id"; $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id";
if ($source == 'internal') $sql.=", '-1' as socid"; if ($source == 'internal') $sql.=", '-1' as socid";
if ($source == 'external') $sql.=", t.fk_soc as socid"; if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid";
$sql.= ", t.name as nom, t.firstname"; $sql.= ", t.name as nom, t.firstname";
$sql.= ", tc.source, tc.element, tc.code, tc.libelle"; $sql.= ", tc.source, tc.element, tc.code, tc.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
$sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; $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 == '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"; if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
$sql.= " WHERE ec.element_id =".$this->id; $sql.= " WHERE ec.element_id =".$this->id;
$sql.= " AND ec.fk_c_type_contact=tc.rowid"; $sql.= " AND ec.fk_c_type_contact=tc.rowid";
$sql.= " AND tc.element='".$this->element."'"; $sql.= " AND tc.element='".$this->element."'";
if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
if ($source == 'external') $sql.= " AND tc.source = 'external'"; if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'";
$sql.= " AND tc.active=1"; $sql.= " AND tc.active=1";
if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'";
$sql.=" ORDER BY t.name ASC"; $sql.=" ORDER BY t.name ASC";
@ -492,9 +492,10 @@ class CommonObject
/** /**
* \brief On recupere les id de liste_contact * \brief Return list of id of contacts of project
* \param source Source du contact external (llx_socpeople) ou internal (llx_user) * \param source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe)
* \return array * \return array Array of id of contacts (if source=external or internal)
* Array of id of third parties with at least one contact on project (if source=thirdparty)
*/ */
function getListContactId($source='external') function getListContactId($source='external')
{ {
@ -504,7 +505,8 @@ class CommonObject
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$contactAlreadySelected[$i] = $tab[$i]['id']; if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
else $contactAlreadySelected[$i] = $tab[$i]['id'];
$i++; $i++;
} }
return $contactAlreadySelected; return $contactAlreadySelected;

View File

@ -708,9 +708,10 @@ class Form
* \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 show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
* \param exclude Liste des id contacts a exclure * \param exclude Liste des id contacts a exclure
* \param limitto Disable answers that are not id in this array list
* \return int <0 if KO, Nb of contact in list if OK * \return int <0 if KO, Nb of contact in list if OK
*/ */
function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='') function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='')
{ {
// Permettre l'exclusion de contacts // Permettre l'exclusion de contacts
if (is_array($exclude)) if (is_array($exclude))
@ -743,13 +744,19 @@ class Form
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($htmlname != 'none') if ($htmlname != 'none')
{ {
$disabled=0;
if (is_array($limitto) && sizeof($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
if ($selected && $selected == $obj->rowid) if ($selected && $selected == $obj->rowid)
{ {
print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>'; print '<option value="'.$obj->rowid.'"';
if ($disabled) print ' disabled="true"';
print ' selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
} }
else else
{ {
print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>'; print '<option value="'.$obj->rowid.'"';
if ($disabled) print ' disabled="true"';
print '>'.$obj->name.' '.$obj->firstname.'</option>';
} }
} }
else else
@ -778,11 +785,12 @@ class Form
* \param selected Id user preselected * \param selected Id user preselected
* \param htmlname Field name in form * \param htmlname Field name in form
* \param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue * \param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
* \param exclude List of users id to exclude * \param exclude Array list of users id to exclude
* \param disabled If select list must be disabled * \param disabled If select list must be disabled
* \param include List of users id to include * \param include Array list of users id to include
* \param enableonly Array list of users id to be enabled. All other must be disabled
*/ */
function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='') function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='')
{ {
global $conf; global $conf;
@ -812,14 +820,20 @@ class Form
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$disableline=0;
if (is_array($enableonly) && sizeof($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1;
if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid)) if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
{ {
print '<option value="'.$obj->rowid.'" selected="true">'; print '<option value="'.$obj->rowid.'"';
if ($disableline) print ' disabled="true"';
print ' selected="true">';
} }
else else
{ {
print '<option value="'.$obj->rowid.'">'; print '<option value="'.$obj->rowid.'"';
if ($disableline) print ' disabled="true"';
print '>';
} }
print $obj->name.($obj->name && $obj->firstname?' ':'').$obj->firstname; print $obj->name.($obj->name && $obj->firstname?' ':'').$obj->firstname;
if ($conf->global->MAIN_SHOW_LOGIN) print ' ('.$obj->login.')'; if ($conf->global->MAIN_SHOW_LOGIN) print ' ('.$obj->login.')';

View File

@ -444,22 +444,33 @@ class FormCompany
/** /**
* \brief Return list of third parties * \brief Return list of third parties
* \param object Object we try to find contacts * \param object Object we try to find contacts
* \param var_id Name of id field * \param var_id Name of id field
* \param selected Pre-selected third party * \param selected Pre-selected third party
* \param htmlname Name of HTML form * \param htmlname Name of HTML form
* \param limitto Disable answers that are not id in this array list
*/ */
function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany') function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='')
{ {
global $conf, $langs; global $conf, $langs;
// On recherche les societes // On recherche les societes
$sql = "SELECT s.rowid, s.nom FROM"; $sql = "SELECT s.rowid, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s"; $sql.= " ".MAIN_DB_PREFIX."societe as s";
if ($selected && $conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) $sql.= " WHERE rowid = ".$selected; if ($selected && $conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) $sql.= " WHERE rowid = ".$selected;
else
{
// For ajax search we limit here. For combo list, we limit later
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT
&& is_array($limitto) && sizeof($limitto))
{
$sql.= " WHERE rowid in (".join(',',$limitto).")";
}
}
$sql .= " ORDER BY nom ASC"; $sql .= " ORDER BY nom ASC";
//print $sql;
$resql = $object->db->query($sql); $resql = $object->db->query($sql);
if ($resql) if ($resql)
{ {
@ -510,14 +521,20 @@ class FormCompany
{ {
$obj = $object->db->fetch_object($resql); $obj = $object->db->fetch_object($resql);
if ($i == 0) $firstCompany = $obj->rowid; if ($i == 0) $firstCompany = $obj->rowid;
$disabled=0;
if (is_array($limitto) && sizeof($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
if ($selected > 0 && $selected == $obj->rowid) if ($selected > 0 && $selected == $obj->rowid)
{ {
print '<option value="'.$obj->rowid.'" selected="true">'.dol_trunc($obj->nom,24).'</option>'; print '<option value="'.$obj->rowid.'"';
if ($disabled) print ' disabled="true"';
print ' selected="true">'.dol_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->rowid; $firstCompany = $obj->rowid;
} }
else else
{ {
print '<option value="'.$obj->rowid.'">'.dol_trunc($obj->nom,24).'</option>'; print '<option value="'.$obj->rowid.'"';
if ($disabled) print ' disabled="true"';
print '>'.dol_trunc($obj->nom,24).'</option>';
} }
$i ++; $i ++;
} }

View File

@ -144,6 +144,8 @@ class Project extends CommonObject
*/ */
function update($user, $notrigger=0) function update($user, $notrigger=0)
{ {
global $langs,$conf;
// Clean parameters // Clean parameters
$this->title = trim($this->title); $this->title = trim($this->title);
$this->description = trim($this->description); $this->description = trim($this->description);

View File

@ -158,7 +158,7 @@ llxHeader('', $langs->trans("Task"));
$html = new Form($db); $html = new Form($db);
$formcompany = new FormCompany($db); $formcompany = new FormCompany($db);
$contactstatic = new Contact($db); $contactstatic = new Contact($db);
$projectstatic = new Project($db); $project = new Project($db);
/* *************************************************************************** */ /* *************************************************************************** */
@ -176,11 +176,11 @@ if ($id > 0 || ! empty($ref))
if ( $task->fetch($id,$ref) > 0) if ( $task->fetch($id,$ref) > 0)
{ {
$result=$projectstatic->fetch($task->fk_project); $result=$project->fetch($task->fk_project);
if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); if (! empty($project->socid)) $project->societe->fetch($project->socid);
// To verify role of users // To verify role of users
$userAccess = $projectstatic->restrictedProjectArea($user); $userAccess = $project->restrictedProjectArea($user);
$head = task_prepare_head($task); $head = task_prepare_head($task);
dol_fiche_head($head, 'contact', $langs->trans("Task"), 0, 'projecttask'); dol_fiche_head($head, 'contact', $langs->trans("Task"), 0, 'projecttask');
@ -203,13 +203,13 @@ if ($id > 0 || ! empty($ref))
// Project // Project
print '<tr><td>'.$langs->trans("Project").'</td><td>'; print '<tr><td>'.$langs->trans("Project").'</td><td>';
print $projectstatic->getNomUrl(1); print $project->getNomUrl(1);
print '</td></tr>'; print '</td></tr>';
// Customer // Customer
print "<tr><td>".$langs->trans("Company")."</td>"; print "<tr><td>".$langs->trans("Company")."</td>";
print '<td colspan="3">'; print '<td colspan="3">';
if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1); if ($project->societe->id > 0) print $project->societe->getNomUrl(1);
else print '&nbsp;'; else print '&nbsp;';
print '</td></tr>'; print '</td></tr>';
@ -231,7 +231,7 @@ if ($id > 0 || ! empty($ref))
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Source").'</td>'; print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Company").'</td>'; print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>'; print '<td>'.$langs->trans("ProjectContact").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>'; print '<td>'.$langs->trans("ContactType").'</td>';
print '<td colspan="3">&nbsp;</td>'; print '<td colspan="3">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
@ -257,7 +257,8 @@ if ($id > 0 || ! empty($ref))
print '<td colspan="1">'; print '<td colspan="1">';
// On recupere les id des users deja selectionnes // On recupere les id des users deja selectionnes
$html->select_users($user->id,'contactid',0); $contactsofproject=$project->getListContactId('internal');
$html->select_users($user->id,'contactid',0,'',0,'',$contactsofproject);
print '</td>'; print '</td>';
print '<td>'; print '<td>';
$formcompany->selectTypeContact($task, '', 'type','internal','rowid'); $formcompany->selectTypeContact($task, '', 'type','internal','rowid');
@ -274,7 +275,7 @@ if ($id > 0 || ! empty($ref))
print '<input type="hidden" name="id" value="'.$id.'">'; print '<input type="hidden" name="id" value="'.$id.'">';
// Line to add an external contact. Only if project linked to a third party. // Line to add an external contact. Only if project linked to a third party.
if ($projectstatic->socid) if ($project->socid)
{ {
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
@ -284,12 +285,14 @@ if ($id > 0 || ! empty($ref))
print '</td>'; print '</td>';
print '<td colspan="1">'; print '<td colspan="1">';
$thirdpartyofproject=$project->getListContactId('thirdparty');
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id; $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id;
$selectedCompany = $formcompany->selectCompaniesForNewContact($task, 'id', $selectedCompany, 'newcompany'); $selectedCompany = $formcompany->selectCompaniesForNewContact($task, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject);
print '</td>'; print '</td>';
print '<td colspan="1">'; print '<td colspan="1">';
$nbofcontacts=$html->select_contacts($selectedCompany,'','contactid',0); $contactofproject=$project->getListContactId('external');
$nbofcontacts=$html->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject);
if ($nbofcontacts == 0) print $langs->trans("NoContactDefined"); if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
print '</td>'; print '</td>';
print '<td>'; print '<td>';
@ -310,7 +313,7 @@ if ($id > 0 || ! empty($ref))
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Source").'</td>'; print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Company").'</td>'; print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>'; print '<td>'.$langs->trans("ProjectContact").'</td>';
print '<td>'.$langs->trans("ContactType").'</td>'; print '<td>'.$langs->trans("ContactType").'</td>';
print '<td align="center">'.$langs->trans("Status").'</td>'; print '<td align="center">'.$langs->trans("Status").'</td>';
print '<td colspan="2">&nbsp;</td>'; print '<td colspan="2">&nbsp;</td>';

View File

@ -122,7 +122,7 @@ if ($action=='delete')
* View * View
*/ */
llxHeader('',$langs->trans('Project'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes'); llxHeader('',$langs->trans('Project'));
$form = new Form($db); $form = new Form($db);

View File

@ -592,6 +592,27 @@ class Task extends CommonObject
return $projectsrole; return $projectsrole;
} }
/**
* \brief Return list of id of contacts of task
* \return array Array of id of contacts
*/
function getListContactId()
{
$contactAlreadySelected = array();
$tab = $this->liste_contact(-1,'internal');
$num=sizeof($tab);
$i = 0;
while ($i < $num)
{
if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
else $contactAlreadySelected[$i] = $tab[$i]['id'];
$i++;
}
return $contactAlreadySelected;
}
/** /**
* \brief Add time spent * \brief Add time spent
* \param user user id * \param user user id

View File

@ -226,8 +226,8 @@ if ($_GET["id"] > 0)
// Contributor // Contributor
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
// TODO We should use here a combo list with contacts affected to task only $contactoftask=$task->getListContactId('thirdparty');
print $html->select_users($_POST["userid"]?$_POST["userid"]:$user->id,'userid'); print $html->select_users($_POST["userid"]?$_POST["userid"]:$user->id,'userid',0,'',0,'',$contactoftask);
print '</td>'; print '</td>';
// Note // Note