diff --git a/include/class.ticket.php b/include/class.ticket.php index 477135e0e997fd95057bb35d6f6ac302579c663b..261bc253ff2e86730f0dd336ce8155dc2b58888b 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"'