Adding the management setting models and views.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 18 Nov 2016 13:55:42 +0000 (08:55 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 18 Nov 2016 13:55:42 +0000 (08:55 -0500)
Update the table name from settings to management.
Update my table names and the create scripts for the names.
Adding the default_date_range field.
Setting up the management model and view.
Setting up the data abstract class for management.

classes/data/dataManagement.php
models/admin/management/coupons.php [new file with mode: 0644]
setup/adminTabs.php
setup/databaseScripts/create_database_V0.0.2.sql
setup/validActions.php
views/admin/management/coupons.html [new file with mode: 0644]

index f23de95..bec335b 100644 (file)
@@ -107,7 +107,7 @@ class GlmDataCouponsManagement extends GlmDataAbstract
         /*
          * Table Name
          */
-        $this->table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'settings';
+        $this->table = GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . 'management';
 
         /*
          * Table Data Fields
@@ -143,6 +143,13 @@ class GlmDataCouponsManagement extends GlmDataAbstract
                 'required' => false,
                 'use'      => 'a'
             ),
+            // Default Date Range
+            'default_date_rang' => array(
+                'field'    => 'default_date_range',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
 
          );
 
diff --git a/models/admin/management/coupons.php b/models/admin/management/coupons.php
new file mode 100644 (file)
index 0000000..4b1d469
--- /dev/null
@@ -0,0 +1,215 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Coupons Add-on - Management Coupons Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author     Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  coupons.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Management Coupons data abstract
+require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataManagement.php';
+require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php';
+
+/**
+ * GlmMembersAdmin_management_coupons
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author    Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *            @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ *            Exp $
+ */
+class GlmMembersAdmin_management_coupons extends GlmDataCouponsManagement
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * dbh Postgres database connection
+     *
+     * @var mixed
+     * @access public
+     */
+    public $dbh;
+    /**
+     * settings used for the schema and tablenames
+     *
+     * @var mixed
+     * @access public
+     */
+    public $settings = array();
+
+    /**
+     * 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 members data class
+        parent::__construct(false, false);
+
+    }
+
+    /**
+     * modelAction
+     *
+     * @param bool $actionData
+     * @access public
+     * @return void
+     */
+    public function modelAction($actionData = false)
+    {
+
+        $option                = false;
+        $test_result           = false;
+        $import_result         = false;
+        $settings_updated      = false;
+        $settings_update_error = false;
+        $coupon_settings        = false;
+        $icalFeedResult        = false;
+        $import_feeds          = false;
+        $option2               = false;
+
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        switch ($option) {
+
+            case 'settings':
+
+            default:
+
+                // Make sure option is set if default
+                $option = 'settings';
+
+                // Determine if current user can edit configurations
+                if (!current_user_can('glm_members_management')) {
+                    return array(
+                        'status'           => false,
+                        'menuItemRedirect' => 'error',
+                        'modelRedirect'    => 'index',
+                        'view'             => 'admin/error/index.html',
+                        'data'             => array(
+                            'reason' => 'User does not have rights to make configuration changes.'
+                        )
+                    );
+                }
+
+                // Check for submission option
+                $option2 = '';
+                if (isset($_REQUEST['option2'])) {
+                    $option2 = $_REQUEST['option2'];
+                }
+
+                switch($option2) {
+
+                    // Update the settings and redisplay the form
+                    case 'submit':
+
+                        // Update the coupon management settings
+                        $coupon_settings = $this->updateEntry(1);
+                        if ($coupon_settings['status']) {
+                            $settings_updated = true;
+                        } else {
+                            $settings_update_error = true;
+                        }
+
+                        break;
+
+                    // Default is to get the current settings and display the form
+                    default:
+
+                        // Try to get the first (should be only) entry for general settings.
+                        $coupon_settings = $this->editEntry(1);
+                        //echo '<pre>$coupon_settings: ' . print_r( $coupon_settings, true ) . '</pre>';
+
+                        if ($coupon_settings === false) {
+
+                            if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+                                glmMembersAdmin::addNotice("<b>&nbsp;&nbsp;/models/admin/management/coupons.php: Unable to load coupons management settings.", 'Alert');
+                            }
+
+                        }
+
+                        break;
+
+                }
+
+                break;
+
+        }
+
+        // Populate the state list for coupon default state selection
+        $coupon_settings['coupon_default_state'] = $this->config['states'];
+
+        // Compile template data
+        $template_data = array(
+            'import_feeds'        => $import_feeds,
+            'option'              => $option,
+            'testResult'          => $test_result,
+            'importResult'        => $import_result,
+            'settingsUpdated'     => $settings_updated,
+            'settingsUpdateError' => $settings_update_error,
+            'couponsSettings'      => $coupon_settings,
+            'icalFeedResult'      => $icalFeedResult,
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => true,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/management/coupons.html',
+            'data'             => $template_data
+        );
+
+
+    }
+
+}
+
+?>
index 3a0799a..c0efef6 100644 (file)
@@ -48,4 +48,19 @@ if (current_user_can('glm_members_members')) {
             return $addOnTabs;
         }
     );
