From e0c7d90a23f5031680024c3758e0a36478e0843f Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Tue, 26 Jun 2018 11:04:02 -0500
Subject: [PATCH] Agent Ticket on Behalf of User Fix:

This commit fixes an Issue that resulted from allowing Agents to add Collaborators when opening a Ticket on behalf of a User and being able to decide who will receive an email alert. If an Agent were to add an initial response to the Ticket, two email alerts would be sent out (New Ticket Notice and Response/Reply Template). Now, only the New Ticket Notice is sent out unless the Agent chooses not to send any alert.

Additionally, if the Autoresponder is set to NOT alert a User when an Agent creates a ticket on their behalf and the Agent includes an initial Agent response, the Response/Reply Template is sent out.
---
 include/class.ticket.php | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index aac5be02a..604ead02f 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -2944,9 +2944,8 @@ implements RestrictedAccess, Threadable, Searchable {
                 $collabsCc['cc'] = $collabsCc[0];
             }
 
-            if (Ticket::checkReply('user', $vars['emailreply']))
-              $email->send($user, $msg['subj'], $msg['body'], $attachments,
-                      $options, $collabsCc);
+            $email->send($user, $msg['subj'], $msg['body'], $attachments,
+                    $options, $collabsCc);
 
         }
 
@@ -4046,8 +4045,7 @@ implements RestrictedAccess, Threadable, Searchable {
             $vars['response'] = $ticket->replaceVars($vars['response']);
             // $vars['cannedatachments'] contains the attachments placed on
             // the response form.
-            $response = $ticket->postReply($vars, $errors,
-                    !isset($vars['alertuser']));
+            $response = $ticket->postReply($vars, $errors, is_null($vars['emailreply']) ?: !isset($vars['emailreply']));
         }
 
         // Not assigned...save optional note if any
@@ -4059,6 +4057,7 @@ implements RestrictedAccess, Threadable, Searchable {
         }
 
         if (!$cfg->notifyONNewStaffTicket()
+            || !isset($vars['emailreply'])
             || !($dept=$ticket->getDept())
         ) {
             return $ticket; //No alerts.
-- 
GitLab