Merge pull request #24081 from MaximilienR-easya/dev_NEW_dont_send_ticket_mail_to_closed_contact

don't send ticket email to closed contact
This commit is contained in:
Laurent Destailleur 2023-03-04 15:17:57 +01:00 committed by GitHub
commit 9d304cd169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 25 deletions

View File

@ -1277,7 +1277,7 @@ class FormTicket
} }
// Load translation files required by the page // 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 // 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')) { if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
@ -1467,11 +1467,13 @@ class FormTicket
print '</td></tr>'; print '</td></tr>';
// Recipients / adressed-to // Recipients / adressed-to
print '<tr class="email_line"><td>'.$langs->trans('MailRecipients').'</td><td>'; print '<tr class="email_line"><td>'.$langs->trans('MailRecipients');
print ' '.$form->textwithpicto('', $langs->trans("TicketMessageRecipientsHelp"), 1, 'help');
print '</td><td>';
if ($res) { if ($res) {
// Retrieve email of all contacts (internal and external) // Retrieve email of all contacts (internal and external)
$contacts = $ticketstat->getInfosTicketInternalContact(); $contacts = $ticketstat->getInfosTicketInternalContact(1);
$contacts = array_merge($contacts, $ticketstat->getInfosTicketExternalContact()); $contacts = array_merge($contacts, $ticketstat->getInfosTicketExternalContact(1));
$sendto = array(); $sendto = array();

View File

@ -247,6 +247,7 @@ TicketAssignedEmailBody=You have been assigned the ticket #%s by %s
MarkMessageAsPrivate=Mark message as private 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) 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 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 TicketEmailOriginIssuer=Issuer at origin of the tickets
InitialMessage=Initial Message InitialMessage=Initial Message
LinkToAContract=Link to a contract LinkToAContract=Link to a contract

View File

@ -802,7 +802,7 @@ if ($action == 'create' || $action == 'presend') {
// Confirmation close // Confirmation close
if ($action == 'close') { if ($action == 'close') {
$thirdparty_contacts = $object->getInfosTicketExternalContact(); $thirdparty_contacts = $object->getInfosTicketExternalContact(1);
$contacts_select = array( $contacts_select = array(
'-2' => $langs->trans('TicketNotifyAllTiersAtClose'), '-2' => $langs->trans('TicketNotifyAllTiersAtClose'),
'-3' => $langs->trans('TicketNotNotifyTiersAtClose') '-3' => $langs->trans('TicketNotNotifyTiersAtClose')

View File

@ -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 * 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 * Get array of all contacts for a ticket
* Override method of file commonobject.class.php to add phone number * Override method of file commonobject.class.php to add phone number
* *
* @param int $status Status of lines to get (-1=all) * @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 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 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 string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
* @return array|int Array of contacts * @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; global $langs;
@ -2175,10 +2178,16 @@ class Ticket extends CommonObject
$sql .= " AND tc.element='".$this->db->escape($this->element)."'"; $sql .= " AND tc.element='".$this->db->escape($this->element)."'";
if ($source == 'internal') { if ($source == 'internal') {
$sql .= " AND tc.source = 'internal'"; $sql .= " AND tc.source = 'internal'";
if ($status >= 0) {
$sql .= " AND t.statut = ".((int) $status);
}
} }
if ($source == 'external' || $source == 'thirdparty') { if ($source == 'external' || $source == 'thirdparty') {
$sql .= " AND tc.source = 'external'"; $sql .= " AND tc.source = 'external'";
if ($status >= 0) {
$sql .= " AND t.statut = ".((int) $status);
}
} }
if (!empty($code)) { if (!empty($code)) {
@ -2186,8 +2195,8 @@ class Ticket extends CommonObject
} }
$sql .= " AND tc.active=1"; $sql .= " AND tc.active=1";
if ($status >= 0) { if ($statusoflink >= 0) {
$sql .= " AND ec.statut = ".((int) $status); $sql .= " AND ec.statut = ".((int) $statusoflink);
} }
$sql .= " ORDER BY t.lastname ASC"; $sql .= " ORDER BY t.lastname ASC";
@ -2498,7 +2507,7 @@ class Ticket extends CommonObject
*/ */
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) { if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
// Retrieve internal contact datas // Retrieve internal contact datas
$internal_contacts = $object->getInfosTicketInternalContact(); $internal_contacts = $object->getInfosTicketInternalContact(1);
$assigned_user_dont_have_email = ''; $assigned_user_dont_have_email = '';
@ -2588,7 +2597,7 @@ class Ticket extends CommonObject
*/ */
if ($send_email > 0) { if ($send_email > 0) {
// Retrieve internal contact datas // Retrieve internal contact datas
$internal_contacts = $object->getInfosTicketInternalContact(); $internal_contacts = $object->getInfosTicketInternalContact(1);
$sendto = array(); $sendto = array();
if (is_array($internal_contacts) && count($internal_contacts) > 0) { if (is_array($internal_contacts) && count($internal_contacts) > 0) {
@ -2657,7 +2666,7 @@ class Ticket extends CommonObject
*/ */
if (empty($object->private)) { if (empty($object->private)) {
// Retrieve email of all contacts (external) // Retrieve email of all contacts (external)
$external_contacts = $object->getInfosTicketExternalContact(); $external_contacts = $object->getInfosTicketExternalContact(1);
// If no contact, get email from thirdparty // If no contact, get email from thirdparty
if (is_array($external_contacts) && count($external_contacts) === 0) { 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 no receiver defined, load all ticket linked contacts
if (!is_array($array_receiver) || !count($array_receiver) > 0) { if (!is_array($array_receiver) || !count($array_receiver) > 0) {
$array_receiver = $this->getInfosTicketInternalContact(); $array_receiver = $this->getInfosTicketInternalContact(1);
$array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact()); $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact(1));
} }
if ($send_internal_cc) { if ($send_internal_cc) {