Adding models views and data classes.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Nov 2016 15:05:15 +0000 (10:05 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Nov 2016 15:05:15 +0000 (10:05 -0500)
Adding the data class for CouponCategories and dataCoupons.
Adding view files for Category settings.
Adding models for Setting Categories.

classes/data/dataCouponCategories.php [new file with mode: 0644]
classes/data/dataCoupons.php [new file with mode: 0644]
models/admin/coupons/index.php
models/admin/settings/couponCategories.php [new file with mode: 0644]
setup/adminMenus.php
setup/validActions.php
views/admin/coupons/header.html [new file with mode: 0644]
views/admin/coupons/index.html
views/admin/settings/couponCategories.html [new file with mode: 0644]

diff --git a/classes/data/dataCouponCategories.php b/classes/data/dataCouponCategories.php
new file mode 100644 (file)
index 0000000..d34b74a
--- /dev/null
@@ -0,0 +1,156 @@
+<?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 $
+ */
+
+/**
+ * GlmDataCouponsAmenities 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 GlmDataCouponCategories 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 . 'categories';
+
+        /*
+         * Table Data Fields
+         */
+        $this->fields = array(
+
+            'id' => array(
+                'field'     => 'id',
+                'type'      => 'integer',
+                'view_only' => true,
+                'use'       => 'a',
+            ),
+
+            // Name
+            'name' => array(
+                'field'    => 'name',
+                'type'     => 'text',
+                'required' => true,
+                'unique'   => true,
+                'use'      => 'a',
+            ),
+
+        );
+
+    }
+
+    /**
+     * 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 amenity
+     * 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;
+    }
+
+}
diff --git a/classes/data/dataCoupons.php b/classes/data/dataCoupons.php
new file mode 100644 (file)
index 0000000..2cf4d77
--- /dev/null
@@ -0,0 +1,464 @@
+<?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 $
+ */
+
+/**
+ * GlmDataCoupons 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 GlmDataCoupons 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;
+    /**
+     * postAddTimes
+     *
+     * @var bool
+     * @access public
+     */
+    public $postCategories = true;
+
+    /**
+     * 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 . 'coupons';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array (
+
+            'id'            => array (
+                'field'     => 'id',
+                'type'      => 'integer',
+                'view_only' => true,
+                'use'       => 'a'
+            ),
+
+            // Status
+            'status'       => array (
+                'field'    => 'status',
+                'type'     => 'list',
+                'list'     => $this->config['status'],
+                'required' => true,
+                'default'  => $this->config['status_numb']['Pending'],
+                'use'      => 'a'
+            ),
+
+            // Date/Time Created
+            'created'   => array (
+                'field' => 'created',
+                'type'  => 'datetime',
+                'use'   => 'lgieu'
+            ),
+
+            // Date/Time Updated
+            'updated'   => array (
+                'field' => 'updated',
+                'type'  => 'datetime',
+                'use'   => 'a'
+            ),
+
+            // Date/Time Approved
+            'approved'  => array (
+                'field' => 'approved',
+                'type'  => 'datetime',
+                'use'   => 'lge'
+            ),
+
+            // Date Start Date
+            'start_date' => array(
+                'field' => 'start_date',
+                'type'  => 'date',
+                'use'   => 'a'
+            ),
+
+            // Date End Date
+            'end_date' => array(
+                'field' => 'end_date',
+                'type'  => 'date',
+                'use'   => 'a'
+            ),
+
+            // Date Expire Date
+            'expire' => array(
+                'field' => 'expire',
+                'type'  => 'date',
+                'use'   => 'a'
+            ),
+
+            // Reference Type - Insert new record
+            'ref_type_insert' => array (
+                'field'       => 'ref_type',
+                'type'        => 'integer',
+                'use'         => 'i'
+            ),
+
+            // Reference Type - Output only
+            'ref_type'     => array (
+                'field'    => 'ref_type',
+                'type'     => 'list',
+                    'list' => $this->config['ref_type'],
+                'use'      => 'a'
+            ),
+
+            // Ref_name (member name - need to update this to be Reference Type aware)
+            'ref_dest'          => array (
+                'field'         => 'ref_dest',
+                'type'          => 'pointer',
+                    'p_table'   => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
+                    'p_field'   => 'name',
+                    'p_orderby' => 'name',
+                    'p_blank'   => true,
+                'use'           => 'a'
+            ),
+
+            // Reference Target ID
+            'ref_dest_id' => array (
+                'field'   => 'ref_dest',
+                'as'      => 'ref_dest_id',
+                'type'    => 'integer',
+                'use'     => 'lged'
+            ),
+
+            // Coupon Name
+            'name'         => array (
+                'field'    => 'name',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+
+            // Name Slug for URLs
+            'name_slug'    => array (
+                'field'    => 'name_slug',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'lge'
+            ),
+
+            // Description
+            'descr'        => array (
+                'field'    => 'descr',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+
+            // Coupon Image
+            'image'     => array(
+                'field' => 'image',
+                'type'  => 'image',
+                'use'   => 'a'
+            ),
+
+            // Coupon URL
+            'url'       => array (
+                'field' => 'url',
+                'type'  => 'text',
+                'use'   => 'a'
+            ),
+
+         );
+
+    }
+
+    /**
+     * 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)
+    {
+
+        // 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;
+    }
+
+    /**
+     * Update coupon slug - should be called after an coupon record is added or updated.
+     *
+     * Since slugs must be unique, if there's already a slug matching the slug directly
+     * derived from the coupon name, then append "-n" where n is a sequential number
+     * that makes the slug unique.
+     *
+     * This function will try numbers from 1 to $maxTries to get a unique slug.
+     *
+     * @param integer id ID of coupon that needs the slug updated
+     * @param integer maxTries Maximum number of tries to create a unique slug
+     *      default 100
+     *
+     * @return string Slug stored in this coupon record
+     *      If this function fails, it will return false.
+     * @access public
+     */
+    public function updateSlug($id = false, $maxTries = 100)
+    {
+
+        if ($id == false) {
+            return false;
+        }
+
+        // Get the coupon entry
+        $e = $this->getEntry($id);
+        if (!$e) {
+            return false;
+        }
+
+        // Make a slug out of the coupon name
+        $slug = sanitize_title($e['name']);
+
+        // If slug is the same as it was then do nothing
+        if ($e['name_slug'] == $slug) {
+            return $slug;
+        }
+
+        // Loop until we have a unique slug - limit loops to 50 just in case
+        $saveSlug = $slug;
+        for ($loop = 1 ; $loop <= $maxTries ; $loop++) {
+
+            // New Slug - Check if the new slug is unique
+            $matchingSlugs = $this->wpdb->get_results(
+                "
+                SELECT id, name_slug
+                  FROM ".$this->table."
+                 WHERE name_slug = '$slug'
+                   AND id != $id
+                ",
+                ARRAY_A
+            );
+
+            // If there's no matching results then we're good to use this one
+            if (!is_array($matchingSlugs) || count($matchingSlugs) == 0) {
+
+                // Write new slug and return
+                $sql = "
+                    UPDATE ".$this->table."
+                       SET name_slug = '$slug'
+                     WHERE id = $id
+                ;";
+                $this->wpdb->query($sql);
+
+                return $slug;
+
+            }
+
+            $slug = $saveSlug."-$loop";
+
+        } // for
+
+        // Unable to create unique slug
+        $sql = "
+            UPDATE ".$this->table."
+               SET name_slug = ''
+             WHERE id = $id
+        ;";
+        $this->wpdb->query($sql);
+
+        return false;
+    }
+
+    /**
+     * Update timestamps for created, updated, approved
+     *
+     * @param string $field Field to update
+     * @param integer $id ID of coupon
+     *
+     * @return void
+     */
+    public function updateTimestamp($field = false, $id = false)
+    {
+
+        if (!in_array($field, array('created', 'updated', 'approved')) || !$id) {
+            return false;
+        }
+
+        $sql = "
+            UPDATE ".$this->table."
+               SET $field = now()
+             WHERE id = $id
+        ;";
+        $this->wpdb->query($sql);
+
+
+    }
+
+    /**
+     * Delete an coupon and all data associated with it.
+     *
+     * @param integer $id ID of coupon
+     *
+     * @return void
+     */
+    public function deleteCoupon($id = false)
+    {
+
+        // Check ID
+        $id = ($id - 0);
+        if ($id <= 0) {
+            return false;
+        }
+
+        // Try to get the coupon data
+        $coupon = $this->getEntry($id);
+        if (!$coupon) {
+            return false;
+        }
+
+        // Delete the coupon
+        $coupon = $this->deleteEntry($id, true);
+
+        return $coupon;
+
+    }
+
+    /**
+     * Get ID/Name list
+     *
+     * @param string $where
+     *
+     * @return array ID/Name pairs
+     */
+    public function getIdName($where = 'true')
+    {
+        $savedFields = $this->fields;
+        $savedCategories = $this->postCategories;
+
+        $this->postCategories = false;
+
+        $this->fields = array(
+            'id' => $savedFields['id'],
+            'name' => $savedFields['name']
+        );
+
+        $r = $this->getList($where);
+
+        $this->fields = $savedFields;
+        $this->postCategories = $savedCategories;
+
+        return $r;
+
+    }
+
+}
index ab6c37d..6205278 100644 (file)
  */
 
 // Load Coupons data abstract
