Fix: Contacts in task list must be limited to contact linked to project
This commit is contained in:
parent
6848d72010
commit
e86d33e008
@ -162,10 +162,10 @@ class CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Recupere les lignes de contact de l'objet
|
||||
* \param statut Statut des lignes detail a recuperer
|
||||
* \param source Source du contact external (llx_socpeople) ou internal (llx_user)
|
||||
* \return array Tableau des rowid des contacts
|
||||
* \brief Get array of all contacts for an object
|
||||
* \param statut Status of lines to get (-1=all)
|
||||
* \param source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user)
|
||||
* \return array Array of id of contacts
|
||||
*/
|
||||
function liste_contact($statut=-1,$source='external')
|
||||
{
|
||||
@ -175,18 +175,18 @@ class CommonObject
|
||||
|
||||
$sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id";
|
||||
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.= ", tc.source, tc.element, tc.code, tc.libelle";
|
||||
$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";
|
||||
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.= " AND ec.fk_c_type_contact=tc.rowid";
|
||||
$sql.= " AND tc.element='".$this->element."'";
|
||||
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";
|
||||
if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'";
|
||||
$sql.=" ORDER BY t.name ASC";
|
||||
@ -413,7 +413,7 @@ class CommonObject
|
||||
function fetch_object()
|
||||
{
|
||||
$object = $this->origin;
|
||||
|
||||
|
||||
// TODO uniformise code
|
||||
if ($object == 'shipping') $object = 'expedition';
|
||||
if ($object == 'delivery') $object = 'livraison';
|
||||
@ -492,9 +492,10 @@ class CommonObject
|
||||
|
||||
|
||||
/**
|
||||
* \brief On recupere les id de liste_contact
|
||||
* \param source Source du contact external (llx_socpeople) ou internal (llx_user)
|
||||
* \return array
|
||||
* \brief Return list of id of contacts of project
|
||||
* \param source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe)
|
||||
* \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')
|
||||
{
|
||||
@ -504,7 +505,8 @@ class CommonObject
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$contactAlreadySelected[$i] = $tab[$i]['id'];
|
||||
if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
|
||||
else $contactAlreadySelected[$i] = $tab[$i]['id'];
|
||||
$i++;
|
||||
}
|
||||
return $contactAlreadySelected;
|
||||
@ -964,22 +966,22 @@ class CommonObject
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Fetch field list
|
||||
*/
|
||||
function getFieldList()
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
|
||||
$this->field_list = array();
|
||||
|
||||
|
||||
$sql = "SELECT rowid, name, alias, title, align, sort, search, enabled, rang";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_field_list";
|
||||
$sql.= " WHERE element = '".$this->fieldListName."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
$sql.= " ORDER BY rang ASC";
|
||||
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -989,9 +991,9 @@ class CommonObject
|
||||
while ($i < $num)
|
||||
{
|
||||
$fieldlist = array();
|
||||
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
|
||||
$fieldlist["id"] = $obj->rowid;
|
||||
$fieldlist["name"] = $obj->name;
|
||||
$fieldlist["alias"] = $obj->alias;
|
||||
@ -1001,9 +1003,9 @@ class CommonObject
|
||||
$fieldlist["search"] = $obj->search;
|
||||
$fieldlist["enabled"] = verifCond($obj->enabled);
|
||||
$fieldlist["order"] = $obj->rang;
|
||||
|
||||
|
||||
array_push($this->field_list,$fieldlist);
|
||||
|
||||
|
||||
$i++;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
@ -1013,14 +1015,14 @@ class CommonObject
|
||||
print $sql;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
function showLinkedObjectBlock($object,$objectid,$somethingshown=0)
|
||||
{
|
||||
global $langs,$bc;
|
||||
|
||||
|
||||
$num = sizeof($objectid);
|
||||
if ($num)
|
||||
{
|
||||
@ -1030,7 +1032,7 @@ class CommonObject
|
||||
if ($object == 'facture') $tplpath = $classpath = 'compta/'.$object;
|
||||
if ($object == 'propal') $tplpath = $classpath = 'comm/'.$object;
|
||||
if ($object == 'commande') $tplpath = $classpath = $object;
|
||||
|
||||
|
||||
$classname = ucfirst($object);
|
||||
if(!class_exists($classname)) require(DOL_DOCUMENT_ROOT."/".$classpath."/".$object.".class.php");
|
||||
$linkedObjectBlock = new $classname($this->db);
|
||||
|
||||
@ -708,9 +708,10 @@ class Form
|
||||
* \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 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
|
||||
*/
|
||||
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
|
||||
if (is_array($exclude))
|
||||
@ -743,13 +744,19 @@ class Form
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($htmlname != 'none')
|
||||
{
|
||||
$disabled=0;
|
||||
if (is_array($limitto) && sizeof($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
|
||||
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
|
||||
{
|
||||
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
|
||||
@ -778,11 +785,12 @@ class Form
|
||||
* \param selected Id user preselected
|
||||
* \param htmlname Field name in form
|
||||
* \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 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;
|
||||
|
||||
@ -812,14 +820,20 @@ class Form
|
||||
while ($i < $num)
|
||||
{
|
||||
$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))
|
||||
{
|
||||
print '<option value="'.$obj->rowid.'" selected="true">';
|
||||
print '<option value="'.$obj->rowid.'"';
|
||||
if ($disableline) print ' disabled="true"';
|
||||
print ' selected="true">';
|
||||
}
|
||||
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;
|
||||
if ($conf->global->MAIN_SHOW_LOGIN) print ' ('.$obj->login.')';
|
||||
|
||||
@ -444,22 +444,33 @@ class FormCompany
|
||||
|
||||
|
||||
/**
|
||||
* \brief Return list of third parties
|
||||
* \param object Object we try to find contacts
|
||||
* \param var_id Name of id field
|
||||
* \param selected Pre-selected third party
|
||||
* \param htmlname Name of HTML form
|
||||
* \brief Return list of third parties
|
||||
* \param object Object we try to find contacts
|
||||
* \param var_id Name of id field
|
||||
* \param selected Pre-selected third party
|
||||
* \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;
|
||||
|
||||
// On recherche les societes
|
||||
$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;
|
||||
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";
|
||||
|
||||
//print $sql;
|
||||
$resql = $object->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -510,14 +521,20 @@ class FormCompany
|
||||
{
|
||||
$obj = $object->db->fetch_object($resql);
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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 ++;
|
||||
}
|
||||
|
||||
@ -144,6 +144,8 @@ class Project extends CommonObject
|
||||
*/
|
||||
function update($user, $notrigger=0)
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
// Clean parameters
|
||||
$this->title = trim($this->title);
|
||||
$this->description = trim($this->description);
|
||||
|
||||
@ -158,7 +158,7 @@ llxHeader('', $langs->trans("Task"));
|
||||
$html = new Form($db);
|
||||
$formcompany = new FormCompany($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)
|
||||
{
|
||||
$result=$projectstatic->fetch($task->fk_project);
|
||||
if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
|
||||
|
||||
$result=$project->fetch($task->fk_project);
|
||||
if (! empty($project->socid)) $project->societe->fetch($project->socid);
|
||||
|
||||
// To verify role of users
|
||||
$userAccess = $projectstatic->restrictedProjectArea($user);
|
||||
$userAccess = $project->restrictedProjectArea($user);
|
||||
|
||||
$head = task_prepare_head($task);
|
||||
dol_fiche_head($head, 'contact', $langs->trans("Task"), 0, 'projecttask');
|
||||
@ -203,13 +203,13 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
// Project
|
||||
print '<tr><td>'.$langs->trans("Project").'</td><td>';
|
||||
print $projectstatic->getNomUrl(1);
|
||||
print $project->getNomUrl(1);
|
||||
print '</td></tr>';
|
||||
|
||||
// Customer
|
||||
print "<tr><td>".$langs->trans("Company")."</td>";
|
||||
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 ' ';
|
||||
print '</td></tr>';
|
||||
|
||||
@ -231,7 +231,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Source").'</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 colspan="3"> </td>';
|
||||
print "</tr>\n";
|
||||
@ -257,7 +257,8 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
print '<td colspan="1">';
|
||||
// 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>';
|
||||
$formcompany->selectTypeContact($task, '', 'type','internal','rowid');
|
||||
@ -274,7 +275,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print '<input type="hidden" name="id" value="'.$id.'">';
|
||||
|
||||
// Line to add an external contact. Only if project linked to a third party.
|
||||
if ($projectstatic->socid)
|
||||
if ($project->socid)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
@ -284,12 +285,14 @@ if ($id > 0 || ! empty($ref))
|
||||
print '</td>';
|
||||
|
||||
print '<td colspan="1">';
|
||||
$thirdpartyofproject=$project->getListContactId('thirdparty');
|
||||
$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 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");
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
@ -310,7 +313,7 @@ if ($id > 0 || ! empty($ref))
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Source").'</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 align="center">'.$langs->trans("Status").'</td>';
|
||||
print '<td colspan="2"> </td>';
|
||||
|
||||
@ -66,9 +66,9 @@ if ($task->fetch($id,$ref) > 0)
|
||||
{
|
||||
$projectstatic = new Project($db);
|
||||
$projectstatic->fetch($task->fk_project);
|
||||
|
||||
|
||||
if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
|
||||
|
||||
|
||||
$upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($task->ref);
|
||||
}
|
||||
else
|
||||
@ -122,12 +122,12 @@ if ($action=='delete')
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader('',$langs->trans('Project'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
|
||||
llxHeader('',$langs->trans('Project'));
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
if ($id > 0 || ! empty($ref))
|
||||
{
|
||||
{
|
||||
// To verify role of users
|
||||
$userAccess = $projectstatic->restrictedProjectArea($user);
|
||||
|
||||
@ -143,7 +143,7 @@ if ($id > 0 || ! empty($ref))
|
||||
}
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
|
||||
// Ref
|
||||
print '<tr><td width="30%">';
|
||||
print $langs->trans("Ref");
|
||||
@ -165,11 +165,11 @@ if ($id > 0 || ! empty($ref))
|
||||
if ($projectstatic->societe->id) print $projectstatic->societe->getNomUrl(1);
|
||||
else print ' ';
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
// Files infos
|
||||
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.sizeof($filearray).'</td></tr>';
|
||||
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
|
||||
|
||||
|
||||
print "</table>\n";
|
||||
print "</div>\n";
|
||||
|
||||
|
||||
@ -592,6 +592,27 @@ class Task extends CommonObject
|
||||
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
|
||||
* \param user user id
|
||||
|
||||
@ -226,8 +226,8 @@ if ($_GET["id"] > 0)
|
||||
|
||||
// Contributor
|
||||
print '<td nowrap="nowrap">';
|
||||
// TODO We should use here a combo list with contacts affected to task only
|
||||
print $html->select_users($_POST["userid"]?$_POST["userid"]:$user->id,'userid');
|
||||
$contactoftask=$task->getListContactId('thirdparty');
|
||||
print $html->select_users($_POST["userid"]?$_POST["userid"]:$user->id,'userid',0,'',0,'',$contactoftask);
|
||||
print '</td>';
|
||||
|
||||
// Note
|
||||
|
||||
Loading…
Reference in New Issue
Block a user