From bf04371308523a1657b51f8b3d72d9c6261546a3 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Thu, 22 Mar 2018 12:51:08 +0000 Subject: [PATCH] Collaborators Fixes * Dont't fetch templates while in a loop * Tidy up the code --- include/class.ticket.php | 52 ++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/include/class.ticket.php b/include/class.ticket.php index 7da02a0af..a6c4d7867 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2939,47 +2939,41 @@ implements RestrictedAccess, Threadable, Searchable { $user = $this->getOwner(); if (($email=$email) && ($tpl = $dept->getTemplate()) - && ($msg=$tpl->getReplyMsgTemplate()) - ) { + && ($msg=$tpl->getReplyMsgTemplate())) { + $msg = $this->replaceVars($msg->asArray(), $variables + array('recipient' => $user) ); - $attachments = $cfg->emailAttachments()?$response->getAttachments():array(); - } - if ($vars['emailcollab'] == 1) { + $attachments = $cfg->emailAttachments() ? $response->getAttachments() : array(); //Cc collaborators - if($vars['ccs']) { - $collabsCc = array(); - $collabsCc[] = Collaborator::getCollabList($vars['ccs']); - $collabsCc['cc'] = $collabsCc; - $email->send($user, $msg['subj'], $msg['body'], $attachments, - $options, $collabsCc); - } - else { - $email->send($user, $msg['subj'], $msg['body'], $attachments, - $options); + $collabsCc = array(); + if ($vars['ccs'] && $vars['emailcollab']) { + $collabsCc[] = Collaborator::getCollabList($vars['ccs']); + $collabsCc['cc'] = $collabsCc; } + $email->send($user, $msg['subj'], $msg['body'], $attachments, + $options, $collabsCc); + //Bcc Collaborators - if($vars['bccs']) { - foreach ($vars['bccs'] as $uid) { - $recipient = User::lookup($uid); - if (($bcctpl = $dept->getTemplate()) + if ($vars['bccs'] + && $vars['emailcollab'] + && ($bcctpl = $dept->getTemplate()) && ($bccmsg=$bcctpl->getReplyMsgTemplate())) { - $bccmsg = $this->replaceVars($bccmsg->asArray(), $variables + - array('recipient' => $user, 'recipient.name.first' => $recipient->getName()->getFirst()) - ); + foreach ($vars['bccs'] as $uid) { + if (!($recipient = User::lookup($uid))) + continue; - $email->send($recipient, $bccmsg['subj'], $bccmsg['body'], $attachments, - $options); + $msg = $this->replaceVars($bccmsg->asArray(), $variables + array( + 'recipient' => $user, + 'recipient.name.first' => + $recipient->getName()->getFirst())); + + $email->send($recipient, $msg['subj'], $msg['body'], $attachments, $options); } - } } - } - else - $email->send($user, $msg['subj'], $msg['body'], $attachments, - $options); + } return $response; } -- GitLab