From 71fc59169ff8182f84d6cfce5814f027296c10f8 Mon Sep 17 00:00:00 2001 From: Maximilien Rozniecki Date: Wed, 1 Mar 2023 10:44:20 +0100 Subject: [PATCH 1/7] add a new function inside ticket.class to remove the closed contact from the receiver list of contact --- htdocs/langs/en_US/ticket.lang | 1 + htdocs/ticket/class/ticket.class.php | 37 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/htdocs/langs/en_US/ticket.lang b/htdocs/langs/en_US/ticket.lang index c0ca780ee06..d48b2c9beb2 100644 --- a/htdocs/langs/en_US/ticket.lang +++ b/htdocs/langs/en_US/ticket.lang @@ -223,6 +223,7 @@ TicketUpdated=Ticket updated SendMessageByEmail=Send message by email TicketNewMessage=New message ErrorMailRecipientIsEmptyForSendTicketMessage=Recipient is empty. No email send +WarningMailNotSendContactIsClosed=E-mail to %s refused for shipment as this contact is closed TicketGoIntoContactTab=Please go into "Contacts" tab to select them TicketMessageMailIntro=Message header TicketMessageMailIntroHelp=This text is added only at the beginning of the email and will not be saved. diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 6f309b7656f..f1f84fb8a9b 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -2812,6 +2812,7 @@ class Ticket extends CommonObject $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM; $is_sent = false; + $array_receiver = $this->removeClosedContact($array_receiver); if (is_array($array_receiver) && count($array_receiver) > 0) { foreach ($array_receiver as $key => $receiver) { $deliveryreceipt = 0; @@ -3028,6 +3029,42 @@ class Ticket extends CommonObject $return .= ''; return $return; } + + /** + * Remove the closed contact + * + * @param array $to Array of receiver. exemple array('john@doe.com' => 'John Doe ', etc...) + * @return array array of email => name + */ + public function removeClosedContact($to) + { + global $db, $langs; + $langs->load("ticket"); + + if (isset($this->id)) { + $sql = "SELECT IF(tc.source = 'external', sc.email, u.email)"; + $sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_type_contact tc on (ec.element_id = ". $this->id ." AND ec.fk_c_type_contact = tc.rowid)"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople sc on (ec.fk_socpeople = sc.rowid AND tc.source = 'external')"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u on (ec.fk_socpeople = u.rowid AND tc.source = 'internal')"; + $sql .= " WHERE IF(tc.source = 'external', sc.statut = 1, u.statut = 1)"; + $resql = $db->query($sql); + if ($resql) { + for ($i = 0; $db->num_rows($resql) > $i; $i++) { + $non_closed_contacts[] = $db->fetch_row($resql); + } + } + $to = array_filter($to, function($v, $k) use($non_closed_contacts, $langs) { + foreach($non_closed_contacts as $non_closed_contact) { + if ($k == $non_closed_contact[0]) + return true; + } + setEventMessages($langs->trans('WarningMailNotSendContactIsClosed', str_replace(array('>', '<'), '', $v)), null, 'warnings'); + return false; + }, ARRAY_FILTER_USE_BOTH); + } + return $to; + } } From 233d737a89270f48ee82b961feb9fff23787010d Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 1 Mar 2023 09:57:09 +0000 Subject: [PATCH 2/7] Fixing style errors. --- htdocs/ticket/class/ticket.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index f1f84fb8a9b..45e3cf361b3 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -3054,8 +3054,8 @@ class Ticket extends CommonObject $non_closed_contacts[] = $db->fetch_row($resql); } } - $to = array_filter($to, function($v, $k) use($non_closed_contacts, $langs) { - foreach($non_closed_contacts as $non_closed_contact) { + $to = array_filter($to, function ($v, $k) use ($non_closed_contacts, $langs) { + foreach ($non_closed_contacts as $non_closed_contact) { if ($k == $non_closed_contact[0]) return true; } From d1b5fc6bc1b0fda806db5a94eaf3729f1404d18b Mon Sep 17 00:00:00 2001 From: Maximilien Rozniecki Date: Wed, 1 Mar 2023 11:04:00 +0100 Subject: [PATCH 3/7] removed function from FOR loop test part --- htdocs/ticket/class/ticket.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 45e3cf361b3..ce0997c7a02 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -3050,11 +3050,12 @@ class Ticket extends CommonObject $sql .= " WHERE IF(tc.source = 'external', sc.statut = 1, u.statut = 1)"; $resql = $db->query($sql); if ($resql) { - for ($i = 0; $db->num_rows($resql) > $i; $i++) { + $num = $db->num_rows($resql); + for ($i = 0; $num > $i; $i++) { $non_closed_contacts[] = $db->fetch_row($resql); } } - $to = array_filter($to, function ($v, $k) use ($non_closed_contacts, $langs) { + $to = array_filter($to, function($v, $k) use($non_closed_contacts, $langs) { foreach ($non_closed_contacts as $non_closed_contact) { if ($k == $non_closed_contact[0]) return true; From 1bd49ca07a23f7e45b07e4dc4a79eeaedf10762c Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 1 Mar 2023 10:04:30 +0000 Subject: [PATCH 4/7] Fixing style errors. --- 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 ce0997c7a02..9f9a2b702aa 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -3055,7 +3055,7 @@ class Ticket extends CommonObject $non_closed_contacts[] = $db->fetch_row($resql); } } - $to = array_filter($to, function($v, $k) use($non_closed_contacts, $langs) { + $to = array_filter($to, function ($v, $k) use ($non_closed_contacts, $langs) { foreach ($non_closed_contacts as $non_closed_contact) { if ($k == $non_closed_contact[0]) return true; From f362c66b28967a1da925edfa4204285c9eeb2aa1 Mon Sep 17 00:00:00 2001 From: Maximilien Rozniecki Date: Wed, 1 Mar 2023 16:54:49 +0100 Subject: [PATCH 5/7] changed by ->db inside ticket.class.php --- htdocs/ticket/class/ticket.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index ce0997c7a02..09c9c07977f 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -3038,7 +3038,7 @@ class Ticket extends CommonObject */ public function removeClosedContact($to) { - global $db, $langs; + global $langs; $langs->load("ticket"); if (isset($this->id)) { @@ -3048,11 +3048,11 @@ class Ticket extends CommonObject $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople sc on (ec.fk_socpeople = sc.rowid AND tc.source = 'external')"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u on (ec.fk_socpeople = u.rowid AND tc.source = 'internal')"; $sql .= " WHERE IF(tc.source = 'external', sc.statut = 1, u.statut = 1)"; - $resql = $db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $num = $this->db->num_rows($resql); for ($i = 0; $num > $i; $i++) { - $non_closed_contacts[] = $db->fetch_row($resql); + $non_closed_contacts[] = $this->db->fetch_row($resql); } } $to = array_filter($to, function($v, $k) use($non_closed_contacts, $langs) { From fd93a3fe15a34abf0c73faa9601d67b7a5c26a64 Mon Sep 17 00:00:00 2001 From: Maximilien Rozniecki Date: Fri, 3 Mar 2023 14:53:06 +0100 Subject: [PATCH 6/7] not adding the closed contact --- htdocs/core/class/html.formticket.class.php | 4 +- htdocs/ticket/card.php | 2 +- htdocs/ticket/class/ticket.class.php | 87 +++++++-------------- 3 files changed, 32 insertions(+), 61 deletions(-) diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index e8187fe7290..8ca26430438 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -1470,8 +1470,8 @@ class FormTicket print ''.$langs->trans('MailRecipients').''; if ($res) { // Retrieve email of all contacts (internal and external) - $contacts = $ticketstat->getInfosTicketInternalContact(); - $contacts = array_merge($contacts, $ticketstat->getInfosTicketExternalContact()); + $contacts = $ticketstat->getInfosTicketInternalContact(1); + $contacts = array_merge($contacts, $ticketstat->getInfosTicketExternalContact(1)); $sendto = array(); diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 5bd24b7406e..1147e07d6e1 100755 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -802,7 +802,7 @@ if ($action == 'create' || $action == 'presend') { // Confirmation close if ($action == 'close') { - $thirdparty_contacts = $object->getInfosTicketExternalContact(); + $thirdparty_contacts = $object->getInfosTicketExternalContact(1); $contacts_select = array( '-2' => $langs->trans('TicketNotifyAllTiersAtClose'), '-3' => $langs->trans('TicketNotNotifyTiersAtClose') diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 896eefb2b41..21fc03998f2 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -2039,13 +2039,14 @@ class Ticket extends CommonObject } /** - * Retrieve informations about internal contacts + * Retrieve informations about internal contacts * - * @return array Array with datas : firstname, lastname, socid (-1 for internal users), email, code, libelle, status + * @param int $status Status of user or company + * @return array Array with datas : firstname, lastname, socid (-1 for internal users), email, code, libelle, status */ - public function getInfosTicketInternalContact() + public function getInfosTicketInternalContact($status = -1) { - return $this->listeContact(-1, 'internal'); + return $this->listeContact(-1, 'internal', 0, '', $status); } /** @@ -2061,11 +2062,12 @@ class Ticket extends CommonObject /** * Retrieve informations about external contacts * - * @return array Array with datas : firstname, lastname, socid (-1 for internal users), email, code, libelle, status + * @param int $status Status of user or company + * @return array Array with datas : firstname, lastname, socid (-1 for internal users), email, code, libelle, status */ - public function getInfosTicketExternalContact() + public function getInfosTicketExternalContact($status = -1) { - return $this->listeContact(-1, 'external'); + return $this->listeContact(-1, 'external', 0, '', $status); } /** @@ -2129,13 +2131,14 @@ class Ticket extends CommonObject * Get array of all contacts for a ticket * Override method of file commonobject.class.php to add phone number * - * @param int $status Status of lines to get (-1=all) - * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) - * @param int $list 0:Return array contains all properties, 1:Return array contains just id - * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) - * @return array|int Array of contacts + * @param int $statusoflink Status of lines to get (-1=all) + * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) + * @param int $list 0:Return array contains all properties, 1:Return array contains just id + * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) + * @param int $status Status of user or company + * @return array|int Array of contacts */ - public function listeContact($status = -1, $source = 'external', $list = 0, $code = '') + public function listeContact($statusoflink = -1, $source = 'external', $list = 0, $code = '', $status = -1) { global $langs; @@ -2175,10 +2178,16 @@ class Ticket extends CommonObject $sql .= " AND tc.element='".$this->db->escape($this->element)."'"; if ($source == 'internal') { $sql .= " AND tc.source = 'internal'"; + if ($status >= 0) { + $sql .= " AND t.statut = ".((int) $status); + } } if ($source == 'external' || $source == 'thirdparty') { $sql .= " AND tc.source = 'external'"; + if ($status >= 0) { + $sql .= " AND t.statut = ".((int) $status); + } } if (!empty($code)) { @@ -2186,8 +2195,8 @@ class Ticket extends CommonObject } $sql .= " AND tc.active=1"; - if ($status >= 0) { - $sql .= " AND ec.statut = ".((int) $status); + if ($statusoflink >= 0) { + $sql .= " AND ec.statut = ".((int) $statusoflink); } $sql .= " ORDER BY t.lastname ASC"; @@ -2498,7 +2507,7 @@ class Ticket extends CommonObject */ if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) { // Retrieve internal contact datas - $internal_contacts = $object->getInfosTicketInternalContact(); + $internal_contacts = $object->getInfosTicketInternalContact(1); $assigned_user_dont_have_email = ''; @@ -2588,7 +2597,7 @@ class Ticket extends CommonObject */ if ($send_email > 0) { // Retrieve internal contact datas - $internal_contacts = $object->getInfosTicketInternalContact(); + $internal_contacts = $object->getInfosTicketInternalContact(1); $sendto = array(); if (is_array($internal_contacts) && count($internal_contacts) > 0) { @@ -2657,7 +2666,7 @@ class Ticket extends CommonObject */ if (empty($object->private)) { // Retrieve email of all contacts (external) - $external_contacts = $object->getInfosTicketExternalContact(); + $external_contacts = $object->getInfosTicketExternalContact(1); // If no contact, get email from thirdparty if (is_array($external_contacts) && count($external_contacts) === 0) { @@ -2802,8 +2811,8 @@ class Ticket extends CommonObject // If no receiver defined, load all ticket linked contacts if (!is_array($array_receiver) || !count($array_receiver) > 0) { - $array_receiver = $this->getInfosTicketInternalContact(); - $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact()); + $array_receiver = $this->getInfosTicketInternalContact(1); + $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact(1)); } if ($send_internal_cc) { @@ -2812,7 +2821,6 @@ class Ticket extends CommonObject $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM; $is_sent = false; - $array_receiver = $this->removeClosedContact($array_receiver); if (is_array($array_receiver) && count($array_receiver) > 0) { foreach ($array_receiver as $key => $receiver) { $deliveryreceipt = 0; @@ -3029,43 +3037,6 @@ class Ticket extends CommonObject $return .= ''; return $return; } - - /** - * Remove the closed contact - * - * @param array $to Array of receiver. exemple array('john@doe.com' => 'John Doe ', etc...) - * @return array array of email => name - */ - public function removeClosedContact($to) - { - global $langs; - $langs->load("ticket"); - - if (isset($this->id)) { - $sql = "SELECT IF(tc.source = 'external', sc.email, u.email)"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_type_contact tc on (ec.element_id = ". $this->id ." AND ec.fk_c_type_contact = tc.rowid)"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople sc on (ec.fk_socpeople = sc.rowid AND tc.source = 'external')"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u on (ec.fk_socpeople = u.rowid AND tc.source = 'internal')"; - $sql .= " WHERE IF(tc.source = 'external', sc.statut = 1, u.statut = 1)"; - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - for ($i = 0; $num > $i; $i++) { - $non_closed_contacts[] = $this->db->fetch_row($resql); - } - } - $to = array_filter($to, function ($v, $k) use ($non_closed_contacts, $langs) { - foreach ($non_closed_contacts as $non_closed_contact) { - if ($k == $non_closed_contact[0]) - return true; - } - setEventMessages($langs->trans('WarningMailNotSendContactIsClosed', str_replace(array('>', '<'), '', $v)), null, 'warnings'); - return false; - }, ARRAY_FILTER_USE_BOTH); - } - return $to; - } } From 799df44172b6209fc25c620f9b114bcbd04c2600 Mon Sep 17 00:00:00 2001 From: Maximilien Rozniecki Date: Fri, 3 Mar 2023 16:11:44 +0100 Subject: [PATCH 7/7] added textwithpicto to explain if needed that only active user are added as Recipient --- htdocs/core/class/html.formticket.class.php | 6 ++++-- htdocs/langs/en_US/ticket.lang | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 8ca26430438..9095805489f 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -1277,7 +1277,7 @@ class FormTicket } // Load translation files required by the page - $langs->loadLangs(array('other', 'mails')); + $langs->loadLangs(array('other', 'mails', 'ticket')); // Clear temp files. Must be done at beginning, before call of triggers if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { @@ -1467,7 +1467,9 @@ class FormTicket print ''; // Recipients / adressed-to - print ''.$langs->trans('MailRecipients').''; + print ''.$langs->trans('MailRecipients'); + print ' '.$form->textwithpicto('', $langs->trans("TicketMessageRecipientsHelp"), 1, 'help'); + print ''; if ($res) { // Retrieve email of all contacts (internal and external) $contacts = $ticketstat->getInfosTicketInternalContact(1); diff --git a/htdocs/langs/en_US/ticket.lang b/htdocs/langs/en_US/ticket.lang index d48b2c9beb2..570e7c127aa 100644 --- a/htdocs/langs/en_US/ticket.lang +++ b/htdocs/langs/en_US/ticket.lang @@ -223,7 +223,6 @@ TicketUpdated=Ticket updated SendMessageByEmail=Send message by email TicketNewMessage=New message ErrorMailRecipientIsEmptyForSendTicketMessage=Recipient is empty. No email send -WarningMailNotSendContactIsClosed=E-mail to %s refused for shipment as this contact is closed TicketGoIntoContactTab=Please go into "Contacts" tab to select them TicketMessageMailIntro=Message header TicketMessageMailIntroHelp=This text is added only at the beginning of the email and will not be saved. @@ -248,6 +247,7 @@ TicketAssignedEmailBody=You have been assigned the ticket #%s by %s MarkMessageAsPrivate=Mark message as private TicketMessageSendEmailHelp=An email will be sent to all assigned contact (internal contacts, but also external contacts except if the option "%s" is checked) TicketMessagePrivateHelp=This message will not display to external users +TicketMessageRecipientsHelp=Recipient field completed with active contacts linked to the ticket TicketEmailOriginIssuer=Issuer at origin of the tickets InitialMessage=Initial Message LinkToAContract=Link to a contract