From e86d33e008efd5c5f4c8124737ffb4a4f8c06d3b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Apr 2010 13:39:16 +0000 Subject: [PATCH] Fix: Contacts in task list must be limited to contact linked to project --- htdocs/core/commonobject.class.php | 50 ++++++++++++++++-------------- htdocs/html.form.class.php | 30 +++++++++++++----- htdocs/html.formcompany.class.php | 35 +++++++++++++++------ htdocs/projet/project.class.php | 2 ++ htdocs/projet/tasks/contact.php | 29 +++++++++-------- htdocs/projet/tasks/document.php | 14 ++++----- htdocs/projet/tasks/task.class.php | 21 +++++++++++++ htdocs/projet/tasks/time.php | 4 +-- 8 files changed, 122 insertions(+), 63 deletions(-) diff --git a/htdocs/core/commonobject.class.php b/htdocs/core/commonobject.class.php index 5236ce1191f..1f8ecf5bf00 100644 --- a/htdocs/core/commonobject.class.php +++ b/htdocs/core/commonobject.class.php @@ -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); diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index d75162526cb..61d6ccf789b 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -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 ''; + print ''; } else { - print ''; + print ''; } } 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 ''; + print ''; $firstCompany = $obj->rowid; } else { - print ''; + print ''; } $i ++; } diff --git a/htdocs/projet/project.class.php b/htdocs/projet/project.class.php index b7d1837066e..b293cb3eb0c 100644 --- a/htdocs/projet/project.class.php +++ b/htdocs/projet/project.class.php @@ -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); diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 0525ab48b97..aa40c3bc601 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -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 ''.$langs->trans("Project").''; - print $projectstatic->getNomUrl(1); + print $project->getNomUrl(1); print ''; // Customer print "".$langs->trans("Company").""; print ''; - if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1); + if ($project->societe->id > 0) print $project->societe->getNomUrl(1); else print ' '; print ''; @@ -231,7 +231,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''.$langs->trans("Source").''; print ''.$langs->trans("Company").''; - print ''.$langs->trans("Contacts").''; + print ''.$langs->trans("ProjectContact").''; print ''.$langs->trans("ContactType").''; print ' '; print "\n"; @@ -257,7 +257,8 @@ if ($id > 0 || ! empty($ref)) print ''; // 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 ''; print ''; $formcompany->selectTypeContact($task, '', 'type','internal','rowid'); @@ -274,7 +275,7 @@ if ($id > 0 || ! empty($ref)) print ''; // Line to add an external contact. Only if project linked to a third party. - if ($projectstatic->socid) + if ($project->socid) { $var=!$var; print ""; @@ -284,12 +285,14 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; + $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 ''; print ''; - $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 ''; print ''; @@ -310,7 +313,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''.$langs->trans("Source").''; print ''.$langs->trans("Company").''; - print ''.$langs->trans("Contacts").''; + print ''.$langs->trans("ProjectContact").''; print ''.$langs->trans("ContactType").''; print ''.$langs->trans("Status").''; print ' '; diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php index ae35bc06a72..e51530b7ef0 100644 --- a/htdocs/projet/tasks/document.php +++ b/htdocs/projet/tasks/document.php @@ -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 ''; - + // Ref print ''; - + // Files infos print ''; print ''; - + print "
'; 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 '
'.$langs->trans("NbOfAttachedFiles").''.sizeof($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
\n"; print "\n"; diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php index c184c1a21b6..92a1bdb94d4 100644 --- a/htdocs/projet/tasks/task.class.php +++ b/htdocs/projet/tasks/task.class.php @@ -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 diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 437e116e849..df05e56fea9 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -226,8 +226,8 @@ if ($_GET["id"] > 0) // Contributor print ''; - // 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 ''; // Note