From b535bc0cb96c919312d26ed7b203f87f143ad936 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 2 Sep 2019 11:27:04 +0200 Subject: [PATCH 01/15] start dev --- htdocs/core/lib/company.lib.php | 1 + .../install/mysql/migration/10.0.0-11.0.0.sql | 17 +++++++++-- .../mysql/tables/llx_societe_contact.key.sql | 22 ++++++++++++++ .../mysql/tables/llx_societe_contact.sql | 29 +++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_societe_contact.key.sql create mode 100644 htdocs/install/mysql/tables/llx_societe_contact.sql diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2f6c474e632..8d862d3a9af 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -896,6 +896,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') 't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10), 't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20), 't.address'=>array('label'=>(empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked'=>1, 'position'=>30), + 't.address'=>array('label'=>(empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked'=>1, 'position'=>30), 't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>40, 'class'=>'center'), ); // Extra fields diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 8efe44db103..5bc114c2294 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -89,5 +89,18 @@ ALTER TABLE llx_projet ADD COLUMN usage_organize_event integer DEFAULT 0; UPDATE llx_projet set usage_opportunity = 1 WHERE fk_opp_status > 0; - - \ No newline at end of file +create table llx_societe_contact +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + datec datetime NULL, -- date de creation de l'enregistrement + statut smallint DEFAULT 5, -- 5 inactif, 4 actif + + element_id int NOT NULL, -- la reference de l'element. + fk_c_type_contact int NOT NULL, -- nature du contact. + fk_socpeople integer NOT NULL +)ENGINE=innodb; + +ALTER TABLE llx_societe_contact ADD UNIQUE INDEX idx_societe_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople); + +ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); +ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_contact.key.sql b/htdocs/install/mysql/tables/llx_societe_contact.key.sql new file mode 100644 index 00000000000..1409e7edc24 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_societe_contact.key.sql @@ -0,0 +1,22 @@ +-- ======================================================================== +-- Copyright (C) 2019 Florian HENRY +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + +ALTER TABLE llx_societe_contact ADD UNIQUE INDEX idx_societe_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople); + +ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); +ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_contact.sql b/htdocs/install/mysql/tables/llx_societe_contact.sql new file mode 100644 index 00000000000..040f8ded124 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_societe_contact.sql @@ -0,0 +1,29 @@ +-- ======================================================================== +-- Copyright (C) 2019 Florian HENRY +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + + +create table llx_societe_contact +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + datec datetime NULL, -- date de creation de l'enregistrement + statut smallint DEFAULT 5, -- 5 inactif, 4 actif + + element_id int NOT NULL, -- la reference de l'element. + fk_c_type_contact int NOT NULL, -- nature du contact. + fk_socpeople integer NOT NULL +)ENGINE=innodb; From 405c92640c077c4fbda99604123f4574681b1816 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 2 Sep 2019 14:47:32 +0200 Subject: [PATCH 02/15] on going --- htdocs/contact/class/contact.class.php | 50 +++++++++++++- htdocs/core/class/commonobject.class.php | 69 +++++++++++++++++++ htdocs/core/lib/company.lib.php | 44 ++++++++++-- .../install/mysql/migration/10.0.0-11.0.0.sql | 23 ++++--- ...t.key.sql => llx_societe_contacts.key.sql} | 8 +-- ...e_contact.sql => llx_societe_contacts.sql} | 17 ++--- htdocs/langs/en_US/main.lang | 14 +++- 7 files changed, 195 insertions(+), 30 deletions(-) rename htdocs/install/mysql/tables/{llx_societe_contact.key.sql => llx_societe_contacts.key.sql} (61%) rename htdocs/install/mysql/tables/{llx_societe_contact.sql => llx_societe_contacts.sql} (69%) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index e064b93504d..db6ab29b802 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -82,7 +82,7 @@ class Contact extends CommonObject public $civility_id; // In fact we store civility_code public $civility_code; - public $civility; + public $civility; public $address; public $zip; public $town; @@ -139,6 +139,8 @@ class Contact extends CommonObject public $oldcopy; // To contains a clone of this when we need to save old properties of object + public $roles=array(); + /** * Constructor @@ -1449,4 +1451,50 @@ class Contact extends CommonObject return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + + /** + * Fetch Role for a contact + * + * @return float|int + * @throws Exception + */ + public function fetchRole() + { + + global $langs; + $error= 0; + $num=0; + + $sql ="SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle"; + $sql.=" FROM ".MAIN_DB_PREFIX."societe_contacts as sc "; + $sql.=" INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql.=" ON tc.rowid = sc.fk_c_type_contact"; + $sql.=" AND sc.fk_socpeople = ". $this->id; + $sql.=" AND tc.source = 'external' AND tc.active=1"; + $sql.=" AND sc.entity IN (".getEntity('societe').')'; + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + + $this->roles=array(); + $resql=$this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + if ($num > 0) { + while ($obj = $this->db->fetch_object($resql)) { + $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; + $this->roles[$this->id]=array('id'=>$obj->rowid,'element'=>$obj->element,'source'=>$obj->source,'code'=>$obj->code,'label'=>($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle)); + } + } + } else { + $error++; + $this->errors[]=$this->db->lasterror(); + } + + if (empty($error)) { + return $num; + } else { + return $error * -1; + } + } + } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c57148124be..0eea968ecd2 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1210,6 +1210,75 @@ abstract class CommonObject } } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return array with list of possible values for type of contacts + * + * @param string $source 'internal', 'external' or 'all' + * @param int $option 0=Return array id->label, 1=Return array code->label + * @param int $activeonly 0=all status of contact, 1=only the active + * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') + * @param string $element Filter Element Type + * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) + */ + public function listeTypeContacts($source = 'internal', $option = 0, $activeonly = 0, $code = '', $element = '') + { + // phpcs:enable + global $langs; + + if (empty($order)) $order='position'; + if ($order == 'position') $order.=',code'; + + $tab = array(); + $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + + $sqlWhere=array(); + if (!empty($element)) + $sqlWhere[]=" tc.element='".$this->db->escape($element)."'"; + + if ($activeonly == 1) + $sqlWhere[]=" tc.active=1"; // only the active types + + if (! empty($source) && $source != 'all') + $sqlWhere[]=" tc.source='".$this->db->escape($source)."'"; + + if (! empty($code)) + $sqlWhere[]=" tc.code='".$this->db->escape($code)."'"; + + if (count($sqlWhere)>0) { + $sql .= " WHERE ". implode(' AND ', $sqlWhere); + } + + $sql.= $this->db->order('tc.element, tc.position', 'ASC'); + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + + $libelle_element = $langs->trans('ContactDefault_'.ucfirst($obj->element)); + $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); + if (empty($option)) $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type; + else $tab[$obj->code]=$libelle_element.' - '.$libelle_type; + $i++; + } + return $tab; + } + else + { + $this->error=$this->db->lasterror(); + //dol_print_error($this->db); + return null; + } + } + /** * Return id of contacts for a source and a contact code. * Example: contact client de facturation ('external', 'BILLING') diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 8d862d3a9af..cfc1fcfb30f 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -869,6 +869,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if ($search_status=='') $search_status=1; // always display active customer first $search_name = GETPOST("search_name", 'alpha'); $search_addressphone = GETPOST("search_addressphone", 'alpha'); + $search_role = GETPOST("search_role", 'array'); if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="t.lastname"; @@ -887,7 +888,8 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') 'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1), 'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOfFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20), 'address' =>array('type'=>'varchar(128)', 'label'=>'Address', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>30), - 'statut' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>40, 'arrayofkeyval'=>array(0=>$contactstatic->LibStatut(0, 1), 1=>$contactstatic->LibStatut(1, 1))), + 'role' =>array('type'=>'checkbox', 'label'=>'Role', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>40), + 'statut' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>50, 'arrayofkeyval'=>array(0=>$contactstatic->LibStatut(0, 1), 1=>$contactstatic->LibStatut(1, 1))), ); // Definition of fields for list @@ -896,8 +898,8 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') 't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10), 't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20), 't.address'=>array('label'=>(empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked'=>1, 'position'=>30), - 't.address'=>array('label'=>(empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked'=>1, 'position'=>30), - 't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>40, 'class'=>'center'), + 'sc.role'=>array('label'=>"Role", 'checked'=>1, 'position'=>40), + 't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>50, 'class'=>'center'), ); // Extra fields if (is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label'])) @@ -927,6 +929,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') { $search_status = ''; $search_name = ''; + $search_role = ''; $search_addressphone = ''; $search_array_options=array(); @@ -968,6 +971,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $param="socid=".urlencode($object->id); if ($search_status != '') $param.='&search_status='.urlencode($search_status); + if (count($search_role)>0) $param.=implode('&search_role[]=', $search_role); if ($search_name != '') $param.='&search_name='.urlencode($search_name); if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); // Add $param from extra fields @@ -978,9 +982,15 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $sql .= " t.civility as civility_id, t.address, t.zip, t.town"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)"; + if (count($search_role)>0) { + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_contacts as sc on (sc.fk_socpeople = t.rowid)"; + } $sql .= " WHERE t.fk_soc = ".$object->id; if ($search_status!='' && $search_status != '-1') $sql .= " AND t.statut = ".$db->escape($search_status); if ($search_name) $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name); + if (count($search_role)>0) { + $sql .= ' AND sc.fk_c_type_contact IN ('.implode(',',$search_role).')'; + } // Add where from extra fields $extrafieldsobjectkey=$contactstatic->table_element; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; @@ -993,6 +1003,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $num = $db->num_rows($result); + // Fields title search // -------------------------------------------------------------------- print ''; @@ -1002,11 +1013,16 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; if ($key == 'status' || $key == 'statut') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) + if (! empty($arrayfields['t.'.$key]['checked']) || ! empty($arrayfields['sc.'.$key]['checked'])) { + print ''; if (in_array($key, array('lastname','name'))) print ''; elseif (in_array($key, array('statut'))) print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0, 1),'1'=>$contactstatic->LibStatut(1, 1)), $search_status); + elseif (in_array($key, array('role'))) { + $contactType=$contactstatic->listeTypeContacts('external', '', 1); + print $form->multiselectarray('search_role', $contactType, $search_role); + } print ''; } } @@ -1035,7 +1051,10 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; if ($key == 'status' || $key == 'statut') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; + if ($key == 'role') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked']) || ! empty($arrayfields['sc.'.$key]['checked'])) { + print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; + } } // Extra fields $extrafieldsobjectkey=$contactstatic->table_element; @@ -1082,6 +1101,11 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $contactstatic->setGenderFromCivility(); $contactstatic->fetch_optionals(); + $resultRole=$contactstatic->fetchRole(); + if ($resultRole<0) { + setEventMessages(null, $contactstatic->errors,'errors'); + } + if (is_array($contactstatic->array_options)) { foreach($contactstatic->array_options as $key => $val) @@ -1125,6 +1149,16 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') print ''; } + // Role + if (! empty($arrayfields['sc.role']['checked'])) + { + print ''; + foreach($contactstatic->roles as $key=>$val) { + print '
    '.implode(' ', $val['label']).'
