From db65223a1666d5a851847243a7483b6fb9c4c7eb Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@enhancesoft.com>
Date: Wed, 27 Nov 2013 23:11:37 +0000
Subject: [PATCH] Fixes

---
 include/ajax.tickets.php          | 15 +++++++++------
 include/class.thread.php          |  9 +++++++++
 include/class.ticket.php          | 12 +++---------
 include/staff/ticket-view.inc.php |  2 +-
 4 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php
index 93e90758c..058bb12a3 100644
--- a/include/ajax.tickets.php
+++ b/include/ajax.tickets.php
@@ -470,11 +470,15 @@ class TicketsAjaxAPI extends AjaxController {
         }
 
         $errors = $info = array();
-        if ($user && ($c=$ticket->addCollaborator($user, $errors))) {
-            $info =array('msg' => sprintf('%s added as a collaborator',
-                        $c->getName()));
-
-            return self::_collaborators($ticket, $info);
+        if ($user) {
+            if ($user->getId() == $ticket->getOwnerId())
+                $errors['err'] = sprintf('Ticket owner, %s, is a collaborator by default!',
+                        $user->getName());
+            elseif (($c=$ticket->addCollaborator($user, $errors))) {
+                $info = array('msg' => sprintf('%s added as a collaborator',
+                            $c->getName()));
+                return self::_collaborators($ticket, $info);
+            }
         }
 
         if($errors && $errors['err']) {
@@ -483,7 +487,6 @@ class TicketsAjaxAPI extends AjaxController {
             $info +=array('error' =>'Unable to add collaborator - try again');
         }
 
-
         return self::_addcollaborator($ticket, $user, $form, $info);
     }
 
diff --git a/include/class.thread.php b/include/class.thread.php
index f797e6465..3ebdc83a6 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -763,6 +763,15 @@ Class ThreadEntry {
         if(!$vars['ticketId'] || !$vars['type'] || !in_array($vars['type'], array('M','R','N')))
             return false;
 
+        //Strip quoted reply...on emailed  messages
+        if($vars['origin']
+                && !strcasecmp($vars['origin'], 'Email')
+                && $cfg->stripQuotedReply()
+                && ($tag=$cfg->getReplySeparator())
+                && strpos($vars['body'], $tag))
+            if((list($msg) = explode($tag, $vars['body'], 2)) && trim($msg))
+                $vars['body'] = $msg;
+
         if (isset($vars['attachments'])) {
             foreach ($vars['attachments'] as &$a) {
                 // Change <img src="cid:"> inside the message to point to
diff --git a/include/class.ticket.php b/include/class.ticket.php
index 0f7d7e752..318d20535 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -594,7 +594,8 @@ class Ticket {
 
     function addCollaborator($user, &$errors) {
 
-        if(!$user) return null;
+        if(!$user || $user->getId()==$this->getOwnerId())
+            return null;
 
         $vars = array(
                 'ticketId' => $this->getId(),
@@ -1443,14 +1444,7 @@ class Ticket {
     function postMessage($vars, $origin='', $alerts=true) {
         global $cfg;
 
-        //Strip quoted reply...on emailed replies
-        if(!strcasecmp($origin, 'Email')
-                && $cfg->stripQuotedReply()
-                && ($tag=$cfg->getReplySeparator())
-                && strpos($vars['message'], $tag))
-            if((list($msg) = explode($tag, $vars['message'], 2)) && trim($msg))
-                $vars['message'] = $msg;
-
+        $vars['origin'] = $origin;
         if(isset($vars['ip']))
             $vars['ip_address'] = $vars['ip'];
         elseif(!$vars['ip_address'] && $_SERVER['REMOTE_ADDR'])
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 3866de15b..275bd2c2b 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -430,7 +430,7 @@ $tcount+= $ticket->getNumNotes();
             'table-row-group':'none'; ?>;">
             <tr>
                 <td width="120">
-                    <label><strong>CC:</strong></label>
+                    <label><strong>Recipients:</strong></label>
                 </td>
                 <td>
                     <?php
-- 
GitLab