diff --git a/include/class.thread.php b/include/class.thread.php index b1a0f1bf7a0eb462bf5df7acb3ff0eae4a3321ad..d371f3da28c80a17ce8662122e21e77b26aaf010 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -1505,8 +1505,18 @@ implements TemplateVariable { )); //add recipients to thread entry - if ($vars['thread_entry_recipients']) + if ($vars['thread_entry_recipients']) { + $count = 0; + foreach ($vars['thread_entry_recipients'] as $key => $value) + $count = $count + count($value); + + if ($count > 1) + $entry->flags |= ThreadEntry::FLAG_REPLY_ALL; + else + $entry->flags |= ThreadEntry::FLAG_REPLY_USER; + $entry->recipients = json_encode($vars['thread_entry_recipients']); + } if (Collaborator::getIdByUserId($vars['userId'], $vars['threadId'])) @@ -2866,14 +2876,6 @@ implements TemplateVariable { $vars['pid'] = $this->getLastMessage()->getId(); $vars['flags'] = 0; - switch ($vars['reply-to']) { - case 'all': - $vars['flags'] |= ThreadEntry::FLAG_REPLY_ALL; - break; - case 'user': - $vars['flags'] |= ThreadEntry::FLAG_REPLY_USER; - break; - } if (!($resp = ResponseThreadEntry::add($vars, $errors))) return $resp; diff --git a/include/class.ticket.php b/include/class.ticket.php index 615931fa0bca9a134e6ac543ee21651ce55c69dd..40d0edf5511f57c3c047617ec66973c0d2f06c0f 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2667,6 +2667,42 @@ implements RestrictedAccess, Threadable, Searchable { if ($vars['userId'] == $this->user_id) $isMsg = true; + // Get active recipients of the response + // Initial Message from Tickets created by Agent + if ($vars['reply-to']) { + if ($vars['reply-to'] == 'all' || $vars['reply-to'] == 'user') { + if ($user = User::lookup($this->user_id)) + $vars['thread_entry_recipients']['to'][] = $user->getEmail()->address; + } + if ($vars['ccs'] && $vars['reply-to'] == 'all') { + foreach ($vars['ccs'] as $key => $uid) { + if (!$cc = User::lookup($uid)) + continue; + else + $vars['thread_entry_recipients']['cc'][] = $cc->getEmail()->address; + } + } + } + // Messages from User front end + elseif (strtolower($origin) != 'email') { + $recipients = $this->getRecipients('all'); + foreach ($recipients as $key => $recipient) { + $recipientContact = $recipient->getContact(); + // Do not put the Ticket Owner as a recipient if they are opening a new Ticket + if(get_class($recipientContact) == 'TicketOwner' && !is_null($this->getLastMsgDate())) { + if ($recipientContact->getId() == $vars['userId']) + unset($recipients[$key]); + } + // Do not put a Collaborator as a recipient if they are replying from Web Portal + elseif (get_class($recipientContact) == 'Collaborator') { + if ($recipient->getContact()->getUserId() == $vars['userId']) + unset($recipients[$key]); + } + } + if ($recipients && $recipients instanceof MailingList) + $vars['thread_entry_recipients'] = $recipients->getEmailAddresses(); + } + if (!($message = $this->getThread()->addMessage($vars, $errors))) return null;