From eca531f04c0df19986ec80a02717577cf681dbf9 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 10 Aug 2015 14:56:36 -0500
Subject: [PATCH] ticket: Fix auto-claim from canned auto-reply

---
 include/class.ticket.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index 53dce9cb9..1c9b8dda3 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -1903,7 +1903,7 @@ class Ticket {
                       'cannedattachments' => $files);
 
         $errors = array();
-        if(!($response=$this->postReply($info, $errors, false)))
+        if (!($response=$this->postReply($info, $errors, false, false)))
             return null;
 
         $this->markUnAnswered();
@@ -1941,11 +1941,10 @@ class Ticket {
     }
 
     /* public */
-    function postReply($vars, &$errors, $alert = true) {
+    function postReply($vars, &$errors, $alert=true, $claim=true) {
         global $thisstaff, $cfg;
 
-
-        if(!$vars['poster'] && $thisstaff)
+        if (!$vars['poster'] && $thisstaff)
             $vars['poster'] = $thisstaff;
 
         if(!$vars['staffId'] && $thisstaff)
@@ -1964,10 +1963,11 @@ class Ticket {
             $this->setStatus($vars['reply_status_id']);
 
         // Claim on response bypasses the department assignment restrictions
-        if($thisstaff && $this->isOpen() && !$this->getStaffId()
-                && $cfg->autoClaimTickets())
+        if ($claim && $thisstaff && $this->isOpen() && !$this->getStaffId()
+            && $cfg->autoClaimTickets()
+        ) {
             $this->setStaffId($thisstaff->getId()); //direct assignment;
-
+        }
 
         $this->onResponse($response, array('assignee' => $assignee)); //do house cleaning..
 
@@ -2302,7 +2302,7 @@ class Ticket {
     }
 
     function lookupByNumber($number, $email=null) {
-        return self::lookup(self:: getIdByNumber($number, $email));
+        return self::lookup(self::getIdByNumber($number, $email));
     }
 
     static function isTicketNumberUnique($number) {
-- 
GitLab