From ce81a4b293c011d7c6bbdb90256904ca65bb82ad Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Thu, 12 Oct 2017 18:09:45 +0000
Subject: [PATCH] Ticket Notice Alert

This commit addresses a few issues on Agent opened tickets.

* Send a response (if any) when User Alert is unchecked
* Include response attachments when sending ticket notice
* Post internal (if any) when ticket is not assigned
---
 include/class.ticket.php | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index 7cc661f95..5e77e6aeb 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -3577,11 +3577,12 @@ implements RestrictedAccess, Threadable {
             $vars['response'] = $ticket->replaceVars($vars['response']);
             // $vars['cannedatachments'] contains the attachments placed on
             // the response form.
-            $response = $ticket->postReply($vars, $errors, false);
+            $response = $ticket->postReply($vars, $errors,
+                    !isset($vars['alertuser']));
         }
 
         // Not assigned...save optional note if any
-        if (!$vars['assignId'] && $vars['note']) {
+        if (!$ticket->isAssigned() && $vars['note']) {
             if (!$cfg->isRichTextEnabled()) {
                 $vars['note'] = new TextThreadEntryBody($vars['note']);
             }
@@ -3599,7 +3600,15 @@ implements RestrictedAccess, Threadable {
             && ($msg=$tpl->getNewTicketNoticeMsgTemplate())
             && ($email=$dept->getEmail())
         ) {
-            $message = (string) $ticket->getLastMessage();
+           $attachments = array();
+           $message = $ticket->getLastMessage();
+           if ($cfg->emailAttachments()) {
+               $attachments = $message->getAttachments();
+               if ($response && $response->getNumAttachments())
+                 $attachments = $attachments->merge($response->getAttachments());
+           }
+
+            $message = (string) $message;
             if ($response) {
                 $message .= ($cfg->isRichTextEnabled()) ? "<br><br>" : "\n\n";
                 $message .= $response->getBody();
@@ -3612,9 +3621,6 @@ implements RestrictedAccess, Threadable {
             else
                 $signature='';
 
-            $attachments = ($cfg->emailAttachments() && $response)
-                ? $response->getAttachments() : array();
-
             $msg = $ticket->replaceVars($msg->asArray(),
                 array(
                     'message'   => $message,
-- 
GitLab