From 4abef0cf8b89248136b69c8d66c5fb6e9fb1a44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Fali=C3=A8re?= Date: Fri, 29 Sep 2023 17:12:36 +0200 Subject: [PATCH 1/5] NEW contact type on auto add contributor --- htdocs/ticket/class/ticket.class.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 8e46133829282..7f1fa755b42be 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2019-2023 Frédéric France * Copyright (C) 2020 Laurent Destailleur * Copyright (C) 2023 Charlene Benke + * Copyright (C) 2023 Benjamin Falière * * 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 @@ -570,7 +571,18 @@ public function create($user, $notrigger = 0) if (!$error && !empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT)) { // 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)) { + $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++; } } From 1f61616d070a9b90b34c3c708b127c809275fa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Fali=C3=A8re?= Date: Mon, 2 Oct 2023 11:02:28 +0200 Subject: [PATCH 2/5] ADD second option --- htdocs/ticket/class/ticket.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 7f1fa755b42be..53589b1099e52 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -573,7 +573,7 @@ public function create($user, $notrigger = 0) // add creator as contributor // We first check the type of contact (internal or external) - if (!empty($user->socid) && !empty($user->contact_id)) { + if (!empty($user->socid) && !empty($user->contact_id) && $conf->global->TICKET_ADD_AUTHOR_AS_CONTACT == 2) { $contact_type = 'external'; $contributor_id = $user->contact_id; } else { From e60fe76397cfbb0475e9628a04e8edc06c929c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Fali=C3=A8re?= Date: Tue, 14 Nov 2023 09:12:40 +0100 Subject: [PATCH 3/5] RESTORE ticket module for external and fix constant --- htdocs/core/class/conf.class.php | 2 +- htdocs/public/ticket/create_ticket.php | 2 ++ htdocs/ticket/class/ticket.class.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 70ea0db8fbec2..5bf406d92eb46 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -860,7 +860,7 @@ public function setValues($db) // 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 87791f4a2442f..a57988e621242 100644 --- a/htdocs/public/ticket/create_ticket.php +++ b/htdocs/public/ticket/create_ticket.php @@ -335,6 +335,8 @@ $object->context['disableticketemail'] = 1; // 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++; $errors = array($langs->trans("AlreadyTooMuchPostOnThisIPAdress")); diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index fabf7343546cf..595f5741c1ac4 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -569,7 +569,7 @@ public function create($user, $notrigger = 0) $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ticket"); } - if (!$error && !empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT)) { + if (!$error && !empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT) && empty($this->context["createdfrompublicinterface"])) { // add creator as contributor // We first check the type of contact (internal or external) From a70a0fbe8bfcb30c508dd40be125044ee9baff5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Fali=C3=A8re?= Date: Tue, 14 Nov 2023 09:20:51 +0100 Subject: [PATCH 4/5] GetDolGlobalInt --- htdocs/ticket/class/ticket.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 595f5741c1ac4..4d096998d3510 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -573,7 +573,7 @@ public function create($user, $notrigger = 0) // add creator as contributor // We first check the type of contact (internal or external) - if (!empty($user->socid) && !empty($user->contact_id) && $conf->global->TICKET_ADD_AUTHOR_AS_CONTACT == 2) { + if (!empty($user->socid) && !empty($user->contact_id) && getDolGlobalInt('TICKET_ADD_AUTHOR_AS_CONTACT') == 2) { $contact_type = 'external'; $contributor_id = $user->contact_id; } else { From db1806d5bbfc061b0a84d0740a3e97ef72cf749e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 21 Feb 2024 18:06:09 +0100 Subject: [PATCH 5/5] Update ticket.class.php --- htdocs/ticket/class/ticket.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index fee38803af810..0109f35c15bec 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -568,7 +568,7 @@ public function create($user, $notrigger = 0) $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ticket"); } - if (!$error && !empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT) && empty($this->context["createdfrompublicinterface"])) { + if (!$error && getDolGlobalString('TICKET_ADD_AUTHOR_AS_CONTACT') && empty($this->context["createdfrompublicinterface"])) { // add creator as contributor // We first check the type of contact (internal or external)