'; + } + print ''; + } + // Status if (! empty($arrayfields['t.statut']['checked'])) { diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 5bc114c2294..1b705133a19 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -89,18 +89,19 @@ ALTER TABLE llx_projet ADD COLUMN usage_organize_event integer DEFAULT 0; UPDATE llx_projet set usage_opportunity = 1 WHERE fk_opp_status > 0; -create table llx_societe_contact +create table llx_societe_contacts ( rowid integer AUTO_INCREMENT PRIMARY KEY, - datec datetime NULL, -- date de creation de l'enregistrement - statut smallint DEFAULT 5, -- 5 inactif, 4 actif - - element_id int NOT NULL, -- la reference de l'element. - fk_c_type_contact int NOT NULL, -- nature du contact. - fk_socpeople integer NOT NULL + entity integer DEFAULT 1 NOT NULL, + date_creation datetime NOT NULL, + fk_soc integer NOT NULL, + fk_c_type_contact int NOT NULL, + fk_socpeople integer NOT NULL, + tms TIMESTAMP, + import_key VARCHAR(14) )ENGINE=innodb; -ALTER TABLE llx_societe_contact ADD UNIQUE INDEX idx_societe_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople); - -ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); -ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid); +ALTER TABLE llx_societe_contacts ADD UNIQUE INDEX idx_societe_contacts_idx1 (entity, fk_soc, fk_c_type_contact, fk_socpeople); +ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); +ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); +ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_contact.key.sql b/htdocs/install/mysql/tables/llx_societe_contacts.key.sql similarity index 61% rename from htdocs/install/mysql/tables/llx_societe_contact.key.sql rename to htdocs/install/mysql/tables/llx_societe_contacts.key.sql index 1409e7edc24..2b2eae8b2ca 100644 --- a/htdocs/install/mysql/tables/llx_societe_contact.key.sql +++ b/htdocs/install/mysql/tables/llx_societe_contacts.key.sql @@ -16,7 +16,7 @@ -- -- ======================================================================== -ALTER TABLE llx_societe_contact ADD UNIQUE INDEX idx_societe_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople); - -ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); -ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid); +ALTER TABLE llx_societe_contacts ADD UNIQUE INDEX idx_societe_contacts_idx1 (entity, fk_soc, fk_c_type_contact, fk_socpeople); +ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); +ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid); +ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid); diff --git a/htdocs/install/mysql/tables/llx_societe_contact.sql b/htdocs/install/mysql/tables/llx_societe_contacts.sql similarity index 69% rename from htdocs/install/mysql/tables/llx_societe_contact.sql rename to htdocs/install/mysql/tables/llx_societe_contacts.sql index 040f8ded124..31d82f3003d 100644 --- a/htdocs/install/mysql/tables/llx_societe_contact.sql +++ b/htdocs/install/mysql/tables/llx_societe_contacts.sql @@ -17,13 +17,14 @@ -- ======================================================================== -create table llx_societe_contact +create table llx_societe_contacts ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - datec datetime NULL, -- date de creation de l'enregistrement - statut smallint DEFAULT 5, -- 5 inactif, 4 actif - - element_id int NOT NULL, -- la reference de l'element. - fk_c_type_contact int NOT NULL, -- nature du contact. - fk_socpeople integer NOT NULL + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, + date_creation datetime NOT NULL, + fk_soc integer NOT NULL, + fk_c_type_contact int NOT NULL, + fk_socpeople integer NOT NULL, + tms TIMESTAMP, + import_key VARCHAR(14) )ENGINE=innodb; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 5c3e30967de..2b92ed783fe 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -989,4 +989,16 @@ ToApprove=To approve GlobalOpenedElemView=Global view NoArticlesFoundForTheKeyword=No article found for the keyword '%s' NoArticlesFoundForTheCategory=No article found for the category -ToAcceptRefuse=To accept | refuse \ No newline at end of file +ToAcceptRefuse=To accept | refuse +ContactDefault_agenda=Event +ContactDefault_commande=Order +ContactDefault_contrat=Contract +ContactDefault_facture=Invoice +ContactDefault_fichinter=Intervention +ContactDefault_invoice_supplier=Supplier Invoice +ContactDefault_order_supplier=Supplier Order +ContactDefault_project=Project +ContactDefault_project_task=Task +ContactDefault_propal=Proposal +ContactDefault_supplier_proposal=Supplier Proposal +ContactDefault_ticketsup=Ticket From d811de4da2e7028d4ffd4150532dcd95ffeb5548 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 2 Sep 2019 22:01:48 +0200 Subject: [PATCH 03/15] let only triggers part --- htdocs/contact/card.php | 28 ++++++- htdocs/contact/class/contact.class.php | 93 +++++++++++++++++++++++- htdocs/contact/list.php | 10 +++ htdocs/core/class/commonobject.class.php | 7 +- htdocs/core/class/html.form.class.php | 40 ++++++++++ htdocs/core/lib/company.lib.php | 29 ++++---- 6 files changed, 179 insertions(+), 28 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 76d0e3911b5..20a61ec4e3e 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -371,6 +371,7 @@ if (empty($reshook)) $object->priv = GETPOST("priv", 'int'); $object->note_public = GETPOST("note_public", 'none'); $object->note_private = GETPOST("note_private", 'none'); + $object->roles = GETPOST("roles", 'array'); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); @@ -474,9 +475,6 @@ else // Si edition contact deja existant $object = new Contact($db); $res=$object->fetch($id, $user); - if ($res < 0) { dol_print_error($db, $object->error); exit; } - $res=$object->fetch_optionals(); - if ($res < 0) { dol_print_error($db, $object->error); exit; } // Show tabs $head = contact_prepare_head($object); @@ -724,6 +722,15 @@ else print ""; } + //Role + if (!empty($socid)) { + print '' . $langs->trans("Role") . ''; + print ''; + $contactType = $object->listeTypeContacts('external', '', 1); + print $form->multiselectarray('roles', $contactType); + print ''; + } + // Other attributes $parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3); $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -1040,6 +1047,14 @@ else print ""; } + //Role + if (!empty($object->socid)) { + print '' . $langs->trans("Role") . ''; + print ''; + print $form->showRoles("roles", $object, 'edit' ,$object->roles); + print ''; + } + // Other attributes $parameters=array('colspan' => ' colspan="3"', 'cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -1238,6 +1253,13 @@ else print ''; } + if (!empty($object->socid)) { + print '' . $langs->trans("Roles") . ''; + print ''; + print $form->showRoles("roles", $object, 'view'); + print ''; + } + // Other attributes $cols = 3; $parameters=array('socid'=>$socid); diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index db6ab29b802..d718a898f2d 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -399,6 +399,14 @@ class Contact extends CommonObject } } + if (! $error) { + $result=$this->updateRoles(); + if ($result < 0) + { + $error++; + } + } + if (! $error && $this->user_id > 0) { $tmpobj = new User($this->db); @@ -861,6 +869,11 @@ class Contact extends CommonObject // fetch optionals attributes and labels $this->fetch_optionals(); + $resultRole=$this->fetchRoles(); + if ($resultRole<0) { + return $resultRole; + } + return 1; } else @@ -995,6 +1008,20 @@ class Contact extends CommonObject } } + if (! $error) + { + // Remove Roles + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) + { + $error++; + $this->error .= $this->db->lasterror(); + $errorflag=-1; + } + } + if (! $error) { // Remove category @@ -1458,14 +1485,13 @@ class Contact extends CommonObject * @return float|int * @throws Exception */ - public function fetchRole() + public function fetchRoles() { - global $langs; $error= 0; $num=0; - $sql ="SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle"; + $sql ="SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle, sc.rowid as contactroleid"; $sql.=" FROM ".MAIN_DB_PREFIX."societe_contacts as sc "; $sql.=" INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc"; $sql.=" ON tc.rowid = sc.fk_c_type_contact"; @@ -1482,11 +1508,13 @@ class Contact extends CommonObject if ($num > 0) { while ($obj = $this->db->fetch_object($resql)) { $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; - $this->roles[$this->id]=array('id'=>$obj->rowid,'element'=>$obj->element,'source'=>$obj->source,'code'=>$obj->code,'label'=>($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle)); + $libelle_element = $langs->trans('ContactDefault_'.$obj->element); + $this->roles[$obj->contactroleid]=array('id'=>$obj->rowid,'element'=>$obj->element,'source'=>$obj->source,'code'=>$obj->code,'label'=>$libelle_element. ' - '.($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle)); } } } else { $error++; + $this->error=$this->db->lasterror(); $this->errors[]=$this->db->lasterror(); } @@ -1497,4 +1525,61 @@ class Contact extends CommonObject } } + /** + * Updates Roles + * + * @return float|int + * @throws Exception + */ + public function updateRoles() + { + global $conf; + + $error=0; + + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_soc=".$this->socid; + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $result = $this->db->query($sql); + if (!$result) { + $this->errors[]=$this->db->lasterror().' sql='.$sql; + $error++; + } else { + if (count($this->roles)>0) { + foreach ($this->roles as $keyRoles => $valRoles) { + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_contacts"; + $sql .= " (entity,"; + $sql .= "date_creation,"; + $sql .= "fk_soc,"; + $sql .= "fk_c_type_contact,"; + $sql .= "fk_socpeople) "; + $sql .= " VALUES (" . $conf->entity . ","; + $sql .= "'" . $this->db->idate(dol_now()) . "',"; + $sql .= $this->socid . ", "; + $sql .= $valRoles . " , " ; + $sql .= $this->id; + $sql .= ")"; + dol_syslog(get_class($this) . "::".__METHOD__, LOG_DEBUG); + + $result = $this->db->query($sql); + if (!$result) + { + $this->errors[]=$this->db->lasterror().' sql='.$sql; + $error++; + } + } + } + } + if (empty($error)) { + $this->db->commit(); + return 1; + } else { + $this->error=implode(' ', $this->errors); + $this->db->rollback(); + return $error*-1; + } + } + } diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index b0db8b0affb..585d6db499d 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -84,6 +84,7 @@ $search_zip=GETPOST('search_zip', 'alpha'); $search_town=GETPOST('search_town', 'alpha'); $search_import_key=GETPOST("search_import_key", "alpha"); $search_country=GETPOST("search_country", 'intcomma'); +$search_roles=GETPOST("search_roles", 'array'); if ($search_status=='') $search_status=1; // always display active customer first @@ -242,6 +243,7 @@ if (empty($reshook)) $search_import_key=''; $toselect=''; $search_array_options=array(); + $search_roles=array(); } // Mass actions @@ -334,6 +336,9 @@ if (strlen($search_linkedin)) $sql.= natural_search('p.linkedin', $search_ if (strlen($search_email)) $sql.= natural_search('p.email', $search_email); if (strlen($search_zip)) $sql.= natural_search("p.zip", $search_zip); if (strlen($search_town)) $sql.= natural_search("p.town", $search_town); +if (count($search_roles)>0) { + $sql .= " AND p.rowid IN (SELECT sc.fk_socpeople FROM ".MAIN_DB_PREFIX."societe_contacts as sc WHERE sc.fk_c_type_contact IN (".implode(',', $search_roles)."))"; +} if ($search_no_email != '' && $search_no_email >= 0) $sql.= " AND p.no_email = ".$db->escape($search_no_email); if ($search_status != '' && $search_status >= 0) $sql.= " AND p.statut = ".$db->escape($search_status); @@ -438,6 +443,7 @@ if ($search_status != '') $param.='&search_status='.urlencode($search_status if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".urlencode($search_priv); if ($search_import_key != '') $param.='&search_import_key='.urlencode($search_import_key); if ($optioncss != '') $param.='&optioncss='.$optioncss; +if (count($search_roles)>0) $param.=implode('&search_roles[]=', $search_roles); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -510,6 +516,10 @@ if (! empty($conf->categorie->enabled)) $moreforfilter.=$formother->select_categories(Categorie::TYPE_SUPPLIER, $search_categ_supplier, 'search_categ_supplier', 1); $moreforfilter.=''; } + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('Roles'). ': '; + $moreforfilter.=$form->showRoles("search_roles", $objecttmp, 'edit', $search_roles); + $moreforfilter.='
'; } if ($moreforfilter) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0eea968ecd2..716b615f503 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1226,9 +1226,6 @@ abstract class CommonObject // phpcs:enable global $langs; - if (empty($order)) $order='position'; - if ($order == 'position') $order.=',code'; - $tab = array(); $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; @@ -1262,11 +1259,11 @@ abstract class CommonObject { $obj = $this->db->fetch_object($resql); - $libelle_element = $langs->trans('ContactDefault_'.ucfirst($obj->element)); + $libelle_element = $langs->trans('ContactDefault_'.$obj->element); $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); if (empty($option)) $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type; - else $tab[$obj->code]=$libelle_element.' - '.$libelle_type; + else $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type; $i++; } return $tab; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 5ee969a73a0..4eca1ef0f85 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6484,6 +6484,46 @@ class Form return 'ErrorBadValueForParameterRenderMode'; // Should not happened } + /** + * showContactRoles on view and edit mode + * + * @param string $htmlname Html component name and id + * @param Contact $contact Contact Obejct + * @param string $rendermode view, edit + * @param array $selected $key=>$val $val is selected Roles for input mode + * @return string String with contacts roles + */ + public function showRoles($htmlname = '', Contact $contact, $rendermode = 'view', $selected = array()) + { + if ($rendermode === 'view') { + $toprint = array(); + foreach ($contact->roles as $key => $val) { + $toprint[] = '
  • ' . $val['label'] . '
  • '; + } + return '
      ' . implode(' ', $toprint) . '
    '; + } + + if ($rendermode === 'edit') + { + $contactType=$contact->listeTypeContacts('external', '', 1); + + if (count($selected)>0) { + $newselected=array(); + foreach($selected as $key=>$val) { + if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) { + $newselected[]=$val['id']; + } else { + break; + } + } + if (count($newselected)>0) $selected=$newselected; + } + return $this->multiselectarray($htmlname, $contactType, $selected); + } + + return 'ErrorBadValueForParameterRenderMode'; // Should not happened + } + /** * Show linked object block. diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index cfc1fcfb30f..14b20bbe46b 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -869,7 +869,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if ($search_status=='') $search_status=1; // always display active customer first $search_name = GETPOST("search_name", 'alpha'); $search_addressphone = GETPOST("search_addressphone", 'alpha'); - $search_role = GETPOST("search_role", 'array'); + $search_roles = GETPOST("search_roles", 'array'); if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="t.lastname"; @@ -898,7 +898,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') 't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10), 't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20), 't.address'=>array('label'=>(empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked'=>1, 'position'=>30), - 'sc.role'=>array('label'=>"Role", 'checked'=>1, 'position'=>40), + 'sc.role'=>array('label'=>"Roles", 'checked'=>1, 'position'=>40), 't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>50, 'class'=>'center'), ); // Extra fields @@ -929,7 +929,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') { $search_status = ''; $search_name = ''; - $search_role = ''; + $search_roles = array(); $search_addressphone = ''; $search_array_options=array(); @@ -971,7 +971,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $param="socid=".urlencode($object->id); if ($search_status != '') $param.='&search_status='.urlencode($search_status); - if (count($search_role)>0) $param.=implode('&search_role[]=', $search_role); + if (count($search_roles)>0) $param.=implode('&search_roles[]=', $search_roles); if ($search_name != '') $param.='&search_name='.urlencode($search_name); if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); // Add $param from extra fields @@ -982,14 +982,11 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $sql .= " t.civility as civility_id, t.address, t.zip, t.town"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)"; - if (count($search_role)>0) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_contacts as sc on (sc.fk_socpeople = t.rowid)"; - } $sql .= " WHERE t.fk_soc = ".$object->id; if ($search_status!='' && $search_status != '-1') $sql .= " AND t.statut = ".$db->escape($search_status); if ($search_name) $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name); - if (count($search_role)>0) { - $sql .= ' AND sc.fk_c_type_contact IN ('.implode(',',$search_role).')'; + if (count($search_roles)>0) { + $sql .= " AND t.rowid IN (SELECT sc.fk_socpeople FROM ".MAIN_DB_PREFIX."societe_contacts as sc WHERE sc.fk_c_type_contact IN (".implode(',', $search_roles)."))"; } // Add where from extra fields $extrafieldsobjectkey=$contactstatic->table_element; @@ -1020,8 +1017,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if (in_array($key, array('lastname','name'))) print ''; elseif (in_array($key, array('statut'))) print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0, 1),'1'=>$contactstatic->LibStatut(1, 1)), $search_status); elseif (in_array($key, array('role'))) { - $contactType=$contactstatic->listeTypeContacts('external', '', 1); - print $form->multiselectarray('search_role', $contactType, $search_role); + print $form->showRoles("search_roles", $contactstatic, 'edit', $search_roles); } print ''; } @@ -1052,9 +1048,12 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; if ($key == 'status' || $key == 'statut') $align.=($align?' ':'').'center'; if ($key == 'role') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked']) || ! empty($arrayfields['sc.'.$key]['checked'])) { + if (! empty($arrayfields['t.'.$key]['checked'])) { print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; } + if (! empty($arrayfields['sc.'.$key]['checked'])) { + print getTitleFieldOfList($arrayfields['sc.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 'sc.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; + } } // Extra fields $extrafieldsobjectkey=$contactstatic->table_element; @@ -1101,7 +1100,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $contactstatic->setGenderFromCivility(); $contactstatic->fetch_optionals(); - $resultRole=$contactstatic->fetchRole(); + $resultRole=$contactstatic->fetchRoles(); if ($resultRole<0) { setEventMessages(null, $contactstatic->errors,'errors'); } @@ -1153,9 +1152,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if (! empty($arrayfields['sc.role']['checked'])) { print ''; - foreach($contactstatic->roles as $key=>$val) { - print '
      '.implode(' ', $val['label']).'
    '; - } + print $form->showRoles("roles", $contactstatic, 'view'); print ''; } From 6c20fbafdf0c5811a5802da2c11468b0798a0359 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 3 Sep 2019 17:04:42 +0200 Subject: [PATCH 04/15] add trigger files --- htdocs/contact/card.php | 4 +- htdocs/contact/class/contact.class.php | 43 +++++++ htdocs/contact/list.php | 4 +- htdocs/core/class/commonobject.class.php | 42 +++--- htdocs/core/class/html.form.class.php | 41 ------ htdocs/core/class/html.formcompany.class.php | 64 +++++++--- htdocs/core/lib/company.lib.php | 6 +- ...rface_90_modSociete_ContactRoles.class.php | 120 ++++++++++++++++++ 8 files changed, 241 insertions(+), 83 deletions(-) create mode 100644 htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 20a61ec4e3e..5861cc71d38 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -1051,7 +1051,7 @@ else if (!empty($object->socid)) { print '' . $langs->trans("Role") . ''; print ''; - print $form->showRoles("roles", $object, 'edit' ,$object->roles); + print $formcompany->showRoles("roles", $object, 'edit' ,$object->roles); print ''; } @@ -1256,7 +1256,7 @@ else if (!empty($object->socid)) { print '' . $langs->trans("Roles") . ''; print ''; - print $form->showRoles("roles", $object, 'view'); + print $formcompany->showRoles("roles", $object, 'view'); print ''; } diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index d718a898f2d..6b46e32f532 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1525,6 +1525,49 @@ class Contact extends CommonObject } } + /** + * Get Contact roles for a thirdparty + * + * @param string $element element type + * @return array|int + * @throws Exception + */ + public function getContactRoles($element = '') + { + $tab=array(); + + $sql = "SELECT sc.fk_socpeople as id, sc.fk_c_type_contact"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; + $sql.= ", ".MAIN_DB_PREFIX."societe_contacts sc"; + $sql.= " WHERE sc.fk_soc =".$this->socid; + $sql.= " AND sc.fk_c_type_contact=tc.rowid"; + $sql.= " AND tc.element='".$element."'"; + $sql.= " AND tc.active=1"; + + dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + $tab[]=array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact); + + $i++; + } + + return $tab; + } + else + { + $this->error=$this->db->error(); + dol_print_error($this->db); + return -1; + } + } + /** * Updates Roles * diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 585d6db499d..6b595a05860 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -36,6 +36,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; // Load translation files required by the page $langs->loadLangs(array("companies", "suppliers", "categories")); @@ -264,6 +265,7 @@ if ($search_priv < 0) $search_priv=''; $form=new Form($db); $formother=new FormOther($db); +$formcompany=new FormCompany($db); $contactstatic=new Contact($db); $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses")); @@ -518,7 +520,7 @@ if (! empty($conf->categorie->enabled)) } $moreforfilter.='
    '; $moreforfilter.=$langs->trans('Roles'). ': '; - $moreforfilter.=$form->showRoles("search_roles", $objecttmp, 'edit', $search_roles); + $moreforfilter.=$formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles); $moreforfilter.='
    '; } if ($moreforfilter) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 716b615f503..1a1b5c597ce 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1224,9 +1224,10 @@ abstract class CommonObject public function listeTypeContacts($source = 'internal', $option = 0, $activeonly = 0, $code = '', $element = '') { // phpcs:enable - global $langs; + global $langs, $conf; $tab = array(); + $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; @@ -1251,27 +1252,36 @@ abstract class CommonObject dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - $libelle_element = $langs->trans('ContactDefault_'.$obj->element); - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); - if (empty($option)) $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type; - else $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type; - $i++; + if ($resql) { + $num = $this->db->num_rows($resql); + if ($num > 0) { + while ($obj = $this->db->fetch_object($resql)) { + if (strpos($obj->element, 'project')!==false) { + $element='projet'; + } elseif($obj->element=='contrat') { + $element='contract'; + } elseif(strpos($obj->element, 'supplier')!==false && $obj->element!='supplier_proposal') { + $element='fournisseur'; + } elseif(strpos($obj->element, 'supplier')!==false && $obj->element!='supplier_proposal') { + $element='fournisseur'; + } else { + $element=$obj->element; + } + if ($conf->{$element}->enabled) { + $libelle_element = $langs->trans('ContactDefault_' . $obj->element); + $transkey = "TypeContact_" . $this->element . "_" . $source . "_" . $obj->code; + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); + if (empty($option)) + $tab[$obj->rowid] = $libelle_element . ' - ' . $libelle_type; + else $tab[$obj->rowid] = $libelle_element . ' - ' . $libelle_type; + } + } } return $tab; } else { $this->error=$this->db->lasterror(); - //dol_print_error($this->db); return null; } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4eca1ef0f85..f351a361d14 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6484,47 +6484,6 @@ class Form return 'ErrorBadValueForParameterRenderMode'; // Should not happened } - /** - * showContactRoles on view and edit mode - * - * @param string $htmlname Html component name and id - * @param Contact $contact Contact Obejct - * @param string $rendermode view, edit - * @param array $selected $key=>$val $val is selected Roles for input mode - * @return string String with contacts roles - */ - public function showRoles($htmlname = '', Contact $contact, $rendermode = 'view', $selected = array()) - { - if ($rendermode === 'view') { - $toprint = array(); - foreach ($contact->roles as $key => $val) { - $toprint[] = '
  • ' . $val['label'] . '
  • '; - } - return '
      ' . implode(' ', $toprint) . '
    '; - } - - if ($rendermode === 'edit') - { - $contactType=$contact->listeTypeContacts('external', '', 1); - - if (count($selected)>0) { - $newselected=array(); - foreach($selected as $key=>$val) { - if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) { - $newselected[]=$val['id']; - } else { - break; - } - } - if (count($newselected)>0) $selected=$newselected; - } - return $this->multiselectarray($htmlname, $contactType, $selected); - } - - return 'ErrorBadValueForParameterRenderMode'; // Should not happened - } - - /** * Show linked object block. * diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 2207ab8ab2b..81b87b6f340 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -29,28 +29,11 @@ * Class to build HTML component for third parties management * Only common components are here. */ -class FormCompany + +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; + +class FormCompany extends Form { - /** - * @var DoliDB Database handler. - */ - public $db; - - /** - * @var string Error code (or message) - */ - public $error=''; - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** @@ -763,6 +746,45 @@ class FormCompany } } + /** + * showContactRoles on view and edit mode + * + * @param string $htmlname Html component name and id + * @param Contact $contact Contact Obejct + * @param string $rendermode view, edit + * @param array $selected $key=>$val $val is selected Roles for input mode + * @return string String with contacts roles + */ + public function showRoles($htmlname = '', Contact $contact, $rendermode = 'view', $selected = array()) + { + if ($rendermode === 'view') { + $toprint = array(); + foreach ($contact->roles as $key => $val) { + $toprint[] = '
  • ' . $val['label'] . '
  • '; + } + return '
      ' . implode(' ', $toprint) . '
    '; + } + + if ($rendermode === 'edit') + { + $contactType=$contact->listeTypeContacts('external', '', 1); + if (count($selected)>0) { + $newselected=array(); + foreach($selected as $key=>$val) { + if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) { + $newselected[]=$val['id']; + } else { + break; + } + } + if (count($newselected)>0) $selected=$newselected; + } + return $this->multiselectarray($htmlname, $contactType, $selected); + } + + return 'ErrorBadValueForParameterRenderMode'; // Should not happened + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return a select list with zip codes and their town diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 14b20bbe46b..331b03bacc4 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -859,6 +859,8 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') global $user,$conf,$extrafields,$hookmanager; global $contextpage; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; + $formcompany = new FormCompany($db); $form = new Form($db); $optioncss = GETPOST('optioncss', 'alpha'); @@ -1017,7 +1019,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if (in_array($key, array('lastname','name'))) print ''; elseif (in_array($key, array('statut'))) print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0, 1),'1'=>$contactstatic->LibStatut(1, 1)), $search_status); elseif (in_array($key, array('role'))) { - print $form->showRoles("search_roles", $contactstatic, 'edit', $search_roles); + print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles); } print ''; } @@ -1152,7 +1154,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') if (! empty($arrayfields['sc.role']['checked'])) { print ''; - print $form->showRoles("roles", $contactstatic, 'view'); + print $formcompany->showRoles("roles", $contactstatic, 'view'); print ''; } diff --git a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php new file mode 100644 index 00000000000..8fba51e7a69 --- /dev/null +++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php @@ -0,0 +1,120 @@ + + * Copyright (C) 2009-2017 Regis Houssin + * Copyright (C) 2011-2014 Juanjo Menent + * Copyright (C) 2013 Cedric GROSS + * Copyright (C) 2014 Marcos García + * Copyright (C) 2015 Bahfir Abbes + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php + * \ingroup agenda + * \brief Trigger file for agenda module + */ + +require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; + + +/** + * Class of triggered functions for agenda module + */ +class InterfaceContactRoles extends DolibarrTriggers +{ + public $family = 'agenda'; + public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; + + /** + * Version of the trigger + * @var string + */ + public $version = self::VERSION_DOLIBARR; + + /** + * @var string Image of the trigger + */ + public $picto = 'action'; + + /** + * Function called when a Dolibarrr business event is done. + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) + * + * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database: + * $object->actiontypecode (translation action code: AC_OTH, ...) + * $object->actionmsg (note, long text) + * $object->actionmsg2 (label, short text) + * $object->sendtoid (id of contact or array of ids) + * $object->socid (id of thirdparty) + * $object->fk_project + * $object->fk_element + * $object->elementtype + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) + { + // Lors de la création d'un document, récupération des contacts et rôle associés à la société et association avec le document + if ($action === 'PROPAL_CREATE' || $action === 'ORDER_CREATE' || $action === 'BILL_CREATE' || $action === 'ORDER_SUPPLIER_CREATE' || $action === 'BILL_SUPPLIER_CREATE' + || $action === 'CONTRACT_CREATE' || $action === 'FICHINTER_CREATE' || $action === 'PROJECT_CREATE' || $action === 'TICKET_CREATE' || $action === 'ACTION_CREATE') { + + if(!empty($object->socid) && $object->socid != '-1') { + global $db, $langs; + + $contactdefault = new Contact($this->db); + $contactdefault->socid=$object->socid; + $TContact = $contactdefault->getContactRoles(); + + // Le trigger est appelé avant que le core n'ajoute lui-même des contacts (contact propale, clone), il ne faut pas les associer avant sinon bug + $TContactAlreadyLinked = array(); + if ($object->id > 0) + { + $class = get_class($object); + $cloneFrom = new $class($db); + $r = $cloneFrom->fetch($object->id); + + if (!empty($cloneFrom->id)) $TContactAlreadyLinked = array_merge($cloneFrom->liste_contact(-1,'external'), $cloneFrom->liste_contact(-1,'internal')); + } + + foreach($TContact as $i => $infos) { + // Gestion du cas du clone + foreach ($TContactAlreadyLinked as $contactData) { + if($contactData['id'] == $infos['fk_socpeople'] && $contactData['fk_c_type_contact'] == $infos['type_contact']) unset($TContact[$i]); + } + } + + $nb = 0; + foreach($TContact as $infos) { + // Gestion du cas spécifique de la création de propale avec sélection du contact, cela créé un bug si le contact est ajouté par le module contactdefault + $res = $object->add_contact($infos['fk_socpeople'], $infos['type_contact']); + if($res > 0) $nb++; + } + + if($nb > 0) { + setEventMessage($langs->trans('ContactAddedAutomatically', $nb)); + } + } + + dol_syslog( + "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id + ); + } + } +} From d50114df649a0d7752f4a549e5d541da1dc27eeb Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 6 Sep 2019 09:20:18 +0200 Subject: [PATCH 05/15] mostlyDone --- htdocs/contact/class/contact.class.php | 2 +- ...rface_90_modSociete_ContactRoles.class.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 6b46e32f532..fad72d69637 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1544,7 +1544,7 @@ class Contact extends CommonObject $sql.= " AND tc.element='".$element."'"; $sql.= " AND tc.active=1"; - dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php index 8fba51e7a69..36a8274c602 100644 --- a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php +++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php @@ -71,16 +71,20 @@ class InterfaceContactRoles extends DolibarrTriggers */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { - // Lors de la création d'un document, récupération des contacts et rôle associés à la société et association avec le document + if ($action === 'PROPAL_CREATE' || $action === 'ORDER_CREATE' || $action === 'BILL_CREATE' || $action === 'ORDER_SUPPLIER_CREATE' || $action === 'BILL_SUPPLIER_CREATE' || $action === 'CONTRACT_CREATE' || $action === 'FICHINTER_CREATE' || $action === 'PROJECT_CREATE' || $action === 'TICKET_CREATE' || $action === 'ACTION_CREATE') { - if(!empty($object->socid) && $object->socid != '-1') { - global $db, $langs; + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $socid=(property_exists($object, 'socid')?$object->socid:$object->fk_soc); + + if(!empty($socid) && $socid != '-1') { + global $db, $langs; + var_dump($socid); $contactdefault = new Contact($this->db); - $contactdefault->socid=$object->socid; - $TContact = $contactdefault->getContactRoles(); + $contactdefault->socid=$socid; + $TContact = $contactdefault->getContactRoles($object->element); // Le trigger est appelé avant que le core n'ajoute lui-même des contacts (contact propale, clone), il ne faut pas les associer avant sinon bug $TContactAlreadyLinked = array(); @@ -90,7 +94,7 @@ class InterfaceContactRoles extends DolibarrTriggers $cloneFrom = new $class($db); $r = $cloneFrom->fetch($object->id); - if (!empty($cloneFrom->id)) $TContactAlreadyLinked = array_merge($cloneFrom->liste_contact(-1,'external'), $cloneFrom->liste_contact(-1,'internal')); + if (!empty($cloneFrom->id)) $TContactAlreadyLinked = array_merge($cloneFrom->liste_contact(-1, 'external'), $cloneFrom->liste_contact(-1, 'internal')); } foreach($TContact as $i => $infos) { @@ -111,10 +115,6 @@ class InterfaceContactRoles extends DolibarrTriggers setEventMessage($langs->trans('ContactAddedAutomatically', $nb)); } } - - dol_syslog( - "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id - ); } } } From 617e430998034d71b59b5b864f5a7e0911be9b9a Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 9 Sep 2019 12:31:17 +0200 Subject: [PATCH 06/15] fix stravis and sticker --- htdocs/core/class/html.formcompany.class.php | 2 +- htdocs/install/mysql/migration/10.0.0-11.0.0.sql | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 81b87b6f340..c7467922da5 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -755,7 +755,7 @@ class FormCompany extends Form * @param array $selected $key=>$val $val is selected Roles for input mode * @return string String with contacts roles */ - public function showRoles($htmlname = '', Contact $contact, $rendermode = 'view', $selected = array()) + public function showRoles($htmlname, Contact $contact, $rendermode = 'view', $selected = array()) { if ($rendermode === 'view') { $toprint = array(); diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index ec124c8a1a1..2caf438b471 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -175,4 +175,5 @@ INSERT INTO llx_c_hrm_public_holiday (code, entity, fk_country, dayrule, year, m INSERT INTO llx_c_hrm_public_holiday (code, entity, fk_country, dayrule, year, month, day, active) VALUES('IN-REPUBLICDAY', 0, 117, '', 0, 1, 26, 1); INSERT INTO llx_c_hrm_public_holiday (code, entity, fk_country, dayrule, year, month, day, active) VALUES('IN-GANDI', 0, 117, '', 0, 10, 2, 1); - +ALTER TABLE llx_supplier_proposaldet ADD COLUMN date_start datetime DEFAULT NULL AFTER product_type; +ALTER TABLE llx_supplier_proposaldet ADD COLUMN date_end datetime DEFAULT NULL AFTER date_start; From 42b3640a5a0cdb0ffc463e720c5f6e0a04fe9c15 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 9 Sep 2019 14:12:28 +0200 Subject: [PATCH 07/15] fix travis --- .../triggers/interface_90_modSociete_ContactRoles.class.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php index 36a8274c602..8d2418a8a94 100644 --- a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php +++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php @@ -81,12 +81,11 @@ class InterfaceContactRoles extends DolibarrTriggers if(!empty($socid) && $socid != '-1') { global $db, $langs; - var_dump($socid); + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $contactdefault = new Contact($this->db); $contactdefault->socid=$socid; $TContact = $contactdefault->getContactRoles($object->element); - // Le trigger est appelé avant que le core n'ajoute lui-même des contacts (contact propale, clone), il ne faut pas les associer avant sinon bug $TContactAlreadyLinked = array(); if ($object->id > 0) { @@ -98,7 +97,6 @@ class InterfaceContactRoles extends DolibarrTriggers } foreach($TContact as $i => $infos) { - // Gestion du cas du clone foreach ($TContactAlreadyLinked as $contactData) { if($contactData['id'] == $infos['fk_socpeople'] && $contactData['fk_c_type_contact'] == $infos['type_contact']) unset($TContact[$i]); } @@ -106,7 +104,6 @@ class InterfaceContactRoles extends DolibarrTriggers $nb = 0; foreach($TContact as $infos) { - // Gestion du cas spécifique de la création de propale avec sélection du contact, cela créé un bug si le contact est ajouté par le module contactdefault $res = $object->add_contact($infos['fk_socpeople'], $infos['type_contact']); if($res > 0) $nb++; } From ee931d0f25dfe42fa9138b180815a9beca1f7ceb Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 9 Sep 2019 14:53:23 +0200 Subject: [PATCH 08/15] fix travis --- .../interface_90_modSociete_ContactRoles.class.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php index 8d2418a8a94..e9bf9d38a50 100644 --- a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php +++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php @@ -53,14 +53,8 @@ class InterfaceContactRoles extends DolibarrTriggers * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) * * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database: - * $object->actiontypecode (translation action code: AC_OTH, ...) - * $object->actionmsg (note, long text) - * $object->actionmsg2 (label, short text) - * $object->sendtoid (id of contact or array of ids) - * $object->socid (id of thirdparty) - * $object->fk_project - * $object->fk_element - * $object->elementtype + * $object->socid or $object->fk_soc(id of thirdparty) + * $object->element (element type of object) * * @param string $action Event action code * @param Object $object Object @@ -113,5 +107,6 @@ class InterfaceContactRoles extends DolibarrTriggers } } } - } + return 0; + } } From ad92efaee14e8ad5e8523fd6064928ad917cee7a Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 9 Sep 2019 14:58:29 +0200 Subject: [PATCH 09/15] add trans --- htdocs/langs/en_US/main.lang | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index c4611836a51..04f45f8de4b 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1004,3 +1004,4 @@ ContactDefault_project_task=Task ContactDefault_propal=Proposal ContactDefault_supplier_proposal=Supplier Proposal ContactDefault_ticketsup=Ticket +ContactAddedAutomatically=Contact added from contact thirdparty roles From f1d098adccc5b624c27e578cb263275ac74ca76b Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 27 Sep 2019 20:15:11 +0200 Subject: [PATCH 10/15] fix remove error dispplaying --- htdocs/contact/card.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 5861cc71d38..e4fc61f2e54 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -475,6 +475,9 @@ else // Si edition contact deja existant $object = new Contact($db); $res=$object->fetch($id, $user); + if ($res<0) { + setEventMessage($this->error,'errors'); + } // Show tabs $head = contact_prepare_head($object); From 8c9cee156590c001b9346de882f3ec9e75d182e0 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 2 Oct 2019 12:49:38 +0200 Subject: [PATCH 11/15] resolve conflict --- htdocs/core/lib/company.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 5729270fe73..669c1936a50 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -920,7 +920,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $contactstatic->fields=array( 'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1), - 'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOfFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20), + 'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOrFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20), 'address' =>array('type'=>'varchar(128)', 'label'=>'Address', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>30), 'role' =>array('type'=>'checkbox', 'label'=>'Role', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>40), 'statut' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>50, 'arrayofkeyval'=>array(0=>$contactstatic->LibStatut(0, 1), 1=>$contactstatic->LibStatut(1, 1))), From bc32d684a497611ed187fe16a56049fa80554c5b Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 4 Oct 2019 16:12:33 +0000 Subject: [PATCH 12/15] Fixing style errors. --- htdocs/contact/card.php | 4 ++-- htdocs/contact/class/contact.class.php | 1 - htdocs/core/lib/company.lib.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 5b1e302632e..1a271918b61 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -476,7 +476,7 @@ else $object = new Contact($db); $res=$object->fetch($id, $user); if ($res<0) { - setEventMessage($this->error,'errors'); + setEventMessage($this->error, 'errors'); } // Show tabs @@ -1054,7 +1054,7 @@ else if (!empty($object->socid)) { print '' . $langs->trans("Role") . ''; print ''; - print $formcompany->showRoles("roles", $object, 'edit' ,$object->roles); + print $formcompany->showRoles("roles", $object, 'edit', $object->roles); print ''; } diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index cb738249a44..560a6e2bc0d 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1610,5 +1610,4 @@ class Contact extends CommonObject return $error*-1; } } - } diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 4ead0601a40..91ba98d0ad4 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1142,7 +1142,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $resultRole=$contactstatic->fetchRoles(); if ($resultRole<0) { - setEventMessages(null, $contactstatic->errors,'errors'); + setEventMessages(null, $contactstatic->errors, 'errors'); } if (is_array($contactstatic->array_options)) From b9a92546b6edc24eddc1407fb5f3b13150f398f4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 7 Oct 2019 15:20:52 +0200 Subject: [PATCH 13/15] Update card.php --- htdocs/contact/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 1a271918b61..0e73d0a8786 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -476,7 +476,7 @@ else $object = new Contact($db); $res=$object->fetch($id, $user); if ($res<0) { - setEventMessage($this->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } // Show tabs From 240785922e778d317adced723a4e543fc082bc58 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 7 Oct 2019 15:23:30 +0200 Subject: [PATCH 14/15] Update interface_90_modSociete_ContactRoles.class.php --- .../triggers/interface_90_modSociete_ContactRoles.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php index e9bf9d38a50..f43c127576c 100644 --- a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php +++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php @@ -103,7 +103,7 @@ class InterfaceContactRoles extends DolibarrTriggers } if($nb > 0) { - setEventMessage($langs->trans('ContactAddedAutomatically', $nb)); + setEventMessages($langs->trans('ContactAddedAutomatically', $nb), null, 'mesgs'); } } } From 3a15485e9962fe9dcd783c574d44e745f5870db4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 7 Oct 2019 15:27:23 +0200 Subject: [PATCH 15/15] Update interface_90_modSociete_ContactRoles.class.php --- .../triggers/interface_90_modSociete_ContactRoles.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php index f43c127576c..13eb44d4eee 100644 --- a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php +++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php @@ -73,7 +73,7 @@ class InterfaceContactRoles extends DolibarrTriggers $socid=(property_exists($object, 'socid')?$object->socid:$object->fk_soc); - if(!empty($socid) && $socid != '-1') { + if (! empty($socid) && $socid > 0) { global $db, $langs; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $contactdefault = new Contact($this->db);