From 46afc966676fdd4ca60b01827473f8e23a8c661e Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Tue, 17 Apr 2018 13:06:49 -0500
Subject: [PATCH] additional cc/bcc changes

---
 include/ajax.thread.php                       | 20 +++++++++----------
 include/class.thread.php                      | 16 +++++++++++++++
 .../client/templates/thread-entry.tmpl.php    | 11 +++++-----
 .../staff/templates/collaborators.tmpl.php    |  2 +-
 include/staff/ticket-view.inc.php             |  2 +-
 scp/ajax.php                                  |  4 ++--
 6 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/include/ajax.thread.php b/include/ajax.thread.php
index a66062e0b..0369548ed 100644
--- a/include/ajax.thread.php
+++ b/include/ajax.thread.php
@@ -74,11 +74,11 @@ class ThreadAjaxAPI extends AjaxController {
         if (!$user_info)
             $info['error'] = __('Unable to find user in directory');
 
-        return self::_addcollaborator($thread, null, $form, $info);
+        return self::_addcollaborator($thread, null, $form, 'addcc', $info);
     }
 
     //Collaborators utils
-    function addCollaborator($tid, $uid=0) {
+    function addCollaborator($tid, $type=null, $uid=0) {
         global $thisstaff;
 
         if (!($thread=Thread::lookup($tid))
@@ -90,7 +90,7 @@ class ThreadAjaxAPI extends AjaxController {
 
         //If not a post then assume new collaborator form
         if(!$_POST)
-            return self::_addcollaborator($thread, $user);
+            return self::_addcollaborator($thread, $user, null, $type);
 
         $user = $form = null;
         if (isset($_POST['id']) && $_POST['id']) { //Existing user/
@@ -107,7 +107,7 @@ class ThreadAjaxAPI extends AjaxController {
                             array(), $errors))) {
                 $info = array('msg' => sprintf(__('%s added as a collaborator'),
                             Format::htmlchars($c->getName())));
-                $c->setCc();
+                $type == 'addbcc' ? $c->setBcc() : $c->setCc();
                 $c->save();
                 return self::_collaborators($thread, $info);
             }
@@ -119,7 +119,7 @@ class ThreadAjaxAPI extends AjaxController {
             $info +=array('error' =>__('Unable to add collaborator.').' '.__('Internal error occurred'));
         }
 
-        return self::_addcollaborator($thread, $user, $form, $info);
+        return self::_addcollaborator($thread, $user, $form, $type, $info);
     }
 
     function updateCollaborator($tid, $cid) {
@@ -194,15 +194,15 @@ class ThreadAjaxAPI extends AjaxController {
         return $resp;
     }
 
-    function _addcollaborator($thread, $user=null, $form=null, $info=array()) {
+    function _addcollaborator($thread, $user=null, $form=null, $type=null, $info=array()) {
         global $thisstaff;
 
         $info += array(
                     'title' => __('Add a collaborator'),
-                    'action' => sprintf('#thread/%d/add-collaborator',
-                        $thread->getId()),
-                    'onselect' => sprintf('ajax.php/thread/%d/add-collaborator/',
-                        $thread->getId()),
+                    'action' => sprintf('#thread/%d/add-collaborator/%s',
+                        $thread->getId(), $type),
+                    'onselect' => sprintf('ajax.php/thread/%d/add-collaborator/%s/',
+                        $thread->getId(), $type),
                     );
 
         ob_start();
diff --git a/include/class.thread.php b/include/class.thread.php
index dd10d3a0d..b5176ada2 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -778,6 +778,18 @@ implements TemplateVariable {
         ),
     );
 
+    // Thread entry types
+    static protected $types = array(
+            'M' => 'message',
+            'R' => 'response',
+            'N' => 'note',
+            'B' => 'bccmessage',
+    );
+
+    function getTypeName() {
+      return self::$types[$this->type];
+    }
+
     function postEmail($mailinfo) {
         global $ost;
 
@@ -1720,6 +1732,10 @@ implements TemplateVariable {
     static function getPermissions() {
         return self::$perms;
     }
+
+    static function getTypes() {
+        return self::$types;
+    }
 }
 
 RolePermission::register(/* @trans */ 'Tickets', ThreadEntry::getPermissions());
diff --git a/include/client/templates/thread-entry.tmpl.php b/include/client/templates/thread-entry.tmpl.php
index ad9f3dc9f..e49b3b038 100644
--- a/include/client/templates/thread-entry.tmpl.php
+++ b/include/client/templates/thread-entry.tmpl.php
@@ -1,6 +1,6 @@
 <?php
 global $cfg;
-$entryTypes = array('M'=>'message', 'R'=>'response', 'N'=>'note', 'B' => 'bccmessage');
+$entryTypes = ThreadEntry::getTypes();
 $user = $entry->getUser() ?: $entry->getStaff();
 if ($entry->staff && $cfg->hideStaffName())
     $name = __('Staff');
@@ -11,13 +11,14 @@ if ($cfg->isAvatarsEnabled() && $user)
     $avatar = $user->getAvatar();
 ?>
 <?php
-  if ($entryTypes[$entry->type] == 'note') {
-    $entryTypes[$entry->type] = 'bccmessage';
+$type = $entryTypes[$entry->type];
+if ($type == 'note') {
+    $type =  'bccmessage';
     $entry->type = 'B';
-  }
+}
 ?>
 
-<div class="thread-entry <?php echo $entryTypes[$entry->type]; ?> <?php if ($avatar) echo 'avatar'; ?>">
+<div class="thread-entry <?php echo $type; ?> <?php if ($avatar) echo 'avatar'; ?>">
 <?php if ($avatar) { ?>
     <span class="<?php echo ($entry->type == 'M' || $entry->type == 'B') ? 'pull-left' : 'pull-right'; ?> avatar">
 <?php echo $avatar; ?>
diff --git a/include/staff/templates/collaborators.tmpl.php b/include/staff/templates/collaborators.tmpl.php
index 7f80a5804..1a50164f1 100644
--- a/include/staff/templates/collaborators.tmpl.php
+++ b/include/staff/templates/collaborators.tmpl.php
@@ -65,7 +65,7 @@ if(($users=$thread->getCollaborators())) {?>
     ?>
     <td>
       <div><a class="collaborator" id="addcollaborator"
-          href="#thread/<?php echo $thread->getId(); ?>/add-collaborator"
+          href="#thread/<?php echo $thread->getId(); ?>/add-collaborator/addcc"
           ><i class="icon-plus-sign"></i> <?php echo __('Add Collaborator'); ?></a></div>
     </td>
     </table>
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index dd3511224..b5ededef8 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -1197,7 +1197,7 @@ $(function() {
 
    if(el.val().includes("NEW")) {
      $("li[title='— Add New —']").remove();
-     var url = 'ajax.php/thread/' + tid + '/add-collaborator' ;
+     var url = 'ajax.php/thread/' + tid + '/add-collaborator/' + addTo ;
       $.userLookup(url, function(user) {
         e.preventDefault();
          if($('.dialog#confirm-action').length) {
diff --git a/scp/ajax.php b/scp/ajax.php
index c746da68d..85d010e92 100644
--- a/scp/ajax.php
+++ b/scp/ajax.php
@@ -211,9 +211,9 @@ $dispatcher = patterns('',
         url_get('^(?P<tid>\d+)/collaborators/preview$', 'previewCollaborators'),
         url_get('^(?P<tid>\d+)/collaborators$', 'showCollaborators'),
         url_post('^(?P<tid>\d+)/collaborators$', 'updateCollaborators'),
-        url_get('^(?P<tid>\d+)/add-collaborator/(?P<uid>\d+)$', 'addCollaborator'),
+        url_get('^(?P<tid>\d+)/add-collaborator/(?P<type>\w+)/(?P<uid>\d+)$', 'addCollaborator'),
         url_get('^(?P<tid>\d+)/add-collaborator/auth:(?P<bk>\w+):(?P<id>.+)$', 'addRemoteCollaborator'),
-        url('^(?P<tid>\d+)/add-collaborator$', 'addCollaborator'),
+        url('^(?P<tid>\d+)/add-collaborator/(?P<type>\w+)$', 'addCollaborator'),
         url_get('^(?P<tid>\d+)/collaborators/(?P<cid>\d+)/view$', 'viewCollaborator'),
         url_post('^(?P<tid>\d+)/collaborators/(?P<cid>\d+)$', 'updateCollaborator')
     )),
-- 
GitLab