--- /dev/null
+<?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> /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
+ );
+
+
+ }
+
+}
+
+?>
--- /dev/null
+{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>