+    if (apply_filters('glm_members_permit_admin_members_coupons_tab', true)) {
+        add_filter('glm-member-db-add-tab-for-management',
+            function($addOnTabs) {
+                $newTabs = array(
+                    array(
+                        'text' => 'Coupons',
+                        'menu' => 'management',
+                        'action' => 'coupons'
+                    )
+                );
+                $addOnTabs = array_merge($addOnTabs, $newTabs);
+                return $addOnTabs;
+            }
+        );
+    }
 }
index d309c90..0c36e32 100644 (file)
@@ -61,18 +61,19 @@ CREATE TABLE {prefix}coupon_categories (
 ----
 
 -- Settings
-CREATE TABLE {prefix}settings (
+CREATE TABLE {prefix}management (
     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
+    default_date_range TINYTEXT NULL, -- Default span for start and end dates
     PRIMARY KEY (id)
 );
 
 ----
 
 -- Data for Settings
-INSERT INTO {prefix}settings
-(id,notify_to,notify_from,notify_message)
+INSERT INTO {prefix}management
+(id,notify_to,notify_from,notify_message,default_date_range)
 VALUES
-(1, '', '', '');
+(1, '', '', '','6 months');
index 0129c0e..1716329 100644 (file)
@@ -45,6 +45,9 @@ $glmMembersCouponsAddOnValidActions = array(
         'settings' => array(
             'couponCategories' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG,
         ),
+        'management' => array(
+            'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG
+        ),
     ),
     'frontActions' => array(
         'coupons' => array(
diff --git a/views/admin/management/coupons.html b/views/admin/management/coupons.html
new file mode 100644 (file)
index 0000000..153d3ba
--- /dev/null
@@ -0,0 +1,91 @@
+{include file='admin/management/header.html'}
+
+    <h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+        <a id="glm-settings" data-show-table="glm-table-settings" class="glm-settings-tab nav-tab{if $option=='settings'} nav-tab-active{/if}">Settings</a>
+    </h2>
+
+    <!-- Management Settings -->
+
+    <table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
+        <tr>
+            <td colspan="2">
+                {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
+                {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
+                <h2>Management Settings</h2>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                    <input type="hidden" name="glm_action" value="coupons">
+                    <input type="hidden" name="option" value="settings">
+                    <input type="hidden" name="option2" value="submit">
+                    <table class="glm-admin-table">
+                        <tr>
+                            <th {if $couponsSettings.fieldRequired.default_date_range}class="glm-required"{/if}>Default date range for start and end dates:</th>
+                            <td {if $couponsSettings.fieldFail.default_date_range}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+                                <input type="text" name="default_date_range" value="{$couponsSettings.fieldData.default_date_range}" class="glm-form-text-input-medium">
+                                {if $couponsSettings.fieldFail.default_date_range}<p>{$couponsSettings.fieldFail.default_date_range}</p>{/if}
+                            </td>
+                        </tr>
+                        <tr>
+                            <td>
+                                <h1> E-Mail Notification Settings </h1>
+                            </td>
+                        </tr>
+                        <tr>
+                        </tr>
+                        <tr>
+                            <th class="emailLabel"> Recipient Email Address (comma separated) </th>
+                            <td><input class="glm-form-text-input-medium" name="notify_to" id="toEmailAddress" type="text" value="{$couponsSettings.fieldData.notify_to}"></td>
+                        </tr>
+                        <tr>
+                            <th class="emailLabel"> Sender Email Address </th>
+                            <td><input class="glm-form-text-input-medium" name="notify_from" id="fromEmailAddress" type="text" value="{$couponsSettings.fieldData.notify_from}"></td>
+                        </tr>
+                        <tr>
+                            <th>Email Notification</th>
+                            <td>
+                                <textarea rows="3" cols="90" name="notify_message" id="emailNotification">{$couponsSettings.fieldData.notify_message} </textarea>
+                            </td>
+                        </tr>
+                        <tr>
+                    </table>
+                    <input type="submit" value="Update Settings" class="button-primary">
+                </form>
+            </td>
+        </tr>
+    </table>
+
+    <script type="text/javascript">
+
+        jQuery(document).ready(function($) {
+
+            /*
+             * Edit area tabs
+             */
+            $('.glm-settings-tab').click( function() {
+
+                // Clear tabl highlights and hide all tables
+                $('.glm-settings-tab').removeClass('nav-tab-active');
+                $('.glm-settings-table').addClass('glm-hidden');
+
+                // Highlight selected tab
+                $(this).addClass('nav-tab-active');
+
+                // Show selected table
+                var table = $(this).attr('data-show-table');
+                $('#' + table).removeClass('glm-hidden');
+
+            });
+
+            // 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).fadeIn(500).fadeOut(500);
+
+                if('{$couponsSettings.fieldData.calendar_view}'){
+                    $("#calendar-view").val('{$couponsSettings.fieldData.calendar_view}');
+                } else {
+                    $("#calendar-view").val("agenda");
+                }
+        });
+    </script>