From b56397da057997fb474dc502bf9e366100da4f05 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Mon, 13 Jul 2015 15:47:53 +0000
Subject: [PATCH] Review Fixes

---
 include/class.export.php      |  2 +-
 include/class.forms.php       | 10 +++++-----
 include/class.task.php        |  7 +++----
 include/staff/tasks.inc.php   |  4 ++--
 include/staff/tickets.inc.php |  2 +-
 5 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/include/class.export.php b/include/class.export.php
index a5e950c7f..b6b9449a5 100644
--- a/include/class.export.php
+++ b/include/class.export.php
@@ -139,7 +139,7 @@ class Export {
                 'created' =>        __('Date Created'),
                 'cdata.title' =>    __('Title'),
                 'dept::getLocalName' => __('Department'),
-                'flags' =>          __('Current Status'), //FIXME: self:getStatus()?
+                '::getStatus' =>    __('Current Status'),
                 'duedate' =>        __('Due Date'),
                 'staff::getName' => __('Agent Assigned'),
                 'team::getName' =>  __('Team Assigned'),
diff --git a/include/class.forms.php b/include/class.forms.php
index 7e58209ce..ebc3c5588 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -326,9 +326,10 @@ class SimpleForm extends Form {
 class CustomForm extends SimpleForm {
 
     function getFields() {
+        global $thisstaff, $thisclient;
 
         $options = $this->options;
-        $user = @$options['user'];
+        $user = $options['user'] ?: $thisstaff ?: $thisclient;
         $isedit = ($options['mode'] == 'edit');
         $fields = array();
         foreach (parent::getFields() as $field) {
@@ -391,7 +392,6 @@ implements FormRenderer {
       ob_start();
 ?>
       <table class="<?php echo 'grid form' ?>">
-          <colgroup width="8.333333%"><col span="12"/></colgroup>
           <caption><?php echo Format::htmlchars($this->title ?: $form->getTitle()); ?>
                   <div><small><?php echo Format::viewableImages($form->getInstructions()); ?></small></div>
           </caption>
@@ -700,10 +700,10 @@ class FormField {
 
     function isEditable($user=null) {
 
-        if ($user instanceof EndUser)
-            $flag = DynamicFormField::FLAG_CLIENT_EDIT;
-        else
+        if ($user instanceof Staff)
             $flag = DynamicFormField::FLAG_AGENT_EDIT;
+        else
+            $flag = DynamicFormField::FLAG_CLIENT_EDIT;
 
         return (($this->get('flags') & $flag) != 0);
     }
diff --git a/include/class.task.php b/include/class.task.php
index 867d9151c..5f9206e80 100644
--- a/include/class.task.php
+++ b/include/class.task.php
@@ -1118,11 +1118,10 @@ class Task extends TaskModel implements RestrictedAccess, Threadable {
 
     /* static routines */
     static function lookupIdByNumber($number) {
-        $sql = 'SELECT id FROM '.TASK_TABLE
-              .' WHERE `number`='.db_input($number);
-        list($id) = db_fetch_row(db_query($sql));
 
-        return $id;
+        if (($task = self::lookup(array('number' => $number))))
+            return $task->getId();
+
     }
 
     static function isNumberUnique($number) {
diff --git a/include/staff/tasks.inc.php b/include/staff/tasks.inc.php
index 6260027a6..5a3a80df9 100644
--- a/include/staff/tasks.inc.php
+++ b/include/staff/tasks.inc.php
@@ -1,5 +1,5 @@
 <?php
-$tasks = TaskModel::objects();
+$tasks = Task::objects();
 $date_header = $date_col = false;
 
 // Figure out REFRESH url — which might not be accurate after posting a
@@ -126,7 +126,7 @@ $tasks->values('id', 'number', 'created', 'staff_id', 'team_id',
         'dept__name', 'cdata__title', 'flags');
 // Apply requested quick filter
 
-$queue_sort_key = sprintf(':Q:%s:sort', $queue_name);
+$queue_sort_key = sprintf(':Q%s:%s:sort', ObjectModel::OBJECT_TYPE_TASK, $queue_name);
 
 if (isset($_GET['sort'])) {
         $_SESSION[$queue_sort_key] = $_GET['sort'];
diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php
index 2aeb8ed11..4a6519410 100644
--- a/include/staff/tickets.inc.php
+++ b/include/staff/tickets.inc.php
@@ -192,7 +192,7 @@ $pageNav->setURL('tickets.php', $args);
 $tickets = $pageNav->paginate($tickets);
 
 // Apply requested sorting
-$queue_sort_key = sprintf(':Q:%s:sort', $queue_name);
+$queue_sort_key = sprintf(':Q%s:%s:sort', ObjectModel::OBJECT_TYPE_TICKET, $queue_name);
 
 if (isset($_GET['sort'])) {
     $_SESSION[$queue_sort_key] = $_GET['sort'];
-- 
GitLab