From 033f8796b6793cd0e1276c43b343e5b6fcbfcd3c Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Fri, 19 Oct 2012 14:34:43 -0400 Subject: [PATCH] Use auto-rely template. --- include/class.ticket.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/include/class.ticket.php b/include/class.ticket.php index 477135e0e..261bc253f 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1461,6 +1461,7 @@ class Ticket { } function postCannedReply($canned, $msgId, $alert=true) { + global $ost, $cfg; if((!is_object($canned) && !($canned=Canned::lookup($canned))) || !$canned->isEnabled()) return false; @@ -1473,7 +1474,38 @@ class Ticket { 'response' => $this->replaceVars($canned->getResponse()), 'cannedattachments' => $files); - return $this->postReply($info, $errors, $alert); + if(!($respId=$this->postReply($info, $errors, false))) + return false; + + $this->markUnAnswered(); + + if(!$alert) return $respId; + + $dept = $this->getDept(); + + if(!($tpl = $dept->getTemplate())) + $tpl= $cfg->getDefaultTemplate(); + + if(!$dept || !($email=$dept->getEmail())) + $email = $cfg->getDefaultEmail(); + + if($tpl && ($msg=$tpl->getAutoReplyMsgTemplate()) && $email) { + + if($dept && $dept->isPublic()) + $signature=$dept->getSignature(); + else + $signature=''; + + $msg = $this->replaceVars($msg, array('response' => $info['response'], 'signature' => $signature)); + + if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator())) + $msg['body'] ="\n$tag\n\n".$msg['body']; + + $attachments =($cfg->emailAttachments() && $files)?$this->getAttachments($respId, 'R'):array(); + $email->send($this->getEmail(), $msg['subj'], $msg['body'], $attachments); + } + + return $respId; } /* public */ @@ -1487,7 +1519,7 @@ class Ticket { if($errors) return 0; - $poster = $thisstaff?$thisstaff->getName():'SYSTEM (Canned Response)'; + $poster = $thisstaff?$thisstaff->getName():'SYSTEM (Canned Reply)'; $sql='INSERT INTO '.TICKET_THREAD_TABLE.' SET created=NOW() ' .' ,thread_type="R"' -- GitLab