Update db tables.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Nov 2016 18:17:31 +0000 (13:17 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Nov 2016 18:17:31 +0000 (13:17 -0500)
Had some defines not setup correctly for the table name prefixes.
Updated the database now to have a table for the coupon to category
relationship (many to many).
WIP on the edit coupon page.

14 files changed:
classes/data/dataCoupons.php
defines.php
index.php
models/admin/coupons/index.php
models/admin/coupons/list.php [new file with mode: 0644]
models/admin/settings/couponCategories.php
setup/databaseScripts/create_database_V0.0.1.sql [deleted file]
setup/databaseScripts/create_database_V0.0.2.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V0.0.2.sql [new file with mode: 0644]
setup/validActions.php
views/admin/coupons/edit.html [new file with mode: 0644]
views/admin/coupons/list.html [new file with mode: 0644]
views/admin/settings/couponCategories.html

index 2cf4d77..b7637cf 100644 (file)
@@ -85,7 +85,6 @@ class GlmDataCoupons extends GlmDataAbstract
      * @var bool
      * @access public
      */
-    public $postCategories = true;
 
     /**
      * Constructor
@@ -162,23 +161,26 @@ class GlmDataCoupons extends GlmDataAbstract
 
             // Date Start Date
             'start_date' => array(
-                'field' => 'start_date',
-                'type'  => 'date',
-                'use'   => 'a'
+                'field'    => 'start_date',
+                'type'     => 'date',
+                'required' => true,
+                'use'      => 'a'
             ),
 
             // Date End Date
             'end_date' => array(
-                'field' => 'end_date',
-                'type'  => 'date',
-                'use'   => 'a'
+                'field'    => 'end_date',
+                'type'     => 'date',
+                'required' => true,
+                'use'      => 'a'
             ),
 
             // Date Expire Date
             'expire' => array(
-                'field' => 'expire',
-                'type'  => 'date',
-                'use'   => 'a'
+                'field'    => 'expire',
+                'type'     => 'date',
+                'required' => true,
+                'use'      => 'a'
             ),
 
             // Reference Type - Insert new record
@@ -273,26 +275,6 @@ class GlmDataCoupons extends GlmDataAbstract
      */
     public function entryPostProcessing($r, $a)
     {
-
-        // Get Member Category data for this entry
-        if ($this->postCategories) {
-            $sql = "
-                SELECT EC.coupon AS coupon_id, C.id, C.name, C.descr,
-                       COALESCE (
-                            (
-                            SELECT name
-                              FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "categories
-                             WHERE id = C.parent
-                            ), ''
-                       ) AS parent_name
-                  FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "categories AS C,
-                       ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX. "coupon_categories AS EC
-                 WHERE C.id = EC.category
-                   AND EC.coupon = ".$r['id']."
-            ;";
-            $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A);
-        }
-
         return $r;
     }
 
