From 4c5767b849e175c1b9061c19edffeff0e7ef19f8 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@enhancesoft.com>
Date: Fri, 27 Feb 2015 21:48:43 +0000
Subject: [PATCH] bugs: Fix collaborators lookup

---
 include/class.thread.php                             |  4 ++--
 include/class.ticket.php                             | 12 +++++++-----
 include/staff/templates/dynamic-form-simple.tmpl.php |  7 ++++---
 include/staff/templates/list-items.tmpl.php          |  4 ++--
 4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index e90fc095f..587e01349 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -934,8 +934,8 @@ class ThreadEntry extends VerySimpleModel {
             //We have a valid ticket and user
             if ($ticket->getUserId() == $user->getId() //owner
                     ||  ($c = Collaborator::lookup( // check if collaborator
-                            array('userId' => $user->getId(),
-                                  'ticketId' => $ticket->getId())))) {
+                            array('user_id' => $user->getId(),
+                                  'thread_id' => $ticket->getThreadId())))) {
 
                 $mailinfo['userId'] = $user->getId();
                 return $ticket->getLastMessage();
diff --git a/include/class.ticket.php b/include/class.ticket.php
index 5df9f9a82..e78336dab 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -396,8 +396,8 @@ implements RestrictedAccess, Threadable {
 
         // 2) Query the database to check for expanded access...
         if (Collaborator::lookup(array(
-                        'userId' => $user->getId(),
-                        'ticketId' => $this->getId())))
+                        'user_id' => $user->getId(),
+                        'thread_id' => $this->getThreadId())))
             return true;
 
         return false;
@@ -1543,7 +1543,8 @@ implements RestrictedAccess, Threadable {
                     User::lookup($message->getUserId()), $this);
         else
             $user = Collaborator::lookup(array(
-                    'userId'=>$message->getUserId(), 'ticketId'=>$this->getId()));
+                    'user_id' => $message->getUserId(),
+                    'thread_id' => $this->getThreadId()));
 
         /**********   double check auto-response  ************/
         if (!$user)
@@ -1990,8 +1991,9 @@ implements RestrictedAccess, Threadable {
                 $thisstaff->getName(), $user->getName());
 
         //Remove the new owner from list of collaborators
-        $c = Collaborator::lookup(array('userId' => $user->getId(),
-                    'ticketId' => $this->getId()));
+        $c = Collaborator::lookup(array(
+                    'user_id' => $user->getId(),
+                    'thread_id' => $this->getThreadId()));
         if ($c && $c->remove())
             $note.= ' '._S('(removed as collaborator)');
 
diff --git a/include/staff/templates/dynamic-form-simple.tmpl.php b/include/staff/templates/dynamic-form-simple.tmpl.php
index 1c31b8fed..30b43c6b9 100644
--- a/include/staff/templates/dynamic-form-simple.tmpl.php
+++ b/include/staff/templates/dynamic-form-simple.tmpl.php
@@ -1,4 +1,4 @@
-        <?php
+<?php
         echo $form->getMedia();
         foreach ($form->getFields() as $name=>$f) { ?>
             <div class="flush-left custom-field" id="field<?php echo $f->getWidget()->id;
@@ -28,5 +28,6 @@
                 <div class="error"><?php echo $e; ?></div>
             <?php } ?>
             </div>
-        <?php }
-        ?>
+        <?php
+        }
+?>
diff --git a/include/staff/templates/list-items.tmpl.php b/include/staff/templates/list-items.tmpl.php
index e57a8bf09..c1df52999 100644
--- a/include/staff/templates/list-items.tmpl.php
+++ b/include/staff/templates/list-items.tmpl.php
@@ -1,4 +1,5 @@
-    <?php if ($list) {
+<?php
+    if ($list) {
         $page = ($_GET['p'] && is_numeric($_GET['p'])) ? $_GET['p'] : 1;
         $count = $list->getNumItems();
         $pageNav = new Pagenate($count, $page, PAGE_LIMIT);
@@ -124,4 +125,3 @@ if ($list) {
     <div><?php echo __('Page').':'.$pageNav->getPageLinks('items', $pjax_container); ?></div>
 <?php } ?>
 </div>
-
-- 
GitLab