Can now List, Add, Edit, Delete payment types.
--- /dev/null
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Management
+ *
+ * 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: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $
+ */
+
+/**
+ * GlmDataBillingManagement 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 GlmDataPaymentTypes 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_BILLING_PLUGIN_DB_PREFIX . 'payment_types';
+
+ /*
+ * Table Data Fields
+ */
+
+ $this->fields = array (
+
+ 'id' => array (
+ 'field' => 'id',
+ 'type' => 'integer',
+ 'view_only' => true,
+ 'use' => 'a',
+ ),
+
+ // Default Billing Period
+ 'name' => array(
+ 'field' => 'name',
+ 'type' => 'text',
+ 'use' => 'a',
+ ),
+
+ // Default Invoice Date
+ 'qcode' => array(
+ 'field' => 'qcode',
+ 'type' => 'text',
+ 'use' => 'a',
+ ),
+
+ // Notification From Email
+ 'category' => array(
+ 'field' => 'category',
+ 'type' => 'text',
+ 'use' => 'a',
+ ),
+
+ // Notification Message
+ 'amount' => array(
+ 'field' => 'amount',
+ 'type' => 'text',
+ 'use' => 'a',
+ ),
+
+ // Logo for Invioce PDF
+ 'notes' => array(
+ 'field' => 'notes',
+ 'type' => 'text',
+ 'use' => 'a',
+ ),
+
+ // Name
+ 'dynamic_amount' => array(
+ 'field' => 'dynamic_amount',
+ '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)
+ {
+ return $r;
+ }
+
+}
+
+?>
+++ /dev/null
-The admin controller executes models under this directory.
-
-Typically you should add a directory here that matches the page where the action should take place.
-
-Under that directory place the model for the various actions.
\ No newline at end of file
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin PaymentTypes 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 Member Types data abstract
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataPaymentTypes.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_paymentTypes extends GlmDataPaymentTypes
+{
+
+ /**
+ * 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 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.
+ *
+ */
+ public function modelAction ($actionData = false)
+ {
+
+ $success = true;
+ $havePaymentTypes = false;
+ $paymentTypes = false;
+ $error = false;
+ $enable_members = $this->config['settings']['enable_members'];
+
+ // Check for region id
+ $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);
+ }
+ break;
+
+ }
+
+ }
+
+ // Get a current list of members
+ $paymentTypes = $this->getList('', 'name');
+
+ // echo '<pre>$paymentTypes: ' . print_r( $paymentTypes, true ) . '</pre>';
+
+ // If we have list entries - even if it's an empty list
+ $success = true;
+ $havePaymentTypes = false;
+ if ($paymentTypes !== false) {
+
+ $success = true;
+
+ // If we have any entries
+ if (count($paymentTypes) > 0) {
+ $havePaymentTypes = 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
+ );
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'enable_members' => $enable_members,
+ 'havePaymentTypes' => $havePaymentTypes,
+ 'paymentTypes' => $paymentTypes
+ );
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => $success,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/settings/paymentTypes.html',
+ 'data' => $templateData
+ );
+
+ }
+
+
+}
+
+?>
return $addOnTabs;
}
);
+ add_filter( 'glm-member-db-add-tab-for-settings',
+ function( $addOnTabs ) {
+ $newTabs = array(
+ array(
+ 'text' => 'Payment Types',
+ 'menu' => 'settings',
+ 'action' => 'paymentTypes',
+ )
+ );
+ $addOnTabs = array_merge( $addOnTabs, $newTabs );
+ return $addOnTabs;
+ }
+ );
}
$glmMembersBillingAddOnValidActions = array(
'adminActions' => array(
'settings' => array(
- 'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'paymentTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
),
),
'frontActions' => array(
+++ /dev/null
-The admin controller uses views (templates) under this directory to generate final output.
-
-Typically you should add a directory here that matches the page where the view is used.
-
-Under that directory place the view (template) for the various actions.
\ No newline at end of file
--- /dev/null
+{include file='admin/settings/header.html'}
+
+ <!-- Add PaymentTypes Button and Dialog Box -->
+ <div id="newPaymentTypeButton" class="button button-primary glm-right">Add a PaymentType</div>
+ <div id="newPaymentTypeDialog" class="glm-dialog-box" title="Enter a New PaymentType">
+ <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="glm_action" value="paymentTypes">
+ <input type="hidden" name="option" value="addNew">
+ <table class="glm-admin-table">
+ <tr>
+ <th class="glm-required">PaymentType Name:</th>
+ <td>
+ <input type="text" name="name" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Code:</th>
+ <td>
+ <input type="text" name="qcode" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Category:</th>
+ <td>
+ <input type="text" name="category" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Amount:</th>
+ <td>
+ <input type="text" name="amount" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th>Dynamic Amount:</th>
+ <td>
+ <input type="checkbox" name="dynamic_amount" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th>Notes:</th>
+ <td>
+ <textarea name="notes" class="glm-form-textarea"></textarea>
+ </td>
+ </tr>
+ </table>
+ <p><span class="glm-required">*</span> Required</p>
+ <a id="newPaymentTypeCancel" class="button button-primary glm-right">Cancel</a>
+ <input type="submit" value="Add new PaymentType" class="button button-primary">
+ </form>
+ </div>
+
+ <!-- Add PaymentTypes Button -->
+ <div id="deletePaymentTypeDialog" class="glm-dialog-box" title="Delete PaymentType">
+ <center>
+ <p>Are you sure you want to delete this paymentType?</p>
+ <p><div id="deletePaymentTypeConfirm" class="button button-primary">Yes, delete this paymentType</div></p>
+ <p><div id="deletePaymentTypeCancel" class="button button-primary">Cancel</div></p>
+ </center>
+ </div>
+
+ <!-- Edit PaymentTypes Dialog Box -->
+ <div id="editPaymentTypeDialog" class="glm-dialog-box" title="Edit this PaymentType">
+ <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="glm_action" value="paymentTypes">
+ <input type="hidden" name="option" value="update">
+ <input id="editPaymentTypeID" type="hidden" name="id" value="">
+ <table class="glm-admin-table">
+ <tr>
+ <th class="glm-required">PaymentType Name:</th>
+ <td>
+ <input id="editPaymentTypeName" type="text" name="name" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Code:</th>
+ <td>
+ <input id="editPaymentTypeQCode" type="text" name="qcode" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Category:</th>
+ <td>
+ <input id="editPaymentTypeCategory" type="text" name="category" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Amount:</th>
+ <td>
+ <input id="editPaymentTypeAmount" type="text" name="amount" class="glm-form-text-input" required>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Dynamic Amount:</th>
+ <td>
+ <input id="editPaymentTypeDynamicAmount" type="checkbox" name="dynamic_amount" class="glm-form-text-input">
+ </td>
+ </tr>
+ <tr>
+ <th>Notes:</th>
+ <td>
+ <textarea id="editPaymentTypeNotes" name="notes" class="glm-form-textarea"></textarea>
+ </td>
+ </tr>
+ </table>
+ <p><span class="glm-required">*</span> Required</p>
+ <a id="editPaymentTypeCancel" class="button button-primary glm-right">Cancel</a>
+ <input type="submit" value="Update this PaymentType">
+ </form>
+ </div>
+
+ <h2>PaymentTypes</h2>
+
+ <table class="wp-list-table widefat fixed posts glm-admin-table">
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>PaymentType</th>
+ <th>Amount</th>
+ <th> </th>
+ </tr>
+ </thead>
+ <tbody>
+ {if $havePaymentTypes}
+ {assign var="i" value="0"}
+ {foreach $paymentTypes as $t}
+ {if $i++ is odd by 1}
+ <tr>
+ {else}
+ <tr class="alternate">
+ {/if}
+ <td>{$t.id}</td>
+ <td>
+ <a class="editPaymentType"
+ data-paymentTypeID="{$t.id}"
+ data-paymentTypeName="{$t.name}"
+ data-paymentTypeQCode="{$t.qcode}"
+ data-paymentTypeCategory="{$t.category}"
+ data-paymentTypeAmount="{$t.amount}"
+ data-paymentTypeDynamicAmount="{$t.dynamic_amount}"
+ data-paymentTypeNotes="{$t.notes}">{$t.name}</a>
+ </td>
+ <td>
+ {$t.amount}
+ </td>
+ <td>
+ <div class="deletePaymentTypeButton button button-secondary glm-button-small glm-right" data-paymentTypeID="{$t.id}">Delete</div>
+ </td>
+ </tr>
+ {/foreach}
+ {else}
+ <tr class="alternate"><td colspan="2">(no paymentTypes listed)</td></tr>
+ {/if}
+ </tbody>
+ </table>
+
+ <script type="text/javascript">
+ jQuery(document).ready(function($) {
+
+ $("#newPaymentTypeDialog").dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: "glm-dialog-no-close"
+ });
+ $("#editPaymentTypeDialog").dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: "glm-dialog-no-close"
+ });
+ $("#deletePaymentTypeDialog").dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: "glm-dialog-no-close"
+ });
+
+ $('#newPaymentTypeButton').click( function() {
+ $("#newPaymentTypeDialog").dialog("open");
+ });
+ $('.editPaymentType').click( function() {
+
+ var paymentTypeID = $(this).data('paymenttypeid');
+ var paymentTypeName = $(this).data('paymenttypename');
+ var paymentTypeQCode = $(this).data('paymenttypeqcode');
+ var paymentTypeCategory = $(this).data('paymenttypecategory');
+ var paymentTypeAmount = $(this).data('paymenttypeamount');
+ var paymentTypeDynamicAmount = $(this).data('paymenttypedynamicamount');
+ var paymentTypeNotes = $(this).data('paymenttypenotes');
+
+ // Set the values of the edit form for the selected paymentType
+ $('#editPaymentTypeID').val( paymentTypeID );
+ $('#editPaymentTypeName').val( paymentTypeName );
+ $('#editPaymentTypeQCode').val( paymentTypeQCode );
+ $('#editPaymentTypeCategory').val( paymentTypeCategory );
+ $('#editPaymentTypeAmount').val( paymentTypeAmount );
+ $('#editPaymentTypeDynamicAmount').val( paymentTypeDynamicAmount );
+ $('#editPaymentTypeNotes').val( paymentTypeNotes );
+
+ $("#editPaymentTypeDialog").dialog("open");
+ });
+ $('#editPaymentTypeCancel').click( function() {
+ $("#editPaymentTypeDialog").dialog("close");
+ });
+ $('#newPaymentTypeCancel').click( function() {
+ $("#newPaymentTypeDialog").dialog("close");
+ });
+
+ var id = false;
+ $('.deletePaymentTypeButton').click( function() {
+ id = $(this).attr('data-paymentTypeID');
+ $("#deletePaymentTypeDialog").dialog("open");
+ });
+ $('#deletePaymentTypeConfirm').click( function() {
+ $("#deletePaymentTypeDialog").dialog("close");
+ window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=paymentTypes&option=delete&id=" + id;
+ });
+ $('#deletePaymentTypeCancel').click( function() {
+ $("#deletePaymentTypeDialog").dialog("close");
+ });
+
+ });
+ </script>
+
+{include file='admin/footer.html'}