Merge pull request #13976 from OPEN-DSI/new_ticket_public_notify_new_message

NEW Ticket message notifications when edited from public interface
This commit is contained in:
Laurent Destailleur 2020-05-28 17:31:26 +02:00 committed by GitHub
commit 2f0a5b2634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 217 additions and 105 deletions

View File

@ -106,6 +106,12 @@ if ($action == 'setvar') {
if (!$res > 0) { if (!$res > 0) {
$error++; $error++;
} }
$param_public_notification_new_message_default_email = GETPOST('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL', 'alpha');
$res = dolibarr_set_const($db, 'TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL', $param_public_notification_new_message_default_email, 'chaine', 0, '', $conf->entity);
if (!$res > 0) {
$error++;
}
} }
if ($action == 'setvarother') { if ($action == 'setvarother') {
@ -375,6 +381,30 @@ if (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE))
print '</td>'; print '</td>';
print '<td class="center">'; print '<td class="center">';
print $form->textwithpicto('', $langs->trans("TicketUrlPublicInterfaceHelpAdmin"), 1, 'help'); print $form->textwithpicto('', $langs->trans("TicketUrlPublicInterfaceHelpAdmin"), 1, 'help');
print '</td></tr>';
// Activate email notification when a new message is added
print '<tr class="pair"><td>' . $langs->trans("TicketsPublicNotificationNewMessage") . '</td>';
print '<td class="left">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED');
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED", $arrval, $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED);
}
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsPublicNotificationNewMessageHelp"), 1, 'help');
print '</td>';
print '</tr>';
// Send notification when a new message is added to a email if a user is not assigned to the ticket
print '<tr><td>' . $langs->trans("TicketPublicNotificationNewMessageDefaultEmail") . '</label>';
print '</td><td>';
print '<input type="text" name="TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL" value="' . $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL . '" size="40" ></td>';
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketPublicNotificationNewMessageDefaultEmailHelp"), 1, 'help');
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';

View File

@ -130,6 +130,10 @@ TicketNumberingModules=Tickets numbering module
TicketNotifyTiersAtCreation=Notify third party at creation TicketNotifyTiersAtCreation=Notify third party at creation
TicketGroup=Group TicketGroup=Group
TicketsDisableCustomerEmail=Always disable emails when a ticket is created from public interface TicketsDisableCustomerEmail=Always disable emails when a ticket is created from public interface
TicketsPublicNotificationNewMessage=Send email(s) when a new message is added
TicketsPublicNotificationNewMessageHelp=Send email(s) when a new message is added from public interface (to assigned user or the notifications email to (update) and/or the notifications email to)
TicketPublicNotificationNewMessageDefaultEmail=Notifications email to (update)
TicketPublicNotificationNewMessageDefaultEmailHelp=Send email new message notifications to this address if the ticket don't have a user assigned or the user don't have a email.
# #
# Index & list page # Index & list page
# #

View File

@ -130,6 +130,10 @@ TicketNumberingModules=Module de numérotation des tickets
TicketNotifyTiersAtCreation=Notifier le tiers à la création TicketNotifyTiersAtCreation=Notifier le tiers à la création
TicketGroup=Groupe TicketGroup=Groupe
TicketsDisableCustomerEmail=Toujours désactiver les courriels lorsqu'un ticket est créé depuis l'interface publique TicketsDisableCustomerEmail=Toujours désactiver les courriels lorsqu'un ticket est créé depuis l'interface publique
TicketsPublicNotificationNewMessage=Envoi d'e-mails lorsqu'un nouveau message est ajouté
TicketsPublicNotificationNewMessageHelp=Envoi d'e-mails lorsqu'un nouveau message est ajouté depuis l'interface public (à l'utilisateur assigné ou à l'e-mail de notification à (nouveaux message) et/ou l'e-mail de notification à)
TicketPublicNotificationNewMessageDefaultEmail=E-mail de notification à (nouveaux message)
TicketPublicNotificationNewMessageDefaultEmailHelp=Envoyer des notifications de nouveaux message par e-mail à cette adresse si aucun utilisateur n'a été affecté au ticket ou qu'il n'a pas d'e-mail.
# #
# Index & list page # Index & list page
# #