@@ -443,9 +425,6 @@ class GlmDataCoupons extends GlmDataAbstract
     public function getIdName($where = 'true')
     {
         $savedFields = $this->fields;
-        $savedCategories = $this->postCategories;
-
-        $this->postCategories = false;
 
         $this->fields = array(
             'id' => $savedFields['id'],
@@ -455,7 +434,6 @@ class GlmDataCoupons extends GlmDataAbstract
         $r = $this->getList($where);
 
         $this->fields = $savedFields;
-        $this->postCategories = $savedCategories;
 
         return $r;
 
index d430da2..3c50f2e 100644 (file)
@@ -13,7 +13,7 @@ define('GLM_MEMBERS_COUPONS_PLUGIN_SLUG', 'glm-member-db-coupons');
 
 // Database table prefixes - change if using add-on tables
 global $wpdb;
-define('GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX', $wpdb->prefix.'glmMembersCoupons');
+define('GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_membersCoupons_');
 define('GLM_MEMBERS_COUPONS_PLUGIN_ACTIVE_DB_OPTION', 'glmMembersCouponsDbVersion');
 
 // Determine which system we're running on - If not provided, assume PRODUCTION
index f28eda8..1be5c74 100644 (file)
--- a/index.php
+++ b/index.php
@@ -38,7 +38,7 @@
  *  version from this plugin.
  */
 define('GLM_MEMBERS_COUPONS_PLUGIN_VERSION', '0.0.1');
-define('GLM_MEMBERS_COUPONS_PLUGIN_DB_VERSION', '0.0.1');
+define('GLM_MEMBERS_COUPONS_PLUGIN_DB_VERSION', '0.0.2');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
 define('GLM_MEMBERS_COUPONS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0');
index 6205278..89b9e59 100644 (file)
@@ -107,15 +107,13 @@ class GlmMembersAdmin_coupons_index extends GlmDataCoupons
             $lockedWhere = 'ref_type = '.$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$memberID;
         }
 
-        /*
         // Check for required Coupon Categories
-        require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
-        $CouponCategories = new GlmDataCouponsCategories($this->wpdb, $this->config);
+        require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCouponCategories.php';
+        $CouponCategories = new GlmDataCouponCategories($this->wpdb, $this->config);
         $couponCategoriesStats = $CouponCategories->getStats();
         if ($couponCategoriesStats && $couponCategoriesStats > 0) {
             $haveCategories = true;
         }
-         */
 
         // Get full list of names matching this where clause for search box
         $namesList = $this->getIdName($lockedWhereT);
diff --git a/models/admin/coupons/list.php b/models/admin/coupons/list.php
new file mode 100644 (file)
index 0000000..8d3ba50
--- /dev/null
@@ -0,0 +1,623 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Coupons List
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Contacts data class
+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';
+
+class GlmMembersAdmin_coupons_list extends GlmDataCoupons
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Coupon ID
+     *
+     * @var $couponID
+     * @access public
+     */
+    public $couponID = false;
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        /*
+         * Run constructor for the Contacts data class
+         *
+         * Note, the third parameter is a flag that indicates to the Contacts
+         * data class that it should flag a group of fields as 'view_only'.
+         */
+        parent::__construct(false, false, true);
+
+    }
+
+    public function modelAction($actionData = false)
+    {
+
+        $lockedToMember   = false;
+        $numbCoupons       = 0;
+        $option           = 'list';
+        $coupons           = false;
+        $haveCoupons       = false;
+        $coupon            = false;
+        $haveCoupon        = false;
+        $this->couponID    = false;
+        $couponUpdated     = false;
+        $couponUpdateError = false;
+        $couponAdded       = false;
+        $couponAddError    = 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'];
+
+        // 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);
+        if ($lockedToMember) {
+            $memberID = $lockedToMember;
+            $this->fields['admin_name']['required']  = true;
+            $this->fields['admin_email']['required'] = true;
+            $this->fields['admin_phone']['required'] = true;
+
+        // Check for Member Menu Use
+        } elseif (defined('GLM_COUPONS_MEMBER_MENU')) {
+
+            // Try to get member ID
+            $memberID = (isset($_REQUEST['member']) ? $_REQUEST['member'] : 0);
+
+            // If there's no valid member ID, we can't continue
+            if ($memberID == 0) {
+                return array(
+                    'status'           => false,
+                    'menuItemRedirect' => 'error',
+                    'modelRedirect'    => 'index',
+                    'view'             => 'admin/error/index.html',
+                    'data'             => array(
+                        'reason' => 'No member ID was provided.'
+                    )
+                );
+            }
+        }
+
+        // If not a valid member ID
+        if ($memberID > 0) {
+
+            // Get base member information
+            require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
+            $Member     = new GlmDataMembers($this->wpdb, $this->config);
+            $memberData = $Member->getEntry($memberID);
+
+            if (!$memberData) {
+                return array(
+                    'status'           => false,
+                    'menuItemRedirect' => 'error',
+                    'modelRedirect'    => 'index',
+                    'view'             => 'admin/error/index.html',
+                    'data'             => array(
+                        'reason' => 'No member data found for provided member ID.'
+                    )
+                );
+            } else{
+                $haveMember = true;
+                $memberName = $memberData['name'];
+            }
+
+        }
+
+        // Get a list of categories
+        $Categories = new GlmDataCouponCategories($this->wpdb, $this->config);
+        $categories = $Categories->getList(false);
+
+        // Get any provided option
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        // Get coupon ID if supplied
+        if (isset($_REQUEST['coupon'])) {
+
+            // Make sure it's numeric
+            $this->couponID = ($_REQUEST['coupon'] - 0);
+
+            if ($this->couponID <= 0) {
+                $this->couponID = false;
+            }
+
+        }
+
+        // Check for specific_dates submission
+
+        // Do selected option
+        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);
+
+                if ($coupon['status']) {
+                    $haveCoupon = true;
+                    $couponAdded = true;
+
+                    // Update created timestamp and name slug for URLs
+                    $this->updateTimestamp('created', $this->couponID);
+                    $this->updateSlug($this->couponID);
+
+                    // Get this again so we have the created date
+                    $coupon = $this->editEntry($this->couponID);
+
+                    $option = 'edit';
+                    $couponAdded = true;
+
+                } else {
+                    $option = 'add';
+                    $couponAddError = true;
+                }
+
+                $view = 'edit';
+
+                break;
+
+            case 'edit':
+
+                $coupon = $this->editEntry($this->couponID);
+
+                if ($coupon['status']) {
+                    $haveCoupon = true;
+                }
+
+                $view = 'edit';
+                break;
+
+            case 'update':
+
+                // Get the original Coupon Status. Before the update.
+                $old_coupon_status = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT status
+                           FROM " . GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . "coupons
+                          WHERE id = %d",
+                       $this->couponID
+                    )
+                );
+
+                $this->updateCategories();
+                $categories = $Categories->getListSortedParentChild(false);
+
+                if ( $this->config['settings']['use_coupon_amenities'] ) {
+                    $this->updateAmenities();
+                    $amenities = $Amenities->getList(false);
+                }
+
+                // Try to update this coupon
+                $coupon = $this->updateEntry($this->couponID);
+
+                // Check if that was successful
+                if ($coupon['status']) {
+                    $couponUpdated = true;
+
+                    // Check if the coupon is being approved
+                    if ( $coupon['fieldData']['status']['value'] && $old_coupon_status ) {
+                        $new_status = $coupon['fieldData']['status']['value'];
+                        if ( $old_coupon_status == 20 && $new_status == 10 ) {
+                            // Update approved timestamp.
+                            $this->updateTimestamp('approved', $this->couponID);
+                        }
+                    }
+
+                    // Update updated timestamp and name slug for URLs
+                    $this->updateTimestamp('updated', $this->couponID);
+                    $this->updateSlug($this->couponID);
+
+                    $coupon = $this->editEntry($this->couponID);
+                } else {
+                    $couponUpdateError = true;
+                }
+
+                $haveCoupon = true;
+                $view = 'edit';
+
+                break;
+
+            case 'delete':
+
+                $coupon = $this->deleteCoupon($this->couponID);
+
+                if ($coupon) {
+                    $couponDeleted = true;
+                } else {
+                    $couponDeleteError = true;
+                }
+
+            case 'list':
+            default:
+
+                $where = 'true';
+
+                // Check for Archived filter
+                if (isset($_REQUEST['filterArchived']) && $_REQUEST['filterArchived'] == 'on') {
+                    $filterArchived = true;
+                    $where .= " AND status = " . $this->config['status_numb']['Archived'];
+                }
+
+                // Check for Pending filter
+                if (isset($_REQUEST['filterPending']) && $_REQUEST['filterPending'] == 'on') {
+                    $filterPending = true;
+                    $where .= " AND status = " . $this->config['status_numb']['Pending'];
+                }
+
+                // Add "selected" element default false;
+                reset($categories);
+                while (list($k, $v) = each($categories)) {
+                    $categories[$k]['selected'] = false;
+                }
+
+                // Check if there is a category filter (multi-select)
+                if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) {
+
+                    $cats = '';
+                    $catsSep = '';
+
+                    // For each selected category
+                    foreach($_REQUEST['filterCategories'] as $c) {
+                        $cats .= $catsSep.$c;
+                        $catsSep = ',';
+                        $categories[$c]['selected'] = true;
+                    }
+
+                    $where .= " AND id in (
+                            SELECT DISTINCT(EC.coupon)
+                              FROM ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories EC,
+                                   ".GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX."categories C
+                             WHERE (
+                                   EC.category in ($cats)
+                                   OR (C.parent in ($cats) AND EC.category = C.id)
+                                   )
+                    )";
+                }
+
+                // Check if we have a Text Search string
+                if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') {
+                    $textSearch = trim($_REQUEST['textSearch']);
+                    $where .= " AND name LIKE '%$textSearch%'";
+                }
+
+
+                // If we have a From date
+                $dateWhere = '';
+                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' ";
+                }
+
+                // If we have a to Date
+                if (isset($_REQUEST['toDate']) && trim($_REQUEST['toDate']) != '') {
+
+                    $toDate = date('m/d/Y', strtotime($_REQUEST['toDate']));
+                    $toMYSQL = date('Y-m-d', strtotime($toDate." +1 day"));
+
+                    // If we have a from date then we need Parens and AND
+                    if ($dateWhere != '') {
+                        $dateWhere = "( ".$dateWhere." AND start_time <= '$toMYSQL' )";
+
+                    // Otherwise we don't
+                    } else {
+                        $dateWhere = " start_time <= '$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
+                        )
+                    ";
+                }
+
+                // Check if the list is for a specific member
+                if (defined('GLM_COUPONS_MEMBER_MENU') || $memberID) {
+                    $where .= " AND ref_dest = $memberID";
+                }
+
+                // Get the total number of coupons listed
+                $numbCoupons = $this->getStats($where);
+
+                // If the number of coupons is less than a page, don't do paging
+                if ($numbCoupons <= $limit) {
+                    $paging = false;
+                }
+
+                // Get full list of names matching this where clause for search box
+                $namesList = $this->getIdName($where);
+
+                // Check if we're doing paging
+                if (isset($_REQUEST['pageSelect'])) {
+
+                    // If request is for Next
+                    if ($_REQUEST['pageSelect'][0] == 'N') {
+                        $newStart = $_REQUEST['nextStart'] - 0;
+
+                    // Otherwise it must be Previous
+                    } else {
+                        $newStart = $_REQUEST['prevStart'] - 0;
+                    }
+
+                    if ($newStart > 0) {
+                        $start = $newStart;
+                    }
+                }
+
+                // Get the list of coupons and determine number of coupons in list
+                //$saveFLT = $this->postFirstAndLastTimes;
+                //$this->postFirstAndLastTimes = true;
+                $couponsResult = $this->getList($where, 'name', true, 'id', $start, $limit);
+                //$this->postFirstAndLastTimes = $saveFLT;
+
+                // Get paging results
+                $numbDisplayed = $couponsResult['returned'];
+                $lastDisplayed = $couponsResult['last'];
+                if ($start == 1) {
+                    $prevStart = false;
+                } else {
+                    $prevStart = $start - $limit;
+                    if ($start < 1) {
+                        $start = 1;
+                    }
+                }
+                if ($couponsResult['returned'] == $limit) {
+                    $nextStart = $start + $limit;
+                }
+
+                // since we're doing paging, we have to break out just the coupons data
+                $coupons = $couponsResult['list'];
+                if (count($coupons)>0) {
+                    $haveCoupons = true;
+                }
+                unset($couponsResult);
+
+                break;
+
+        }
+        //
+        // If we have an coupon ID
+        if ($this->couponID) {
+
+        }
+        $templateData = array(
+            '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,
+            'categories'        => $categories,
+            'fromDate'          => $fromDate,
+            'toDate'            => $toDate,
+            'filterArchived'    => $filterArchived,
+            'filterPending'     => $filterPending,
+            'couponDeleted'      => $couponDeleted,
+            'couponDeleteError'  => $couponDeleteError,
+            'locations'         => $locations,
+            'haveLocations'     => $haveLocations,
+            'numbLocations'     => $numbLocations,
+            'memberID'          => $memberID,
+            'haveMember'        => $haveMember,
+            'memberName'        => $memberName,
+            'memberData'        => $memberData,
+            'numbDisplayed'     => $numbDisplayed,
+            'lastDisplayed'     => $lastDisplayed,
+            'paging'            => $paging,
+            'prevStart'         => $prevStart,
+            'nextStart'         => $nextStart,
+            'start'             => $start = 1,
+            'limit'             => $limit,
+            'namesList'         => $namesList,
+
+        );
+
+        // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => "admin/coupons/$view.html",
+            'data'          => $templateData
+        );
+
+    }
+
+    /**
+     * Update categories for the current submission
+     *
+     * @return void
+     */
+    public function updateCategories()
+    {
+
+        // Instatiate the dataCategories class
+        $Categories = new GlmDataCouponsCategories($this->wpdb, $this->config);
+
+        // Instatiate Coupon/Categories data class
+        $CouponCategories = new GlmDataCouponsCouponCategories($this->wpdb, $this->config);
+
+        // Get any selected categories
+        $selectedCategories = array();
+        $newCategory = false;
+        if (isset($_REQUEST['category']) && is_array($_REQUEST['category']) && count($_REQUEST['category']) > 0) {
+
+            /*
+             *  For each selected category
+             *
+             *  Note that categories are submitted with either a positive key, which indicates
+             *  that it represents an existing category, or a negative key, which indicates
+             *  that the user is trying to add it to the list of categories.
+             *
+             */
+            foreach ($_REQUEST['category'] as $key) {
+
+                // Make sure key is an integer
+                $key = intval($key -0);
+
+                // If negative, this is a new category that needs to be added to the category table
+                if ($key < 0) {
+
+                    $newCategory = true;
+
+                    // Check if a parent is specified
+                    $parent = 0;
+                    if ($_REQUEST['newCatParent'][$key] != '') {
+                        $parent = $_REQUEST['newCatParent'][$key] -0;
+                    } elseif ($_REQUEST['newCatParentName'][$key]) {
+                        $parent = $_REQUEST['newCatParentName'][$key];
+                    }
+
+                    // Clean up the category name
+                    $category = filter_var($_REQUEST['newCategory'][$key]);
+
+                    // Add it to the category table and get the new category ID
+                    $categoryID = $Categories->addCategory($category, $parent);
+
+                    // If we got a new category ID, add it to the array of currently selected couponCategory records
+                    if ($categoryID) {
+                        $selectedCategories[$categoryID] = $categoryID;
+                    }
+
+                    // Otherwise if it's positive, the category is an existing one
+                } else if ($key > 0) {
+
+                    $selectedCategories[$key] = $key;
+
+                }
+
+                // If there's selected categories
+                if (count($selectedCategories) > 0) {
+
+                    // Update the selected categories for this coupon record, returns new list
+                    $CouponCategories->setCouponCategories($this->couponID, $selectedCategories);
+
+                }
+
+                // If there's been a new category
+                if ($newCategory) {
+
+                    // Get the full category list again
+                    $this->categories = $Categories->getListSortedParentChild();
+
+                }
+
+            } // For each category being submitted
+
+            // Otherwise if this is a submission and there's no categories submitted, so make sure there's none stored
+        } elseif ( isset($_REQUEST['option']) && ( $_REQUEST['option'] === 'submit' || $_REQUEST['option'] === 'update' ) ) {
+            $CouponCategories->clearCouponCategories($this->couponID);
+        }
+
+    }
+
+}
index 45e80be..ef3bccb 100644 (file)
@@ -38,7 +38,7 @@ class GlmMembersAdmin_settings_couponCategories extends GlmDataCouponCategories
      */
     public $config;
 