-//require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php';
+require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php';
 
-class GlmMembersAdmin_coupons_index
-    // extends GlmDataCoupons
+class GlmMembersAdmin_coupons_index extends GlmDataCoupons
 {
 
     /**
@@ -96,6 +95,7 @@ class GlmMembersAdmin_coupons_index
         $numbCoupons     = 0;
         $numbPending    = 0;
         $namesList      = false;
+        $pending        = false;
         $haveCategories = false;
 
         // Check if there's a logged in user who is locked to their own entity
@@ -107,6 +107,7 @@ class GlmMembersAdmin_coupons_index
             $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);
@@ -114,6 +115,7 @@ class GlmMembersAdmin_coupons_index
         if ($couponCategoriesStats && $couponCategoriesStats > 0) {
             $haveCategories = true;
         }
+         */
 
         // Get full list of names matching this where clause for search box
         $namesList = $this->getIdName($lockedWhereT);
@@ -135,7 +137,6 @@ class GlmMembersAdmin_coupons_index
         // Get list of Pending Coupons
         $pending = $this->getIdName($lockedWhereT.' T.status = '.$this->config['status_numb']['Pending']);
 
-
         // Compile template data
         $templateData = array(
             'lockedToMember' => $lockedToMember,
diff --git a/models/admin/settings/couponCategories.php b/models/admin/settings/couponCategories.php
new file mode 100644 (file)
index 0000000..45e80be
--- /dev/null
@@ -0,0 +1,200 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Coupon Categories List
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Coupon Categories data abstract
+require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCouponCategories.php';
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_settings_couponCategories extends GlmDataCouponCategories
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller 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.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $success        = true;
+        $haveCategories = false;
+        $categories     = false;
+        $error          = false;
+        $enable_members = $this->config['settings']['enable_members'];
+
+        // Check if a category ID is supplied
+        $id = 0;
+        if (isset($_REQUEST['id'])) {
+            $id = $_REQUEST['id']-0;
+        }
+
+        // If there's an action option
+        if (isset($_REQUEST['option'])) {
+
+            switch($_REQUEST['option']) {
+
+                case 'addNew':
+                    $this->insertEntry();
+                    break;
+
+                case 'update':
+                    if ($id > 0) {
+                        $this->updateEntry($id);
+                    }
+                    break;
+
+                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;
+
+            }
+
+        }
+
+        // Get a current list of categories
+        $categories = $this->getList();
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+            glmMembersAdmin::addNotice($categories, 'DataBlock', 'Category Data');
+        }
+
+        // If we have list entries - even if it's an empty list
+        $success = true;
+        $haveCategories = false;
+        if ($categories !== false) {
+
+            $success = true;
+
+            // If we have any entries
+            if (count($categories) > 0) {
+                $haveCategories = true;
+            }
+        }
+
+        // If we had a fatal error, redirect to the error page
+        if ($error) {
+            return array(
+                'status' => $success,
+                'menuItemRedirect' => 'error',
+                'modelRedirect'    => 'index',
+                'view'             => 'admin/error/index.html',
+                'data'             => false
+            );
+        }
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+            glmMembersAdmin::addNotice($categories, 'DataBlock', 'Categories Data');
+        }
+
+        // Compile template data
+        $templateData = array(
+            'enable_members' => $enable_members,
+            'haveCategories' => $haveCategories,
+            'categories'     => $categories
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/settings/couponCategories.html',
+            'data'             => $templateData
+        );
+
+    }
+
+
+}
index a2a1604..72584ce 100644 (file)
@@ -54,6 +54,6 @@ add_submenu_page(
     'Coupons',
     'Coupons',
     'glm_members_members',
-    'glm-members-admin-menu-coupons',
+    'glm-members-admin-menu-coupons-index',
     function(){$this->controller('coupons');}
 );
index 396bd6c..3e1a9b5 100644 (file)
  *
  * This array is integrated into the valid actions array in the main GLM Member
  * DB plugin when this plugin registers itself.
- *
- * EXAMPLE
- *
- * $glmMembersCouponsAddOnValidActions = array(
- *     'adminActions' => array(
- *         'members' => array(
- *             'sample' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
- *         ),
- *         'sample' => array(
- *             'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
- *             'more' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
- *         ),
- *         'info' => array(
- *             'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG
- *         )
- *     ),
- *     'frontActions' => array(
- *         'sample' => array(
- *             'list' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
- *             'detail' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG
- *         )
- *     )
- * );
- *
- *
- *
- *
  */
 
 $glmMembersCouponsAddOnValidActions = array(
     'adminActions' => array(
         'coupons' => array(
-            'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG
-        )
+            'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG
+        ),
+        'dashboard' => array(
+            'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
+        ),
+        'member' => array(
+            'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
+        ),
+        'settings' => array(
+            'couponCategories' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
+        ),
     ),
     'frontActions' => array(
+        'coupons' => array(
+            'list' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
+        ),
     )
 );
 
diff --git a/views/admin/coupons/header.html b/views/admin/coupons/header.html
new file mode 100644 (file)
index 0000000..3e46df2
--- /dev/null
@@ -0,0 +1,9 @@
+<div class="wrap">
+    <h2>All Coupons</h2>
+    <h2 class="nav-tab-wrapper">
+        <a href="{$thisUrl}?page={$thisPage}&glm_action=index" class="nav-tab{if $thisAction==index} nav-tab-active{/if}">Dashboard</a>
+        <a href="{$thisUrl}?page={$thisPage}&glm_action=list" class="nav-tab{if $thisAction==list} nav-tab-active{/if}">Coupon List</a>
+    </h2>
+    <div id="glm-admin-content-container">
+
+
index eb39bf6..f681229 100644 (file)
@@ -1,27 +1,27 @@
 {include file='admin/coupons/header.html'}
 
 {if apply_filters('glm_members_permit_admin_coupons_index_add_coupon', true)}
-    <a href="{$thisUrl}?page={$thisPage}&glm_action=list&option=add" class="button button-primary glm-button glm-right">Add A New Event</a>
+    <a href="{$thisUrl}?page={$thisPage}&glm_action=list&option=add" class="button button-primary glm-button glm-right">Add A New Coupon</a>
 {/if}
 
 <table class="glm-admin-table">
     <tr>
         <td colspan="2" align="">
-            <input  id="glmEventsList" type="text" id="autoTest" style="margin-left: 2em;">
-            <span class="glm-left">Events Search:</span>
+            <input  id="glmCouponsList" type="text" id="autoTest" style="margin-left: 2em;">
+            <span class="glm-left">Coupons Search:</span>
         </td>
     </tr>
 
     {if apply_filters('glm_members_permit_admin_coupons_index_coupon_config_warning', true)}
       {if !$haveCategories}
         <tr>
-            <th><span class="glm-error">You do not have any Events Categories setup.</span></th>
-            <td><a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=couponCategories">Click here to add Event Categories.</a></td>
+            <th><span class="glm-error">You do not have any Coupons Categories setup.</span></th>
+            <td><a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=couponCategories">Click here to add Coupon Categories.</a></td>
         </tr>
       {/if}
     {/if}
 
-{if $numbEvents == 0}
+{if $numbCoupons == 0}
     <tr><td colspan="2">&nbsp;</td></tr>
     <tr>
        <th> <span class="glm-error">You do not have any coupons listed.</span></th>
 </table>
 
 <table class="glm-admin-table">
-    <tr><th>Number of Events Listed: </th><td>{$numbEvents}</td></tr>
+    <tr><th>Number of Coupons Listed: </th><td>{$numbCoupons}</td></tr>
     <tr><th>Number Pending: </th><td>{$numbPending}</td></tr>
 </table>
 
 {if $pending}
-    <h3 class="glm-error">&nbsp;<br>Events Pending Review</h3>
+    <h3 class="glm-error">&nbsp;<br>Coupons Pending Review</h3>
 
     <table class="wp-list-table widefat fixed posts glm-admin-table"">
         <thead>
             <tr>
-                <th>Event Name</th>
+                <th>Coupon Name</th>
             </tr>
         </thead>
         <tbody>
@@ -79,7 +79,7 @@
         {/foreach}
         ];
 
-        $( "#glmEventsList" ).autocomplete({
+        $( "#glmCouponsList" ).autocomplete({
              source: availableTags,
              html: true,
              select: function( coupon, ui ) {
diff --git a/views/admin/settings/couponCategories.html b/views/admin/settings/couponCategories.html
new file mode 100644 (file)
index 0000000..7f4be05
--- /dev/null
@@ -0,0 +1,191 @@
+{include file='admin/settings/header.html'}
+
+    <!-- Add Categories Button and Dialog Box -->
+    <div id="newCategoryButton" class="button button-primary glm-right">Add a Category</div>
+    <div id="newCategoryDialog" class="glm-dialog-box" title="Enter a New Category">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="couponCategories">
+            <input type="hidden" name="option" value="addNew">
+
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">Category Name:</th>
+                    <td>
+                        <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 type="submit" value="Add new Category" class="button button-primary">
+        </form>
+    </div>
+
+    <!-- Delete Category Button and Dialog Box -->
+    <div id="deleteCategoryDialog" class="glm-dialog-box" title="Delete Category">
+        <center>
+            <p>Are you sure you want to delete this category?</p>
+            <p><div id="deleteCategoryConfirm" class="button button-primary">Yes, delete this category</div></p>
+            <p><div id="deleteCategoryCancel" class="button button-primary">Cancel</div></p>
+        </center>
+    </div>
+
+    <!-- Edit Category Dialog Box -->
+    <div id="editCategoryDialog" class="glm-dialog-box" title="Edit this Category">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="couponCategories">
+            <input type="hidden" name="option" value="update">
+            <input id="editCategoryID" type="hidden" name="id" value="">
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">Category Name:</th>
+                    <td>
+                        <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>
+            <input type="submit" value="Update this Category">
+        </form>
+    </div>
+
+    <h2>Categories</h2>
+
+    <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}
+                <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>
+                </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}
+            <tr class="alternate"><td colspan="2">(no categories listed)</td></tr>
+{/if}
+        </tbody>
+    </table>
+
+    <script type="text/javascript">
+        jQuery(document).ready(function($) {
+
+            $("#newCategoryDialog").dialog({
+               autoOpen: false,
+               minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+            $("#editCategoryDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+            $("#deleteCategoryDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+
+            $('#newCategoryButton').click( function() {
+                $("#newCategoryDialog").dialog("open");
+            });
+            $('.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() {
+                $("#editCategoryDialog").dialog("close");
+            });
+            $('#newCategoryCancel').click( function() {
+                $("#newCategoryDialog").dialog("close");
+            });
+
+            var id = false;
+            $('.deleteCategoryButton').click( function() {
+                id = $(this).attr('data-categoryID');
+                $("#deleteCategoryDialog").dialog("open");
+            });
+            $('#deleteCategoryConfirm').click( function() {
+                $("#deleteCategoryDialog").dialog("close");
+                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=couponCategories&option=delete&id=" + id;
+            });
+            $('#deleteCategoryCancel').click( function() {
+                $("#deleteCategoryDialog").dialog("close");
+            });
+
+        });
+    </script>
+
+{include file='admin/footer.html'}