diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index 7576164ae30d2..acd65fbbbaa2d 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -80,47 +80,22 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf if ($res > 0) { // Send email to notification email if (!getDolGlobalString('TICKET_DISABLE_ALL_MAILS')) { - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); - - $appli = $mysoc->name; - // Send email to assigned user - $subject = '['.$appli.'] '.$langs->transnoentities('TicketAssignedToYou'); - $message = '
'.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."
"; - $message .= ''.$langs->trans('Message').' :
'.$object->message.'
'.$langs->trans('SeeThisTicketIntomanagementInterface').'
'; $sendto = $userstat->email; - $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; - - $message = dol_nl2br($message); + $subject_assignee = 'TicketAssignedToYou'; + $body_assignee = 'TicketAssignedEmailBody'; + $see_ticket_assignee = 'SeeThisTicketIntomanagementInterface'; if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'); $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } - include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); - if ($mailfile->error) { - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); - } else { - $result = $mailfile->sendfile(); + + if (!empty($sendto)) { + $this->composeAndSendAssigneeMessage($sendto, $subject_assignee, $body_assignee, $see_ticket_assignee, $object, $langs); } + if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } @@ -178,10 +153,15 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf $subject_admin = 'TicketNewEmailSubjectAdmin'; $body_admin = 'TicketNewEmailBodyAdmin'; + $subject_customer = 'TicketNewEmailSubjectCustomer'; $body_customer = 'TicketNewEmailBodyCustomer'; $see_ticket_customer = 'TicketNewEmailBodyInfosTrackUrlCustomer'; + $subject_assignee = 'TicketAssignedToYou'; + $body_assignee = 'TicketAssignedEmailBody'; + $see_ticket_assignee = 'SeeThisTicketIntomanagementInterface'; + // Send email to notification email if (getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO') && empty($object->context['disableticketemail'])) { $sendto = !getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO') ? '' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO; @@ -190,6 +170,35 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf } } + // Send email to assignee if an assignee was set at creation + if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) { + $userstat = new User($this->db); + $res = $userstat->fetch($object->fk_user_assign); + if ($res > 0) { + // Send email to notification email + if (getDolGlobalString('TICKET_DISABLE_ALL_MAILS')) { + // Send email to assigned user + $sendto = $userstat->email; + + if (!getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; + } + + if (!empty($sendto)) { + $this->composeAndSendAssigneeMessage($sendto, $subject_assignee, $body_assignee, $see_ticket_assignee, $object, $langs); + } + + if (!getDolUserString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } + } + } else { + $this->error = $userstat->error; + $this->errors = $userstat->errors; + } + } + // Send email to customer if (!getDolGlobalInt('TICKET_DISABLE_CUSTOMER_MAILS') && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) { $sendto = ''; @@ -464,4 +473,62 @@ private function composeAndSendCustomerMessage($sendto, $base_subject, $body, $s $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } } + + /** + * Composes and sends a message concerning a ticket, to be sent to user assigned to the ticket + * + * @param string $sendto Addresses to send the mail, format "first@address.net, second@address.net, " etc. + * @param string $base_subject email subject. Non-translated string. + * @param string $body email body (first line). Non-translated string. + * @param string $see_ticket string indicating the ticket public address + * @param Ticket $object the ticket thet the email refers to + * @param Translate $langs the translation object + * @return void + */ + private function composeAndSendAssigneeMessage($sendto, $base_subject, $body, $see_ticket, Ticket $object, Translate $langs) + { + global $conf, $user, $mysoc; + + // Init to avoid errors + $filepath = array(); + $filename = array(); + $mimetype = array(); + + // Send email to assigned user + $subject = '[' . $mysoc->name . '] '.$langs->transnoentities($base_subject); + $message = ''.$langs->transnoentities($body, $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."
"; + $message .= ''.$langs->trans('Message').' :
'.$object->message.'