diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 8e461338292..74368f93910 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 @@ -1713,9 +1714,10 @@ class Ticket extends CommonObject * @param array $mimetype_list List of MIME type of attached files * @param array $mimefilename_list List of attached file name in message * @param boolean $send_email Whether the message is sent by email + * @param boolean $public_area 1=Is the public area * @return int <0 if KO, >0 if OK */ - public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email = false) + public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email = false, $public_area = false) { global $conf, $langs; $error = 0; @@ -1758,6 +1760,20 @@ class Ticket extends CommonObject $actioncomm->fk_element = $this->id; $actioncomm->fk_project = $this->fk_project; + // add contact id from author email on public interface + if ($public_area && !empty($this->origin_email) && !empty($conf->global->TICKET_ASSIGN_CONTACT_TO_MESSAGE)) { + $contacts = $this->searchContactByEmail($this->origin_email); + if (!empty($contacts)) { + // Ensure that contact is active and select first active contact + foreach ($contacts as $contact) { + if ((int) $contact->statut == 1) { + $actioncomm->contact_id = $contact->id; + break; + } + } + } + } + $attachedfiles = array(); $attachedfiles['paths'] = $filename_list; $attachedfiles['names'] = $mimefilename_list; @@ -2560,7 +2576,7 @@ class Ticket extends CommonObject $listofnames = $resarray['listofnames']; $listofmimes = $resarray['listofmimes']; - $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email); + $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email, $public_area); if ($id <= 0) { $error++; $this->error = $object->error;