From eb957e5381a2bc9c67c5cf03c0862df7b640c417 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Tue, 24 Jun 2014 05:21:21 +0000
Subject: [PATCH] Add ticket status list

First implementation of built-in custom list
---
 bootstrap.php                       |  3 +
 include/class.list.php              | 95 ++++++++++++++++++++++++++++-
 include/staff/dynamic-lists.inc.php | 42 ++++++++++---
 scp/lists.php                       | 16 +++--
 4 files changed, 140 insertions(+), 16 deletions(-)

diff --git a/bootstrap.php b/bootstrap.php
index a4e56510c..08fe94ab9 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -94,9 +94,12 @@ class Bootstrap {
         define('TICKET_EVENT_TABLE',$prefix.'ticket_event');
         define('TICKET_EMAIL_INFO_TABLE',$prefix.'ticket_email_info');
         define('TICKET_COLLABORATOR_TABLE', $prefix.'ticket_collaborator');
+        define('TICKET_STATUS_TABLE', $prefix.'ticket_status');
         define('TICKET_PRIORITY_TABLE',$prefix.'ticket_priority');
+
         define('PRIORITY_TABLE',TICKET_PRIORITY_TABLE);
 
+
         define('FORM_SEC_TABLE',$prefix.'form');
         define('FORM_FIELD_TABLE',$prefix.'form_field');
 
diff --git a/include/class.list.php b/include/class.list.php
index 07c7119d6..e2d7592af 100644
--- a/include/class.list.php
+++ b/include/class.list.php
@@ -129,8 +129,14 @@ abstract class BuiltInCustomList implements CustomList {
     }
 
     static function getLists() {
-        //TODO: define built-in lists
-        return array();
+
+        $list['status'] = array ( //Ticket statuses
+                'name' => 'Ticket Status',
+                'handler' => 'TicketStatusList',
+                'icon' => 'icon-flag',
+                );
+
+        return $list;
     }
 
 }
@@ -451,4 +457,89 @@ class DynamicListItem extends VerySimpleModel {
     }
 }
 
+
+/*
+ * Ticket status List
+ *
+ *
+ */
+
+class TicketStatusList extends BuiltInCustomList {
+
+    var $ht = array(
+            'id' => 'status',
+            'name' => 'Status',
+            'name_plural' => 'Statuses',
+    );
+    // Fields of interest we need to store
+    static $config_fields = array('sort_mode', 'notes');
+
+    function getId() {
+        return $this->ht['id'];
+    }
+
+    function getName() {
+        return $this->ht['name'];
+    }
+
+    function getPluralName() {
+        return $this->ht['name_plural'];
+    }
+
+    function getSortMode() {
+        return $this->ht['sort_mode'];
+    }
+
+    function getNotes() {
+        return $this->ht['notes'];
+    }
+
+    function getInfo() {
+        return $this->config->getInfo() + $this->ht;
+    }
+
+    function getNumItems() {
+        return 0;
+    }
+
+    function getAllItems() {
+
+    }
+
+    function getItems($criteria) {
+
+    }
+
+    function hasProperties() {
+        return true;
+    }
+
+    function getListOrderBy() {
+        switch ($this->setSortMode()) {
+            case 'Alpha':
+                return 'name';
+            case '-Alpha':
+                return '-name';
+            case 'SortCol':
+            default:
+                return 'sort';
+        }
+    }
+
+    function getForm() {
+       return null;
+    }
+
+    function update($vars, &$errors) {
+
+        foreach (static::$config_fields as $f) {
+            if (!isset($vars[$f])) continue;
+
+            if (parent::set($f, $vars[$f]))
+                $this->ht[$field] = $vars[$f];
+        }
+
+        return true;
+    }
+}
 ?>
diff --git a/include/staff/dynamic-lists.inc.php b/include/staff/dynamic-lists.inc.php
index 3ef22874d..9a818ec5d 100644
--- a/include/staff/dynamic-lists.inc.php
+++ b/include/staff/dynamic-lists.inc.php
@@ -10,21 +10,43 @@ $page = ($_GET['p'] && is_numeric($_GET['p'])) ? $_GET['p'] : 1;
 $count = DynamicList::objects()->count();
 $pageNav = new Pagenate($count, $page, PAGE_LIMIT);
 $pageNav->setURL('lists.php');
-$showing=$pageNav->showing().' custom lists';
-?>
+$showing=$pageNav->showing().' Dynamic Lists';
+
+// Get built-in list
+$builtInList = BuiltInCustomList::getLists();
 
+?>
 <form action="lists.php" method="POST" name="lists">
 <?php csrf_token(); ?>
 <input type="hidden" name="do" value="mass_process" >
 <input type="hidden" id="action" name="a" value="" >
 <table class="list" border="0" cellspacing="1" cellpadding="0" width="940">
-    <caption><?php echo $showing; ?></caption>
+    <caption>Custom Lists</caption>
+    <?php
+    if ($builtInList) { ?>
+    <thead>
+        <tr>
+            <th width="7">&nbsp;</th>
+            <th colspan=3>&nbsp;Built-In Lists</th>
+        </tr>
+    </thead>
+    <tbody>
+    <?php foreach ($builtInList as $id => $list) { ?>
+        <tr>
+            <td><i class="<?php echo $list['icon']; ?>"></i></td>
+            <td colspan=3><a href="?id=<?php echo $id; ?>"><?php echo $list['name']; ?></a></td>
+        </tr>
+    <?php }
+    ?>
+    </tbody>
+    <?php
+    } ?>
     <thead>
         <tr>
             <th width="7">&nbsp;</th>
-            <th>List Name</th>
-            <th>Created</th>
-            <th>Last Updated</th>
+            <th>&nbsp;Dynamic Lists</th>
+            <th width="250">Created</th>
+            <th width="250">Last Updated</th>
         </tr>
     </thead>
     <tbody>
@@ -36,9 +58,11 @@ $showing=$pageNav->showing().' custom lists';
                 $sel = true; ?>
         <tr>
             <td>
-                <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $list->get('id'); ?>"
+                <input width="7" type="checkbox" class="ckb" name="ids[]"
+                value="<?php echo $list->getId(); ?>"
                     <?php echo $sel?'checked="checked"':''; ?>></td>
-            <td><a href="?id=<?php echo $list->get('id'); ?>"><?php echo $list->get('name'); ?></a></td>
+            <td><a href="?id=<?php echo $list->getId(); ?>"><?php echo
+            $list->getName(); ?></a></td>
             <td><?php echo $list->get('created'); ?></td>
             <td><?php echo $list->get('updated'); ?></td>
         </tr>
@@ -76,7 +100,7 @@ if ($count) //Show options..
     <hr/>
     <p class="confirm-action" style="display:none;" id="delete-confirm">
         <font color="red"><strong>Are you sure you want to DELETE selected lists?</strong></font>
-        <br><br>Deleted forms CANNOT be recovered.
+        <br><br>Deleted list CANNOT be recovered.
     </p>
     <div>Please confirm to continue.</div>
     <hr style="margin-top:1em"/>
diff --git a/scp/lists.php b/scp/lists.php
index 1b8e40675..56232c76c 100644
--- a/scp/lists.php
+++ b/scp/lists.php
@@ -4,11 +4,17 @@ require_once(INCLUDE_DIR.'class.list.php');
 
 
 $list=null;
-if($_REQUEST['id'] && !($list=DynamicList::lookup($_REQUEST['id'])))
-    $errors['err']='Unknown or invalid dynamic list ID.';
-
-if ($list)
-    $form = $list->getForm();
+if ($_REQUEST['id']) {
+    if (is_numeric($_REQUEST['id']))
+        $list = DynamicList::lookup($_REQUEST['id']);
+    else
+        $list = BuiltInCustomList::lookup($_REQUEST['id']);
+
+    if ($list)
+         $form = $list->getForm();
+    else
+        $errors['err'] = 'Unknown or invalid dynamic list ID.';
+}
 
 if($_POST) {
     $fields = array('name', 'name_plural', 'sort_mode', 'notes');
-- 
GitLab