';
+ }
+
// Status
if (! empty($arrayfields['t.statut']['checked']))
{
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..13eb44d4eee
--- /dev/null
+++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php
@@ -0,0 +1,112 @@
+
+ * 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->socid or $object->fk_soc(id of thirdparty)
+ * $object->element (element type of object)
+ *
+ * @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)
+ {
+
+ 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') {
+
+ 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 > 0) {
+ global $db, $langs;
+ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
+ $contactdefault = new Contact($this->db);
+ $contactdefault->socid=$socid;
+ $TContact = $contactdefault->getContactRoles($object->element);
+
+ $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) {
+ 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) {
+ $res = $object->add_contact($infos['fk_socpeople'], $infos['type_contact']);
+ if($res > 0) $nb++;
+ }
+
+ if($nb > 0) {
+ setEventMessages($langs->trans('ContactAddedAutomatically', $nb), null, 'mesgs');
+ }
+ }
+ }
+ return 0;
+ }
+}
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 1333f3a9200..e4fdd2a52f7 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
@@ -135,6 +135,23 @@ 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_contacts
+(
+ 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;
+
+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);
+
ALTER TABLE llx_accounting_account MODIFY COLUMN rowid bigint AUTO_INCREMENT;
@@ -281,3 +298,5 @@ create table llx_fichinterdet_rec
import_key varchar(14) NULL DEFAULT NULL
)ENGINE=innodb;
+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;
diff --git a/htdocs/install/mysql/tables/llx_societe_contacts.key.sql b/htdocs/install/mysql/tables/llx_societe_contacts.key.sql
new file mode 100644
index 00000000000..2b2eae8b2ca
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_societe_contacts.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_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_contacts.sql b/htdocs/install/mysql/tables/llx_societe_contacts.sql
new file mode 100644
index 00000000000..31d82f3003d
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_societe_contacts.sql
@@ -0,0 +1,30 @@
+-- ========================================================================
+-- 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_contacts
+(
+ 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 a69947dfd8c..04f45f8de4b 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -991,4 +991,17 @@ 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
+ContactAddedAutomatically=Contact added from contact thirdparty roles