From fd93a3fe15a34abf0c73faa9601d67b7a5c26a64 Mon Sep 17 00:00:00 2001 From: Maximilien Rozniecki Date: Fri, 3 Mar 2023 14:53:06 +0100 Subject: [PATCH] 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; - } }