diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index 58eeaf18dc3a6..bead2d3faf659 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -77,45 +77,48 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf if ($res > 0) { // Send email to notification email if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) { - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); +// Init to avoid errors +// $filepath = array(); +// $filename = array(); +// $mimetype = array(); // Send email to assigned user - $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketAssignedToYou'); - $message = '

'.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; - $message .= ''; - $message .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; - $message .= '

'.$langs->trans('SeeThisTicketIntomanagementInterface').'

'; +// $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketAssignedToYou'); +// $message = '

'.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; +// $message .= ''; +// $message .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; +// $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'; +// $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; +// +// $message = dol_nl2br($message); if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->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(); - } +// 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($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } @@ -173,10 +176,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 (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) { $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ? '' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO; @@ -185,6 +193,34 @@ 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 && empty($object->context['disableticketemail'])) { + $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 (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) { $sendto = ''; @@ -428,9 +464,9 @@ private function composeAndSendCustomerMessage($sendto, $base_subject, $body, $s $trackid = 'tic'.$object->id; - $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'); - - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { + $old_MAIN_MAIL_AUTOCOPY_TO = null; + if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'); $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } @@ -451,4 +487,72 @@ 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 + $appli = $mysoc->name; + + $subject = '['.$appli.'] '.$langs->transnoentities($base_subject); + $message = '

'.$langs->transnoentities($body, $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; + $message .= ''; + $message .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; + $message .= '

'.$langs->trans($see_ticket).'

'; + + $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; + + $message = dol_nl2br($message); + + $old_MAIN_MAIL_AUTOCOPY_TO = null; + 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 ($result) { + // update last_msg_sent date + $object->fetch($object->id); + $object->date_last_msg_sent = dol_now(); + $object->update($user); + } + } + if (!getDolUserString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } + } }