Adding back in the categories for coupons.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Nov 2016 20:26:34 +0000 (15:26 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Nov 2016 20:26:34 +0000 (15:26 -0500)
These will be just like the categories for the events.
In that they can add more than one category per coupon.

classes/data/dataCoupons.php
classes/data/dataCouponsCouponCategories.php [new file with mode: 0644]
models/admin/coupons/list.php
setup/adminMenus.php
views/admin/coupons/edit.html
views/admin/coupons/list.html

index b7637cf..f56ca16 100644 (file)
@@ -85,6 +85,7 @@ class GlmDataCoupons extends GlmDataAbstract
      * @var bool
      * @access public
      */
+    public $postCategories = true;
 
     /**
      * Constructor
@@ -275,6 +276,17 @@ class GlmDataCoupons extends GlmDataAbstract
      */
     public function entryPostProcessing($r, $a)
     {
+
+        // Get Member Category data for this entry
+        if ($this->postCategories) {
+            $sql = "
+                SELECT CC.coupon AS coupon_id, C.id, C.name
+                  FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "categories AS C,
+                       ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "coupon_categories AS CC
+                 WHERE C.id = CC.category
+                   AND CC.coupon = ".$r['id'];
+            $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A);
+        }
         return $r;
     }
 
@@ -425,6 +437,9 @@ class GlmDataCoupons extends GlmDataAbstract
     public function getIdName($where = 'true')
     {
         $savedFields = $this->fields;
+        $savedCategories = $this->postCategories;
+
+        $this->postCategories = false;
 
         $this->fields = array(
             'id' => $savedFields['id'],
@@ -434,6 +449,7 @@ class GlmDataCoupons extends GlmDataAbstract
         $r = $this->getList($where);
 
         $this->fields = $savedFields;
+        $this->postCategories = $savedCategories;
 
         return $r;
 
diff --git a/classes/data/dataCouponsCouponCategories.php b/classes/data/dataCouponsCouponCategories.php
new file mode 100644 (file)
index 0000000..15d1620
--- /dev/null
@@ -0,0 +1,352 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Coupons
+ *
+ * PHP version 5.3
+ *
+ * @category Data
+ * @package  GLM Member-DB
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  SVN: $Id: dataCoupons.php,v 1.0 2011/01/25 19:31:47 cscott Exp $
+ */
+
+/**
+ * GlmDataCoupon class
+ *
+ * PHP version 5
+ *
+ * @category Data
+ * @package GLM Member DB
+ * @author  Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *          @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott
+ *          Exp $
+ */
+class GlmDataCouponsCouponCategories extends GlmDataAbstract
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Data Table Name
+     *
+     * @var $table
+     * @access public
+     */
+    public $table;
+    /**
+     * Field definitions
+     *
+     * 'type' is type of field as defined by the application
+     * text Regular text field
+     * pointer Pointer to an entry in another table
+     * 'filters' is the filter name for a particular filter ID in PHP filter
+     * functions
+     * See PHP filter_id()
+     *
+     * 'use' is when to use the field
+     * l = List
+     * g = Get
+     * n = New
+     * i = Insert
+     * e = Edit
+     * u = Update
+     * d = Delete
+     * a = All
+     *
+     * @var $ini
+     * @access public
+     */
+    public $fields = false;
+    /**
+     * MemberInfo DB object
+     *
+     * @var $MemberInfo
+     * @access public
+     */
+    public $MemberInfo;
+
+    /**
+     * Constructor
+     *
+     * @param object $d database connection
+     * @param array $config Configuration array
+     * @param bool $limitedEdit Flag to say indicate limited edit requested
+     *
+     * @return void
+     * @access public
+     */
+    public function __construct($wpdb, $config, $limitedEdit = false)
+    {
+
+        // If this class is not being extended along with existing $wpdb and $config
+        if (!$this->wpdb) {
+
+            // Save WordPress Database object
+            $this->wpdb = $wpdb;
+
+            // Save plugin configuration object
+            $this->config = $config;
+
+        }
+
+        /*
+         * Table Name
+         */
+        $this->table = GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . 'coupon_categories';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array (
+
+            'id' => array (
+                'field' => 'id',
+                'type' => 'integer',
+                'view_only' => true,
+                'use' => 'a'
+            ),
+
+            // Coupon ID
+            'coupon' => array(
+                'field' => 'coupon',
+                'type' => 'integer',
+                'required' => true,
+                'use' => 'a'
+            ),
+
+            // Category ID
+            'category' => array(
+                'field' => 'category',
+                'type' => 'integer',
+                'required' => true,
+                'use' => 'a'
+            ),
+
+            // Category Name - for easy reference
+            'category_name' => array(
+                'field' => 'category',
+                'as' => 'category_name',
+                'type' => 'pointer',
+                    'p_table' => GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . 'categories',
+                    'p_field' => 'name',
+                    'p_orderby' => 'name',
+                'use' => 'gl'
+            )
+
+
+        );
+
+    }
+
+    /*
+     * Entry Post Processing Call-Back Method
+     *
+     * Perform post-processing for all result entries.
+     *
+     * In this case we're using it to append an array of category
+     * data to each member result and also sort by member name.
+     *
+     * @param array $r Array of field result data for a single entry
+     * @param string $a Action being performed (l, i, g, ...)
+     *
+     * @return object Class object
+     *
+     */
+    public function entryPostProcessing($r, $a)
+    {
+        return $r;
+    }
+
+    /*
+     * Get list of categories with parent information
+     *
+     * @param integer $couponID Optional coupon ID to match
+     *      Used to find all categories for a particular coupon ID
+     *
+     * @param integer $category Optional category ID to match
+     *      Used to find all coupon records for a particular category
+     *
+     *      NOTE: Both parameters above can't be used at the same time
+     *
+     * @return array List of selected categories
+     *
+     * @access public
+     */
+
+    public function getListWithParents($couponID = false, $category = false)
+    {
+
+        $where = '';
+
+        if ($category) {
+            $where = "WHERE T.category = $category";
+        } elseif ($ventID) {
+            $where = "WHERE T.coupon = $couponID";
+        }
+
+        $sql =  "
+            SELECT T.category, T.coupon,
+                   (
+                       SELECT name
+                         FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories
+                        WHERE id = T.category
+                    ) AS category_name,
+                    (
+                        SELECT parent
+                          FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories
+                         WHERE id = T.category
+                    ) AS category_parent,
+                    COALESCE (
+                        (
+                            SELECT name
+                              FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories
+                             WHERE id = category_parent
+                        ),
+                        ''
+                    ) AS parent_name
+               FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."coupon_categories T
+                    $where
+        ;";
+        $list = $this->wpdb->get_results($sql, ARRAY_A);
+
+        if (is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+            glmMembersAdmin::addNotice($sql, 'DataBlock', "DataAbstract - getListWithParents() query");
+            glmMembersAdmin::addNotice($list, 'DataBlock', 'getListWithParents() data');
+        }
+
+        return $list;
+
+    }
+
+    /**
+     * Use supplied category ID list to set selected categories for this
+     * coupon record. Any others that were set will be cleared.
+     *
+     * @param integer $couponID Coupon Record ID
+     * @param array $selectedCategories Array of selected category IDs (key is also category ID)
+     *
+     * @return array List of selected categories
+     *
+     * @access public
+     */
+
+    public function setCouponCategories($couponID, $selectedCategories)
+    {
+
+        // Check supplied data
+        if (!is_int($couponID) || $couponID <=0 || !is_array($selectedCategories) || count($selectedCategories) == 0 ) {
+            return false;
+        }
+
+        // Get current list
+        $current = $this->getList("T.coupon = $couponID");
+
+        // If we have any currently selected categories
+        if (is_array($current) && count($current) > 0) {
+
+            // For each category in the list
+            foreach ($current as $key => $val) {
+
+                $current[$key]['selected'] = false;
+
+                // Delete existing ones from the supplied selection list and mark selected ones in the current list
+                if (isset($selectedCategories[$val['id']])) {
+
+                    unset($selectedCategories[$val['id']]);
+
+                    $current[$key]['selected'] = true;
+
+                }
+
+            }
+
+        }
+
+        // For each remaining selected category, add the category
+        foreach ($selectedCategories as $s) {
+
+            // Add the category
+            $sql = "
+                INSERT INTO ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."coupon_categories
+                       ( category, coupon )
+                VALUES
+                       ( $s, $couponID )
+            ;";
+            $this->wpdb->query($sql);
+
+
+        }
+
+        // For any existing categories listed that aren't marked as selected, remove them
+        if (is_array($current) && count($current) > 0) {
+            foreach ($current as $key => $val) {
+
+                if (!$val['selected']) {
+
+                    // Delete the entry
+                    // Add the category
+                    $sql = "
+                        DELETE FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."coupon_categories
+                         WHERE coupon = $couponID
+                           AND id = ".$val['id']."
+                    ;";
+                    $this->wpdb->query($sql);
+
+                }
+            }
+        }
+
+        // Get new list and return it
+        $current = $this->getList($couponID);
+
+        if (is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+            glmMembersAdmin::addNotice($current, 'DataBlock', 'Currently Selected Coupon Categories');
+        }
+
+        return $current;
+    }
+
+    /**
+     * Clear all categories for a specific coupon record
+     *
+     * @param integer $couponID Coupon Record ID
+     *
+     * @return null
+     *
+     * @access public
+     */
+
+    public function clearCouponCategories($couponID)
+    {
+
+        $sql = "
+            DELETE FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."coupon_categories
+             WHERE coupon = $couponID
+        ;";
+        $this->wpdb->query($sql);
+
+        // Returns false to indicate there are no categories selected
+        return false;
+
+    }
+
+
+}
+
+?>
index 8d3ba50..8cc2033 100644 (file)
@@ -18,6 +18,7 @@ require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php';
 
 // Load coupon categories data class
 require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCouponCategories.php';
+require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCouponsCouponCategories.php';
 
 class GlmMembersAdmin_coupons_list extends GlmDataCoupons
 {
@@ -91,9 +92,9 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
     public function modelAction($actionData = false)
     {
 
-        $lockedToMember   = false;
+        $lockedToMember    = false;
         $numbCoupons       = 0;
-        $option           = 'list';
+        $option            = 'list';
         $coupons           = false;
         $haveCoupons       = false;
         $coupon            = false;
@@ -103,36 +104,36 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
         $couponUpdateError = false;
         $couponAdded       = false;
         $couponAddError    = false;
-        $view             = 'list';
-        $fromDate         = false;
-        $toDate           = false;
-        $filterArchived   = false;
-        $filterPending    = false;
+        $view              = 'list';
+        $fromDate          = false;
+        $toDate            = false;
+        $filterArchived    = false;
+        $filterPending     = false;
         $couponDeleted     = false;
         $couponDeleteError = false;
-        $locations        = false;
-        $haveLocations    = false;
-        $numbLocations    = 0;
-        $recurrences      = false;
-        $haveRecurrences  = false;
-        $numbRecurrences  = 0;
-        $times            = false;
-        $haveTimes        = false;
-        $firstTime        = false;
-        $lastTime         = false;
-        $memberID         = false;
-        $haveMember       = false;
-        $memberName       = false;
-        $memberData       = false;
-        $numbDisplayed    = false;
-        $lastDisplayed    = false;
-        $paging           = true;
-        $prevStart        = false;
-        $nextStart        = false;
-        $start            = 1;
-        $limit            = 20;        // Set to the number of listings per page
-        $namesList        = false;
-        $enable_members   = $this->config['settings']['enable_members'];
+        $locations         = false;
+        $haveLocations     = false;
+        $numbLocations     = 0;
+        $recurrences       = false;
+        $haveRecurrences   = false;
+        $numbRecurrences   = 0;
+        $times             = false;
+        $haveTimes         = false;
+        $firstTime         = false;
+        $lastTime          = false;
+        $memberID          = false;
+        $haveMember        = false;
+        $memberName        = false;
+        $memberData        = false;
+        $numbDisplayed     = false;
+        $lastDisplayed     = false;
+        $paging            = true;
+        $prevStart         = false;
+        $nextStart         = false;
+        $start             = 1;
+        $limit             = 20;        // Set to the number of listings per page
+        $namesList         = false;
+        $enable_members    = $this->config['settings']['enable_members'];
 
         // Check if there's a logged in user who is locked to their own entity
         $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
@@ -214,19 +215,13 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
         switch ($option) {
 
             case 'add':
-
                 $coupon = $this->newEntry();
-
                 $view = 'edit';
-
                 break;
 
             case 'insert':
-
                 $coupon = $this->insertEntry();
-
                 $this->couponID = $coupon['fieldData']['id'];
-
                 $this->updateCategories();
                 $categories = $Categories->getList(false);
 
@@ -254,7 +249,6 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                 break;
 
             case 'edit':
-
                 $coupon = $this->editEntry($this->couponID);
 
                 if ($coupon['status']) {
@@ -265,7 +259,6 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                 break;
 
             case 'update':
-
                 // Get the original Coupon Status. Before the update.
                 $old_coupon_status = $this->wpdb->get_var(
                     $this->wpdb->prepare(
@@ -277,12 +270,7 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                 );
 
                 $this->updateCategories();
-                $categories = $Categories->getListSortedParentChild(false);
-
-                if ( $this->config['settings']['use_coupon_amenities'] ) {
-                    $this->updateAmenities();
-                    $amenities = $Amenities->getList(false);
-                }
+                $categories = $Categories->getList(false);
 
                 // Try to update this coupon
                 $coupon = $this->updateEntry($this->couponID);
@@ -315,7 +303,6 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                 break;
 
             case 'delete':
-
                 $coupon = $this->deleteCoupon($this->couponID);
 
                 if ($coupon) {
@@ -326,7 +313,6 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
 
             case 'list':
             default:
-
                 $where = 'true';
 
                 // Check for Archived filter
@@ -361,12 +347,11 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                     }
 
                     $where .= " AND id in (
-                            SELECT DISTINCT(EC.coupon)
-                              FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories EC,
+                            SELECT DISTINCT(CC.coupon)
+                              FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."coupon_categories CC,
                                    ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories C
                              WHERE (
-                                   EC.category in ($cats)
-                                   OR (C.parent in ($cats) AND EC.category = C.id)
+                                   CC.category in ($cats)
                                    )
                     )";
                 }
@@ -383,7 +368,7 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                 if (isset($_REQUEST['fromDate']) && trim($_REQUEST['fromDate']) != '') {
                     $fromDate = date('m/d/Y', strtotime($_REQUEST['fromDate']));
                     $fromMYSQL = date('Y-m-d', strtotime($fromDate));
-                    $dateWhere = " end_time >= '$fromMYSQL' ";
+                    $dateWhere = " end_date >= '$fromMYSQL' ";
                 }
 
                 // If we have a to Date
@@ -394,23 +379,18 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
 
                     // If we have a from date then we need Parens and AND
                     if ($dateWhere != '') {
-                        $dateWhere = "( ".$dateWhere." AND start_time <= '$toMYSQL' )";
+                        $dateWhere = "( ".$dateWhere." AND start_date <= '$toMYSQL' )";
 
                     // Otherwise we don't
                     } else {
-                        $dateWhere = " start_time <= '$toMYSQL' ";
+                        $dateWhere = " start_date <= '$toMYSQL' ";
                     }
                 }
 
                 // If we have from and to dates, do search for those inclusive
                 if ($dateWhere != '') {
                     $where .= "
-                        AND id in (
-                            SELECT DISTINCT(coupon)
-                              FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."times
-                             WHERE $dateWhere
-                               AND active
-                        )
+                        AND $dateWhere
                     ";
                 }
 
@@ -487,23 +467,23 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
             'enable_members'    => $enable_members,
             'lockedToMember'    => $lockedToMember,
             'option'            => $option,
-            'coupons'            => $coupons,
-            'haveCoupons'        => $haveCoupons,
-            'coupon'             => $coupon,
-            'haveCoupon'         => $haveCoupon,
-            'couponID'           => $this->couponID,
-            'couponUpdated'      => $couponUpdated,
-            'couponUpdateError'  => $couponUpdateError,
-            'couponAdded'        => $couponAdded,
-            'couponAddError'     => $couponAddError,
-            'numbCoupons'        => $numbCoupons,
+            'coupons'           => $coupons,
+            'haveCoupons'       => $haveCoupons,
+            'coupon'            => $coupon,
+            'haveCoupon'        => $haveCoupon,
+            'couponID'          => $this->couponID,
+            'couponUpdated'     => $couponUpdated,
+            'couponUpdateError' => $couponUpdateError,
+            'couponAdded'       => $couponAdded,
+            'couponAddError'    => $couponAddError,
+            'numbCoupons'       => $numbCoupons,
             'categories'        => $categories,
             'fromDate'          => $fromDate,
             'toDate'            => $toDate,
             'filterArchived'    => $filterArchived,
             'filterPending'     => $filterPending,
-            'couponDeleted'      => $couponDeleted,
-            'couponDeleteError'  => $couponDeleteError,
+            'couponDeleted'     => $couponDeleted,
+            'couponDeleteError' => $couponDeleteError,
             'locations'         => $locations,
             'haveLocations'     => $haveLocations,
             'numbLocations'     => $numbLocations,
@@ -541,7 +521,7 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
     {
 
         // Instatiate the dataCategories class
-        $Categories = new GlmDataCouponsCategories($this->wpdb, $this->config);
+        $Categories = new GlmDataCouponCategories($this->wpdb, $this->config);
 
         // Instatiate Coupon/Categories data class
         $CouponCategories = new GlmDataCouponsCouponCategories($this->wpdb, $this->config);
index 72584ce..b643093 100644 (file)
  *
  */
 add_submenu_page(
-    'glm-members-admin-menu-members',
-    'Coupons',
-    'Coupons',
-    'glm_members_members',
-    'glm-members-admin-menu-coupons-index',
+    'glm-members-admin-menu-members',                    // Parent slug
+    'Coupons',                                           // Page Title
+    'Coupons',                                           // Menu Title
+    'glm_members_members',                               // Capability required
+    'glm-members-admin-menu-coupons-index',              // Menu slug
     function(){$this->controller('coupons');}
 );
+add_submenu_page(
+    'glm-members-admin-menu-members',                    // Parent slug
+    'Coupon List',                                       // Page title
+    '&nbsp;&nbsp;&nbsp;&nbsp;List',                      // Menu Title
+    'glm_members_members',                               // Capability required
+    'glm-members-admin-menu-coupons-list',               // Menu slug
+    function() {$this->controller('coupons', 'list');}
+);
index bf863e0..83d96de 100644 (file)
@@ -6,6 +6,7 @@
 
 {if apply_filters('glm_members_permit_admin_member_coupon', true)}
 
+    <input type="hidden" name="ref_type" value="{$ref_type_numb.Member}">
   {if $haveMember}
     <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=coupons&member={$memberID}" class="button button-secondary glm-button glm-right">Return to Coupons List</a>
   {else}
             </td>
         </tr>
         {/if}
+    {if $enable_members}
+        {if $coupon.fieldData.ref_dest.list|@count > 1}
+            <tr>
+                <th>{$terms.term_member_cap}:</th>
+                <td>
+            {if $haveMember}
+                    <input type="hidden" name="ref_dest" value="{$memberData.id}">
+                    {$memberData.name}
+            {else}
+                    <select id="memberSelect" name="ref_dest">
+                            {foreach $coupon.fieldData.ref_dest.list as $v}
+                                <option value="{$v.value}"{if $v.default} selected{/if}>{$v.name}</option>
+                            {/foreach}
+                    </select>
+            {/if}
+                </td>
+            </tr>
+        {else}
+            <input type="hidden" name="ref_dest" value="0">
+        {/if}
+    {else}
+        {if $coupon.fieldData.ref_dest.value}
+            <input type="hidden" name="ref_dest" value="{$coupon.fieldData.ref_dest.value}">
+        {else}
+            <input type="hidden" name="ref_dest" value="0">
+        {/if}
+    {/if}
         <tr>
             <th {if $coupon.fieldRequired.name}class="glm-required"{/if}>Coupon Name:</th>
             <td {if $coupon.fieldFail.name}class="glm-form-bad-input" data-tabid="glm-coupon-descr"{/if}>
                 {if $coupon.fieldFail.name}<p>{$coupon.fieldFail.name}</p>{/if}<br>
             </td>
         </tr>
+        <tr>
+            <th>Categories</th>
+            <td class="glm-item-container">
+
+                <!--  Add new category dialog -->
+
+                <div id="newCategoryButton" class="button button-secondary glm-right">Add a new Category</div>
+                <div id="newCategoryDialog" class="glm-dialog-box" title="Enter a New Category">
+                        <table class="glm-admin-table">
+                            <tr>
+                                <th class="glm-required">Category Name:</th>
+                                <td id="newCatNameTD">
+                                    <input id="newCatName" type="text" name="newCatName" class="glm-form-text-input">
+                                    <div id="newCatNameRequired"></div>
+                                </td>
+                            </tr>
+                        </table>
+                        <p><span class="glm-required">*</span> Required</p>
+                        <a id="newCategoryCancel" class="button button-primary glm-right">Cancel</a>
+                        <input id="newCategorySubmit" type="submit" value="Add new Category">
+                </div>
+
+                <!-- Category Selection -->
+
+                <select name="categorySelect" id="categorySelect">
+                {if $categories}
+                    <option id="categoryNone" value=""></option>
+                    {foreach $categories as $v}
+                    <option value="{$v.id}">
+                        {$v.name}
+                    </option>
+                    {/foreach}
+                {else}
+                    <option id="" value="">(No Categories Listed - Select "Add a new Category" to the right. )</option>
+                {/if}
+                </select>&nbsp;&nbsp; Select a category to add to box below.<br>
+                <div id="activeCategories" class="glm-dynSelect-box">
+
+                {if isset($coupon.fieldData.categories) && $coupon.fieldData.categories}
+                    {foreach $coupon.fieldData.categories as $c}
+                    <div data-id="{$c.id}" class="glm-dynSelect-item glm-coupons-category">
+                        {$c.name}
+                        <span data-id="{$c.id}" class="glm-dynSelect-delete catDelete">X</span>
+                        <input type="hidden" name="category[{$c.id}]" value="{$c.id}">
+                   </div>
+                    {/foreach}
+                {/if}
+                </div>
+            </td>
+        </tr>
         <tr>
             <th {if $coupon.fieldRequired.start_date}class="glm-required"{/if}>Starting Date:</th>
             <td>
                 // Get the ID, name, and parent of the category
                 var catValue = $('#categorySelect').val();
                 var catName = $('#categorySelect').find(':selected').text();
-                var catParent = $('#categorySelect').find(':selected').attr('data-parent');
 
                 // Check if the category has already been added
                 var found = false;
 
                 // Check if there's a parent
                 parentName = '';
-                if (catParent != '') {
-                    parentName = catParent + ': ';
-                }
 
                 // If not found, Add the category
                 if (!found) {
                 // Get new category information
                 var newCatName = $('#newCatName').val();
                 var newCatParent = $('#newCatParent').val();
-                var catParent = $('#newCatParent').find(':selected').attr('data-parent');
                 var newCatParentName = $('#newCatParentName').val();
 
                 // If there's no name, tell the user we need one.
                 parentName = '';
                 if (newCatParentName && newCatParentName != '') {
                     parentName = newCatParentName + ': ';
-                } else if (catParent && catParent != '') {
-                    parentName = catParent + ': ';
                 }
 
                 // Add the new category to the active categories list
index b270301..d489868 100644 (file)
@@ -64,9 +64,9 @@
                     <th>Coupon Name</th>
                     <th>{$terms.term_member_cap}</th>
                     <th>Status</th>
-                    <th>First Date</th>
-                    <th>Last Date</th>
-                    <th></th>
+                    <th>Start Date</th>
+                    <th>End Date</th>
+                    <th>Expire Date</th>
                 </tr>
             </thead>
             <tbody>
                         {$e.status.name}
                     </td>
                     <td>
-                        {$e.firstDate}
+                        {$e.start_date.date}
                     </td>
                     <td>
-                        {$e.lastDate}
+                        {$e.end_date.date}
                     </td>
                     <td>
-                        <a href="{$siteBaseUrl}coupon-detail/{$e.name_slug}/" target="_blank">View Coupon</a>
+                        {$e.expire.date}
                     </td>
                 </tr>
         {/foreach}