-    /*
+    /**
      * Constructor
      *
      * This contructor sets up this model. At this time that only includes
@@ -61,7 +61,7 @@ class GlmMembersAdmin_settings_couponCategories extends GlmDataCouponCategories
 
     }
 
-    /*
+    /**
      * Perform Model Action
      *
      * This method does the work for this model and returns any resulting data
@@ -128,14 +128,6 @@ class GlmMembersAdmin_settings_couponCategories extends GlmDataCouponCategories
                 case 'delete':
                     if ($id > 0) {
                         $this->deleteEntry($id, true);
-
-                        // Also delete from member info
-                        $this->wpdb->delete(
-                            GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . 'coupon_categories',
-                            array(
-                                'category' => $id
-                            )
-                        );
                     }
                     break;
 
diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql
deleted file mode 100644 (file)
index d916acf..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
--- Gaslight Media Members Database - Coupons Add-On
--- File Created: 11/15/16
--- Database Version: 0.0.1
--- Database Creation Script
---
--- This file is called to create a new set of tables for this
--- add-on for the most recent database version for this add-on.
---
--- There should only be one such file in this directory
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
-
--- Coupons
-CREATE TABLE {prefix}coupons (
-    id INT NOT NULL AUTO_INCREMENT,
-    status INT NULL,                  -- Status of the Coupon (Active Pending)
-    created DATETIME NULL,            -- Create date
-    updated DATETIME NULL,            -- Update date
-    approved DATETIME NULL,           -- Approved date
-    start_date DATE NULL,               -- Starting date of the coupon
-    end_date DATE NULL,                 -- Ending date of the coupon
-    expire DATE NULL,                 -- Expire date of the coupon
-    name TINYTEXT NULL,               -- Coupon name
-    name_slug TINYTEXT NULL,          -- Coupon name slug
-    ref_type INT NULL,                -- Ref type
-    ref_dest INT NULL,                -- Id from ref type table
-    descr TEXT NULL,                  -- Description of the coupon
-    image TINYTEXT NULL,              -- Coupon image
-    url TINYTEXT NULL,                -- website of the coupon
-    PRIMARY KEY(id),
-    INDEX(ref_type),
-    INDEX(ref_dest),
-    INDEX(start_date),
-    INDEX(end_date)
-);
-
-----
-
--- Categories
-CREATE TABLE {prefix}categories (
-    id INT NOT NULL AUTO_INCREMENT,
-    name TINYTEXT NULL,               -- Category Name
-    PRIMARY KEY (id),
-    INDEX(name(20))
-);
-
-----
-
--- Settings
-CREATE TABLE {prefix}settings (
-    id INT NOT NULL AUTO_INCREMENT,
-    notify_to TINYTEXT NULL,          -- To for the notify email
-    notify_from TINYTEXT NULL,        -- From header for notify email
-    notify_message TEXT NULL,         -- Message to add to the notify email
-    PRIMARY KEY (id)
-);
-
-----
-
--- Data for Settings
-INSERT INTO {prefix}settings
-(id,notify_to,notify_from,notify_message)
-VALUES
-(1, '', '', '');
diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.2.sql
new file mode 100644 (file)
index 0000000..d309c90
--- /dev/null
@@ -0,0 +1,78 @@
+-- Gaslight Media Members Database - Coupons Add-On
+-- File Created: 11/15/16
+-- Database Version: 0.0.2
+-- Database Creation Script
+--
+-- This file is called to create a new set of tables for this
+-- add-on for the most recent database version for this add-on.
+--
+-- There should only be one such file in this directory
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+-- Coupons
+CREATE TABLE {prefix}coupons (
+    id INT NOT NULL AUTO_INCREMENT,
+    status INT NULL,                  -- Status of the Coupon (Active Pending)
+    created DATETIME NULL,            -- Create date
+    updated DATETIME NULL,            -- Update date
+    approved DATETIME NULL,           -- Approved date
+    start_date DATE NULL,               -- Starting date of the coupon
+    end_date DATE NULL,                 -- Ending date of the coupon
+    expire DATE NULL,                 -- Expire date of the coupon
+    name TINYTEXT NULL,               -- Coupon name
+    name_slug TINYTEXT NULL,          -- Coupon name slug
+    ref_type INT NULL,                -- Ref type
+    ref_dest INT NULL,                -- Id from ref type table
+    descr TEXT NULL,                  -- Description of the coupon
+    image TINYTEXT NULL,              -- Coupon image
+    url TINYTEXT NULL,                -- website of the coupon
+    PRIMARY KEY(id),
+    INDEX(ref_type),
+    INDEX(ref_dest),
+    INDEX(start_date),
+    INDEX(end_date)
+);
+
+----
+
+-- Categories
+CREATE TABLE {prefix}categories (
+    id INT NOT NULL AUTO_INCREMENT,
+    name TINYTEXT NULL,               -- Category Name
+    PRIMARY KEY (id),
+    INDEX(name(20))
+);
+
+----
+
+-- Coupon-Category - Categories for specific coupon records
+CREATE TABLE {prefix}coupon_categories (
+    id INT NOT NULL AUTO_INCREMENT,
+    coupon INT NULL,                  -- Pointer to the coupon
+    category INT NULL,                -- Pointer to the category
+    PRIMARY KEY (id),
+    INDEX(coupon),
+    INDEX(category)
+);
+
+----
+
+-- Settings
+CREATE TABLE {prefix}settings (
+    id INT NOT NULL AUTO_INCREMENT,
+    notify_to TINYTEXT NULL,          -- To for the notify email
+    notify_from TINYTEXT NULL,        -- From header for notify email
+    notify_message TEXT NULL,         -- Message to add to the notify email
+    PRIMARY KEY (id)
+);
+
+----
+
+-- Data for Settings
+INSERT INTO {prefix}settings
+(id,notify_to,notify_from,notify_message)
+VALUES
+(1, '', '', '');
index 03688e7..8f3f69c 100644 (file)
@@ -15,5 +15,6 @@
 
 $glmMembersCouponsDbVersions = array(
     '0.0.1' => array('version' => '0.0.1', 'tables' => 3),
+    '0.0.2' => array('version' => '0.0.2', 'tables' => 4),
 );
 
diff --git a/setup/databaseScripts/update_database_V0.0.2.sql b/setup/databaseScripts/update_database_V0.0.2.sql
new file mode 100644 (file)
index 0000000..952023a
--- /dev/null
@@ -0,0 +1,18 @@
+-- Gaslight Media Members Database  - Coupons Add-On
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 0.0.2
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashses
+
+
+-- Coupon-Category - Categories for specific coupon records
+CREATE TABLE {prefix}coupon_categories (
+    id INT NOT NULL AUTO_INCREMENT,
+    coupon INT NULL,                  -- Pointer to the coupon
+    category INT NULL,                -- Pointer to the category
+    PRIMARY KEY (id),
+    INDEX(coupon),
+    INDEX(category)
+);
index 3e1a9b5..0129c0e 100644 (file)
@@ -33,7 +33,8 @@
 $glmMembersCouponsAddOnValidActions = array(
     'adminActions' => array(
         'coupons' => array(
-            'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG
+            'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
+            'list' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
         ),
         'dashboard' => array(
             'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
diff --git a/views/admin/coupons/edit.html b/views/admin/coupons/edit.html
new file mode 100644 (file)
index 0000000..bf863e0
--- /dev/null
@@ -0,0 +1,448 @@
+{if $haveMember && !$lockedToMember }
+    {include file='admin/member/header.html'}
+{else}
+    {include file='admin/coupons/header.html'}
+{/if}
+
+{if apply_filters('glm_members_permit_admin_member_coupon', true)}
+
+  {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}
+    <a href="{$thisUrl}?page={$thisPage}&glm_action=list" class="button button-secondary glm-button glm-right">Return to Coupons List</a>
+  {/if}
+
+  {if $option == 'edit' || $option == 'update'}
+    <a id="deleteCouponButton" class="button button-secondary glm-button glm-right">Delete this Coupon</a>
+    <h2>Edit Coupon</h2>
+  {else}
+    <h2>Add new Coupon</h2>
+  {/if}
+
+  {if $haveMember && !$lockedToMember}
+    <form action="{$thisUrl}?page=glm-members-admin-menu-member" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="glm_action" value="coupons">
+  {else}
+    {if $lockedToMember}
+    <form action="{$thisUrl}?page=glm-members-admin-menu-coupons-list" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="glm_action" value="list">
+    {else}
+    <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="glm_action" value="list">
+
+    {/if}
+  {/if}
+        <input type="hidden" name="ref_type" value="{$ref_type_numb.Member}">
+    {if $haveMember}
+        <input type="hidden" name="member" value="{$memberID}">
+    {/if}
+    {if $haveCoupon}
+        <input type="hidden" name="option" value="update">
+        <input type="hidden" name="coupon" value="{$coupon.fieldData.id}">
+    {else}
+        <input type="hidden" name="option" value="insert">
+    {/if}
+
+    <table id="glm-table-descr" class="glm-admin-table glm-coupon-table">
+        {if $haveCoupon}
+            <tr>
+                <th>Name for URLs:</th>
+                <td>{$coupon.fieldData.name_slug}</td>
+            </tr>
+            <tr>
+                <th>Created:</th>
+                <td>{$coupon.fieldData.created.datetime}</td>
+            </tr>
+            <tr>
+                <th>Last Updated:</th>
+                <td>{$coupon.fieldData.updated.datetime}</td>
+            </tr>
+            <tr>
+                <th>Last Approved:</th>
+                <td>{$coupon.fieldData.approved.datetime}</td>
+            </tr>
+        {/if}
+        {if !$lockedToMember}
+        <tr>
+            <th>Status:</th>
+            <td>
+                <select name="status">
+                    {foreach $coupon.fieldData.status.list as $v}
+                        <option value="{$v.value}"{if $v.default} selected{/if}>{$v.name}</option>
+                    {/foreach}
+                </select>
+                {if $coupon.fieldFail.status}<p>{$coupon.fieldFail.status}</p>{/if}
+            </td>
+        </tr>
+        {/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}>
+                <input type="text" name="name" value="{$coupon.fieldData.name|escape}" class="glm-form-text-input-medium" placeholder="Name of this coupon.">
+                {if $coupon.fieldFail.name}<p>{$coupon.fieldFail.name}</p>{/if}<br>
+            </td>
+        </tr>
+        <tr>
+            <th {if $coupon.fieldRequired.start_date}class="glm-required"{/if}>Starting Date:</th>
+            <td>
+                <input data-id="{$coupon.fieldData.id}" type="text" name="start_date" value="{$coupon.fieldData.start_date.date}" class="glm-form-text-input-small glm-date-input recurrence-input" placeholder="Click to Select Date">
+            </td>
+        </tr>
+        <tr>
+            <th {if $coupon.fieldRequired.end_date}class="glm-required"{/if}>Ending Date:</th>
+            <td>
+                <input data-id="{$coupon.fieldData.id}" type="text" name="end_date" value="{$coupon.fieldData.end_date.date}" class="glm-form-text-input-small glm-date-input recurrence-input" placeholder="Click to Select Date">
+            </td>
+        </tr>
+        <tr>
+            <th {if $coupon.fieldRequired.expire}class="glm-required"{/if}>Expire Date:</th>
+            <td>
+                <input data-id="{$coupon.fieldData.id}" type="text" name="expire" value="{$coupon.fieldData.expire.date}" class="glm-form-text-input-small glm-date-input recurrence-input" placeholder="Click to Select Date">
+            </td>
+        </tr>
+        <tr>
+            <th {if $coupon.fieldRequired.descr}class="glm-required"{/if}>Coupon Text:</th>
+            <td {if $coupon.fieldFail.descr}class="glm-form-bad-input" data-tabid="glm-coupon-descr"{/if}>
+                <textarea
+                    name="descr"
+                    class="glm-form-text-input glm-char-count"
+                    data-msgArea="descr-text-msg"
+                    maxlength="600">{$coupon.fieldData.descr}</textarea>
+                <br><span id="descr-text-msg"></span>
+                {if $coupon.fieldFail.descr}<p>{$coupon.fieldFail.descr}</p>{/if}
+            </td>
+        </tr>
+        <tr>
+            <th {if $coupon.fieldRequired.image}class="glm-required"{/if}>Image:</th>
+            <td {if $coupon.fieldFail.image}class="glm-form-bad-input"{/if}>
+                <table class="glm-admin-image-edit-table">
+    {if $coupon.fieldData.image}
+                    <tr>
+                        <td>
+                            <div class="glm-galleryImage" data-id="image">
+                                <img src="{$glmPluginMediaUrl}/images/small/{$coupon.fieldData.image}">
+                            </div>
+                        </td>
+                        <td>
+                            <input type="checkbox" name="image_delete"> Delete Image<br>
+                            {$coupon.fieldData.image}<br>
+                        </td>
+                    </tr>
+    {/if}
+                    <tr><td colspan="2"><b>New image:</b> <input type="file" name="image_new"></td></tr>
+                </table>
+                <div id="glm-galleryImageLarger_image" class="glm-imageDialog">
+                    {if $coupon.fieldData.image}
+                    <img src="{$glmPluginMediaUrl}/images/large/{$coupon.fieldData.image}">
+                    {/if}
+                </div>
+                {if $coupon.fieldFail.image}<p>{$coupon.fieldFail.image}</p>{/if}
+                <p>
+                    Best image size to provide is between 500 and 700 pixels wide and stored as a JPG or JPEG file.
+                    Also try to supply images that have a reasonable "aspect ratio" (not too tall, not too wide).
+                    Files provided like this should have a file size of 100 to 250 KB. Images will be automatically
+                    resized for use in the Web site. Images that are too large will be rejected.
+                </p>
+            </td>
+        </tr>
+        <tr>
+            <th {if $coupon.fieldRequired.url}class="glm-required"{/if}>Web Address (URL):</th>
+            <td {if $coupon.fieldFail.url}class="glm-form-bad-input" data-tabid="glm-coupon-descr"{/if}>
+                <input type="text" name="url" value="{$coupon.fieldData.url}" class="glm-form-text-input-medium" placeholder="ex: http://www.gaslightmedia.com">
+                {if $coupon.fieldFail.url}<p>{$coupon.fieldFail.url}</p>{/if}<br>
+            </td>
+        </tr>
+    </table>
+
+
+        <input id="updateCoupon" type="submit" value="{if $haveCoupon}Update Coupon{else}Save New Coupon{/if}">
+
+    </form>
+
+{else} <!-- Can just display -->
+
+    <table class="glm-admin-table">
+        <tr><th>Name:</th><td>{$coupon.fieldData.name}</td></tr>
+    </table>
+
+{/if}
+
+    <!-- Delete Coupon Dialog Box -->
+
+    <div id="deleteCouponDialog" class="glm-dialog-box" title="Delete Coupon">
+        <center>
+            <p><a id="deleteCouponCancel" class="button button-primary">Cancel</a></p>
+            <p><input id="deleteCouponSubmit" type="submit" value="Delete this coupon"></p>
+        </center>
+        <div class="glm-item-container">
+            <p><center><span class="glm-error">WARNING:</span></center></p>
+            <p>
+                <span class="glm-warning">Clicking the "Delete this Coupon" button above will
+                delete all of the data and images associated with this coupon.
+                </span>
+            </p>
+            <p>
+                <span class="glm-error">
+                    Once deleted, this information will no longer be available and cannot be retrieved!
+                    If you are unsure that you want to completely remove this data, consider changing the status
+                    of this coupon to "Archived" instead.
+                </span>
+            </p>
+        </div>
+    </div>
+    <script type="text/javascript">
+        jQuery(document).ready(function($) {
+            /*
+             * General Coupon Actions
+             */
+
+            // Add Coupon Button Action
+            $('#addCouponButton').click( function() {
+                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=list&option=add";
+            });
+
+            {if $haveCoupon}
+                // Delete Coupon dialog
+                $("#deleteCouponDialog").dialog({
+                    autoOpen: false,
+                    minWidth: 400,
+                    dialogClass: "glm-dialog-no-close"
+                });
+                $('#deleteCouponButton').click( function() {
+                    $('#deleteCouponDialog').dialog('open');
+                });
+                $('#deleteCouponCancel').click( function() {
+                    $("#deleteCouponDialog").dialog("close");
+                });
+                $('#deleteCouponSubmit').click( function() {
+                {if $haveMember}
+                    window.location.replace("{$thisUrl}?page=glm-members-admin-menu-member&glm_action=coupons&option=delete&member={$memberID}&coupon={$coupon.fieldData.id}");
+                {else}
+                    window.location.replace("{$thisUrl}?page={$thisPage}&glm_action=list&option=delete&coupon={$coupon.fieldData.id}");
+                {/if}
+                });
+            {/if}
+
+                // Date Only Pickers
+                $('.glm-date-input').datetimepicker({
+                    format: 'm/d/Y',
+                    lang: 'en',
+                    step: 15,
+                    closeOnWithoutClick: true,
+                    timepicker: false
+                });
+
+            /*
+             * Category Selection
+             */
+
+            // Action to select a category
+            $('#categorySelect').change( function() {
+
+                // 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;
+                $(".glm-coupons-category").each( function() {
+                    var id = $(this).attr('data-id');
+                    if (id == catValue) {
+                        found = true;
+                    }
+                });
+
+                // Check if there's a parent
+                parentName = '';
+                if (catParent != '') {
+                    parentName = catParent + ': ';
+                }
+
+                // If not found, Add the category
+                if (!found) {
+                    $('#activeCategories').append('<div data-id="' + catValue
+                            + '" class="glm-dynSelect-item glm-coupons-category">'
+                            + parentName + catName.trim() + ' <span class="glm-dynSelect-delete catDelete">X</span>'
+                            + '<input type="hidden" name="category[' + catValue + ']" value="' + catValue + '"></div>');
+                }
+
+                // Reset picklist
+                $('#categorySelect').val('');
+
+            });
+
+            // Action to de-select a category
+            $('.catDelete').live('click', function() {
+                $(this).parent().remove();
+            });
+
+            /*
+             * New Category Dialog
+             */
+
+            var newCat = 0;    // Used for new category numbering (new cats are negative numbers)
+
+            // Setup dialog box for adding a new category
+            $("#newCategoryDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+
+            // Ad a new category button action - pop-up dialog
+            $('#newCategoryButton').click( function() {
+                $("#newCategoryDialog").dialog("open");
+            });
+
+            // Submit new category
+             $('#newCategorySubmit').click( function() {
+
+                // Assign new cat number
+                newCat--;
+
+                // 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.
+                if (newCatName == '') {
+                    $('#newCatNameTD').addClass('glm-form-bad-input');
+                    $('#newCatNameRequired').text('A category name is required!');
+                    return false;
+                }
+
+                // Check if there's a parent, get the name - new parent name overrides selected parent
+                parentName = '';
+                if (newCatParentName && newCatParentName != '') {
+                    parentName = newCatParentName + ': ';
+                } else if (catParent && catParent != '') {
+                    parentName = catParent + ': ';
+                }
+
+                // Add the new category to the active categories list
+                $('#activeCategories').append('<div data-id="' + newCat
+                        + '" class="glm-dynSelect-item glm-coupons-category">'
+                        + parentName + newCatName.trim() + ' <span data-id="' + newCat + '" class="glm-dynSelect-delete catDelete">X</span>'
+                        + '<input type="hidden" name="category[' + newCat + ']" value="' + newCat + '">'
+                        + '<input type="hidden" name="newCategory[' + newCat + ']" value="' + newCatName + '">'
+                        + '<input type="hidden" name="newCatParent[' + newCat + ']" value="' + newCatParent + '">'
+                        + '<input type="hidden" name="newCatParentName[' + newCat + ']" value="' + newCatParentName + '">'
+                        + '</div>');
+
+                // Clear the dialog input fields
+                $('#newCatName').val('');
+                $('#newCatParent').val('');
+                $('#newCatParentName').val('');
+
+                $("#newCategoryDialog").dialog("close");
+
+            });
+            $('#newCategoryCancel').click( function() {
+                $("#newCategoryDialog").dialog("close");
+            });
+
+            // Setup dialog box for adding a new category
+            $("#newCategoryDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+
+            // Action to de-select a amenity
+            $('.amenityDelete').live('click', function() {
+                $(this).parent().remove();
+            });
+
+            // Check for any field errors and if found change related tab to error color.
+            $('.glm-form-bad-input').each( function(index) {
+
+                tab = $(this).attr('data-tabid');
+
+                if (!$('#' + tab).hasClass('glm-bad-input-area')) {
+                    $('#' + tab).addClass('glm-bad-input-area');
+                }
+            });
+
+            // Check for most input changes
+            $('input, textarea, select').on( 'change', function() {
+                glmPageUpdateRequired();
+            });
+
+            /*
+             * Checks for leaving the page
+             */
+            var glmSubmitRequired = false;
+
+            // Flag submit button when updates are required.
+            function glmPageUpdateRequired() {
+                $('#updateCoupon').addClass('glm-bad-input-area');
+                glmSubmitRequired = true;
+            }
+            // When submit button is clicked, disable the beforeunload message
+            $('#updateCoupon').on('click', function() {
+                glmSubmitRequired = false;
+                return true;
+            });
+
+            // If submit is required and we're laving the page, alert the user
+            $(window).bind('beforeunload', function() {
+                if (glmSubmitRequired) {
+
+                    return true;
+                }
+            });
+
+           //show error if location can't be found
+           function showError() {
+               alert("Location can't be found");
+           }
+
+            /*
+             * Google Maps
+             *  API reference: https://developers.google.com/maps/documentation/javascript/reference
+             */
+            var map = new Object();
+            var geocoder = new Object();
+            var location = new Object();
+            var marker = new Object();
+
+            /*
+             * Misc support items
+             */
+
+            // Display number of characters remaining in limited field
+            function glmCharsRemaining(f) {
+                var maxChar = f.attr('maxlength');
+                var len = f.val().length;
+                var rem = maxChar - len;
+                var msgArea = f.attr('data-msgArea');
+                if (rem < 0) {
+                    rem = rem * -1;
+                    $('#' + msgArea).html('<span class="glm-error">There are ' + rem + ' more characters than permitted</span>');
+                } else {
+                    $('#' + msgArea).html('Characters remaining: ' + rem);
+                }
+            }
+
+            // Setup initial fields using limited character counts
+            $('.glm-char-count').each( function() {
+                glmCharsRemaining($(this));
+            });
+
+            // Count remaining characters in field
+            $('.glm-char-count').keyup( function() {
+                glmCharsRemaining($(this));
+            });
+
+
+            // Flash certain elements for a short time after display
+            $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+        });
+    </script>
+
+
+{include file='admin/footer.html'}
diff --git a/views/admin/coupons/list.html b/views/admin/coupons/list.html
new file mode 100644 (file)
index 0000000..b270301
--- /dev/null
@@ -0,0 +1,186 @@
+{if $haveMember && !$lockedToMember}
+    {include file='admin/member/header.html'}
+{else}
+    {include file='admin/coupons/header.html'}
+{/if}
+
+{if apply_filters('glm_members_permit_admin_coupons_index_add_coupon', true)}
+    <h2 style="margin-bottom: 1em;">
+      {if $haveMember} {* This is if we're processing coupons for a specific member *}
+        <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=coupons&option=add&member={$memberID}" class="button button-secondary glm-button glm-right">Add A New Coupon</a>
+      {else}
+        <a href="{$thisUrl}?page={$thisPage}&glm_action=list&option=add" class="button button-secondary glm-button glm-right">Add A New Coupon</a>
+      {/if}
+        {if $couponDeleted}<span class="glm-notice glm-flash-updated glm-right">Coupon Deleted</span>{/if}
+        {if $couponDeleteError}<span class="glm-error glm-flash-updated glm-right">Coupon Delete Error</span>{/if}
+    </h2>
+{/if}
+
+    <form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
+        <input type="hidden" name="glm_action" value="list">
+        <input type="hidden" name="prevStart" value="{$prevStart}">
+        <input type="hidden" name="nextStart" value="{$nextStart}">
+        <input type="hidden" name="limit" value="{$limit}">
+        <div class="">
+            <p>
+                <span class="glm-nowrap">
+                    <b>From Date: </b><input type="text" name="fromDate" value="{$fromDate}" class="glm-form-text-input-short glm-date-input">
+                    <b>To Date: </b><input type="text" name="toDate" value="{$toDate}" class="glm-form-text-input-short glm-date-input">
+                </span>
+                <span class="glm-nowrap">
+                    <b>Categories:&nbsp;</b>
+                    <select id="filterCategories" name="filterCategories[]" multiple="multiple" size="1">
+                    {foreach from=$categories item=v}
+                        <option value="{$v.id}" {if $v.selected} selected{/if}>
+                            {$v.name}
+                        </option>
+                    {/foreach}
+                    </select>
+                </span>
+                <span class="glm-nowrap">
+                    <b>Show Archived Only: </b><input type="checkbox" id="filterArchived" name="filterArchived" class="listFilter"{if $filterArchived} checked{/if} style="margin-right: 1em;">
+                    <b>Show Pending Only: </b><input type="checkbox" id="filterPending" name="filterPending" class="listFilter"{if $filterPending} checked{/if} style="margin-right: 1em;">
+                </span>
+                <span class="glm-nowrap">
+                    <b>Text Search: </b><input  id="glmCouponsSearch" name="textSearch" type="text" id="autoTest">
+                    <input type="submit" value="Submit">
+                </span>
+            <p>
+        </div>
+        <br clear="all">
+
+    <p><b>Total found:</b> {$numbCoupons}&nbsp;&nbsp;</p>
+
+
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Coupons" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Coupons" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+
+        <table class="wp-list-table striped glm-admin-table">
+            <thead>
+                <tr>
+                    <th>ID</th>
+                    <th>Coupon Name</th>
+                    <th>{$terms.term_member_cap}</th>
+                    <th>Status</th>
+                    <th>First Date</th>
+                    <th>Last Date</th>
+                    <th></th>
+                </tr>
+            </thead>
+            <tbody>
+    {if $haveCoupons}
+        {assign var="i" value="0"}
+        {foreach $coupons as $e}
+            {if $i++ is odd by 1}
+                <tr>
+            {else}
+                <tr class="alternate">
+            {/if}
+                    <td>
+                        {$e.id}
+                    </td>
+                    <td class="glm-nowrap">
+                {if $haveMember}
+                  {if $lockedToMember}
+                        <a href="{$thisUrl}?page=glm-members-admin-menu-coupons-list&glm_action=list&member={$memberID}&option=edit&coupon={$e.id}">{$e.name}</a>
+                  {else}
+                        <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=coupons&member={$memberID}&option=edit&coupon={$e.id}">{$e.name}</a>
+                  {/if}
+                {else}
+                        <a href="{$thisUrl}?page={$thisPage}&glm_action=list&option=edit&coupon={$e.id}">{$e.name}</a>
+                {/if}
+                    </td>
+                    <td class="glm-nowrap">
+                        {$e.ref_dest}
+                    </td>
+                    <td class="glm-nowrap">
+                        {$e.status.name}
+                    </td>
+                    <td>
+                        {$e.firstDate}
+                    </td>
+                    <td>
+                        {$e.lastDate}
+                    </td>
+                    <td>
+                        <a href="{$siteBaseUrl}coupon-detail/{$e.name_slug}/" target="_blank">View Coupon</a>
+                    </td>
+                </tr>
+        {/foreach}
+    {else}
+                <tr class="alternate"><td colspan="2">(no coupons listed)</td></tr>
+    {/if}
+            </tbody>
+        </table>
+
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Coupons" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Coupons" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+
+    </form>
+
+    <script type="text/javascript">
+        jQuery(document).ready(function($) {
+
+            // Add Coupon Button Action
+            $('#addCouponButton').click( function() {
+                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=list&option=add";
+            });
+
+            // Date Input
+            $('.glm-date-input').datepicker();
+
+            // Flash certain elements for a short time after display
+            $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+            // Filter triggers
+
+            $("#filterArchived").on('click', function() {
+                $("#filterPending").attr('checked', false);
+            });
+
+            $("#filterPending").on('click', function() {
+                $("#filterArchived").attr('checked', false);
+            });
+            /*
+             * Do autocomplete search for member
+             * label: What will be searched
+             * value: What will be displayed when selected
+             * id: Member id added so we can go to the member while showing what was selected
+             * Also note that autocomplete does not properly render HTML codes, so we
+             * "unescape" them for HTML in Smarty.
+             */
+
+             var availableTags = [
+    {foreach $namesList as $e}
+                { label: "{$e.name|replace:'"':"'"}", value: "{$e.name|replace:'"':"'"}", id: '{$e.id}' },
+    {/foreach}
+             ];
+
+             $( "#glmCouponsSearch" ).autocomplete({
+                 source: availableTags,
+                 html: true,
+                 position: { my : "right top", at: "right bottom" },
+                 select: function( coupon, ui ) {
+                     var couponID = ui.item.id;
+                     window.location.replace("{$adminUrl}?page=glm-members-admin-menu-coupons-index&glm_action=list&option=edit&coupon=" + couponID );
+                 },
+                 response: function(coupon, ui) {
+                     if (!ui.content.length) {
+                         var noResult = { value:"",label:"No results found" };
+                         ui.content.push(noResult);
+                     }
+                 }
+             });
+
+             // Expand multi-select on hover
+             $('#filterCategories').multiselect();
+
+        });
+    </script>
+
+
+{include file='admin/footer.html'}
index 7f4be05..cd6bf38 100644 (file)
                         <input type="text" name="name" class="glm-form-text-input">
                     </td>
                 </tr>
-                <tr>
-                    <th>Parent Category:</th>
-                    <td>
-                        <select name="parent">
-                            <option value="0">(none)</option>
-            {if $haveCategories}
-                {foreach $categories as $t}
-                    {if !$t.parent.value} <!-- don't show child categories -->
-                            <option value="{$t.id}">{$t.name}</option>
-                    {/if}
-                {/foreach}
-            {/if}
-                        </select>
-                    </td>
-                </tr>
-                <tr>
-                    <th>Description:</th>
-                    <td>
-                        <textarea name="descr" class="glm-form-textarea"></textarea>
-                    </td>
-                </tr>
             </table>
             <p><span class="glm-required">*</span> Required</p>
             <a id="newCategoryCancel" class="button button-primary glm-right">Cancel</a>
                         <input id="editCategoryName" type="text" name="name" class="glm-form-text-input">
                     </td>
                 </tr>
-                <tr>
-                    <th>Parent Category:</th>
-                    <td>
-                        <select id="editCategoryParent" name="parent">
-                            <option value="0">(none)</option>
-            {if $haveCategories}
-                {foreach $categories as $t}
-                    {if !$t.parent.value} <!-- don't show child categories -->
-                            <option value="{$t.id}">{$t.name}</option>
-                    {/if}
-                {/foreach}
-            {/if}
-                        </select>
-                    </td>
-                </tr>
-                <tr>
-                    <th>Description:</th>
-                    <td>
-                        <textarea id="editCategoryDescr" name="descr" class="glm-form-textarea"></textarea>
-                    </td>
-                </tr>
             </table>
             <p><span class="glm-required">*</span> Required</p>
             <a id="editCategoryCancel" class="button button-primary glm-right">Cancel</a>
 
     <h2>Categories</h2>
 
-    <table class="wp-list-table widefat fixed posts glm-admin-table"">
+    <table class="wp-list-table widefat fixed posts glm-admin-table">
         <thead>
             <tr>
                 <th>ID</th>
                 <th>Category</th>
-                <th>Description</th>
                 <th>&nbsp;</th>
             </tr>
         </thead>
         <tbody>
-{if $haveCategories}
-    {assign var="i" value="0"}
-    {foreach $categories as $t}
-        {if $i++ is odd by 1}
-            <tr>
-        {else}
-            <tr class="alternate">
-        {/if}
+        {if $haveCategories}
+            {assign var="i" value="0"}
+            {foreach $categories as $t}
+                {if $i++ is odd by 1}
+                    <tr>
+                {else}
+                    <tr class="alternate">
+                {/if}
                 <td>{$t.id}</td>
                 <td>
-                    <div{if $t.parent.value} class="glm-indent"{/if}>
-                        <a class="editCategory" data-categoryID="{$t.id}" data-categoryParent="{$t.parent.value}">{$t.name}</a>
+                    <div>
+                        <a class="editCategory" data-categoryID="{$t.id}">{$t.name}</a>
                     </div>
                 </td>
-                <td id="editCategoryDescr_{$t.id}">
-                    {$t.descr}
-                </td>
                 <td>
                     <div class="deleteCategoryButton button button-secondary glm-button-small glm-right" data-categoryID="{$t.id}">Delete</div>
                 </td>
             </tr>
-    {/foreach}
-{else}
+            {/foreach}
+        {else}
             <tr class="alternate"><td colspan="2">(no categories listed)</td></tr>
-{/if}
+        {/if}
         </tbody>
     </table>
 
             $('.editCategory').click( function() {
                 var catID = $(this).attr('data-categoryID');
                 var catName = $(this).text();
-                var catParent = $(this).attr('data-categoryParent');
-                var catDescr = $('#editCategoryDescr_' + catID).html();
                 $('#editCategoryID').val(catID);
                 $('#editCategoryName').val(catName.trim());
-                $('#editCategoryParent').val(catParent);
-                $('#editCategoryDescr').val(catDescr.trim());
                 $("#editCategoryDialog").dialog("open");
             });
             $('#editCategoryCancel').click( function() {