View File

@ -171,7 +171,7 @@ if ($action == "view_ticket" || $action == "presend" || $action == "close" || $a
if (!$error && $action == "add_message" && $display_ticket && GETPOSTISSET('btn_add_message')) if (!$error && $action == "add_message" && $display_ticket && GETPOSTISSET('btn_add_message'))
{ {
// TODO Add message... // TODO Add message...
$ret = $object->dao->newMessage($user, $action, 0); $ret = $object->dao->newMessage($user, $action, 0, 1);

View File

@ -2391,14 +2391,15 @@ class Ticket extends CommonObject
/** /**
* Add new message on a ticket (private area). Can also send it be email if GETPOST('send_email', 'int') is set. * Add new message on a ticket (private/public area). Can also send it be email if GETPOST('send_email', 'int') is set.
* *
* @param User $user User for action * @param User $user User for action
* @param string $action Action string * @param string $action Action string
* @param int $private 1=Message is private. TODO Implement this. What does this means ? * @param int $private 1=Message is private. TODO Implement this. What does this means ?
* @param int $public_area 1=Is the public area
* @return int * @return int
*/ */
public function newMessage($user, &$action, $private = 1) public function newMessage($user, &$action, $private = 1, $public_area = 0)
{ {
global $mysoc, $conf, $langs; global $mysoc, $conf, $langs;
@ -2450,6 +2451,78 @@ class Ticket extends CommonObject
//var_dump($_SESSION); var_dump($listofpaths);exit; //var_dump($_SESSION); var_dump($listofpaths);exit;
/*
* Public area
*/
if (!empty($public_area)) {
/*
* Send emails to assigned users (public area notification)
*/
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
$assigned_user_dont_have_email = '';
$sendto = array();
if ($this->fk_user_assign > 0) {
$assigned_user = new User($this->db);
$assigned_user->fetch($this->fk_user_assign);
if (!empty($assigned_user->email)) {
$sendto[] = $assigned_user->getFullName($langs) . " <" . $assigned_user->email . ">";
} else {
$assigned_user_dont_have_email = $assigned_user->getFullName($langs);
}
}
if (empty($sendto)) {
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
$sendto[] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
} elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
$sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
}
}
// Add global email address recipient
if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
) {
$sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
}
if (!empty($sendto)) {
$label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
$subject = '[' . $label_title . '- ticket #' . $object->track_id . '] ' . $langs->trans('TicketNewMessage');
// Message send
$message = $langs->trans('TicketMessageMailIntroText');
$message .= "\n\n";
$message .= GETPOST('message', 'restricthtml');
// Customer company infos
$message .= "\n\n";
$message .= "==============================================";
$message .= !empty($object->thirdparty->name) ? "\n" . $langs->trans('Thirdparty') . " : " . $object->thirdparty->name : '';
$message .= !empty($object->thirdparty->town) ? "\n" . $langs->trans('Town') . " : " . $object->thirdparty->town : '';
$message .= !empty($object->thirdparty->phone) ? "\n" . $langs->trans('Phone') . " : " . $object->thirdparty->phone : '';
// Email send to
$message .= "\n\n";
if (!empty($assigned_user_dont_have_email)) {
$message .= "\n" . $langs->trans('NoEMail') . ' : ' . $assigned_user_dont_have_email;
}
foreach ($sendto as $val) {
$message .= "\n" . $langs->trans('TicketNotificationRecipient') . ' : ' . $val;
}
// URL ticket
$url_internal_ticket = dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id;
$message .= "\n\n";
$message .= $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal') . ' : <a href="' . $url_internal_ticket . '">' . $object->track_id . '</a>';
$this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
}
}
}
/*
* Private area
*/
else {
/* /*
* Send emails to internal users (linked contacts) * Send emails to internal users (linked contacts)
*/ */
@ -2589,6 +2662,7 @@ class Ticket extends CommonObject
} }
} }
} }
}
// Set status to "answered" if not set yet, but only if internal user // Set status to "answered" if not set yet, but only if internal user
if ($object->fk_statut < 3 && !$user->socid) if ($object->fk_statut < 3 && !$user->socid)