diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index a5fb08f490b..e9ef6837439 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -875,7 +875,7 @@ class Conf extends stdClass // Define list of limited modules (value must be key found for "name" property of module, so for example 'supplierproposal' for Module "Supplier Proposal" if (!isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) { - $this->global->MAIN_MODULES_FOR_EXTERNAL = 'user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,reception,agenda,resource,adherent,blockedlog'; // '' means 'all'. Note that contact is added here as it should be a module later. + $this->global->MAIN_MODULES_FOR_EXTERNAL = 'user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,reception,agenda,resource,adherent,blockedlog,ticket'; // '' means 'all'. Note that contact is added here as it should be a module later. } if (!empty($this->modules_parts['moduleforexternal'])) { // Module part to include an external module into the MAIN_MODULES_FOR_EXTERNAL list foreach ($this->modules_parts['moduleforexternal'] as $key => $value) { diff --git a/htdocs/public/ticket/create_ticket.php b/htdocs/public/ticket/create_ticket.php index a3d40468155..40509ffdfb4 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -337,6 +337,8 @@ if (empty($reshook)) { $object->context['disableticketemail'] = 1; // Disable emails sent by ticket trigger when creation is done from this page, emails are already sent later $object->context['contactid'] = GETPOSTINT('contactid'); // Disable emails sent by ticket trigger when creation is done from this page, emails are already sent later + $object->context['createdfrompublicinterface'] = 1; // To make a difference between a ticket created from the public interface and a ticket directly created from dolibarr + if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) { $error++; array_push($object->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress")); diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 7042af93bf9..9ffd2ea78c3 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -580,9 +580,20 @@ class Ticket extends CommonObject $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ticket"); } - if (!$error && getDolGlobalString('TICKET_ADD_AUTHOR_AS_CONTACT')) { + if (!$error && getDolGlobalString('TICKET_ADD_AUTHOR_AS_CONTACT') && empty($this->context["createdfrompublicinterface"])) { // add creator as contributor - if ($this->add_contact($user->id, 'CONTRIBUTOR', 'internal') < 0) { + + // We first check the type of contact (internal or external) + if (!empty($user->socid) && !empty($user->contact_id) && getDolGlobalInt('TICKET_ADD_AUTHOR_AS_CONTACT') == 2) { + $contact_type = 'external'; + $contributor_id = $user->contact_id; + } else { + $contact_type = 'internal'; + $contributor_id = $user->id; + } + + // We add the creator as contributor + if ($this->add_contact($contributor_id, 'CONTRIBUTOR', $contact_type) < 0) { $error++; } }